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