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