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