Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
Pavel Kotucek | 9876520 | 2016-10-07 08:37:28 +0200 | [diff] [blame] | 15 | #define _GNU_SOURCE |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 16 | |
| 17 | #include <vppinfra/format.h> |
| 18 | #include <vlib/vlib.h> |
| 19 | |
| 20 | #include <vlib/threads.h> |
Pavel Kotucek | 9876520 | 2016-10-07 08:37:28 +0200 | [diff] [blame] | 21 | #include <vlib/unix/unix.h> |
Pavel Kotucek | 1e76583 | 2016-09-23 08:54:14 +0200 | [diff] [blame] | 22 | |
Pavel Kotucek | c08a1ed | 2016-09-23 08:54:14 +0200 | [diff] [blame] | 23 | static u8 * |
| 24 | format_sched_policy_and_priority (u8 * s, va_list * args) |
Pavel Kotucek | 1e76583 | 2016-09-23 08:54:14 +0200 | [diff] [blame] | 25 | { |
Pavel Kotucek | c08a1ed | 2016-09-23 08:54:14 +0200 | [diff] [blame] | 26 | long i = va_arg (*args, long); |
| 27 | struct sched_param sched_param; |
Pavel Kotucek | 1e76583 | 2016-09-23 08:54:14 +0200 | [diff] [blame] | 28 | u8 *t = 0; |
| 29 | |
Pavel Kotucek | c08a1ed | 2016-09-23 08:54:14 +0200 | [diff] [blame] | 30 | switch (sched_getscheduler (i)) |
Pavel Kotucek | 1e76583 | 2016-09-23 08:54:14 +0200 | [diff] [blame] | 31 | { |
| 32 | #define _(v,f,str) case SCHED_POLICY_##f: t = (u8 *) str; break; |
| 33 | foreach_sched_policy |
| 34 | #undef _ |
| 35 | } |
Pavel Kotucek | c08a1ed | 2016-09-23 08:54:14 +0200 | [diff] [blame] | 36 | if (sched_getparam (i, &sched_param) == 0) |
| 37 | return format (s, "%s (%d)", t, sched_param.sched_priority); |
| 38 | else |
| 39 | return format (s, "%s (n/a)", t); |
Pavel Kotucek | 1e76583 | 2016-09-23 08:54:14 +0200 | [diff] [blame] | 40 | } |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 41 | |
| 42 | static clib_error_t * |
| 43 | show_threads_fn (vlib_main_t * vm, |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 44 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 45 | { |
Benoît Ganne | 8b153de | 2021-12-09 18:24:21 +0100 | [diff] [blame^] | 46 | const vlib_thread_main_t *tm = vlib_get_thread_main (); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 47 | vlib_worker_thread_t *w; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 48 | int i; |
| 49 | |
Pavel Kotucek | c08a1ed | 2016-09-23 08:54:14 +0200 | [diff] [blame] | 50 | vlib_cli_output (vm, "%-7s%-20s%-12s%-8s%-25s%-7s%-7s%-7s%-10s", |
| 51 | "ID", "Name", "Type", "LWP", "Sched Policy (Priority)", |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 52 | "lcore", "Core", "Socket", "State"); |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 53 | |
| 54 | #if !defined(__powerpc64__) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 55 | for (i = 0; i < vec_len (vlib_worker_threads); i++) |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 56 | { |
| 57 | w = vlib_worker_threads + i; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 58 | u8 *line = NULL; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 59 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 60 | line = format (line, "%-7d%-20s%-12s%-8d", |
| 61 | i, |
| 62 | w->name ? w->name : (u8 *) "", |
| 63 | w->registration ? w->registration->name : "", w->lwp); |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 64 | |
Pavel Kotucek | c08a1ed | 2016-09-23 08:54:14 +0200 | [diff] [blame] | 65 | line = format (line, "%-25U", format_sched_policy_and_priority, w->lwp); |
Pavel Kotucek | 1e76583 | 2016-09-23 08:54:14 +0200 | [diff] [blame] | 66 | |
Mohsin Kazmi | 5d64c78 | 2018-09-11 20:27:09 +0200 | [diff] [blame] | 67 | int cpu_id = w->cpu_id; |
Benoît Ganne | 8b153de | 2021-12-09 18:24:21 +0100 | [diff] [blame^] | 68 | if (cpu_id > -1 && tm->main_lcore != ~0) |
Pavel Kotucek | 9876520 | 2016-10-07 08:37:28 +0200 | [diff] [blame] | 69 | { |
Mohsin Kazmi | 5d64c78 | 2018-09-11 20:27:09 +0200 | [diff] [blame] | 70 | int core_id = w->core_id; |
Dave Barach | a690fdb | 2020-01-21 12:34:55 -0500 | [diff] [blame] | 71 | int numa_id = w->numa_id; |
| 72 | line = format (line, "%-7u%-7u%-7u%", cpu_id, core_id, numa_id); |
Pavel Kotucek | 9876520 | 2016-10-07 08:37:28 +0200 | [diff] [blame] | 73 | } |
| 74 | else |
| 75 | { |
Mohsin Kazmi | 5d64c78 | 2018-09-11 20:27:09 +0200 | [diff] [blame] | 76 | line = format (line, "%-7s%-7s%-7s%", "n/a", "n/a", "n/a"); |
Pavel Kotucek | 9876520 | 2016-10-07 08:37:28 +0200 | [diff] [blame] | 77 | } |
| 78 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 79 | vlib_cli_output (vm, "%v", line); |
| 80 | vec_free (line); |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 81 | } |
| 82 | #endif |
| 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 88 | /* *INDENT-OFF* */ |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 89 | VLIB_CLI_COMMAND (show_threads_command, static) = { |
| 90 | .path = "show threads", |
| 91 | .short_help = "Show threads", |
| 92 | .function = show_threads_fn, |
| 93 | }; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 94 | /* *INDENT-ON* */ |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 95 | |
| 96 | /* |
| 97 | * Trigger threads to grab frame queue trace data |
| 98 | */ |
| 99 | static clib_error_t * |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 100 | trace_frame_queue (vlib_main_t * vm, unformat_input_t * input, |
| 101 | vlib_cli_command_t * cmd) |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 102 | { |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 103 | unformat_input_t _line_input, *line_input = &_line_input; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 104 | clib_error_t *error = NULL; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 105 | frame_queue_trace_t *fqt; |
| 106 | frame_queue_nelt_counter_t *fqh; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 107 | vlib_thread_main_t *tm = vlib_get_thread_main (); |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 108 | vlib_frame_queue_main_t *fqm; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 109 | u32 num_fq; |
| 110 | u32 fqix; |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 111 | u32 enable = 2; |
| 112 | u32 index = ~(u32) 0; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 113 | |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 114 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 115 | return 0; |
| 116 | |
| 117 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 118 | { |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 119 | if (unformat (line_input, "on")) |
| 120 | enable = 1; |
| 121 | else if (unformat (line_input, "off")) |
| 122 | enable = 0; |
Matus Fabian | 2d41f16 | 2017-02-21 22:27:13 -0800 | [diff] [blame] | 123 | else if (unformat (line_input, "index %u", &index)) |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 124 | ; |
| 125 | else |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 126 | { |
| 127 | error = clib_error_return (0, "parse error: '%U'", |
| 128 | format_unformat_error, line_input); |
| 129 | goto done; |
| 130 | } |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 131 | } |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 132 | |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 133 | if (enable > 1) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 134 | { |
| 135 | error = clib_error_return (0, "expecting on or off"); |
| 136 | goto done; |
| 137 | } |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 138 | |
| 139 | if (vec_len (tm->frame_queue_mains) == 0) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 140 | { |
| 141 | error = clib_error_return (0, "no worker handoffs exist"); |
| 142 | goto done; |
| 143 | } |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 144 | |
| 145 | if (index > vec_len (tm->frame_queue_mains) - 1) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 146 | { |
| 147 | error = clib_error_return (0, |
| 148 | "expecting valid worker handoff queue index"); |
| 149 | goto done; |
| 150 | } |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 151 | |
| 152 | fqm = vec_elt_at_index (tm->frame_queue_mains, index); |
| 153 | |
| 154 | num_fq = vec_len (fqm->vlib_frame_queues); |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 155 | if (num_fq == 0) |
| 156 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 157 | vlib_cli_output (vm, "No frame queues exist\n"); |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 158 | goto done; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | // Allocate storage for trace if necessary |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 162 | vec_validate_aligned (fqm->frame_queue_traces, num_fq - 1, |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 163 | CLIB_CACHE_LINE_BYTES); |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 164 | vec_validate_aligned (fqm->frame_queue_histogram, num_fq - 1, |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 165 | CLIB_CACHE_LINE_BYTES); |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 166 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 167 | for (fqix = 0; fqix < num_fq; fqix++) |
| 168 | { |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 169 | fqt = &fqm->frame_queue_traces[fqix]; |
| 170 | fqh = &fqm->frame_queue_histogram[fqix]; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 171 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 172 | clib_memset (fqt->n_vectors, 0xff, sizeof (fqt->n_vectors)); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 173 | fqt->written = 0; |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 174 | clib_memset (fqh, 0, sizeof (*fqh)); |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 175 | fqm->vlib_frame_queues[fqix]->trace = enable; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 176 | } |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 177 | |
| 178 | done: |
| 179 | unformat_free (line_input); |
| 180 | |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 181 | return error; |
| 182 | } |
| 183 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 184 | /* *INDENT-OFF* */ |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 185 | VLIB_CLI_COMMAND (cmd_trace_frame_queue,static) = { |
| 186 | .path = "trace frame-queue", |
| 187 | .short_help = "trace frame-queue (on|off)", |
| 188 | .function = trace_frame_queue, |
| 189 | .is_mp_safe = 1, |
| 190 | }; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 191 | /* *INDENT-ON* */ |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 192 | |
| 193 | |
| 194 | /* |
| 195 | * Adding two counters and compute percent of total |
| 196 | * Round up, e.g. 0.000001 => 1% |
| 197 | */ |
| 198 | static u32 |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 199 | compute_percent (u64 * two_counters, u64 total) |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 200 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 201 | if (total == 0) |
| 202 | { |
| 203 | return 0; |
| 204 | } |
| 205 | else |
| 206 | { |
| 207 | return (((two_counters[0] + two_counters[1]) * 100) + |
| 208 | (total - 1)) / total; |
| 209 | } |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | /* |
| 213 | * Display frame queue trace data gathered by threads. |
| 214 | */ |
| 215 | static clib_error_t * |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 216 | show_frame_queue_internal (vlib_main_t * vm, |
| 217 | vlib_frame_queue_main_t * fqm, u32 histogram) |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 218 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 219 | clib_error_t *error = NULL; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 220 | frame_queue_trace_t *fqt; |
| 221 | frame_queue_nelt_counter_t *fqh; |
| 222 | u32 num_fq; |
| 223 | u32 fqix; |
| 224 | |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 225 | num_fq = vec_len (fqm->frame_queue_traces); |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 226 | if (num_fq == 0) |
| 227 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 228 | vlib_cli_output (vm, "No trace data for frame queues\n"); |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 229 | return error; |
| 230 | } |
| 231 | |
| 232 | if (histogram) |
| 233 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 234 | vlib_cli_output (vm, "0-1 2-3 4-5 6-7 8-9 10-11 12-13 14-15 " |
| 235 | "16-17 18-19 20-21 22-23 24-25 26-27 28-29 30-31\n"); |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 236 | } |
| 237 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 238 | for (fqix = 0; fqix < num_fq; fqix++) |
| 239 | { |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 240 | fqt = &(fqm->frame_queue_traces[fqix]); |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 241 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 242 | vlib_cli_output (vm, "Thread %d %v\n", fqix, |
| 243 | vlib_worker_threads[fqix].name); |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 244 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 245 | if (fqt->written == 0) |
| 246 | { |
| 247 | vlib_cli_output (vm, " no trace data\n"); |
| 248 | continue; |
| 249 | } |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 250 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 251 | if (histogram) |
| 252 | { |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 253 | fqh = &(fqm->frame_queue_histogram[fqix]); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 254 | u32 nelt; |
| 255 | u64 total = 0; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 256 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 257 | for (nelt = 0; nelt < FRAME_QUEUE_MAX_NELTS; nelt++) |
| 258 | { |
| 259 | total += fqh->count[nelt]; |
| 260 | } |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 261 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 262 | /* |
| 263 | * Print in pairs to condense the output. |
| 264 | * Allow entries with 0 counts to be clearly identified, by rounding up. |
| 265 | * Any non-zero value will be displayed as at least one percent. This |
| 266 | * also means the sum of percentages can be > 100, but that is fine. The |
| 267 | * histogram is counted from the last time "trace frame on" was issued. |
| 268 | */ |
| 269 | vlib_cli_output (vm, |
| 270 | "%3d%% %3d%% %3d%% %3d%% %3d%% %3d%% %3d%% %3d%% " |
| 271 | "%3d%% %3d%% %3d%% %3d%% %3d%% %3d%% %3d%% %3d%%\n", |
| 272 | compute_percent (&fqh->count[0], total), |
| 273 | compute_percent (&fqh->count[2], total), |
| 274 | compute_percent (&fqh->count[4], total), |
| 275 | compute_percent (&fqh->count[6], total), |
| 276 | compute_percent (&fqh->count[8], total), |
| 277 | compute_percent (&fqh->count[10], total), |
| 278 | compute_percent (&fqh->count[12], total), |
| 279 | compute_percent (&fqh->count[14], total), |
| 280 | compute_percent (&fqh->count[16], total), |
| 281 | compute_percent (&fqh->count[18], total), |
| 282 | compute_percent (&fqh->count[20], total), |
| 283 | compute_percent (&fqh->count[22], total), |
| 284 | compute_percent (&fqh->count[24], total), |
| 285 | compute_percent (&fqh->count[26], total), |
| 286 | compute_percent (&fqh->count[28], total), |
| 287 | compute_percent (&fqh->count[30], total)); |
| 288 | } |
| 289 | else |
| 290 | { |
| 291 | vlib_cli_output (vm, |
| 292 | " vector-threshold %d ring size %d in use %d\n", |
| 293 | fqt->threshold, fqt->nelts, fqt->n_in_use); |
Damjan Marion | c0d9ca7 | 2021-05-11 09:39:24 +0200 | [diff] [blame] | 294 | vlib_cli_output (vm, " head %12d tail %12d\n", fqt->head, |
| 295 | fqt->tail); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 296 | vlib_cli_output (vm, |
| 297 | " %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d\n", |
| 298 | fqt->n_vectors[0], fqt->n_vectors[1], |
| 299 | fqt->n_vectors[2], fqt->n_vectors[3], |
| 300 | fqt->n_vectors[4], fqt->n_vectors[5], |
| 301 | fqt->n_vectors[6], fqt->n_vectors[7], |
| 302 | fqt->n_vectors[8], fqt->n_vectors[9], |
| 303 | fqt->n_vectors[10], fqt->n_vectors[11], |
| 304 | fqt->n_vectors[12], fqt->n_vectors[13], |
| 305 | fqt->n_vectors[14], fqt->n_vectors[15]); |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 306 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 307 | if (fqt->nelts > 16) |
| 308 | { |
| 309 | vlib_cli_output (vm, |
| 310 | " %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d\n", |
| 311 | fqt->n_vectors[16], fqt->n_vectors[17], |
| 312 | fqt->n_vectors[18], fqt->n_vectors[19], |
| 313 | fqt->n_vectors[20], fqt->n_vectors[21], |
| 314 | fqt->n_vectors[22], fqt->n_vectors[23], |
| 315 | fqt->n_vectors[24], fqt->n_vectors[25], |
| 316 | fqt->n_vectors[26], fqt->n_vectors[27], |
| 317 | fqt->n_vectors[28], fqt->n_vectors[29], |
| 318 | fqt->n_vectors[30], fqt->n_vectors[31]); |
| 319 | } |
| 320 | } |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 321 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 322 | } |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 323 | return error; |
| 324 | } |
| 325 | |
| 326 | static clib_error_t * |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 327 | show_frame_queue_trace (vlib_main_t * vm, unformat_input_t * input, |
| 328 | vlib_cli_command_t * cmd) |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 329 | { |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 330 | vlib_thread_main_t *tm = vlib_get_thread_main (); |
| 331 | vlib_frame_queue_main_t *fqm; |
| 332 | clib_error_t *error; |
| 333 | |
| 334 | vec_foreach (fqm, tm->frame_queue_mains) |
| 335 | { |
| 336 | vlib_cli_output (vm, "Worker handoff queue index %u (next node '%U'):", |
| 337 | fqm - tm->frame_queue_mains, |
| 338 | format_vlib_node_name, vm, fqm->node_index); |
| 339 | error = show_frame_queue_internal (vm, fqm, 0); |
| 340 | if (error) |
| 341 | return error; |
| 342 | } |
| 343 | return 0; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | static clib_error_t * |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 347 | show_frame_queue_histogram (vlib_main_t * vm, unformat_input_t * input, |
| 348 | vlib_cli_command_t * cmd) |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 349 | { |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 350 | vlib_thread_main_t *tm = vlib_get_thread_main (); |
| 351 | vlib_frame_queue_main_t *fqm; |
| 352 | clib_error_t *error; |
| 353 | |
| 354 | vec_foreach (fqm, tm->frame_queue_mains) |
| 355 | { |
| 356 | vlib_cli_output (vm, "Worker handoff queue index %u (next node '%U'):", |
| 357 | fqm - tm->frame_queue_mains, |
| 358 | format_vlib_node_name, vm, fqm->node_index); |
| 359 | error = show_frame_queue_internal (vm, fqm, 1); |
| 360 | if (error) |
| 361 | return error; |
| 362 | } |
| 363 | return 0; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 364 | } |
| 365 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 366 | /* *INDENT-OFF* */ |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 367 | VLIB_CLI_COMMAND (cmd_show_frame_queue_trace,static) = { |
| 368 | .path = "show frame-queue", |
| 369 | .short_help = "show frame-queue trace", |
| 370 | .function = show_frame_queue_trace, |
| 371 | }; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 372 | /* *INDENT-ON* */ |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 373 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 374 | /* *INDENT-OFF* */ |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 375 | VLIB_CLI_COMMAND (cmd_show_frame_queue_histogram,static) = { |
| 376 | .path = "show frame-queue histogram", |
| 377 | .short_help = "show frame-queue histogram", |
| 378 | .function = show_frame_queue_histogram, |
| 379 | }; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 380 | /* *INDENT-ON* */ |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 381 | |
| 382 | |
| 383 | /* |
| 384 | * Modify the number of elements on the frame_queues |
| 385 | */ |
| 386 | static clib_error_t * |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 387 | test_frame_queue_nelts (vlib_main_t * vm, unformat_input_t * input, |
| 388 | vlib_cli_command_t * cmd) |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 389 | { |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 390 | unformat_input_t _line_input, *line_input = &_line_input; |
| 391 | vlib_thread_main_t *tm = vlib_get_thread_main (); |
| 392 | vlib_frame_queue_main_t *fqm; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 393 | clib_error_t *error = NULL; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 394 | u32 num_fq; |
| 395 | u32 fqix; |
| 396 | u32 nelts = 0; |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 397 | u32 index = ~(u32) 0; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 398 | |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 399 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 400 | return 0; |
| 401 | |
| 402 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 403 | { |
Dave Barach | 7afe9e3 | 2016-11-22 15:23:41 -0500 | [diff] [blame] | 404 | if (unformat (line_input, "nelts %u", &nelts)) |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 405 | ; |
Dave Barach | 7afe9e3 | 2016-11-22 15:23:41 -0500 | [diff] [blame] | 406 | else if (unformat (line_input, "index %u", &index)) |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 407 | ; |
| 408 | else |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 409 | { |
| 410 | error = clib_error_return (0, "parse error: '%U'", |
| 411 | format_unformat_error, line_input); |
| 412 | goto done; |
| 413 | } |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 414 | } |
| 415 | |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 416 | if (index > vec_len (tm->frame_queue_mains) - 1) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 417 | { |
| 418 | error = clib_error_return (0, |
| 419 | "expecting valid worker handoff queue index"); |
| 420 | goto done; |
| 421 | } |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 422 | |
| 423 | fqm = vec_elt_at_index (tm->frame_queue_mains, index); |
| 424 | |
| 425 | if ((nelts != 4) && (nelts != 8) && (nelts != 16) && (nelts != 32)) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 426 | { |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 427 | error = clib_error_return (0, "expecting 4,8,16,32"); |
| 428 | goto done; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 429 | } |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 430 | |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 431 | num_fq = vec_len (fqm->vlib_frame_queues); |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 432 | if (num_fq == 0) |
| 433 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 434 | vlib_cli_output (vm, "No frame queues exist\n"); |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 435 | goto done; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 436 | } |
| 437 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 438 | for (fqix = 0; fqix < num_fq; fqix++) |
| 439 | { |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 440 | fqm->vlib_frame_queues[fqix]->nelts = nelts; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 441 | } |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 442 | |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 443 | done: |
| 444 | unformat_free (line_input); |
| 445 | |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 446 | return error; |
| 447 | } |
| 448 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 449 | /* *INDENT-OFF* */ |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 450 | VLIB_CLI_COMMAND (cmd_test_frame_queue_nelts,static) = { |
| 451 | .path = "test frame-queue nelts", |
| 452 | .short_help = "test frame-queue nelts (4,8,16,32)", |
| 453 | .function = test_frame_queue_nelts, |
| 454 | }; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 455 | /* *INDENT-ON* */ |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 456 | |
| 457 | |
| 458 | /* |
| 459 | * Modify the max number of packets pulled off the frame queues |
| 460 | */ |
| 461 | static clib_error_t * |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 462 | test_frame_queue_threshold (vlib_main_t * vm, unformat_input_t * input, |
| 463 | vlib_cli_command_t * cmd) |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 464 | { |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 465 | unformat_input_t _line_input, *line_input = &_line_input; |
| 466 | vlib_thread_main_t *tm = vlib_get_thread_main (); |
| 467 | vlib_frame_queue_main_t *fqm; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 468 | clib_error_t *error = NULL; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 469 | u32 num_fq; |
| 470 | u32 fqix; |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 471 | u32 threshold = ~(u32) 0; |
| 472 | u32 index = ~(u32) 0; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 473 | |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 474 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 475 | return 0; |
| 476 | |
| 477 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 478 | { |
Dave Barach | 7afe9e3 | 2016-11-22 15:23:41 -0500 | [diff] [blame] | 479 | if (unformat (line_input, "threshold %u", &threshold)) |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 480 | ; |
Dave Barach | 7afe9e3 | 2016-11-22 15:23:41 -0500 | [diff] [blame] | 481 | else if (unformat (line_input, "index %u", &index)) |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 482 | ; |
| 483 | else |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 484 | { |
| 485 | error = clib_error_return (0, "parse error: '%U'", |
| 486 | format_unformat_error, line_input); |
| 487 | goto done; |
| 488 | } |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 489 | } |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 490 | |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 491 | if (index > vec_len (tm->frame_queue_mains) - 1) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 492 | { |
| 493 | error = clib_error_return (0, |
| 494 | "expecting valid worker handoff queue index"); |
| 495 | goto done; |
| 496 | } |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 497 | |
| 498 | fqm = vec_elt_at_index (tm->frame_queue_mains, index); |
| 499 | |
| 500 | |
| 501 | if (threshold == ~(u32) 0) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 502 | { |
| 503 | vlib_cli_output (vm, "expecting threshold value\n"); |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 504 | goto done; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 505 | } |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 506 | |
| 507 | if (threshold == 0) |
| 508 | threshold = ~0; |
| 509 | |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 510 | num_fq = vec_len (fqm->vlib_frame_queues); |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 511 | if (num_fq == 0) |
| 512 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 513 | vlib_cli_output (vm, "No frame queues exist\n"); |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 514 | goto done; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 515 | } |
| 516 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 517 | for (fqix = 0; fqix < num_fq; fqix++) |
| 518 | { |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 519 | fqm->vlib_frame_queues[fqix]->vector_threshold = threshold; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 520 | } |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 521 | |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 522 | done: |
| 523 | unformat_free (line_input); |
| 524 | |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 525 | return error; |
| 526 | } |
| 527 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 528 | /* *INDENT-OFF* */ |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 529 | VLIB_CLI_COMMAND (cmd_test_frame_queue_threshold,static) = { |
| 530 | .path = "test frame-queue threshold", |
| 531 | .short_help = "test frame-queue threshold N (0=no limit)", |
| 532 | .function = test_frame_queue_threshold, |
| 533 | }; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 534 | /* *INDENT-ON* */ |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 535 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 536 | /* |
| 537 | * fd.io coding-style-patch-verification: ON |
| 538 | * |
| 539 | * Local Variables: |
| 540 | * eval: (c-set-style "gnu") |
| 541 | * End: |
| 542 | */ |