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