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