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