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