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 | |
Benoît Ganne | 362456a | 2019-01-21 17:41:25 +0100 | [diff] [blame] | 40 | #include <sys/types.h> |
| 41 | #include <sys/stat.h> |
| 42 | #include <fcntl.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 43 | #include <vlib/vlib.h> |
| 44 | #include <vlib/threads.h> |
Damjan Marion | 8973b07 | 2022-03-01 15:51:18 +0100 | [diff] [blame] | 45 | #include <vlib/stats/stats.h> |
Arthur de Kerhor | 156158f | 2021-02-18 03:09:42 -0800 | [diff] [blame] | 46 | #include <math.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 47 | |
Matus Fabian | d2dc3df | 2015-12-14 10:31:33 -0500 | [diff] [blame] | 48 | static int |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 49 | node_cmp (void *a1, void *a2) |
Matus Fabian | d2dc3df | 2015-12-14 10:31:33 -0500 | [diff] [blame] | 50 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 51 | vlib_node_t **n1 = a1; |
| 52 | vlib_node_t **n2 = a2; |
Matus Fabian | d2dc3df | 2015-12-14 10:31:33 -0500 | [diff] [blame] | 53 | |
| 54 | return vec_cmp (n1[0]->name, n2[0]->name); |
| 55 | } |
| 56 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 57 | static clib_error_t * |
| 58 | show_node_graph (vlib_main_t * vm, |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 59 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 60 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 61 | vlib_node_main_t *nm = &vm->node_main; |
| 62 | vlib_node_t *n; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 63 | u32 node_index; |
| 64 | |
| 65 | vlib_cli_output (vm, "%U\n", format_vlib_node_graph, nm, 0); |
| 66 | |
| 67 | if (unformat (input, "%U", unformat_vlib_node, vm, &node_index)) |
| 68 | { |
| 69 | n = vlib_get_node (vm, node_index); |
| 70 | vlib_cli_output (vm, "%U\n", format_vlib_node_graph, nm, n); |
| 71 | } |
| 72 | else |
| 73 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 74 | vlib_node_t **nodes = vec_dup (nm->nodes); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 75 | uword i; |
| 76 | |
Matus Fabian | d2dc3df | 2015-12-14 10:31:33 -0500 | [diff] [blame] | 77 | vec_sort_with_function (nodes, node_cmp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 78 | |
| 79 | for (i = 0; i < vec_len (nodes); i++) |
| 80 | vlib_cli_output (vm, "%U\n\n", format_vlib_node_graph, nm, nodes[i]); |
| 81 | |
| 82 | vec_free (nodes); |
| 83 | } |
| 84 | |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | VLIB_CLI_COMMAND (show_node_graph_command, static) = { |
| 89 | .path = "show vlib graph", |
| 90 | .short_help = "Show packet processing node graph", |
| 91 | .function = show_node_graph, |
| 92 | }; |
| 93 | |
Benoît Ganne | 362456a | 2019-01-21 17:41:25 +0100 | [diff] [blame] | 94 | static clib_error_t * |
| 95 | show_node_graphviz (vlib_main_t * vm, |
| 96 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 97 | { |
| 98 | clib_error_t *error = 0; |
| 99 | vlib_node_main_t *nm = &vm->node_main; |
Arthur de Kerhor | 156158f | 2021-02-18 03:09:42 -0800 | [diff] [blame] | 100 | vlib_node_t **nodes = nm->nodes; |
Benoît Ganne | 362456a | 2019-01-21 17:41:25 +0100 | [diff] [blame] | 101 | u8 *chroot_filename = 0; |
| 102 | int fd; |
Arthur de Kerhor | 156158f | 2021-02-18 03:09:42 -0800 | [diff] [blame] | 103 | uword *active = 0; |
| 104 | u32 i, j; |
| 105 | unformat_input_t _line_input, *line_input = &_line_input; |
| 106 | u8 filter = 0, calls_filter = 0, vectors_filter = 0, both = 0; |
Benoît Ganne | 362456a | 2019-01-21 17:41:25 +0100 | [diff] [blame] | 107 | |
Arthur de Kerhor | 156158f | 2021-02-18 03:09:42 -0800 | [diff] [blame] | 108 | fd = -1; |
| 109 | /* Get a line of input. */ |
| 110 | if (unformat_user (input, unformat_line_input, line_input)) |
Benoît Ganne | 362456a | 2019-01-21 17:41:25 +0100 | [diff] [blame] | 111 | { |
Arthur de Kerhor | 156158f | 2021-02-18 03:09:42 -0800 | [diff] [blame] | 112 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 113 | { |
| 114 | if (unformat (line_input, "filter")) |
| 115 | filter = 1; |
| 116 | else if (unformat (line_input, "calls") && filter) |
| 117 | calls_filter = 1; |
| 118 | else if (unformat (line_input, "vectors") && filter) |
| 119 | vectors_filter = 1; |
| 120 | else if (unformat (line_input, "file %U", unformat_vlib_tmpfile, |
| 121 | &chroot_filename)) |
| 122 | { |
| 123 | fd = open ((char *) chroot_filename, |
| 124 | O_CREAT | O_TRUNC | O_WRONLY, 0664); |
| 125 | } |
| 126 | else |
| 127 | return clib_error_return (0, "unknown input `%U'", |
| 128 | format_unformat_error, input); |
| 129 | } |
| 130 | unformat_free (line_input); |
Benoît Ganne | 362456a | 2019-01-21 17:41:25 +0100 | [diff] [blame] | 131 | } |
Arthur de Kerhor | 156158f | 2021-02-18 03:09:42 -0800 | [diff] [blame] | 132 | |
| 133 | /*both is set to true if calls_filter and vectors_filter are, or neither */ |
| 134 | both = filter & (!(calls_filter ^ vectors_filter)); |
Benoît Ganne | 362456a | 2019-01-21 17:41:25 +0100 | [diff] [blame] | 135 | |
| 136 | #define format__(vm__, fd__, ...) \ |
| 137 | if ((fd) < 0) \ |
| 138 | { \ |
| 139 | vlib_cli_output((vm__), ## __VA_ARGS__); \ |
| 140 | } \ |
| 141 | else \ |
| 142 | { \ |
| 143 | fdformat((fd__), ## __VA_ARGS__); \ |
| 144 | } |
| 145 | |
| 146 | format__ (vm, fd, "%s", "digraph {\n"); |
| 147 | |
Arthur de Kerhor | 156158f | 2021-02-18 03:09:42 -0800 | [diff] [blame] | 148 | clib_bitmap_alloc (active, vec_len (nodes)); |
| 149 | clib_bitmap_set_region (active, 0, 1, vec_len (nodes)); |
| 150 | if (filter) |
Benoît Ganne | 362456a | 2019-01-21 17:41:25 +0100 | [diff] [blame] | 151 | { |
Arthur de Kerhor | 156158f | 2021-02-18 03:09:42 -0800 | [diff] [blame] | 152 | /*Adding the legend to the dot file*/ |
| 153 | format__ (vm, fd, "%s", |
| 154 | " rankdir=\"LR\"\n nodesep=2\n subgraph cluster_legend {\n " |
| 155 | " label=\"Legend\"\n style=\"solid\"\n labelloc = b\n " |
| 156 | " subgraph cluster_colors {\n label=\"Packets/Call\"\n " |
| 157 | " style=\"solid\"\n labelloc = b\n"); |
| 158 | format__ (vm, fd, "%s", |
| 159 | " 0 [label=\"No packet\", fixedsize=true shape=circle " |
| 160 | "width=2 fontsize=17]\n" |
| 161 | " 1 [label=\"1-32\", fillcolor=1 style=filled " |
| 162 | "colorscheme=ylorrd8 fixedsize=true shape=circle width=2 " |
| 163 | "fontsize=17]\n" |
| 164 | " 2 [label=\"33-64\", fillcolor=2 style=filled " |
| 165 | "colorscheme=ylorrd8 fixedsize=true shape=circle width=2 " |
| 166 | "fontsize=17]\n" |
| 167 | " 3 [label=\"65-96\", fillcolor=3 style=filled " |
| 168 | "colorscheme=ylorrd8 fixedsize=true shape=circle width=2 " |
| 169 | "fontsize=17]\n" |
| 170 | " 4 [label=\"97-128\", fillcolor=4 style=filled " |
| 171 | "colorscheme=ylorrd8 fixedsize=true shape=circle width=2 " |
| 172 | "fontsize=17]\n" |
| 173 | " 5 [label=\"129-160\", fillcolor=5 style=filled " |
| 174 | "colorscheme=ylorrd8 fixedsize=true shape=circle width=2 " |
| 175 | "fontsize=17]\n" |
| 176 | " 6 [label=\"161-192\", fillcolor=6 style=filled " |
| 177 | "colorscheme=ylorrd8 fixedsize=true shape=circle width=2 " |
| 178 | "fontsize=17]\n" |
| 179 | " 7 [label=\"193-224\", fillcolor=7 style=filled " |
| 180 | "colorscheme=ylorrd8 fixedsize=true shape=circle width=2 " |
| 181 | "fontsize=17]\n" |
| 182 | " 8 [label=\"224+\", fillcolor=8 style=filled " |
| 183 | "colorscheme=ylorrd8 fixedsize=true shape=circle width=2 " |
| 184 | "fontsize=17]\n"); |
| 185 | format__ (vm, fd, "%s", |
| 186 | " 0 -> 1 -> 2 -> 3 -> 4 [style=\"invis\",weight =100]\n " |
| 187 | " 5 -> 6 -> 7 -> 8 [style=\"invis\",weight =100]\n }\n " |
| 188 | " subgraph cluster_size {\n label=\"Cycles/Packet\"\n " |
| 189 | " style=\"solid\"\n labelloc = b\n"); |
| 190 | format__ ( |
| 191 | vm, fd, "%s", |
| 192 | " a[label=\"0\",fixedsize=true shape=circle width=1] \n" |
| 193 | " b[label=\"10\",fixedsize=true shape=circle width=2 " |
| 194 | "fontsize=17]\n" |
| 195 | " c[label=\"100\",fixedsize=true shape=circle width=3 " |
| 196 | "fontsize=20]\n" |
| 197 | " d[label=\"1000\",fixedsize=true shape=circle width=4 " |
| 198 | "fontsize=23]\n" |
| 199 | " a -> b -> c -> d [style=\"invis\",weight =100]\n }\n }\n"); |
| 200 | |
| 201 | vlib_worker_thread_barrier_sync (vm); |
| 202 | for (j = 0; j < vec_len (nm->nodes); j++) |
Benoît Ganne | 362456a | 2019-01-21 17:41:25 +0100 | [diff] [blame] | 203 | { |
Arthur de Kerhor | 156158f | 2021-02-18 03:09:42 -0800 | [diff] [blame] | 204 | vlib_node_t *n; |
| 205 | n = nm->nodes[j]; |
| 206 | vlib_node_sync_stats (vm, n); |
| 207 | } |
Benoît Ganne | 362456a | 2019-01-21 17:41:25 +0100 | [diff] [blame] | 208 | |
Arthur de Kerhor | 156158f | 2021-02-18 03:09:42 -0800 | [diff] [blame] | 209 | /* Updating the stats for multithreaded use cases. |
| 210 | * We need to dup the nodes to sum the stats from all threads.*/ |
| 211 | nodes = vec_dup (nm->nodes); |
Damjan Marion | 6ffb7c6 | 2021-03-26 13:06:13 +0100 | [diff] [blame] | 212 | for (i = 1; i < vlib_get_n_threads (); i++) |
Arthur de Kerhor | 156158f | 2021-02-18 03:09:42 -0800 | [diff] [blame] | 213 | { |
| 214 | vlib_node_main_t *nm_clone; |
| 215 | vlib_main_t *vm_clone; |
| 216 | vlib_node_runtime_t *rt; |
| 217 | vlib_node_t *n; |
Benoît Ganne | 362456a | 2019-01-21 17:41:25 +0100 | [diff] [blame] | 218 | |
Damjan Marion | 6ffb7c6 | 2021-03-26 13:06:13 +0100 | [diff] [blame] | 219 | vm_clone = vlib_get_main_by_index (i); |
Arthur de Kerhor | 156158f | 2021-02-18 03:09:42 -0800 | [diff] [blame] | 220 | nm_clone = &vm_clone->node_main; |
| 221 | |
| 222 | for (j = 0; j < vec_len (nm_clone->nodes); j++) |
| 223 | { |
| 224 | n = nm_clone->nodes[j]; |
| 225 | |
| 226 | rt = vlib_node_get_runtime (vm_clone, n->index); |
| 227 | /* Sync the stats directly in the duplicated node.*/ |
| 228 | vlib_node_runtime_sync_stats_node (nodes[j], rt, 0, 0, 0); |
| 229 | } |
| 230 | } |
| 231 | vlib_worker_thread_barrier_release (vm); |
| 232 | |
| 233 | for (i = 0; i < vec_len (nodes); i++) |
| 234 | { |
| 235 | u64 p, c, l; |
| 236 | c = nodes[i]->stats_total.calls - nodes[i]->stats_last_clear.calls; |
| 237 | p = |
| 238 | nodes[i]->stats_total.vectors - nodes[i]->stats_last_clear.vectors; |
| 239 | l = nodes[i]->stats_total.clocks - nodes[i]->stats_last_clear.clocks; |
| 240 | |
| 241 | if ((both && c > 0 && p > 0) || (calls_filter && c > 0) || |
| 242 | (vectors_filter && p > 0)) |
| 243 | { |
| 244 | format__ (vm, fd, " \"%v\" [shape=circle", nodes[i]->name); |
| 245 | /*Changing the size and the font of nodes that receive packets*/ |
| 246 | if (p > 0) |
| 247 | { |
| 248 | f64 x = (f64) l / (f64) p; |
| 249 | f64 size_ratio = (1 + log10 (x + 1)); |
| 250 | format__ (vm, fd, " width=%.2f fontsize=%.2f fixedsize=true", |
| 251 | size_ratio, 11 + 3 * size_ratio); |
| 252 | /*Coloring nodes that are indeed called*/ |
| 253 | if (c > 0) |
| 254 | { |
| 255 | u64 color = ((p - 1) / (32 * c)) + 1; |
| 256 | color = clib_min (color, 8); |
| 257 | format__ ( |
| 258 | vm, fd, |
| 259 | " fillcolor=%u style=filled colorscheme=ylorrd8", |
| 260 | color); |
| 261 | } |
| 262 | } |
| 263 | format__ (vm, fd, "]\n"); |
| 264 | } |
| 265 | else |
| 266 | { |
| 267 | clib_bitmap_set (active, i, 0); |
| 268 | } |
Benoît Ganne | 362456a | 2019-01-21 17:41:25 +0100 | [diff] [blame] | 269 | } |
| 270 | } |
| 271 | |
Arthur de Kerhor | 156158f | 2021-02-18 03:09:42 -0800 | [diff] [blame] | 272 | clib_bitmap_foreach (i, active) |
| 273 | { |
| 274 | for (j = 0; j < vec_len (nodes[i]->next_nodes); j++) |
| 275 | { |
| 276 | if (nodes[i]->next_nodes[j] == VLIB_INVALID_NODE_INDEX) |
| 277 | continue; |
| 278 | |
| 279 | if (!filter || clib_bitmap_get (active, nodes[i]->next_nodes[j])) |
| 280 | { |
| 281 | format__ (vm, fd, " \"%v\" -> \"%v\"\n", nodes[i]->name, |
| 282 | nodes[nodes[i]->next_nodes[j]]->name); |
| 283 | } |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | format__ (vm, fd, "}\n"); |
Benoît Ganne | 362456a | 2019-01-21 17:41:25 +0100 | [diff] [blame] | 288 | |
| 289 | if (fd >= 0) |
| 290 | { |
Arthur de Kerhor | 156158f | 2021-02-18 03:09:42 -0800 | [diff] [blame] | 291 | /*Dumping all the nodes saturates dot capacities to render a directed |
| 292 | * graph. In this case, prefer using he fdp command to generate an |
| 293 | * undirected graph. */ |
| 294 | const char *soft = filter ? "dot" : "fdp"; |
| 295 | vlib_cli_output ( |
| 296 | vm, "vlib graph dumped into `%s'. Run eg. `%s -Tsvg -O %s'.", |
| 297 | chroot_filename, soft, chroot_filename); |
Benoît Ganne | 362456a | 2019-01-21 17:41:25 +0100 | [diff] [blame] | 298 | } |
| 299 | |
Arthur de Kerhor | 156158f | 2021-02-18 03:09:42 -0800 | [diff] [blame] | 300 | clib_bitmap_free (active); |
Benoît Ganne | 362456a | 2019-01-21 17:41:25 +0100 | [diff] [blame] | 301 | vec_free (chroot_filename); |
Arthur de Kerhor | 156158f | 2021-02-18 03:09:42 -0800 | [diff] [blame] | 302 | if (filter) |
| 303 | vec_free (nodes); |
Benoît Ganne | 362456a | 2019-01-21 17:41:25 +0100 | [diff] [blame] | 304 | if (fd >= 0) |
| 305 | close (fd); |
| 306 | return error; |
| 307 | } |
| 308 | |
Arthur de Kerhor | 156158f | 2021-02-18 03:09:42 -0800 | [diff] [blame] | 309 | /*? |
| 310 | * Dump dot files data to draw a graph of all the nodes. |
| 311 | * If the argument 'filter' is provided, only the active nodes (since the last |
Nathan Skrzypczak | ecd6b1a | 2021-09-29 15:35:31 +0200 | [diff] [blame] | 312 | * "clear run" command) are selected and they are scaled and colored according |
Arthur de Kerhor | 156158f | 2021-02-18 03:09:42 -0800 | [diff] [blame] | 313 | * to their utilization. You can choose to filter nodes that are called, |
| 314 | * nodes that receive vectors or both (default). |
| 315 | * The 'file' option allows to save data in a temp file. |
| 316 | * |
| 317 | * @cliexpar |
| 318 | * @clistart |
| 319 | * show vlib graphviz |
| 320 | * show vlib graphviz filter file tmpfile |
| 321 | * show vlib graphviz filter calls file tmpfile |
| 322 | * @cliend |
| 323 | * @cliexcmd{show vlib graphviz [filter][calls][vectors][file <filename>]} |
| 324 | ?*/ |
Benoît Ganne | 362456a | 2019-01-21 17:41:25 +0100 | [diff] [blame] | 325 | VLIB_CLI_COMMAND (show_node_graphviz_command, static) = { |
| 326 | .path = "show vlib graphviz", |
| 327 | .short_help = "Dump packet processing node graph as a graphviz dotfile", |
| 328 | .function = show_node_graphviz, |
Arthur de Kerhor | 156158f | 2021-02-18 03:09:42 -0800 | [diff] [blame] | 329 | .is_mp_safe = 1, |
Benoît Ganne | 362456a | 2019-01-21 17:41:25 +0100 | [diff] [blame] | 330 | }; |
Benoît Ganne | 362456a | 2019-01-21 17:41:25 +0100 | [diff] [blame] | 331 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 332 | static u8 * |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 333 | format_vlib_node_state (u8 * s, va_list * va) |
| 334 | { |
| 335 | vlib_main_t *vm = va_arg (*va, vlib_main_t *); |
| 336 | vlib_node_t *n = va_arg (*va, vlib_node_t *); |
| 337 | char *state; |
| 338 | |
| 339 | state = "active"; |
| 340 | if (n->type == VLIB_NODE_TYPE_PROCESS) |
| 341 | { |
| 342 | vlib_process_t *p = vlib_get_process_from_node (vm, n); |
| 343 | |
| 344 | switch (p->flags & (VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK |
| 345 | | VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT)) |
| 346 | { |
| 347 | default: |
| 348 | if (!(p->flags & VLIB_PROCESS_IS_RUNNING)) |
| 349 | state = "done"; |
| 350 | break; |
| 351 | |
| 352 | case VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK: |
| 353 | state = "time wait"; |
| 354 | break; |
| 355 | |
| 356 | case VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT: |
| 357 | state = "event wait"; |
| 358 | break; |
| 359 | |
| 360 | case (VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT | VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK): |
| 361 | state = |
| 362 | "any wait"; |
| 363 | break; |
| 364 | } |
| 365 | } |
| 366 | else if (n->type != VLIB_NODE_TYPE_INTERNAL) |
| 367 | { |
| 368 | state = "polling"; |
| 369 | if (n->state == VLIB_NODE_STATE_DISABLED) |
| 370 | state = "disabled"; |
| 371 | else if (n->state == VLIB_NODE_STATE_INTERRUPT) |
| 372 | state = "interrupt wait"; |
| 373 | } |
| 374 | |
| 375 | return format (s, "%s", state); |
| 376 | } |
| 377 | |
| 378 | static u8 * |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 379 | format_vlib_node_stats (u8 * s, va_list * va) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 380 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 381 | vlib_main_t *vm = va_arg (*va, vlib_main_t *); |
| 382 | vlib_node_t *n = va_arg (*va, vlib_node_t *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 383 | int max = va_arg (*va, int); |
| 384 | f64 v; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 385 | u8 *ns; |
| 386 | u8 *misc_info = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 387 | u64 c, p, l, d; |
| 388 | f64 x; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 389 | f64 maxc, maxcn; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 390 | u32 maxn; |
Christophe Fontaine | d3c008d | 2017-10-02 18:10:54 +0200 | [diff] [blame] | 391 | u32 indent; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 392 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 393 | if (!n) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 394 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 395 | if (max) |
Dave Barach | 4d1a866 | 2018-09-10 12:31:15 -0400 | [diff] [blame] | 396 | s = format (s, |
| 397 | "%=30s%=17s%=16s%=16s%=16s%=16s", |
| 398 | "Name", "Max Node Clocks", "Vectors at Max", |
| 399 | "Max Clocks", "Avg Clocks", "Avg Vectors/Call"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 400 | else |
Dave Barach | 4d1a866 | 2018-09-10 12:31:15 -0400 | [diff] [blame] | 401 | s = format (s, |
| 402 | "%=30s%=12s%=16s%=16s%=16s%=16s%=16s", |
| 403 | "Name", "State", "Calls", "Vectors", "Suspends", |
| 404 | "Clocks", "Vectors/Call"); |
Dave Barach | 4d1a866 | 2018-09-10 12:31:15 -0400 | [diff] [blame] | 405 | return s; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | indent = format_get_indent (s); |
| 409 | |
| 410 | l = n->stats_total.clocks - n->stats_last_clear.clocks; |
| 411 | c = n->stats_total.calls - n->stats_last_clear.calls; |
| 412 | p = n->stats_total.vectors - n->stats_last_clear.vectors; |
| 413 | d = n->stats_total.suspends - n->stats_last_clear.suspends; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 414 | maxc = (f64) n->stats_total.max_clock; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 415 | maxn = n->stats_total.max_clock_n; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 416 | if (n->stats_total.max_clock_n) |
| 417 | maxcn = (f64) n->stats_total.max_clock / (f64) maxn; |
| 418 | else |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 419 | maxcn = 0.0; |
| 420 | |
| 421 | /* Clocks per packet, per call or per suspend. */ |
| 422 | x = 0; |
| 423 | if (p > 0) |
| 424 | x = (f64) l / (f64) p; |
| 425 | else if (c > 0) |
| 426 | x = (f64) l / (f64) c; |
| 427 | else if (d > 0) |
| 428 | x = (f64) l / (f64) d; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 429 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 430 | if (c > 0) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 431 | v = (double) p / (double) c; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 432 | else |
| 433 | v = 0; |
| 434 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 435 | if (n->type == VLIB_NODE_TYPE_PROCESS) |
| 436 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 437 | vlib_process_t *p = vlib_get_process_from_node (vm, n); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 438 | |
| 439 | /* 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] | 440 | being handled. */ |
| 441 | if (!clib_bitmap_is_zero (p->non_empty_event_type_bitmap)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 442 | misc_info = format (misc_info, "events pending, "); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 443 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 444 | ns = n->name; |
| 445 | |
| 446 | if (max) |
| 447 | 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] | 448 | ns, maxc, maxn, maxcn, x, v); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 449 | else |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 450 | s = format (s, "%-30v%=12U%16Ld%16Ld%16Ld%16.2e%16.2f", ns, |
| 451 | format_vlib_node_state, vm, n, c, p, d, x, v); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 452 | |
| 453 | if (ns != n->name) |
| 454 | vec_free (ns); |
| 455 | |
| 456 | if (misc_info) |
| 457 | { |
| 458 | s = format (s, "\n%U%v", format_white_space, indent + 4, misc_info); |
| 459 | vec_free (misc_info); |
| 460 | } |
| 461 | |
| 462 | return s; |
| 463 | } |
| 464 | |
| 465 | static clib_error_t * |
| 466 | show_node_runtime (vlib_main_t * vm, |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 467 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 468 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 469 | vlib_node_main_t *nm = &vm->node_main; |
| 470 | vlib_node_t *n; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 471 | f64 time_now; |
| 472 | u32 node_index; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 473 | vlib_node_t ***node_dups = 0; |
Dave Barach | a8df85c | 2019-10-01 13:34:23 -0400 | [diff] [blame] | 474 | f64 *internal_node_vector_rates = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 475 | |
| 476 | time_now = vlib_time_now (vm); |
| 477 | |
| 478 | if (unformat (input, "%U", unformat_vlib_node, vm, &node_index)) |
| 479 | { |
| 480 | n = vlib_get_node (vm, node_index); |
| 481 | vlib_node_sync_stats (vm, n); |
| 482 | vlib_cli_output (vm, "%U\n", format_vlib_node_stats, vm, 0, 0); |
| 483 | vlib_cli_output (vm, "%U\n", format_vlib_node_stats, vm, n, 0); |
| 484 | } |
| 485 | else |
| 486 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 487 | vlib_node_t **nodes; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 488 | uword i, j; |
| 489 | f64 dt; |
| 490 | u64 n_input, n_output, n_drop, n_punt; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 491 | u64 n_clocks, l, v, c, d; |
| 492 | int brief = 1; |
Dave Barach | ac78f8a | 2019-10-04 09:59:00 -0400 | [diff] [blame] | 493 | int summary = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 494 | int max = 0; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 495 | vlib_main_t **stat_vms = 0, *stat_vm; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 496 | |
| 497 | /* Suppress nodes with zero calls since last clear */ |
| 498 | if (unformat (input, "brief") || unformat (input, "b")) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 499 | brief = 1; |
| 500 | if (unformat (input, "verbose") || unformat (input, "v")) |
| 501 | brief = 0; |
| 502 | if (unformat (input, "max") || unformat (input, "m")) |
| 503 | max = 1; |
Dave Barach | ac78f8a | 2019-10-04 09:59:00 -0400 | [diff] [blame] | 504 | if (unformat (input, "summary") || unformat (input, "sum") |
| 505 | || unformat (input, "su")) |
| 506 | summary = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 507 | |
Damjan Marion | 6ffb7c6 | 2021-03-26 13:06:13 +0100 | [diff] [blame] | 508 | for (i = 0; i < vlib_get_n_threads (); i++) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 509 | { |
Damjan Marion | 6ffb7c6 | 2021-03-26 13:06:13 +0100 | [diff] [blame] | 510 | stat_vm = vlib_get_main_by_index (i); |
Dave Barach | 80f54e2 | 2017-03-08 19:08:56 -0500 | [diff] [blame] | 511 | if (stat_vm) |
| 512 | vec_add1 (stat_vms, stat_vm); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 513 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 514 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 515 | /* |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 516 | * Barrier sync across stats scraping. |
| 517 | * Otherwise, the counts will be grossly inaccurate. |
| 518 | */ |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 519 | vlib_worker_thread_barrier_sync (vm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 520 | |
| 521 | for (j = 0; j < vec_len (stat_vms); j++) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 522 | { |
| 523 | stat_vm = stat_vms[j]; |
| 524 | nm = &stat_vm->node_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 525 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 526 | for (i = 0; i < vec_len (nm->nodes); i++) |
| 527 | { |
| 528 | n = nm->nodes[i]; |
| 529 | vlib_node_sync_stats (stat_vm, n); |
| 530 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 531 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 532 | nodes = vec_dup (nm->nodes); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 533 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 534 | vec_add1 (node_dups, nodes); |
Dave Barach | a8df85c | 2019-10-01 13:34:23 -0400 | [diff] [blame] | 535 | vec_add1 (internal_node_vector_rates, |
| 536 | vlib_internal_node_vector_rate (stat_vm)); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 537 | } |
| 538 | vlib_worker_thread_barrier_release (vm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 539 | |
| 540 | |
| 541 | for (j = 0; j < vec_len (stat_vms); j++) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 542 | { |
| 543 | stat_vm = stat_vms[j]; |
| 544 | nodes = node_dups[j]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 545 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 546 | vec_sort_with_function (nodes, node_cmp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 547 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 548 | n_input = n_output = n_drop = n_punt = n_clocks = 0; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 549 | for (i = 0; i < vec_len (nodes); i++) |
| 550 | { |
| 551 | n = nodes[i]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 552 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 553 | l = n->stats_total.clocks - n->stats_last_clear.clocks; |
| 554 | n_clocks += l; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 555 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 556 | v = n->stats_total.vectors - n->stats_last_clear.vectors; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 557 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 558 | switch (n->type) |
| 559 | { |
| 560 | default: |
| 561 | continue; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 562 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 563 | case VLIB_NODE_TYPE_INTERNAL: |
| 564 | n_output += (n->flags & VLIB_NODE_FLAG_IS_OUTPUT) ? v : 0; |
| 565 | n_drop += (n->flags & VLIB_NODE_FLAG_IS_DROP) ? v : 0; |
| 566 | n_punt += (n->flags & VLIB_NODE_FLAG_IS_PUNT) ? v : 0; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 567 | if (n->flags & VLIB_NODE_FLAG_IS_HANDOFF) |
| 568 | n_input += v; |
| 569 | break; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 570 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 571 | case VLIB_NODE_TYPE_INPUT: |
| 572 | n_input += v; |
| 573 | break; |
| 574 | } |
| 575 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 576 | |
Damjan Marion | 6ffb7c6 | 2021-03-26 13:06:13 +0100 | [diff] [blame] | 577 | if (vlib_get_n_threads () > 1) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 578 | { |
| 579 | vlib_worker_thread_t *w = vlib_worker_threads + j; |
| 580 | if (j > 0) |
| 581 | vlib_cli_output (vm, "---------------"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 582 | |
Mohsin Kazmi | 5d64c78 | 2018-09-11 20:27:09 +0200 | [diff] [blame] | 583 | if (w->cpu_id > -1) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 584 | vlib_cli_output (vm, "Thread %d %s (lcore %u)", j, w->name, |
Mohsin Kazmi | 5d64c78 | 2018-09-11 20:27:09 +0200 | [diff] [blame] | 585 | w->cpu_id); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 586 | else |
| 587 | vlib_cli_output (vm, "Thread %d %s", j, w->name); |
| 588 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 589 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 590 | dt = time_now - nm->time_last_runtime_stats_clear; |
Damjan Marion | 8973b07 | 2022-03-01 15:51:18 +0100 | [diff] [blame] | 591 | vlib_cli_output ( |
| 592 | vm, |
| 593 | "Time %.1f, %f sec internal node vector rate %.2f loops/sec %.2f\n" |
| 594 | " vector rates in %.4e, out %.4e, drop %.4e, punt %.4e", |
| 595 | dt, vlib_stats_get_segment_update_rate (), |
| 596 | internal_node_vector_rates[j], stat_vm->loops_per_second, |
| 597 | (f64) n_input / dt, (f64) n_output / dt, (f64) n_drop / dt, |
| 598 | (f64) n_punt / dt); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 599 | |
Dave Barach | ac78f8a | 2019-10-04 09:59:00 -0400 | [diff] [blame] | 600 | if (summary == 0) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 601 | { |
Dave Barach | ac78f8a | 2019-10-04 09:59:00 -0400 | [diff] [blame] | 602 | vlib_cli_output (vm, "%U", format_vlib_node_stats, stat_vm, |
| 603 | 0, max); |
| 604 | for (i = 0; i < vec_len (nodes); i++) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 605 | { |
Dave Barach | ac78f8a | 2019-10-04 09:59:00 -0400 | [diff] [blame] | 606 | c = |
| 607 | nodes[i]->stats_total.calls - |
| 608 | nodes[i]->stats_last_clear.calls; |
| 609 | d = |
| 610 | nodes[i]->stats_total.suspends - |
| 611 | nodes[i]->stats_last_clear.suspends; |
| 612 | if (c || d || !brief) |
| 613 | { |
| 614 | vlib_cli_output (vm, "%U", format_vlib_node_stats, |
| 615 | stat_vm, nodes[i], max); |
| 616 | } |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 617 | } |
| 618 | } |
| 619 | vec_free (nodes); |
| 620 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 621 | vec_free (stat_vms); |
| 622 | vec_free (node_dups); |
Dave Barach | a8df85c | 2019-10-01 13:34:23 -0400 | [diff] [blame] | 623 | vec_free (internal_node_vector_rates); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | return 0; |
| 627 | } |
| 628 | |
| 629 | VLIB_CLI_COMMAND (show_node_runtime_command, static) = { |
| 630 | .path = "show runtime", |
| 631 | .short_help = "Show packet processing runtime", |
| 632 | .function = show_node_runtime, |
| 633 | .is_mp_safe = 1, |
| 634 | }; |
| 635 | |
| 636 | static clib_error_t * |
| 637 | clear_node_runtime (vlib_main_t * vm, |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 638 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 639 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 640 | vlib_node_main_t *nm; |
| 641 | vlib_node_t *n; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 642 | int i, j; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 643 | vlib_main_t **stat_vms = 0, *stat_vm; |
| 644 | vlib_node_runtime_t *r; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 645 | |
Damjan Marion | 6ffb7c6 | 2021-03-26 13:06:13 +0100 | [diff] [blame] | 646 | for (i = 0; i < vlib_get_n_threads (); i++) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 647 | { |
Damjan Marion | 6ffb7c6 | 2021-03-26 13:06:13 +0100 | [diff] [blame] | 648 | stat_vm = vlib_get_main_by_index (i); |
Dave Barach | 80f54e2 | 2017-03-08 19:08:56 -0500 | [diff] [blame] | 649 | if (stat_vm) |
| 650 | vec_add1 (stat_vms, stat_vm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 651 | } |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 652 | |
| 653 | vlib_worker_thread_barrier_sync (vm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 654 | |
| 655 | for (j = 0; j < vec_len (stat_vms); j++) |
| 656 | { |
| 657 | stat_vm = stat_vms[j]; |
| 658 | nm = &stat_vm->node_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 659 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 660 | for (i = 0; i < vec_len (nm->nodes); i++) |
| 661 | { |
| 662 | n = nm->nodes[i]; |
| 663 | vlib_node_sync_stats (stat_vm, n); |
| 664 | n->stats_last_clear = n->stats_total; |
| 665 | |
| 666 | r = vlib_node_get_runtime (stat_vm, n->index); |
| 667 | r->max_clock = 0; |
| 668 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 669 | /* Note: input/output rates computed using vlib_global_main */ |
| 670 | nm->time_last_runtime_stats_clear = vlib_time_now (vm); |
| 671 | } |
| 672 | |
Damjan Marion | 8973b07 | 2022-03-01 15:51:18 +0100 | [diff] [blame] | 673 | vlib_stats_set_timestamp (STAT_COUNTER_LAST_STATS_CLEAR, |
| 674 | vm->node_main.time_last_runtime_stats_clear); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 675 | vlib_worker_thread_barrier_release (vm); |
| 676 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 677 | vec_free (stat_vms); |
| 678 | |
| 679 | return 0; |
| 680 | } |
| 681 | |
| 682 | VLIB_CLI_COMMAND (clear_node_runtime_command, static) = { |
| 683 | .path = "clear runtime", |
| 684 | .short_help = "Clear packet processing runtime statistics", |
| 685 | .function = clear_node_runtime, |
| 686 | }; |
| 687 | |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 688 | static clib_error_t * |
| 689 | show_node (vlib_main_t * vm, unformat_input_t * input, |
| 690 | vlib_cli_command_t * cmd) |
| 691 | { |
| 692 | unformat_input_t _line_input, *line_input = &_line_input; |
Paul Vinciguerra | 98afc71 | 2018-09-25 10:02:07 -0700 | [diff] [blame] | 693 | clib_error_t *error = 0; |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 694 | vlib_node_main_t *nm = &vm->node_main; |
| 695 | vlib_node_t *n; |
| 696 | u8 *s = 0, *s2 = 0; |
Florin Coras | 178ecc0 | 2020-03-12 23:26:11 +0000 | [diff] [blame] | 697 | u32 i, node_index = ~0, verbose = 0; |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 698 | char *type_str; |
Paul Vinciguerra | 98afc71 | 2018-09-25 10:02:07 -0700 | [diff] [blame] | 699 | u8 valid_node_name = 0; |
Florin Coras | 178ecc0 | 2020-03-12 23:26:11 +0000 | [diff] [blame] | 700 | u64 cl, ca, v; |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 701 | |
| 702 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 703 | return 0; |
| 704 | |
| 705 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 706 | { |
Paul Vinciguerra | 98afc71 | 2018-09-25 10:02:07 -0700 | [diff] [blame] | 707 | if (unformat (line_input, "index %u", &node_index)) |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 708 | ; |
Florin Coras | 178ecc0 | 2020-03-12 23:26:11 +0000 | [diff] [blame] | 709 | else if (unformat (line_input, "verbose")) |
| 710 | verbose = 1; |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 711 | else |
Paul Vinciguerra | 98afc71 | 2018-09-25 10:02:07 -0700 | [diff] [blame] | 712 | if (unformat (line_input, "%U", unformat_vlib_node, vm, &node_index)) |
| 713 | valid_node_name = 1; |
| 714 | else if (!valid_node_name) |
| 715 | error = clib_error_return (0, "unknown node name: '%U'", |
| 716 | format_unformat_error, line_input); |
| 717 | else |
| 718 | error = clib_error_return (0, "unknown input '%U'", |
| 719 | format_unformat_error, line_input); |
Filip Tehlar | be0ffbc | 2019-07-09 13:52:26 +0000 | [diff] [blame] | 720 | |
| 721 | if (error) |
| 722 | break; |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 723 | } |
Paul Vinciguerra | 98afc71 | 2018-09-25 10:02:07 -0700 | [diff] [blame] | 724 | |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 725 | unformat_free (line_input); |
| 726 | |
Paul Vinciguerra | 98afc71 | 2018-09-25 10:02:07 -0700 | [diff] [blame] | 727 | if (error) |
| 728 | return error; |
| 729 | |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 730 | if (node_index >= vec_len (vm->node_main.nodes)) |
| 731 | return clib_error_return (0, "please specify valid node"); |
| 732 | |
| 733 | n = vlib_get_node (vm, node_index); |
| 734 | vlib_node_sync_stats (vm, n); |
| 735 | |
| 736 | switch (n->type) |
| 737 | { |
| 738 | case VLIB_NODE_TYPE_INTERNAL: |
| 739 | type_str = "internal"; |
| 740 | break; |
| 741 | case VLIB_NODE_TYPE_INPUT: |
| 742 | type_str = "input"; |
| 743 | break; |
| 744 | case VLIB_NODE_TYPE_PRE_INPUT: |
| 745 | type_str = "pre-input"; |
| 746 | break; |
| 747 | case VLIB_NODE_TYPE_PROCESS: |
| 748 | type_str = "process"; |
| 749 | break; |
| 750 | default: |
| 751 | type_str = "unknown"; |
| 752 | } |
| 753 | |
| 754 | if (n->sibling_of) |
| 755 | s = format (s, ", sibling-of %s", n->sibling_of); |
| 756 | |
Benoît Ganne | 62d9fda | 2019-12-16 15:49:47 +0100 | [diff] [blame] | 757 | vlib_cli_output (vm, "node %v, type %s, state %U, index %d%v\n", |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 758 | n->name, type_str, format_vlib_node_state, vm, n, |
| 759 | n->index, s); |
| 760 | vec_reset_length (s); |
| 761 | |
| 762 | if (n->node_fn_registrations) |
| 763 | { |
| 764 | vlib_node_fn_registration_t *fnr = n->node_fn_registrations; |
Damjan Marion | a31698b | 2021-03-10 14:35:28 +0100 | [diff] [blame] | 765 | vlib_node_fn_variant_t *v; |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 766 | while (fnr) |
| 767 | { |
Damjan Marion | a31698b | 2021-03-10 14:35:28 +0100 | [diff] [blame] | 768 | v = vec_elt_at_index (vm->node_main.variants, fnr->march_variant); |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 769 | if (vec_len (s) == 0) |
Damjan Marion | a31698b | 2021-03-10 14:35:28 +0100 | [diff] [blame] | 770 | s = format (s, "\n %-15s %=8s %6s %s", "Name", "Priority", |
| 771 | "Active", "Description"); |
| 772 | s = format (s, "\n %-15s %8d %=6s %s", v->suffix, v->priority, |
| 773 | fnr->function == n->function ? "yes" : "", v->desc); |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 774 | fnr = fnr->next_registration; |
| 775 | } |
| 776 | } |
| 777 | else |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 778 | s = format (s, "\n default only"); |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 779 | vlib_cli_output (vm, " node function variants:%v\n", s); |
| 780 | vec_reset_length (s); |
| 781 | |
| 782 | for (i = 0; i < vec_len (n->next_nodes); i++) |
| 783 | { |
| 784 | vlib_node_t *pn; |
| 785 | if (n->next_nodes[i] == VLIB_INVALID_NODE_INDEX) |
| 786 | continue; |
| 787 | |
| 788 | pn = vec_elt (nm->nodes, n->next_nodes[i]); |
| 789 | |
| 790 | if (vec_len (s) == 0) |
| 791 | s = format (s, "\n %10s %10s %=30s %8s", |
| 792 | "next-index", "node-index", "Node", "Vectors"); |
| 793 | |
Florin Coras | 178ecc0 | 2020-03-12 23:26:11 +0000 | [diff] [blame] | 794 | s = format (s, "\n %=10u %=10u %=30v %=8llu", i, n->next_nodes[i], |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 795 | pn->name, vec_elt (n->n_vectors_by_next_node, i)); |
| 796 | } |
| 797 | |
| 798 | if (vec_len (s) == 0) |
| 799 | s = format (s, "\n none"); |
| 800 | vlib_cli_output (vm, "\n next nodes:%v\n", s); |
| 801 | vec_reset_length (s); |
| 802 | |
| 803 | if (n->type == VLIB_NODE_TYPE_INTERNAL) |
| 804 | { |
| 805 | int j = 0; |
Damjan Marion | f0ca1e8 | 2020-12-13 23:26:56 +0100 | [diff] [blame] | 806 | clib_bitmap_foreach (i, n->prev_node_bitmap) { |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 807 | vlib_node_t *pn = vlib_get_node (vm, i); |
| 808 | if (j++ % 3 == 0) |
| 809 | s = format (s, "\n "); |
| 810 | s2 = format (s2, "%v (%u)", pn->name, i); |
| 811 | s = format (s, "%-35v", s2); |
| 812 | vec_reset_length (s2); |
Damjan Marion | f0ca1e8 | 2020-12-13 23:26:56 +0100 | [diff] [blame] | 813 | } |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 814 | |
| 815 | if (vec_len (s) == 0) |
| 816 | s = format (s, "\n none"); |
| 817 | vlib_cli_output (vm, "\n known previous nodes:%v\n", s); |
| 818 | vec_reset_length (s); |
Florin Coras | 178ecc0 | 2020-03-12 23:26:11 +0000 | [diff] [blame] | 819 | vec_free (s2); |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 820 | } |
| 821 | |
Florin Coras | 178ecc0 | 2020-03-12 23:26:11 +0000 | [diff] [blame] | 822 | if (!verbose) |
| 823 | goto done; |
| 824 | |
| 825 | s = format (s, "\n%8s %=12s %=12s %=12s %=12s %=12s\n", "Thread", "Calls", |
| 826 | "Clocks", "Vectors", "Max Clock", "Max Vectors"); |
Damjan Marion | 6ffb7c6 | 2021-03-26 13:06:13 +0100 | [diff] [blame] | 827 | for (i = 0; i < vlib_get_n_threads (); i++) |
Florin Coras | 178ecc0 | 2020-03-12 23:26:11 +0000 | [diff] [blame] | 828 | { |
Damjan Marion | 6ffb7c6 | 2021-03-26 13:06:13 +0100 | [diff] [blame] | 829 | n = vlib_get_node (vlib_get_main_by_index (i), node_index); |
| 830 | vlib_node_sync_stats (vlib_get_main_by_index (i), n); |
Florin Coras | 178ecc0 | 2020-03-12 23:26:11 +0000 | [diff] [blame] | 831 | |
| 832 | cl = n->stats_total.clocks - n->stats_last_clear.clocks; |
| 833 | ca = n->stats_total.calls - n->stats_last_clear.calls; |
| 834 | v = n->stats_total.vectors - n->stats_last_clear.vectors; |
| 835 | |
| 836 | s = format (s, "%=8u %=12lu %=12lu %=12lu %=12u %=12u\n", i, ca, cl, v, |
| 837 | n->stats_total.max_clock, n->stats_total.max_clock_n); |
| 838 | } |
| 839 | |
| 840 | vlib_cli_output (vm, "%v", s); |
| 841 | |
| 842 | done: |
| 843 | |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 844 | vec_free (s); |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 845 | return 0; |
| 846 | } |
| 847 | |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 848 | VLIB_CLI_COMMAND (show_node_command, static) = { |
| 849 | .path = "show node", |
| 850 | .short_help = "show node [index] <node-name | node-index>", |
| 851 | .function = show_node, |
| 852 | }; |
| 853 | |
| 854 | static clib_error_t * |
| 855 | set_node_fn(vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) |
| 856 | { |
| 857 | unformat_input_t _line_input, *line_input = &_line_input; |
Damjan Marion | a31698b | 2021-03-10 14:35:28 +0100 | [diff] [blame] | 858 | u32 node_index, march_variant; |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 859 | vlib_node_t *n; |
| 860 | clib_error_t *err = 0; |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 861 | |
| 862 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 863 | return 0; |
| 864 | |
| 865 | if (!unformat (line_input, "%U", unformat_vlib_node, vm, &node_index)) |
| 866 | { |
| 867 | err = clib_error_return (0, "please specify valid node name"); |
| 868 | goto done; |
| 869 | } |
| 870 | |
Damjan Marion | a31698b | 2021-03-10 14:35:28 +0100 | [diff] [blame] | 871 | if (!unformat (line_input, "%U", unformat_vlib_node_variant, &march_variant)) |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 872 | { |
Damjan Marion | a31698b | 2021-03-10 14:35:28 +0100 | [diff] [blame] | 873 | err = clib_error_return (0, "please specify node function variant"); |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 874 | goto done; |
| 875 | } |
| 876 | |
| 877 | n = vlib_get_node (vm, node_index); |
| 878 | |
| 879 | if (n->node_fn_registrations == 0) |
| 880 | { |
Damjan Marion | a31698b | 2021-03-10 14:35:28 +0100 | [diff] [blame] | 881 | err = clib_error_return (0, "node doesn't have function variants"); |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 882 | goto done; |
| 883 | } |
| 884 | |
Damjan Marion | a31698b | 2021-03-10 14:35:28 +0100 | [diff] [blame] | 885 | if (vlib_node_set_march_variant (vm, node_index, march_variant)) |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 886 | { |
Damjan Marion | a31698b | 2021-03-10 14:35:28 +0100 | [diff] [blame] | 887 | vlib_node_fn_variant_t *v; |
| 888 | v = vec_elt_at_index (vm->node_main.variants, march_variant); |
| 889 | err = clib_error_return (0, "node function variant '%s' not found", |
| 890 | v->suffix); |
| 891 | goto done; |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 892 | } |
| 893 | |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 894 | |
| 895 | done: |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 896 | unformat_free (line_input); |
| 897 | return err; |
| 898 | } |
| 899 | |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 900 | VLIB_CLI_COMMAND (set_node_fn_command, static) = { |
| 901 | .path = "set node function", |
| 902 | .short_help = "set node function <node-name> <variant-name>", |
| 903 | .function = set_node_fn, |
| 904 | }; |
Damjan Marion | 69abe44 | 2018-08-27 22:43:23 +0200 | [diff] [blame] | 905 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 906 | /* Dummy function to get us linked in. */ |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 907 | void |
| 908 | vlib_node_cli_reference (void) |
| 909 | { |
| 910 | } |
| 911 | |
| 912 | /* |
| 913 | * fd.io coding-style-patch-verification: ON |
| 914 | * |
| 915 | * Local Variables: |
| 916 | * eval: (c-set-style "gnu") |
| 917 | * End: |
| 918 | */ |