Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [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 | */ |
| 15 | /* |
| 16 | * node_cli.c: node CLI |
| 17 | * |
| 18 | * Copyright (c) 2008 Eliot Dresselhaus |
| 19 | * |
| 20 | * Permission is hereby granted, free of charge, to any person obtaining |
| 21 | * a copy of this software and associated documentation files (the |
| 22 | * "Software"), to deal in the Software without restriction, including |
| 23 | * without limitation the rights to use, copy, modify, merge, publish, |
| 24 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 25 | * permit persons to whom the Software is furnished to do so, subject to |
| 26 | * the following conditions: |
| 27 | * |
| 28 | * The above copyright notice and this permission notice shall be |
| 29 | * included in all copies or substantial portions of the Software. |
| 30 | * |
| 31 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 32 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 33 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 34 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 35 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 36 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 37 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 38 | */ |
| 39 | |
| 40 | #include <vlib/vlib.h> |
| 41 | #include <vlib/threads.h> |
| 42 | |
Matus Fabian | d2dc3df | 2015-12-14 10:31:33 -0500 | [diff] [blame] | 43 | static int |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 44 | node_cmp (void *a1, void *a2) |
Matus Fabian | d2dc3df | 2015-12-14 10:31:33 -0500 | [diff] [blame] | 45 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 46 | vlib_node_t **n1 = a1; |
| 47 | vlib_node_t **n2 = a2; |
Matus Fabian | d2dc3df | 2015-12-14 10:31:33 -0500 | [diff] [blame] | 48 | |
| 49 | return vec_cmp (n1[0]->name, n2[0]->name); |
| 50 | } |
| 51 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 52 | static clib_error_t * |
| 53 | show_node_graph (vlib_main_t * vm, |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 54 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 55 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 56 | vlib_node_main_t *nm = &vm->node_main; |
| 57 | vlib_node_t *n; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 58 | u32 node_index; |
| 59 | |
| 60 | vlib_cli_output (vm, "%U\n", format_vlib_node_graph, nm, 0); |
| 61 | |
| 62 | if (unformat (input, "%U", unformat_vlib_node, vm, &node_index)) |
| 63 | { |
| 64 | n = vlib_get_node (vm, node_index); |
| 65 | vlib_cli_output (vm, "%U\n", format_vlib_node_graph, nm, n); |
| 66 | } |
| 67 | else |
| 68 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 69 | vlib_node_t **nodes = vec_dup (nm->nodes); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 70 | uword i; |
| 71 | |
Matus Fabian | d2dc3df | 2015-12-14 10:31:33 -0500 | [diff] [blame] | 72 | vec_sort_with_function (nodes, node_cmp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 73 | |
| 74 | for (i = 0; i < vec_len (nodes); i++) |
| 75 | vlib_cli_output (vm, "%U\n\n", format_vlib_node_graph, nm, nodes[i]); |
| 76 | |
| 77 | vec_free (nodes); |
| 78 | } |
| 79 | |
| 80 | return 0; |
| 81 | } |
| 82 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 83 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 84 | VLIB_CLI_COMMAND (show_node_graph_command, static) = { |
| 85 | .path = "show vlib graph", |
| 86 | .short_help = "Show packet processing node graph", |
| 87 | .function = show_node_graph, |
| 88 | }; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 89 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 90 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 91 | static u8 * |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 92 | format_vlib_node_state (u8 * s, va_list * va) |
| 93 | { |
| 94 | vlib_main_t *vm = va_arg (*va, vlib_main_t *); |
| 95 | vlib_node_t *n = va_arg (*va, vlib_node_t *); |
| 96 | char *state; |
| 97 | |
| 98 | state = "active"; |
| 99 | if (n->type == VLIB_NODE_TYPE_PROCESS) |
| 100 | { |
| 101 | vlib_process_t *p = vlib_get_process_from_node (vm, n); |
| 102 | |
| 103 | switch (p->flags & (VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK |
| 104 | | VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT)) |
| 105 | { |
| 106 | default: |
| 107 | if (!(p->flags & VLIB_PROCESS_IS_RUNNING)) |
| 108 | state = "done"; |
| 109 | break; |
| 110 | |
| 111 | case VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK: |
| 112 | state = "time wait"; |
| 113 | break; |
| 114 | |
| 115 | case VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT: |
| 116 | state = "event wait"; |
| 117 | break; |
| 118 | |
| 119 | case (VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT | VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK): |
| 120 | state = |
| 121 | "any wait"; |
| 122 | break; |
| 123 | } |
| 124 | } |
| 125 | else if (n->type != VLIB_NODE_TYPE_INTERNAL) |
| 126 | { |
| 127 | state = "polling"; |
| 128 | if (n->state == VLIB_NODE_STATE_DISABLED) |
| 129 | state = "disabled"; |
| 130 | else if (n->state == VLIB_NODE_STATE_INTERRUPT) |
| 131 | state = "interrupt wait"; |
| 132 | } |
| 133 | |
| 134 | return format (s, "%s", state); |
| 135 | } |
| 136 | |
| 137 | static u8 * |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 138 | format_vlib_node_stats (u8 * s, va_list * va) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 139 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 140 | vlib_main_t *vm = va_arg (*va, vlib_main_t *); |
| 141 | vlib_node_t *n = va_arg (*va, vlib_node_t *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 142 | int max = va_arg (*va, int); |
| 143 | f64 v; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 144 | u8 *ns; |
| 145 | u8 *misc_info = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 146 | u64 c, p, l, d; |
| 147 | f64 x; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 148 | f64 maxc, maxcn; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 149 | u32 maxn; |
Christophe Fontaine | d3c008d | 2017-10-02 18:10:54 +0200 | [diff] [blame] | 150 | u32 indent; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 151 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 152 | if (!n) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 153 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 154 | if (max) |
| 155 | return format (s, |
| 156 | "%=30s%=17s%=16s%=16s%=16s%=16s", |
| 157 | "Name", "Max Node Clocks", "Vectors at Max", |
| 158 | "Max Clocks", "Avg Clocks", "Avg Vectors/Call"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 159 | else |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 160 | return format (s, |
| 161 | "%=30s%=12s%=16s%=16s%=16s%=16s%=16s", |
| 162 | "Name", "State", "Calls", "Vectors", "Suspends", |
| 163 | "Clocks", "Vectors/Call"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | indent = format_get_indent (s); |
| 167 | |
| 168 | l = n->stats_total.clocks - n->stats_last_clear.clocks; |
| 169 | c = n->stats_total.calls - n->stats_last_clear.calls; |
| 170 | p = n->stats_total.vectors - n->stats_last_clear.vectors; |
| 171 | d = n->stats_total.suspends - n->stats_last_clear.suspends; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 172 | maxc = (f64) n->stats_total.max_clock; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 173 | maxn = n->stats_total.max_clock_n; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 174 | if (n->stats_total.max_clock_n) |
| 175 | maxcn = (f64) n->stats_total.max_clock / (f64) maxn; |
| 176 | else |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 177 | maxcn = 0.0; |
| 178 | |
| 179 | /* Clocks per packet, per call or per suspend. */ |
| 180 | x = 0; |
| 181 | if (p > 0) |
| 182 | x = (f64) l / (f64) p; |
| 183 | else if (c > 0) |
| 184 | x = (f64) l / (f64) c; |
| 185 | else if (d > 0) |
| 186 | x = (f64) l / (f64) d; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 187 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 188 | if (c > 0) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 189 | v = (double) p / (double) c; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 190 | else |
| 191 | v = 0; |
| 192 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 193 | if (n->type == VLIB_NODE_TYPE_PROCESS) |
| 194 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 195 | vlib_process_t *p = vlib_get_process_from_node (vm, n); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 196 | |
| 197 | /* Show processes with events pending. This helps spot bugs where events are not |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 198 | being handled. */ |
| 199 | if (!clib_bitmap_is_zero (p->non_empty_event_type_bitmap)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 200 | misc_info = format (misc_info, "events pending, "); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 201 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 202 | ns = n->name; |
| 203 | |
| 204 | if (max) |
| 205 | s = format (s, "%-30v%=17.2e%=16d%=16.2e%=16.2e%=16.2e", |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 206 | ns, maxc, maxn, maxcn, x, v); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 207 | else |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 208 | s = format (s, "%-30v%=12U%16Ld%16Ld%16Ld%16.2e%16.2f", ns, |
| 209 | format_vlib_node_state, vm, n, c, p, d, x, v); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 210 | |
| 211 | if (ns != n->name) |
| 212 | vec_free (ns); |
| 213 | |
| 214 | if (misc_info) |
| 215 | { |
| 216 | s = format (s, "\n%U%v", format_white_space, indent + 4, misc_info); |
| 217 | vec_free (misc_info); |
| 218 | } |
| 219 | |
| 220 | return s; |
| 221 | } |
| 222 | |
| 223 | static clib_error_t * |
| 224 | show_node_runtime (vlib_main_t * vm, |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 225 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 226 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 227 | vlib_node_main_t *nm = &vm->node_main; |
| 228 | vlib_node_t *n; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 229 | f64 time_now; |
| 230 | u32 node_index; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 231 | vlib_node_t ***node_dups = 0; |
| 232 | f64 *vectors_per_main_loop = 0; |
| 233 | f64 *last_vector_length_per_node = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 234 | |
| 235 | time_now = vlib_time_now (vm); |
| 236 | |
| 237 | if (unformat (input, "%U", unformat_vlib_node, vm, &node_index)) |
| 238 | { |
| 239 | n = vlib_get_node (vm, node_index); |
| 240 | vlib_node_sync_stats (vm, n); |
| 241 | vlib_cli_output (vm, "%U\n", format_vlib_node_stats, vm, 0, 0); |
| 242 | vlib_cli_output (vm, "%U\n", format_vlib_node_stats, vm, n, 0); |
| 243 | } |
| 244 | else |
| 245 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 246 | vlib_node_t **nodes; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 247 | uword i, j; |
| 248 | f64 dt; |
| 249 | u64 n_input, n_output, n_drop, n_punt; |
| 250 | u64 n_internal_vectors, n_internal_calls; |
| 251 | u64 n_clocks, l, v, c, d; |
| 252 | int brief = 1; |
| 253 | int max = 0; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 254 | vlib_main_t **stat_vms = 0, *stat_vm; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 255 | |
| 256 | /* Suppress nodes with zero calls since last clear */ |
| 257 | if (unformat (input, "brief") || unformat (input, "b")) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 258 | brief = 1; |
| 259 | if (unformat (input, "verbose") || unformat (input, "v")) |
| 260 | brief = 0; |
| 261 | if (unformat (input, "max") || unformat (input, "m")) |
| 262 | max = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 263 | |
Dave Barach | 80f54e2 | 2017-03-08 19:08:56 -0500 | [diff] [blame] | 264 | for (i = 0; i < vec_len (vlib_mains); i++) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 265 | { |
Dave Barach | 80f54e2 | 2017-03-08 19:08:56 -0500 | [diff] [blame] | 266 | stat_vm = vlib_mains[i]; |
| 267 | if (stat_vm) |
| 268 | vec_add1 (stat_vms, stat_vm); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 269 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 270 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 271 | /* |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 272 | * Barrier sync across stats scraping. |
| 273 | * Otherwise, the counts will be grossly inaccurate. |
| 274 | */ |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 275 | vlib_worker_thread_barrier_sync (vm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 276 | |
| 277 | for (j = 0; j < vec_len (stat_vms); j++) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 278 | { |
| 279 | stat_vm = stat_vms[j]; |
| 280 | nm = &stat_vm->node_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 281 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 282 | for (i = 0; i < vec_len (nm->nodes); i++) |
| 283 | { |
| 284 | n = nm->nodes[i]; |
| 285 | vlib_node_sync_stats (stat_vm, n); |
| 286 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 287 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 288 | nodes = vec_dup (nm->nodes); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 289 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 290 | vec_add1 (node_dups, nodes); |
| 291 | vec_add1 (vectors_per_main_loop, |
| 292 | vlib_last_vectors_per_main_loop_as_f64 (stat_vm)); |
| 293 | vec_add1 (last_vector_length_per_node, |
| 294 | vlib_last_vector_length_per_node (stat_vm)); |
| 295 | } |
| 296 | vlib_worker_thread_barrier_release (vm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 297 | |
| 298 | |
| 299 | for (j = 0; j < vec_len (stat_vms); j++) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 300 | { |
| 301 | stat_vm = stat_vms[j]; |
| 302 | nodes = node_dups[j]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 303 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 304 | vec_sort_with_function (nodes, node_cmp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 305 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 306 | n_input = n_output = n_drop = n_punt = n_clocks = 0; |
| 307 | n_internal_vectors = n_internal_calls = 0; |
| 308 | for (i = 0; i < vec_len (nodes); i++) |
| 309 | { |
| 310 | n = nodes[i]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 311 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 312 | l = n->stats_total.clocks - n->stats_last_clear.clocks; |
| 313 | n_clocks += l; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 314 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 315 | v = n->stats_total.vectors - n->stats_last_clear.vectors; |
| 316 | c = n->stats_total.calls - n->stats_last_clear.calls; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 317 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 318 | switch (n->type) |
| 319 | { |
| 320 | default: |
| 321 | continue; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 322 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 323 | case VLIB_NODE_TYPE_INTERNAL: |
| 324 | n_output += (n->flags & VLIB_NODE_FLAG_IS_OUTPUT) ? v : 0; |
| 325 | n_drop += (n->flags & VLIB_NODE_FLAG_IS_DROP) ? v : 0; |
| 326 | n_punt += (n->flags & VLIB_NODE_FLAG_IS_PUNT) ? v : 0; |
| 327 | if (!(n->flags & VLIB_NODE_FLAG_IS_OUTPUT)) |
| 328 | { |
| 329 | n_internal_vectors += v; |
| 330 | n_internal_calls += c; |
| 331 | } |
| 332 | if (n->flags & VLIB_NODE_FLAG_IS_HANDOFF) |
| 333 | n_input += v; |
| 334 | break; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 335 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 336 | case VLIB_NODE_TYPE_INPUT: |
| 337 | n_input += v; |
| 338 | break; |
| 339 | } |
| 340 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 341 | |
Dave Barach | 80f54e2 | 2017-03-08 19:08:56 -0500 | [diff] [blame] | 342 | if (vec_len (vlib_mains) > 1) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 343 | { |
| 344 | vlib_worker_thread_t *w = vlib_worker_threads + j; |
| 345 | if (j > 0) |
| 346 | vlib_cli_output (vm, "---------------"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 347 | |
Mohsin Kazmi | 5d64c78 | 2018-09-11 20:27:09 +0200 | [diff] [blame] | 348 | if (w->cpu_id > -1) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 349 | vlib_cli_output (vm, "Thread %d %s (lcore %u)", j, w->name, |
Mohsin Kazmi | 5d64c78 | 2018-09-11 20:27:09 +0200 | [diff] [blame] | 350 | w->cpu_id); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 351 | else |
| 352 | vlib_cli_output (vm, "Thread %d %s", j, w->name); |
| 353 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 354 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 355 | dt = time_now - nm->time_last_runtime_stats_clear; |
| 356 | vlib_cli_output |
| 357 | (vm, |
| 358 | "Time %.1f, average vectors/node %.2f, last %d main loops %.2f per node %.2f" |
| 359 | "\n vector rates in %.4e, out %.4e, drop %.4e, punt %.4e", |
| 360 | dt, |
| 361 | (n_internal_calls > 0 |
| 362 | ? (f64) n_internal_vectors / (f64) n_internal_calls |
| 363 | : 0), |
| 364 | 1 << VLIB_LOG2_MAIN_LOOPS_PER_STATS_UPDATE, |
| 365 | vectors_per_main_loop[j], |
| 366 | last_vector_length_per_node[j], |
| 367 | (f64) n_input / dt, |
| 368 | (f64) n_output / dt, (f64) n_drop / dt, (f64) n_punt / dt); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 369 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 370 | vlib_cli_output (vm, "%U", format_vlib_node_stats, stat_vm, 0, max); |
| 371 | for (i = 0; i < vec_len (nodes); i++) |
| 372 | { |
| 373 | c = |
| 374 | nodes[i]->stats_total.calls - |
| 375 | nodes[i]->stats_last_clear.calls; |
| 376 | d = |
| 377 | nodes[i]->stats_total.suspends - |
| 378 | nodes[i]->stats_last_clear.suspends; |
| 379 | if (c || d || !brief) |
| 380 | { |
| 381 | vlib_cli_output (vm, "%U", format_vlib_node_stats, stat_vm, |
| 382 | nodes[i], max); |
| 383 | } |
| 384 | } |
| 385 | vec_free (nodes); |
| 386 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 387 | vec_free (stat_vms); |
| 388 | vec_free (node_dups); |
| 389 | vec_free (vectors_per_main_loop); |
| 390 | vec_free (last_vector_length_per_node); |
| 391 | } |
| 392 | |
| 393 | return 0; |
| 394 | } |
| 395 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 396 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 397 | VLIB_CLI_COMMAND (show_node_runtime_command, static) = { |
| 398 | .path = "show runtime", |
| 399 | .short_help = "Show packet processing runtime", |
| 400 | .function = show_node_runtime, |
| 401 | .is_mp_safe = 1, |
| 402 | }; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 403 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 404 | |
| 405 | static clib_error_t * |
| 406 | clear_node_runtime (vlib_main_t * vm, |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 407 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 408 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 409 | vlib_node_main_t *nm; |
| 410 | vlib_node_t *n; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 411 | int i, j; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 412 | vlib_main_t **stat_vms = 0, *stat_vm; |
| 413 | vlib_node_runtime_t *r; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 414 | |
Dave Barach | 80f54e2 | 2017-03-08 19:08:56 -0500 | [diff] [blame] | 415 | for (i = 0; i < vec_len (vlib_mains); i++) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 416 | { |
Dave Barach | 80f54e2 | 2017-03-08 19:08:56 -0500 | [diff] [blame] | 417 | stat_vm = vlib_mains[i]; |
| 418 | if (stat_vm) |
| 419 | vec_add1 (stat_vms, stat_vm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 420 | } |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 421 | |
| 422 | vlib_worker_thread_barrier_sync (vm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 423 | |
| 424 | for (j = 0; j < vec_len (stat_vms); j++) |
| 425 | { |
| 426 | stat_vm = stat_vms[j]; |
| 427 | nm = &stat_vm->node_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 428 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 429 | for (i = 0; i < vec_len (nm->nodes); i++) |
| 430 | { |
| 431 | n = nm->nodes[i]; |
| 432 | vlib_node_sync_stats (stat_vm, n); |
| 433 | n->stats_last_clear = n->stats_total; |
| 434 | |
| 435 | r = vlib_node_get_runtime (stat_vm, n->index); |
| 436 | r->max_clock = 0; |
| 437 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 438 | /* Note: input/output rates computed using vlib_global_main */ |
| 439 | nm->time_last_runtime_stats_clear = vlib_time_now (vm); |
| 440 | } |
| 441 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 442 | vlib_worker_thread_barrier_release (vm); |
| 443 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 444 | vec_free (stat_vms); |
| 445 | |
| 446 | return 0; |
| 447 | } |
| 448 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 449 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 450 | VLIB_CLI_COMMAND (clear_node_runtime_command, static) = { |
| 451 | .path = "clear runtime", |
| 452 | .short_help = "Clear packet processing runtime statistics", |
| 453 | .function = clear_node_runtime, |
| 454 | }; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 455 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 456 | |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 457 | static clib_error_t * |
| 458 | show_node (vlib_main_t * vm, unformat_input_t * input, |
| 459 | vlib_cli_command_t * cmd) |
| 460 | { |
| 461 | unformat_input_t _line_input, *line_input = &_line_input; |
Paul Vinciguerra | 98afc71 | 2018-09-25 10:02:07 -0700 | [diff] [blame^] | 462 | clib_error_t *error = 0; |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 463 | vlib_node_main_t *nm = &vm->node_main; |
| 464 | vlib_node_t *n; |
| 465 | u8 *s = 0, *s2 = 0; |
| 466 | u32 i, node_index = ~0; |
| 467 | char *type_str; |
Paul Vinciguerra | 98afc71 | 2018-09-25 10:02:07 -0700 | [diff] [blame^] | 468 | u8 valid_node_name = 0; |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 469 | |
| 470 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 471 | return 0; |
| 472 | |
| 473 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 474 | { |
Paul Vinciguerra | 98afc71 | 2018-09-25 10:02:07 -0700 | [diff] [blame^] | 475 | if (unformat (line_input, "index %u", &node_index)) |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 476 | ; |
| 477 | else |
Paul Vinciguerra | 98afc71 | 2018-09-25 10:02:07 -0700 | [diff] [blame^] | 478 | if (unformat (line_input, "%U", unformat_vlib_node, vm, &node_index)) |
| 479 | valid_node_name = 1; |
| 480 | else if (!valid_node_name) |
| 481 | error = clib_error_return (0, "unknown node name: '%U'", |
| 482 | format_unformat_error, line_input); |
| 483 | else |
| 484 | error = clib_error_return (0, "unknown input '%U'", |
| 485 | format_unformat_error, line_input); |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 486 | } |
Paul Vinciguerra | 98afc71 | 2018-09-25 10:02:07 -0700 | [diff] [blame^] | 487 | |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 488 | unformat_free (line_input); |
| 489 | |
Paul Vinciguerra | 98afc71 | 2018-09-25 10:02:07 -0700 | [diff] [blame^] | 490 | if (error) |
| 491 | return error; |
| 492 | |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 493 | if (node_index >= vec_len (vm->node_main.nodes)) |
| 494 | return clib_error_return (0, "please specify valid node"); |
| 495 | |
| 496 | n = vlib_get_node (vm, node_index); |
| 497 | vlib_node_sync_stats (vm, n); |
| 498 | |
| 499 | switch (n->type) |
| 500 | { |
| 501 | case VLIB_NODE_TYPE_INTERNAL: |
| 502 | type_str = "internal"; |
| 503 | break; |
| 504 | case VLIB_NODE_TYPE_INPUT: |
| 505 | type_str = "input"; |
| 506 | break; |
| 507 | case VLIB_NODE_TYPE_PRE_INPUT: |
| 508 | type_str = "pre-input"; |
| 509 | break; |
| 510 | case VLIB_NODE_TYPE_PROCESS: |
| 511 | type_str = "process"; |
| 512 | break; |
| 513 | default: |
| 514 | type_str = "unknown"; |
| 515 | } |
| 516 | |
| 517 | if (n->sibling_of) |
| 518 | s = format (s, ", sibling-of %s", n->sibling_of); |
| 519 | |
| 520 | vlib_cli_output (vm, "node %s, type %s, state %U, index %d%v\n", |
| 521 | n->name, type_str, format_vlib_node_state, vm, n, |
| 522 | n->index, s); |
| 523 | vec_reset_length (s); |
| 524 | |
| 525 | if (n->node_fn_registrations) |
| 526 | { |
| 527 | vlib_node_fn_registration_t *fnr = n->node_fn_registrations; |
| 528 | while (fnr) |
| 529 | { |
| 530 | if (vec_len (s) == 0) |
| 531 | s = format (s, "\n %-15s %=8s %6s", |
| 532 | "Name", "Priority", "Active"); |
| 533 | s = format (s, "\n %-15s %=8u %=6s", fnr->name, fnr->priority, |
| 534 | fnr->function == n->function ? "yes" : ""); |
| 535 | fnr = fnr->next_registration; |
| 536 | } |
| 537 | } |
| 538 | else |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 539 | s = format (s, "\n default only"); |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 540 | vlib_cli_output (vm, " node function variants:%v\n", s); |
| 541 | vec_reset_length (s); |
| 542 | |
| 543 | for (i = 0; i < vec_len (n->next_nodes); i++) |
| 544 | { |
| 545 | vlib_node_t *pn; |
| 546 | if (n->next_nodes[i] == VLIB_INVALID_NODE_INDEX) |
| 547 | continue; |
| 548 | |
| 549 | pn = vec_elt (nm->nodes, n->next_nodes[i]); |
| 550 | |
| 551 | if (vec_len (s) == 0) |
| 552 | s = format (s, "\n %10s %10s %=30s %8s", |
| 553 | "next-index", "node-index", "Node", "Vectors"); |
| 554 | |
| 555 | s = format (s, "\n %=10u %=10u %-30v %=8llu", i, n->next_nodes[i], |
| 556 | pn->name, vec_elt (n->n_vectors_by_next_node, i)); |
| 557 | } |
| 558 | |
| 559 | if (vec_len (s) == 0) |
| 560 | s = format (s, "\n none"); |
| 561 | vlib_cli_output (vm, "\n next nodes:%v\n", s); |
| 562 | vec_reset_length (s); |
| 563 | |
| 564 | if (n->type == VLIB_NODE_TYPE_INTERNAL) |
| 565 | { |
| 566 | int j = 0; |
| 567 | /* *INDENT-OFF* */ |
| 568 | clib_bitmap_foreach (i, n->prev_node_bitmap, ({ |
| 569 | vlib_node_t *pn = vlib_get_node (vm, i); |
| 570 | if (j++ % 3 == 0) |
| 571 | s = format (s, "\n "); |
| 572 | s2 = format (s2, "%v (%u)", pn->name, i); |
| 573 | s = format (s, "%-35v", s2); |
| 574 | vec_reset_length (s2); |
| 575 | })); |
| 576 | /* *INDENT-ON* */ |
| 577 | |
| 578 | if (vec_len (s) == 0) |
| 579 | s = format (s, "\n none"); |
| 580 | vlib_cli_output (vm, "\n known previous nodes:%v\n", s); |
| 581 | vec_reset_length (s); |
| 582 | } |
| 583 | |
| 584 | vec_free (s); |
| 585 | vec_free (s2); |
| 586 | return 0; |
| 587 | } |
| 588 | |
| 589 | /* *INDENT-OFF* */ |
| 590 | VLIB_CLI_COMMAND (show_node_command, static) = { |
| 591 | .path = "show node", |
| 592 | .short_help = "show node [index] <node-name | node-index>", |
| 593 | .function = show_node, |
| 594 | }; |
| 595 | |
| 596 | static clib_error_t * |
| 597 | set_node_fn(vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) |
| 598 | { |
| 599 | unformat_input_t _line_input, *line_input = &_line_input; |
| 600 | u32 node_index; |
| 601 | vlib_node_t *n; |
| 602 | clib_error_t *err = 0; |
| 603 | vlib_node_fn_registration_t *fnr; |
| 604 | u8 *variant = 0; |
| 605 | |
| 606 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 607 | return 0; |
| 608 | |
| 609 | if (!unformat (line_input, "%U", unformat_vlib_node, vm, &node_index)) |
| 610 | { |
| 611 | err = clib_error_return (0, "please specify valid node name"); |
| 612 | goto done; |
| 613 | } |
| 614 | |
| 615 | if (!unformat (line_input, "%s", &variant)) |
| 616 | { |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 617 | err = clib_error_return (0, "please specify node functional variant"); |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 618 | goto done; |
| 619 | } |
| 620 | |
| 621 | n = vlib_get_node (vm, node_index); |
| 622 | |
| 623 | if (n->node_fn_registrations == 0) |
| 624 | { |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 625 | err = clib_error_return (0, "node doesn't have functional variants"); |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 626 | goto done; |
| 627 | } |
| 628 | |
| 629 | fnr = n->node_fn_registrations; |
| 630 | vec_add1 (variant, 0); |
| 631 | |
| 632 | while (fnr) |
| 633 | { |
| 634 | if (!strncmp (fnr->name, (char *) variant, vec_len (variant) - 1)) |
| 635 | { |
| 636 | int i; |
| 637 | |
| 638 | n->function = fnr->function; |
| 639 | |
| 640 | for (i = 0; i < vec_len (vlib_mains); i++) |
| 641 | { |
| 642 | vlib_node_runtime_t *nrt; |
| 643 | nrt = vlib_node_get_runtime (vlib_mains[i], n->index); |
| 644 | nrt->function = fnr->function; |
| 645 | } |
| 646 | goto done; |
| 647 | } |
| 648 | fnr = fnr->next_registration; |
| 649 | } |
| 650 | |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 651 | err = clib_error_return (0, "node functional variant '%s' not found", variant); |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 652 | |
| 653 | done: |
| 654 | vec_free (variant); |
| 655 | unformat_free (line_input); |
| 656 | return err; |
| 657 | } |
| 658 | |
| 659 | /* *INDENT-OFF* */ |
| 660 | VLIB_CLI_COMMAND (set_node_fn_command, static) = { |
| 661 | .path = "set node function", |
| 662 | .short_help = "set node function <node-name> <variant-name>", |
| 663 | .function = set_node_fn, |
| 664 | }; |
| 665 | /* *INDENT-ON* */ |
| 666 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 667 | /* Dummy function to get us linked in. */ |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 668 | void |
| 669 | vlib_node_cli_reference (void) |
| 670 | { |
| 671 | } |
| 672 | |
| 673 | /* |
| 674 | * fd.io coding-style-patch-verification: ON |
| 675 | * |
| 676 | * Local Variables: |
| 677 | * eval: (c-set-style "gnu") |
| 678 | * End: |
| 679 | */ |