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 | |
| 88 | VLIB_CLI_COMMAND (show_threads_command, static) = { |
| 89 | .path = "show threads", |
| 90 | .short_help = "Show threads", |
| 91 | .function = show_threads_fn, |
| 92 | }; |
| 93 | |
| 94 | /* |
| 95 | * Trigger threads to grab frame queue trace data |
| 96 | */ |
| 97 | static clib_error_t * |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 98 | trace_frame_queue (vlib_main_t * vm, unformat_input_t * input, |
| 99 | vlib_cli_command_t * cmd) |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 100 | { |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 101 | unformat_input_t _line_input, *line_input = &_line_input; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 102 | clib_error_t *error = NULL; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 103 | frame_queue_trace_t *fqt; |
| 104 | frame_queue_nelt_counter_t *fqh; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 105 | vlib_thread_main_t *tm = vlib_get_thread_main (); |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 106 | vlib_frame_queue_main_t *fqm; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 107 | u32 num_fq; |
| 108 | u32 fqix; |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 109 | u32 enable = 2; |
| 110 | u32 index = ~(u32) 0; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 111 | |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 112 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 113 | return 0; |
| 114 | |
| 115 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 116 | { |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 117 | if (unformat (line_input, "on")) |
| 118 | enable = 1; |
| 119 | else if (unformat (line_input, "off")) |
| 120 | enable = 0; |
Matus Fabian | 2d41f16 | 2017-02-21 22:27:13 -0800 | [diff] [blame] | 121 | else if (unformat (line_input, "index %u", &index)) |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 122 | ; |
| 123 | else |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 124 | { |
| 125 | error = clib_error_return (0, "parse error: '%U'", |
| 126 | format_unformat_error, line_input); |
| 127 | goto done; |
| 128 | } |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 129 | } |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 130 | |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 131 | if (enable > 1) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 132 | { |
| 133 | error = clib_error_return (0, "expecting on or off"); |
| 134 | goto done; |
| 135 | } |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 136 | |
| 137 | if (vec_len (tm->frame_queue_mains) == 0) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 138 | { |
| 139 | error = clib_error_return (0, "no worker handoffs exist"); |
| 140 | goto done; |
| 141 | } |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 142 | |
| 143 | if (index > vec_len (tm->frame_queue_mains) - 1) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 144 | { |
| 145 | error = clib_error_return (0, |
| 146 | "expecting valid worker handoff queue index"); |
| 147 | goto done; |
| 148 | } |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 149 | |
| 150 | fqm = vec_elt_at_index (tm->frame_queue_mains, index); |
| 151 | |
| 152 | num_fq = vec_len (fqm->vlib_frame_queues); |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 153 | if (num_fq == 0) |
| 154 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 155 | vlib_cli_output (vm, "No frame queues exist\n"); |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 156 | goto done; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | // Allocate storage for trace if necessary |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 160 | vec_validate_aligned (fqm->frame_queue_traces, num_fq - 1, |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 161 | CLIB_CACHE_LINE_BYTES); |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 162 | vec_validate_aligned (fqm->frame_queue_histogram, num_fq - 1, |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 163 | CLIB_CACHE_LINE_BYTES); |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 164 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 165 | for (fqix = 0; fqix < num_fq; fqix++) |
| 166 | { |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 167 | fqt = &fqm->frame_queue_traces[fqix]; |
| 168 | fqh = &fqm->frame_queue_histogram[fqix]; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 169 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 170 | clib_memset (fqt->n_vectors, 0xff, sizeof (fqt->n_vectors)); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 171 | fqt->written = 0; |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 172 | clib_memset (fqh, 0, sizeof (*fqh)); |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 173 | fqm->vlib_frame_queues[fqix]->trace = enable; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 174 | } |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 175 | |
| 176 | done: |
| 177 | unformat_free (line_input); |
| 178 | |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 179 | return error; |
| 180 | } |
| 181 | |
| 182 | VLIB_CLI_COMMAND (cmd_trace_frame_queue,static) = { |
| 183 | .path = "trace frame-queue", |
| 184 | .short_help = "trace frame-queue (on|off)", |
| 185 | .function = trace_frame_queue, |
| 186 | .is_mp_safe = 1, |
| 187 | }; |
| 188 | |
| 189 | |
| 190 | /* |
| 191 | * Adding two counters and compute percent of total |
| 192 | * Round up, e.g. 0.000001 => 1% |
| 193 | */ |
| 194 | static u32 |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 195 | compute_percent (u64 * two_counters, u64 total) |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 196 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 197 | if (total == 0) |
| 198 | { |
| 199 | return 0; |
| 200 | } |
| 201 | else |
| 202 | { |
| 203 | return (((two_counters[0] + two_counters[1]) * 100) + |
| 204 | (total - 1)) / total; |
| 205 | } |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | /* |
| 209 | * Display frame queue trace data gathered by threads. |
| 210 | */ |
| 211 | static clib_error_t * |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 212 | show_frame_queue_internal (vlib_main_t * vm, |
| 213 | vlib_frame_queue_main_t * fqm, u32 histogram) |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 214 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 215 | clib_error_t *error = NULL; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 216 | frame_queue_trace_t *fqt; |
| 217 | frame_queue_nelt_counter_t *fqh; |
| 218 | u32 num_fq; |
| 219 | u32 fqix; |
| 220 | |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 221 | num_fq = vec_len (fqm->frame_queue_traces); |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 222 | if (num_fq == 0) |
| 223 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 224 | vlib_cli_output (vm, "No trace data for frame queues\n"); |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 225 | return error; |
| 226 | } |
| 227 | |
| 228 | if (histogram) |
| 229 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 230 | vlib_cli_output (vm, "0-1 2-3 4-5 6-7 8-9 10-11 12-13 14-15 " |
| 231 | "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] | 232 | } |
| 233 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 234 | for (fqix = 0; fqix < num_fq; fqix++) |
| 235 | { |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 236 | fqt = &(fqm->frame_queue_traces[fqix]); |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 237 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 238 | vlib_cli_output (vm, "Thread %d %v\n", fqix, |
| 239 | vlib_worker_threads[fqix].name); |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 240 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 241 | if (fqt->written == 0) |
| 242 | { |
| 243 | vlib_cli_output (vm, " no trace data\n"); |
| 244 | continue; |
| 245 | } |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 246 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 247 | if (histogram) |
| 248 | { |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 249 | fqh = &(fqm->frame_queue_histogram[fqix]); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 250 | u32 nelt; |
| 251 | u64 total = 0; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 252 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 253 | for (nelt = 0; nelt < FRAME_QUEUE_MAX_NELTS; nelt++) |
| 254 | { |
| 255 | total += fqh->count[nelt]; |
| 256 | } |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 257 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 258 | /* |
| 259 | * Print in pairs to condense the output. |
| 260 | * Allow entries with 0 counts to be clearly identified, by rounding up. |
| 261 | * Any non-zero value will be displayed as at least one percent. This |
| 262 | * also means the sum of percentages can be > 100, but that is fine. The |
| 263 | * histogram is counted from the last time "trace frame on" was issued. |
| 264 | */ |
| 265 | vlib_cli_output (vm, |
| 266 | "%3d%% %3d%% %3d%% %3d%% %3d%% %3d%% %3d%% %3d%% " |
| 267 | "%3d%% %3d%% %3d%% %3d%% %3d%% %3d%% %3d%% %3d%%\n", |
| 268 | compute_percent (&fqh->count[0], total), |
| 269 | compute_percent (&fqh->count[2], total), |
| 270 | compute_percent (&fqh->count[4], total), |
| 271 | compute_percent (&fqh->count[6], total), |
| 272 | compute_percent (&fqh->count[8], total), |
| 273 | compute_percent (&fqh->count[10], total), |
| 274 | compute_percent (&fqh->count[12], total), |
| 275 | compute_percent (&fqh->count[14], total), |
| 276 | compute_percent (&fqh->count[16], total), |
| 277 | compute_percent (&fqh->count[18], total), |
| 278 | compute_percent (&fqh->count[20], total), |
| 279 | compute_percent (&fqh->count[22], total), |
| 280 | compute_percent (&fqh->count[24], total), |
| 281 | compute_percent (&fqh->count[26], total), |
| 282 | compute_percent (&fqh->count[28], total), |
| 283 | compute_percent (&fqh->count[30], total)); |
| 284 | } |
| 285 | else |
| 286 | { |
| 287 | vlib_cli_output (vm, |
| 288 | " vector-threshold %d ring size %d in use %d\n", |
| 289 | fqt->threshold, fqt->nelts, fqt->n_in_use); |
Damjan Marion | c0d9ca7 | 2021-05-11 09:39:24 +0200 | [diff] [blame] | 290 | vlib_cli_output (vm, " head %12d tail %12d\n", fqt->head, |
| 291 | fqt->tail); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 292 | vlib_cli_output (vm, |
| 293 | " %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d\n", |
| 294 | fqt->n_vectors[0], fqt->n_vectors[1], |
| 295 | fqt->n_vectors[2], fqt->n_vectors[3], |
| 296 | fqt->n_vectors[4], fqt->n_vectors[5], |
| 297 | fqt->n_vectors[6], fqt->n_vectors[7], |
| 298 | fqt->n_vectors[8], fqt->n_vectors[9], |
| 299 | fqt->n_vectors[10], fqt->n_vectors[11], |
| 300 | fqt->n_vectors[12], fqt->n_vectors[13], |
| 301 | fqt->n_vectors[14], fqt->n_vectors[15]); |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 302 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 303 | if (fqt->nelts > 16) |
| 304 | { |
| 305 | vlib_cli_output (vm, |
| 306 | " %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d\n", |
| 307 | fqt->n_vectors[16], fqt->n_vectors[17], |
| 308 | fqt->n_vectors[18], fqt->n_vectors[19], |
| 309 | fqt->n_vectors[20], fqt->n_vectors[21], |
| 310 | fqt->n_vectors[22], fqt->n_vectors[23], |
| 311 | fqt->n_vectors[24], fqt->n_vectors[25], |
| 312 | fqt->n_vectors[26], fqt->n_vectors[27], |
| 313 | fqt->n_vectors[28], fqt->n_vectors[29], |
| 314 | fqt->n_vectors[30], fqt->n_vectors[31]); |
| 315 | } |
| 316 | } |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 317 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 318 | } |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 319 | return error; |
| 320 | } |
| 321 | |
| 322 | static clib_error_t * |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 323 | show_frame_queue_trace (vlib_main_t * vm, unformat_input_t * input, |
| 324 | vlib_cli_command_t * cmd) |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 325 | { |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 326 | vlib_thread_main_t *tm = vlib_get_thread_main (); |
| 327 | vlib_frame_queue_main_t *fqm; |
| 328 | clib_error_t *error; |
| 329 | |
| 330 | vec_foreach (fqm, tm->frame_queue_mains) |
| 331 | { |
| 332 | vlib_cli_output (vm, "Worker handoff queue index %u (next node '%U'):", |
| 333 | fqm - tm->frame_queue_mains, |
| 334 | format_vlib_node_name, vm, fqm->node_index); |
| 335 | error = show_frame_queue_internal (vm, fqm, 0); |
| 336 | if (error) |
| 337 | return error; |
| 338 | } |
| 339 | return 0; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | static clib_error_t * |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 343 | show_frame_queue_histogram (vlib_main_t * vm, unformat_input_t * input, |
| 344 | vlib_cli_command_t * cmd) |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 345 | { |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 346 | vlib_thread_main_t *tm = vlib_get_thread_main (); |
| 347 | vlib_frame_queue_main_t *fqm; |
| 348 | clib_error_t *error; |
| 349 | |
| 350 | vec_foreach (fqm, tm->frame_queue_mains) |
| 351 | { |
| 352 | vlib_cli_output (vm, "Worker handoff queue index %u (next node '%U'):", |
| 353 | fqm - tm->frame_queue_mains, |
| 354 | format_vlib_node_name, vm, fqm->node_index); |
| 355 | error = show_frame_queue_internal (vm, fqm, 1); |
| 356 | if (error) |
| 357 | return error; |
| 358 | } |
| 359 | return 0; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | VLIB_CLI_COMMAND (cmd_show_frame_queue_trace,static) = { |
| 363 | .path = "show frame-queue", |
| 364 | .short_help = "show frame-queue trace", |
| 365 | .function = show_frame_queue_trace, |
| 366 | }; |
| 367 | |
| 368 | VLIB_CLI_COMMAND (cmd_show_frame_queue_histogram,static) = { |
| 369 | .path = "show frame-queue histogram", |
| 370 | .short_help = "show frame-queue histogram", |
| 371 | .function = show_frame_queue_histogram, |
| 372 | }; |
| 373 | |
| 374 | |
| 375 | /* |
| 376 | * Modify the number of elements on the frame_queues |
| 377 | */ |
| 378 | static clib_error_t * |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 379 | test_frame_queue_nelts (vlib_main_t * vm, unformat_input_t * input, |
| 380 | vlib_cli_command_t * cmd) |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 381 | { |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 382 | unformat_input_t _line_input, *line_input = &_line_input; |
| 383 | vlib_thread_main_t *tm = vlib_get_thread_main (); |
| 384 | vlib_frame_queue_main_t *fqm; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 385 | clib_error_t *error = NULL; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 386 | u32 num_fq; |
| 387 | u32 fqix; |
| 388 | u32 nelts = 0; |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 389 | u32 index = ~(u32) 0; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 390 | |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 391 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 392 | return 0; |
| 393 | |
| 394 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 395 | { |
Dave Barach | 7afe9e3 | 2016-11-22 15:23:41 -0500 | [diff] [blame] | 396 | if (unformat (line_input, "nelts %u", &nelts)) |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 397 | ; |
Dave Barach | 7afe9e3 | 2016-11-22 15:23:41 -0500 | [diff] [blame] | 398 | else if (unformat (line_input, "index %u", &index)) |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 399 | ; |
| 400 | else |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 401 | { |
| 402 | error = clib_error_return (0, "parse error: '%U'", |
| 403 | format_unformat_error, line_input); |
| 404 | goto done; |
| 405 | } |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 406 | } |
| 407 | |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 408 | if (index > vec_len (tm->frame_queue_mains) - 1) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 409 | { |
| 410 | error = clib_error_return (0, |
| 411 | "expecting valid worker handoff queue index"); |
| 412 | goto done; |
| 413 | } |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 414 | |
| 415 | fqm = vec_elt_at_index (tm->frame_queue_mains, index); |
| 416 | |
| 417 | if ((nelts != 4) && (nelts != 8) && (nelts != 16) && (nelts != 32)) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 418 | { |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 419 | error = clib_error_return (0, "expecting 4,8,16,32"); |
| 420 | goto done; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 421 | } |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 422 | |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 423 | num_fq = vec_len (fqm->vlib_frame_queues); |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 424 | if (num_fq == 0) |
| 425 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 426 | vlib_cli_output (vm, "No frame queues exist\n"); |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 427 | goto done; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 428 | } |
| 429 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 430 | for (fqix = 0; fqix < num_fq; fqix++) |
| 431 | { |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 432 | fqm->vlib_frame_queues[fqix]->nelts = nelts; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 433 | } |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 434 | |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 435 | done: |
| 436 | unformat_free (line_input); |
| 437 | |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 438 | return error; |
| 439 | } |
| 440 | |
| 441 | VLIB_CLI_COMMAND (cmd_test_frame_queue_nelts,static) = { |
| 442 | .path = "test frame-queue nelts", |
| 443 | .short_help = "test frame-queue nelts (4,8,16,32)", |
| 444 | .function = test_frame_queue_nelts, |
| 445 | }; |
| 446 | |
| 447 | |
| 448 | /* |
| 449 | * Modify the max number of packets pulled off the frame queues |
| 450 | */ |
| 451 | static clib_error_t * |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 452 | test_frame_queue_threshold (vlib_main_t * vm, unformat_input_t * input, |
| 453 | vlib_cli_command_t * cmd) |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 454 | { |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 455 | unformat_input_t _line_input, *line_input = &_line_input; |
| 456 | vlib_thread_main_t *tm = vlib_get_thread_main (); |
| 457 | vlib_frame_queue_main_t *fqm; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 458 | clib_error_t *error = NULL; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 459 | u32 num_fq; |
| 460 | u32 fqix; |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 461 | u32 threshold = ~(u32) 0; |
| 462 | u32 index = ~(u32) 0; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 463 | |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 464 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 465 | return 0; |
| 466 | |
| 467 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 468 | { |
Dave Barach | 7afe9e3 | 2016-11-22 15:23:41 -0500 | [diff] [blame] | 469 | if (unformat (line_input, "threshold %u", &threshold)) |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 470 | ; |
Dave Barach | 7afe9e3 | 2016-11-22 15:23:41 -0500 | [diff] [blame] | 471 | else if (unformat (line_input, "index %u", &index)) |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 472 | ; |
| 473 | else |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 474 | { |
| 475 | error = clib_error_return (0, "parse error: '%U'", |
| 476 | format_unformat_error, line_input); |
| 477 | goto done; |
| 478 | } |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 479 | } |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 480 | |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 481 | if (index > vec_len (tm->frame_queue_mains) - 1) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 482 | { |
| 483 | error = clib_error_return (0, |
| 484 | "expecting valid worker handoff queue index"); |
| 485 | goto done; |
| 486 | } |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 487 | |
| 488 | fqm = vec_elt_at_index (tm->frame_queue_mains, index); |
| 489 | |
| 490 | |
| 491 | if (threshold == ~(u32) 0) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 492 | { |
| 493 | vlib_cli_output (vm, "expecting threshold value\n"); |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 494 | goto done; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 495 | } |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 496 | |
| 497 | if (threshold == 0) |
| 498 | threshold = ~0; |
| 499 | |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 500 | num_fq = vec_len (fqm->vlib_frame_queues); |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 501 | if (num_fq == 0) |
| 502 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 503 | vlib_cli_output (vm, "No frame queues exist\n"); |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 504 | goto done; |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 505 | } |
| 506 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 507 | for (fqix = 0; fqix < num_fq; fqix++) |
| 508 | { |
Damjan Marion | aaef1eb | 2016-11-08 17:37:01 +0100 | [diff] [blame] | 509 | fqm->vlib_frame_queues[fqix]->vector_threshold = threshold; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 510 | } |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 511 | |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 512 | done: |
| 513 | unformat_free (line_input); |
| 514 | |
Damjan Marion | 0f8ecf0 | 2016-06-27 08:30:30 +0200 | [diff] [blame] | 515 | return error; |
| 516 | } |
| 517 | |
| 518 | VLIB_CLI_COMMAND (cmd_test_frame_queue_threshold,static) = { |
| 519 | .path = "test frame-queue threshold", |
| 520 | .short_help = "test frame-queue threshold N (0=no limit)", |
| 521 | .function = test_frame_queue_threshold, |
| 522 | }; |
| 523 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 524 | /* |
| 525 | * fd.io coding-style-patch-verification: ON |
| 526 | * |
| 527 | * Local Variables: |
| 528 | * eval: (c-set-style "gnu") |
| 529 | * End: |
| 530 | */ |