blob: dc21a3f2c67d8f0363f68bb6cfe9d45217e2ff91 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
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 * main.c: main vector processing loop
17 *
18 * Copyright (c) 2008 Eliot Dresselhaus
19 *
20 * Permission is hereby granted, free of charge, to any person obtaining
21 * a copy of this software and associated documentation files (the
22 * "Software"), to deal in the Software without restriction, including
23 * without limitation the rights to use, copy, modify, merge, publish,
24 * distribute, sublicense, and/or sell copies of the Software, and to
25 * permit persons to whom the Software is furnished to do so, subject to
26 * the following conditions:
27 *
28 * The above copyright notice and this permission notice shall be
29 * included in all copies or substantial portions of the Software.
30 *
31 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 */
39
40#include <math.h>
41#include <vppinfra/format.h>
42#include <vlib/vlib.h>
43#include <vlib/threads.h>
Damjan Marion8973b072022-03-01 15:51:18 +010044#include <vlib/stats/stats.h>
Dave Barach5c20a012017-06-13 08:48:31 -040045#include <vppinfra/tw_timer_1t_3w_1024sl_ov.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070046
Damjan Marion04a7f052017-07-10 15:06:17 +020047#include <vlib/unix/unix.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070048
Ed Warnickecb9cada2015-12-08 15:45:58 -070049#define VLIB_FRAME_MAGIC (0xabadc0ed)
Ed Warnickecb9cada2015-12-08 15:45:58 -070050
51always_inline u32 *
52vlib_frame_find_magic (vlib_frame_t * f, vlib_node_t * node)
53{
Damjan Marionb32bd702021-12-23 17:05:02 +010054 return (void *) f + node->magic_offset;
Ed Warnickecb9cada2015-12-08 15:45:58 -070055}
56
Andreas Schultz58b2eb12019-07-15 15:40:56 +020057static vlib_frame_t *
Dave Barach9b8ffd92016-07-08 08:13:45 -040058vlib_frame_alloc_to_node (vlib_main_t * vm, u32 to_node_index,
59 u32 frame_flags)
Ed Warnickecb9cada2015-12-08 15:45:58 -070060{
Dave Barach9b8ffd92016-07-08 08:13:45 -040061 vlib_node_main_t *nm = &vm->node_main;
62 vlib_frame_size_t *fs;
63 vlib_node_t *to_node;
64 vlib_frame_t *f;
Damjan Marionb32bd702021-12-23 17:05:02 +010065 u32 l, n;
Ed Warnickecb9cada2015-12-08 15:45:58 -070066
Dave Baracha8f4ebd2021-02-08 07:56:22 -050067 ASSERT (vm == vlib_get_main ());
68
Ed Warnickecb9cada2015-12-08 15:45:58 -070069 to_node = vlib_get_node (vm, to_node_index);
70
Damjan Marionb32bd702021-12-23 17:05:02 +010071 vec_validate (nm->frame_sizes, to_node->frame_size_index);
72 fs = vec_elt_at_index (nm->frame_sizes, to_node->frame_size_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070073
Damjan Marionb32bd702021-12-23 17:05:02 +010074 if (fs->frame_size == 0)
75 fs->frame_size = to_node->frame_size;
76 else
77 ASSERT (fs->frame_size == to_node->frame_size);
78
79 n = fs->frame_size;
Andreas Schultz58b2eb12019-07-15 15:40:56 +020080 if ((l = vec_len (fs->free_frames)) > 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -070081 {
82 /* Allocate from end of free list. */
Andreas Schultz58b2eb12019-07-15 15:40:56 +020083 f = fs->free_frames[l - 1];
Damjan Marion8bea5892022-04-04 22:40:45 +020084 vec_set_len (fs->free_frames, l - 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -070085 }
86 else
87 {
Damjan Marionb32bd702021-12-23 17:05:02 +010088 f = clib_mem_alloc_aligned_no_fail (n, CLIB_CACHE_LINE_BYTES);
Ed Warnickecb9cada2015-12-08 15:45:58 -070089 }
90
91 /* Poison frame when debugging. */
92 if (CLIB_DEBUG > 0)
Damjan Marionb32bd702021-12-23 17:05:02 +010093 clib_memset_u8 (f, 0xfe, n);
Ed Warnickecb9cada2015-12-08 15:45:58 -070094
95 /* Insert magic number. */
96 {
Dave Barach9b8ffd92016-07-08 08:13:45 -040097 u32 *magic;
Ed Warnickecb9cada2015-12-08 15:45:58 -070098
99 magic = vlib_frame_find_magic (f, to_node);
100 *magic = VLIB_FRAME_MAGIC;
101 }
102
Damjan Marion633b6fd2018-09-14 14:38:53 +0200103 f->frame_flags = VLIB_FRAME_IS_ALLOCATED | frame_flags;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700104 f->n_vectors = 0;
Damjan Marionb32bd702021-12-23 17:05:02 +0100105 f->scalar_offset = to_node->scalar_offset;
106 f->vector_offset = to_node->vector_offset;
107 f->aux_offset = to_node->aux_offset;
Damjan Mariona3d59862018-11-10 10:23:00 +0100108 f->flags = 0;
Dmitry Valter9f5b3692022-09-05 15:30:18 +0000109 f->frame_size_index = to_node->frame_size_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700110
111 fs->n_alloc_frames += 1;
112
Andreas Schultz58b2eb12019-07-15 15:40:56 +0200113 return f;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700114}
115
116/* Allocate a frame for from FROM_NODE to TO_NODE via TO_NEXT_INDEX.
117 Returns frame index. */
Andreas Schultz58b2eb12019-07-15 15:40:56 +0200118static vlib_frame_t *
Dave Barach9b8ffd92016-07-08 08:13:45 -0400119vlib_frame_alloc (vlib_main_t * vm, vlib_node_runtime_t * from_node_runtime,
120 u32 to_next_index)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700121{
Dave Barach9b8ffd92016-07-08 08:13:45 -0400122 vlib_node_t *from_node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700123
124 from_node = vlib_get_node (vm, from_node_runtime->node_index);
125 ASSERT (to_next_index < vec_len (from_node->next_nodes));
126
Dave Barach9b8ffd92016-07-08 08:13:45 -0400127 return vlib_frame_alloc_to_node (vm, from_node->next_nodes[to_next_index],
Ed Warnickecb9cada2015-12-08 15:45:58 -0700128 /* frame_flags */ 0);
129}
130
131vlib_frame_t *
132vlib_get_frame_to_node (vlib_main_t * vm, u32 to_node_index)
133{
Andreas Schultz58b2eb12019-07-15 15:40:56 +0200134 vlib_frame_t *f = vlib_frame_alloc_to_node (vm, to_node_index,
135 /* frame_flags */
136 VLIB_FRAME_FREE_AFTER_DISPATCH);
137 return vlib_get_frame (vm, f);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700138}
139
Dave Barachc74b43c2020-04-09 17:24:07 -0400140static inline void
141vlib_validate_frame_indices (vlib_frame_t * f)
142{
143 if (CLIB_DEBUG > 0)
144 {
145 int i;
146 u32 *from = vlib_frame_vector_args (f);
147
148 /* Check for bad buffer index values */
149 for (i = 0; i < f->n_vectors; i++)
150 {
151 if (from[i] == 0)
152 {
153 clib_warning ("BUG: buffer index 0 at index %d", i);
154 ASSERT (0);
155 }
156 else if (from[i] == 0xfefefefe)
157 {
158 clib_warning ("BUG: frame poison pattern at index %d", i);
159 ASSERT (0);
160 }
161 }
162 }
163}
164
Dave Barach9b8ffd92016-07-08 08:13:45 -0400165void
166vlib_put_frame_to_node (vlib_main_t * vm, u32 to_node_index, vlib_frame_t * f)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700167{
Dave Barach9b8ffd92016-07-08 08:13:45 -0400168 vlib_pending_frame_t *p;
169 vlib_node_t *to_node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700170
171 if (f->n_vectors == 0)
172 return;
173
Dave Baracha8f4ebd2021-02-08 07:56:22 -0500174 ASSERT (vm == vlib_get_main ());
175
Dave Barachc74b43c2020-04-09 17:24:07 -0400176 vlib_validate_frame_indices (f);
177
Ed Warnickecb9cada2015-12-08 15:45:58 -0700178 to_node = vlib_get_node (vm, to_node_index);
179
180 vec_add2 (vm->node_main.pending_frames, p, 1);
181
Damjan Marion633b6fd2018-09-14 14:38:53 +0200182 f->frame_flags |= VLIB_FRAME_PENDING;
Andreas Schultz58b2eb12019-07-15 15:40:56 +0200183 p->frame = vlib_get_frame (vm, f);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700184 p->node_runtime_index = to_node->runtime_index;
185 p->next_frame_index = VLIB_PENDING_FRAME_NO_NEXT_FRAME;
186}
187
188/* Free given frame. */
189void
Dmitry Valter9f5b3692022-09-05 15:30:18 +0000190vlib_frame_free (vlib_main_t *vm, vlib_frame_t *f)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700191{
Dave Barach9b8ffd92016-07-08 08:13:45 -0400192 vlib_node_main_t *nm = &vm->node_main;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400193 vlib_frame_size_t *fs;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400194
Dave Baracha8f4ebd2021-02-08 07:56:22 -0500195 ASSERT (vm == vlib_get_main ());
Damjan Marion633b6fd2018-09-14 14:38:53 +0200196 ASSERT (f->frame_flags & VLIB_FRAME_IS_ALLOCATED);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700197
Dmitry Valter9f5b3692022-09-05 15:30:18 +0000198 fs = vec_elt_at_index (nm->frame_sizes, f->frame_size_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700199
Damjan Marion633b6fd2018-09-14 14:38:53 +0200200 ASSERT (f->frame_flags & VLIB_FRAME_IS_ALLOCATED);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700201
202 /* No next frames may point to freed frame. */
203 if (CLIB_DEBUG > 0)
204 {
Dave Barach9b8ffd92016-07-08 08:13:45 -0400205 vlib_next_frame_t *nf;
Andreas Schultz58b2eb12019-07-15 15:40:56 +0200206 vec_foreach (nf, vm->node_main.next_frames) ASSERT (nf->frame != f);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700207 }
208
Damjan Marion296988d2019-02-21 20:24:54 +0100209 f->frame_flags &= ~(VLIB_FRAME_IS_ALLOCATED | VLIB_FRAME_NO_APPEND);
Stanislav Zaikin3791a032022-03-31 14:16:28 +0200210 f->flags = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700211
Andreas Schultz58b2eb12019-07-15 15:40:56 +0200212 vec_add1 (fs->free_frames, f);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700213 ASSERT (fs->n_alloc_frames > 0);
214 fs->n_alloc_frames -= 1;
215}
216
217static clib_error_t *
218show_frame_stats (vlib_main_t * vm,
Dave Barach9b8ffd92016-07-08 08:13:45 -0400219 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700220{
Dave Barach9b8ffd92016-07-08 08:13:45 -0400221 vlib_frame_size_t *fs;
222
Damjan Marionb32bd702021-12-23 17:05:02 +0100223 vlib_cli_output (vm, "%=8s%=6s%=12s%=12s", "Thread", "Size", "# Alloc",
224 "# Free");
225 foreach_vlib_main ()
226 {
227 vlib_node_main_t *nm = &this_vlib_main->node_main;
228 vec_foreach (fs, nm->frame_sizes)
229 {
230 u32 n_alloc = fs->n_alloc_frames;
231 u32 n_free = vec_len (fs->free_frames);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700232
Damjan Marionb32bd702021-12-23 17:05:02 +0100233 if (n_alloc + n_free > 0)
234 vlib_cli_output (vm, "%=8d%=6d%=12d%=12d",
235 this_vlib_main->thread_index, fs->frame_size,
236 n_alloc, n_free);
237 }
238 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700239
240 return 0;
241}
242
Dave Barach9b8ffd92016-07-08 08:13:45 -0400243/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700244VLIB_CLI_COMMAND (show_frame_stats_cli, static) = {
245 .path = "show vlib frame-allocation",
246 .short_help = "Show node dispatch frame statistics",
247 .function = show_frame_stats,
248};
Dave Barach9b8ffd92016-07-08 08:13:45 -0400249/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700250
251/* Change ownership of enqueue rights to given next node. */
252static void
253vlib_next_frame_change_ownership (vlib_main_t * vm,
254 vlib_node_runtime_t * node_runtime,
255 u32 next_index)
256{
Dave Barach9b8ffd92016-07-08 08:13:45 -0400257 vlib_node_main_t *nm = &vm->node_main;
258 vlib_next_frame_t *next_frame;
259 vlib_node_t *node, *next_node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700260
261 node = vec_elt (nm->nodes, node_runtime->node_index);
262
263 /* Only internal & input nodes are allowed to call other nodes. */
264 ASSERT (node->type == VLIB_NODE_TYPE_INTERNAL
265 || node->type == VLIB_NODE_TYPE_INPUT
266 || node->type == VLIB_NODE_TYPE_PROCESS);
267
268 ASSERT (vec_len (node->next_nodes) == node_runtime->n_next_nodes);
269
Dave Barach9b8ffd92016-07-08 08:13:45 -0400270 next_frame =
271 vlib_node_runtime_get_next_frame (vm, node_runtime, next_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700272 next_node = vec_elt (nm->nodes, node->next_nodes[next_index]);
273
274 if (next_node->owner_node_index != VLIB_INVALID_NODE_INDEX)
275 {
276 /* Get frame from previous owner. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400277 vlib_next_frame_t *owner_next_frame;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700278 vlib_next_frame_t tmp;
279
280 owner_next_frame =
281 vlib_node_get_next_frame (vm,
282 next_node->owner_node_index,
283 next_node->owner_next_index);
284
285 /* Swap target next frame with owner's. */
286 tmp = owner_next_frame[0];
287 owner_next_frame[0] = next_frame[0];
288 next_frame[0] = tmp;
289
290 /*
291 * If next_frame is already pending, we have to track down
292 * all pending frames and fix their next_frame_index fields.
293 */
294 if (next_frame->flags & VLIB_FRAME_PENDING)
Dave Barach9b8ffd92016-07-08 08:13:45 -0400295 {
296 vlib_pending_frame_t *p;
Andreas Schultz58b2eb12019-07-15 15:40:56 +0200297 if (next_frame->frame != NULL)
Dave Barach9b8ffd92016-07-08 08:13:45 -0400298 {
299 vec_foreach (p, nm->pending_frames)
300 {
Andreas Schultz58b2eb12019-07-15 15:40:56 +0200301 if (p->frame == next_frame->frame)
Dave Barach9b8ffd92016-07-08 08:13:45 -0400302 {
303 p->next_frame_index =
304 next_frame - vm->node_main.next_frames;
305 }
306 }
307 }
308 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700309 }
310 else
311 {
312 /* No previous owner. Take ownership. */
313 next_frame->flags |= VLIB_FRAME_OWNER;
314 }
Dave Barach9b8ffd92016-07-08 08:13:45 -0400315
Ed Warnickecb9cada2015-12-08 15:45:58 -0700316 /* Record new owner. */
317 next_node->owner_node_index = node->index;
318 next_node->owner_next_index = next_index;
319
320 /* Now we should be owner. */
321 ASSERT (next_frame->flags & VLIB_FRAME_OWNER);
Dave Barach9b8ffd92016-07-08 08:13:45 -0400322}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700323
324/* Make sure that magic number is still there.
325 Otherwise, it is likely that caller has overrun frame arguments. */
326always_inline void
327validate_frame_magic (vlib_main_t * vm,
Dave Barach9b8ffd92016-07-08 08:13:45 -0400328 vlib_frame_t * f, vlib_node_t * n, uword next_index)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700329{
Dave Barach9b8ffd92016-07-08 08:13:45 -0400330 vlib_node_t *next_node = vlib_get_node (vm, n->next_nodes[next_index]);
331 u32 *magic = vlib_frame_find_magic (f, next_node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700332 ASSERT (VLIB_FRAME_MAGIC == magic[0]);
333}
334
335vlib_frame_t *
336vlib_get_next_frame_internal (vlib_main_t * vm,
337 vlib_node_runtime_t * node,
Dave Barach9b8ffd92016-07-08 08:13:45 -0400338 u32 next_index, u32 allocate_new_next_frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700339{
Dave Barach9b8ffd92016-07-08 08:13:45 -0400340 vlib_frame_t *f;
341 vlib_next_frame_t *nf;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700342 u32 n_used;
343
344 nf = vlib_node_runtime_get_next_frame (vm, node, next_index);
345
346 /* Make sure this next frame owns right to enqueue to destination frame. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400347 if (PREDICT_FALSE (!(nf->flags & VLIB_FRAME_OWNER)))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700348 vlib_next_frame_change_ownership (vm, node, next_index);
349
350 /* ??? Don't need valid flag: can use frame_index == ~0 */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400351 if (PREDICT_FALSE (!(nf->flags & VLIB_FRAME_IS_ALLOCATED)))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700352 {
Andreas Schultz58b2eb12019-07-15 15:40:56 +0200353 nf->frame = vlib_frame_alloc (vm, node, next_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700354 nf->flags |= VLIB_FRAME_IS_ALLOCATED;
355 }
356
Andreas Schultz58b2eb12019-07-15 15:40:56 +0200357 f = nf->frame;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700358
359 /* Has frame been removed from pending vector (e.g. finished dispatching)?
360 If so we can reuse frame. */
Damjan Marion633b6fd2018-09-14 14:38:53 +0200361 if ((nf->flags & VLIB_FRAME_PENDING)
362 && !(f->frame_flags & VLIB_FRAME_PENDING))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700363 {
364 nf->flags &= ~VLIB_FRAME_PENDING;
365 f->n_vectors = 0;
Damjan Marion9162c2d2018-11-20 09:55:10 +0100366 f->flags = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700367 }
368
Damjan Marion296988d2019-02-21 20:24:54 +0100369 /* Allocate new frame if current one is marked as no-append or
370 it is already full. */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700371 n_used = f->n_vectors;
Damjan Marion296988d2019-02-21 20:24:54 +0100372 if (n_used >= VLIB_FRAME_SIZE || (allocate_new_next_frame && n_used > 0) ||
373 (f->frame_flags & VLIB_FRAME_NO_APPEND))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700374 {
375 /* Old frame may need to be freed after dispatch, since we'll have
Dave Barach9b8ffd92016-07-08 08:13:45 -0400376 two redundant frames from node -> next node. */
377 if (!(nf->flags & VLIB_FRAME_NO_FREE_AFTER_DISPATCH))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700378 {
Andreas Schultz58b2eb12019-07-15 15:40:56 +0200379 vlib_frame_t *f_old = vlib_get_frame (vm, nf->frame);
Damjan Marion633b6fd2018-09-14 14:38:53 +0200380 f_old->frame_flags |= VLIB_FRAME_FREE_AFTER_DISPATCH;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700381 }
382
383 /* Allocate new frame to replace full one. */
Andreas Schultz58b2eb12019-07-15 15:40:56 +0200384 f = nf->frame = vlib_frame_alloc (vm, node, next_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700385 n_used = f->n_vectors;
386 }
387
388 /* Should have free vectors in frame now. */
389 ASSERT (n_used < VLIB_FRAME_SIZE);
390
391 if (CLIB_DEBUG > 0)
392 {
393 validate_frame_magic (vm, f,
Dave Barach9b8ffd92016-07-08 08:13:45 -0400394 vlib_get_node (vm, node->node_index), next_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700395 }
396
397 return f;
398}
399
400static void
401vlib_put_next_frame_validate (vlib_main_t * vm,
402 vlib_node_runtime_t * rt,
Dave Barach9b8ffd92016-07-08 08:13:45 -0400403 u32 next_index, u32 n_vectors_left)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700404{
Dave Barach9b8ffd92016-07-08 08:13:45 -0400405 vlib_node_main_t *nm = &vm->node_main;
406 vlib_next_frame_t *nf;
407 vlib_frame_t *f;
408 vlib_node_runtime_t *next_rt;
409 vlib_node_t *next_node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700410 u32 n_before, n_after;
411
412 nf = vlib_node_runtime_get_next_frame (vm, rt, next_index);
Andreas Schultz58b2eb12019-07-15 15:40:56 +0200413 f = vlib_get_frame (vm, nf->frame);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700414
415 ASSERT (n_vectors_left <= VLIB_FRAME_SIZE);
Dave Barachc74b43c2020-04-09 17:24:07 -0400416
417 vlib_validate_frame_indices (f);
418
Ed Warnickecb9cada2015-12-08 15:45:58 -0700419 n_after = VLIB_FRAME_SIZE - n_vectors_left;
420 n_before = f->n_vectors;
421
422 ASSERT (n_after >= n_before);
423
424 next_rt = vec_elt_at_index (nm->nodes_by_type[VLIB_NODE_TYPE_INTERNAL],
425 nf->node_runtime_index);
426 next_node = vlib_get_node (vm, next_rt->node_index);
427 if (n_after > 0 && next_node->validate_frame)
428 {
Dave Barach9b8ffd92016-07-08 08:13:45 -0400429 u8 *msg = next_node->validate_frame (vm, rt, f);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700430 if (msg)
431 {
432 clib_warning ("%v", msg);
433 ASSERT (0);
434 }
435 vec_free (msg);
436 }
437}
438
439void
440vlib_put_next_frame (vlib_main_t * vm,
441 vlib_node_runtime_t * r,
Dave Barach9b8ffd92016-07-08 08:13:45 -0400442 u32 next_index, u32 n_vectors_left)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700443{
Dave Barach9b8ffd92016-07-08 08:13:45 -0400444 vlib_node_main_t *nm = &vm->node_main;
445 vlib_next_frame_t *nf;
446 vlib_frame_t *f;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700447 u32 n_vectors_in_frame;
448
Damjan Marion910d3692019-01-21 11:48:34 +0100449 if (CLIB_DEBUG > 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700450 vlib_put_next_frame_validate (vm, r, next_index, n_vectors_left);
451
452 nf = vlib_node_runtime_get_next_frame (vm, r, next_index);
Andreas Schultz58b2eb12019-07-15 15:40:56 +0200453 f = vlib_get_frame (vm, nf->frame);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700454
455 /* Make sure that magic number is still there. Otherwise, caller
456 has overrun frame meta data. */
457 if (CLIB_DEBUG > 0)
458 {
Dave Barach9b8ffd92016-07-08 08:13:45 -0400459 vlib_node_t *node = vlib_get_node (vm, r->node_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700460 validate_frame_magic (vm, f, node, next_index);
461 }
462
463 /* Convert # of vectors left -> number of vectors there. */
464 ASSERT (n_vectors_left <= VLIB_FRAME_SIZE);
465 n_vectors_in_frame = VLIB_FRAME_SIZE - n_vectors_left;
466
467 f->n_vectors = n_vectors_in_frame;
468
469 /* If vectors were added to frame, add to pending vector. */
470 if (PREDICT_TRUE (n_vectors_in_frame > 0))
471 {
Dave Barach9b8ffd92016-07-08 08:13:45 -0400472 vlib_pending_frame_t *p;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700473 u32 v0, v1;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400474
Ed Warnickecb9cada2015-12-08 15:45:58 -0700475 r->cached_next_index = next_index;
476
Damjan Marion633b6fd2018-09-14 14:38:53 +0200477 if (!(f->frame_flags & VLIB_FRAME_PENDING))
Dave Barach9b8ffd92016-07-08 08:13:45 -0400478 {
479 __attribute__ ((unused)) vlib_node_t *node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700480
Dave Barach9b8ffd92016-07-08 08:13:45 -0400481 node = vlib_get_node (vm, r->node_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700482
Dave Barach9b8ffd92016-07-08 08:13:45 -0400483 vec_add2 (nm->pending_frames, p, 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700484
Andreas Schultz58b2eb12019-07-15 15:40:56 +0200485 p->frame = nf->frame;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400486 p->node_runtime_index = nf->node_runtime_index;
487 p->next_frame_index = nf - nm->next_frames;
488 nf->flags |= VLIB_FRAME_PENDING;
Damjan Marion633b6fd2018-09-14 14:38:53 +0200489 f->frame_flags |= VLIB_FRAME_PENDING;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400490 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700491
492 /* Copy trace flag from next_frame and from runtime. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400493 nf->flags |=
494 (nf->flags & VLIB_NODE_FLAG_TRACE) | (r->
495 flags & VLIB_NODE_FLAG_TRACE);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700496
497 v0 = nf->vectors_since_last_overflow;
498 v1 = v0 + n_vectors_in_frame;
499 nf->vectors_since_last_overflow = v1;
500 if (PREDICT_FALSE (v1 < v0))
501 {
Dave Barach9b8ffd92016-07-08 08:13:45 -0400502 vlib_node_t *node = vlib_get_node (vm, r->node_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700503 vec_elt (node->n_vectors_by_next_node, next_index) += v0;
504 }
505 }
506}
507
508/* Sync up runtime (32 bit counters) and main node stats (64 bit counters). */
Arthur de Kerhor156158f2021-02-18 03:09:42 -0800509void
510vlib_node_runtime_sync_stats_node (vlib_node_t *n, vlib_node_runtime_t *r,
511 uword n_calls, uword n_vectors,
512 uword n_clocks)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700513{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700514 n->stats_total.calls += n_calls + r->calls_since_last_overflow;
515 n->stats_total.vectors += n_vectors + r->vectors_since_last_overflow;
516 n->stats_total.clocks += n_clocks + r->clocks_since_last_overflow;
517 n->stats_total.max_clock = r->max_clock;
518 n->stats_total.max_clock_n = r->max_clock_n;
519
520 r->calls_since_last_overflow = 0;
521 r->vectors_since_last_overflow = 0;
522 r->clocks_since_last_overflow = 0;
523}
524
Arthur de Kerhor156158f2021-02-18 03:09:42 -0800525void
526vlib_node_runtime_sync_stats (vlib_main_t *vm, vlib_node_runtime_t *r,
527 uword n_calls, uword n_vectors, uword n_clocks)
528{
529 vlib_node_t *n = vlib_get_node (vm, r->node_index);
530 vlib_node_runtime_sync_stats_node (n, r, n_calls, n_vectors, n_clocks);
531}
532
Dave Barach9b8ffd92016-07-08 08:13:45 -0400533always_inline void __attribute__ ((unused))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700534vlib_process_sync_stats (vlib_main_t * vm,
535 vlib_process_t * p,
Tom Seidenberg6c81f5a2020-07-10 15:49:03 +0000536 uword n_calls, uword n_vectors, uword n_clocks)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700537{
Dave Barach9b8ffd92016-07-08 08:13:45 -0400538 vlib_node_runtime_t *rt = &p->node_runtime;
539 vlib_node_t *n = vlib_get_node (vm, rt->node_index);
Tom Seidenberg6c81f5a2020-07-10 15:49:03 +0000540 vlib_node_runtime_sync_stats (vm, rt, n_calls, n_vectors, n_clocks);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700541 n->stats_total.suspends += p->n_suspends;
542 p->n_suspends = 0;
543}
544
Dave Barach9b8ffd92016-07-08 08:13:45 -0400545void
546vlib_node_sync_stats (vlib_main_t * vm, vlib_node_t * n)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700547{
Dave Barach9b8ffd92016-07-08 08:13:45 -0400548 vlib_node_runtime_t *rt;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700549
550 if (n->type == VLIB_NODE_TYPE_PROCESS)
551 {
552 /* Nothing to do for PROCESS nodes except in main thread */
Damjan Marionfd8deb42021-03-06 12:26:28 +0100553 if (vm != vlib_get_first_main ())
Dave Barach9b8ffd92016-07-08 08:13:45 -0400554 return;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700555
Dave Barach9b8ffd92016-07-08 08:13:45 -0400556 vlib_process_t *p = vlib_get_process_from_node (vm, n);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700557 n->stats_total.suspends += p->n_suspends;
558 p->n_suspends = 0;
559 rt = &p->node_runtime;
560 }
561 else
Dave Barach9b8ffd92016-07-08 08:13:45 -0400562 rt =
563 vec_elt_at_index (vm->node_main.nodes_by_type[n->type],
564 n->runtime_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700565
Tom Seidenberg6c81f5a2020-07-10 15:49:03 +0000566 vlib_node_runtime_sync_stats (vm, rt, 0, 0, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700567
568 /* Sync up runtime next frame vector counters with main node structure. */
569 {
Dave Barach9b8ffd92016-07-08 08:13:45 -0400570 vlib_next_frame_t *nf;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700571 uword i;
572 for (i = 0; i < rt->n_next_nodes; i++)
573 {
574 nf = vlib_node_runtime_get_next_frame (vm, rt, i);
Dave Barach9b8ffd92016-07-08 08:13:45 -0400575 vec_elt (n->n_vectors_by_next_node, i) +=
576 nf->vectors_since_last_overflow;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700577 nf->vectors_since_last_overflow = 0;
578 }
579 }
580}
581
582always_inline u32
583vlib_node_runtime_update_stats (vlib_main_t * vm,
584 vlib_node_runtime_t * node,
585 uword n_calls,
Tom Seidenberg6c81f5a2020-07-10 15:49:03 +0000586 uword n_vectors, uword n_clocks)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700587{
588 u32 ca0, ca1, v0, v1, cl0, cl1, r;
589
590 cl0 = cl1 = node->clocks_since_last_overflow;
591 ca0 = ca1 = node->calls_since_last_overflow;
592 v0 = v1 = node->vectors_since_last_overflow;
593
594 ca1 = ca0 + n_calls;
595 v1 = v0 + n_vectors;
596 cl1 = cl0 + n_clocks;
597
598 node->calls_since_last_overflow = ca1;
599 node->clocks_since_last_overflow = cl1;
600 node->vectors_since_last_overflow = v1;
Dave Barach4d1a8662018-09-10 12:31:15 -0400601
Ed Warnickecb9cada2015-12-08 15:45:58 -0700602 node->max_clock_n = node->max_clock > n_clocks ?
Dave Barach9b8ffd92016-07-08 08:13:45 -0400603 node->max_clock_n : n_vectors;
604 node->max_clock = node->max_clock > n_clocks ? node->max_clock : n_clocks;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700605
606 r = vlib_node_runtime_update_main_loop_vector_stats (vm, node, n_vectors);
607
Tom Seidenberg6c81f5a2020-07-10 15:49:03 +0000608 if (PREDICT_FALSE (ca1 < ca0 || v1 < v0 || cl1 < cl0))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700609 {
610 node->calls_since_last_overflow = ca0;
611 node->clocks_since_last_overflow = cl0;
612 node->vectors_since_last_overflow = v0;
Dave Barach4d1a8662018-09-10 12:31:15 -0400613
Tom Seidenberg6c81f5a2020-07-10 15:49:03 +0000614 vlib_node_runtime_sync_stats (vm, node, n_calls, n_vectors, n_clocks);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700615 }
616
617 return r;
618}
619
Dave Barach17e5d802019-05-01 11:30:13 -0400620always_inline void
Ed Warnickecb9cada2015-12-08 15:45:58 -0700621vlib_process_update_stats (vlib_main_t * vm,
622 vlib_process_t * p,
Dave Barachec595ef2019-01-24 10:34:24 -0500623 uword n_calls, uword n_vectors, uword n_clocks)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700624{
625 vlib_node_runtime_update_stats (vm, &p->node_runtime,
Tom Seidenberg6c81f5a2020-07-10 15:49:03 +0000626 n_calls, n_vectors, n_clocks);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700627}
628
629static clib_error_t *
630vlib_cli_elog_clear (vlib_main_t * vm,
Dave Barach9b8ffd92016-07-08 08:13:45 -0400631 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700632{
Damjan Marionf553a2c2021-03-26 13:45:37 +0100633 elog_reset_buffer (&vlib_global_main.elog_main);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700634 return 0;
635}
636
Dave Barach9b8ffd92016-07-08 08:13:45 -0400637/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700638VLIB_CLI_COMMAND (elog_clear_cli, static) = {
Dave Barache5389bb2016-03-28 17:12:19 -0400639 .path = "event-logger clear",
640 .short_help = "Clear the event log",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700641 .function = vlib_cli_elog_clear,
642};
Dave Barach9b8ffd92016-07-08 08:13:45 -0400643/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700644
645#ifdef CLIB_UNIX
646static clib_error_t *
647elog_save_buffer (vlib_main_t * vm,
Dave Barach9b8ffd92016-07-08 08:13:45 -0400648 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700649{
Damjan Marionf553a2c2021-03-26 13:45:37 +0100650 elog_main_t *em = &vlib_global_main.elog_main;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400651 char *file, *chroot_file;
652 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700653
Dave Barach9b8ffd92016-07-08 08:13:45 -0400654 if (!unformat (input, "%s", &file))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700655 {
656 vlib_cli_output (vm, "expected file name, got `%U'",
657 format_unformat_error, input);
658 return 0;
659 }
660
661 /* It's fairly hard to get "../oopsie" through unformat; just in case */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400662 if (strstr (file, "..") || index (file, '/'))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700663 {
664 vlib_cli_output (vm, "illegal characters in filename '%s'", file);
665 return 0;
666 }
667
668 chroot_file = (char *) format (0, "/tmp/%s%c", file, 0);
669
Dave Barach9b8ffd92016-07-08 08:13:45 -0400670 vec_free (file);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700671
672 vlib_cli_output (vm, "Saving %wd of %wd events to %s",
Dave Barach9b8ffd92016-07-08 08:13:45 -0400673 elog_n_events_in_buffer (em),
674 elog_buffer_capacity (em), chroot_file);
675
Ed Warnickecb9cada2015-12-08 15:45:58 -0700676 vlib_worker_thread_barrier_sync (vm);
Dave Barach903fd512017-04-01 11:07:40 -0400677 error = elog_write_file (em, chroot_file, 1 /* flush ring */ );
Dave Barach9b8ffd92016-07-08 08:13:45 -0400678 vlib_worker_thread_barrier_release (vm);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700679 vec_free (chroot_file);
680 return error;
681}
682
Dave Barach81481312017-05-16 09:08:14 -0400683void
Dave Barach27d978c2020-11-03 09:59:06 -0500684vlib_post_mortem_dump (void)
Dave Barach81481312017-05-16 09:08:14 -0400685{
Damjan Marionfd8deb42021-03-06 12:26:28 +0100686 vlib_global_main_t *vgm = vlib_get_global_main ();
Dave Barach27d978c2020-11-03 09:59:06 -0500687
Damjan Marionfd8deb42021-03-06 12:26:28 +0100688 for (int i = 0; i < vec_len (vgm->post_mortem_callbacks); i++)
689 (vgm->post_mortem_callbacks[i]) ();
Dave Barach81481312017-05-16 09:08:14 -0400690}
691
Dave Barach9b8ffd92016-07-08 08:13:45 -0400692/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700693VLIB_CLI_COMMAND (elog_save_cli, static) = {
Dave Barache5389bb2016-03-28 17:12:19 -0400694 .path = "event-logger save",
695 .short_help = "event-logger save <filename> (saves log in /tmp/<filename>)",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700696 .function = elog_save_buffer,
697};
Dave Barach9b8ffd92016-07-08 08:13:45 -0400698/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700699
Dave Barache5389bb2016-03-28 17:12:19 -0400700static clib_error_t *
701elog_stop (vlib_main_t * vm,
Dave Barach9b8ffd92016-07-08 08:13:45 -0400702 unformat_input_t * input, vlib_cli_command_t * cmd)
Dave Barache5389bb2016-03-28 17:12:19 -0400703{
Damjan Marionf553a2c2021-03-26 13:45:37 +0100704 elog_main_t *em = &vlib_global_main.elog_main;
Dave Barache5389bb2016-03-28 17:12:19 -0400705
706 em->n_total_events_disable_limit = em->n_total_events;
707
708 vlib_cli_output (vm, "Stopped the event logger...");
709 return 0;
710}
711
Dave Barach9b8ffd92016-07-08 08:13:45 -0400712/* *INDENT-OFF* */
Dave Barache5389bb2016-03-28 17:12:19 -0400713VLIB_CLI_COMMAND (elog_stop_cli, static) = {
714 .path = "event-logger stop",
715 .short_help = "Stop the event-logger",
716 .function = elog_stop,
717};
Dave Barach9b8ffd92016-07-08 08:13:45 -0400718/* *INDENT-ON* */
Dave Barache5389bb2016-03-28 17:12:19 -0400719
720static clib_error_t *
721elog_restart (vlib_main_t * vm,
Dave Barach9b8ffd92016-07-08 08:13:45 -0400722 unformat_input_t * input, vlib_cli_command_t * cmd)
Dave Barache5389bb2016-03-28 17:12:19 -0400723{
Damjan Marionf553a2c2021-03-26 13:45:37 +0100724 elog_main_t *em = &vlib_global_main.elog_main;
Dave Barache5389bb2016-03-28 17:12:19 -0400725
726 em->n_total_events_disable_limit = ~0;
727
728 vlib_cli_output (vm, "Restarted the event logger...");
729 return 0;
730}
731
Dave Barach9b8ffd92016-07-08 08:13:45 -0400732/* *INDENT-OFF* */
Dave Barache5389bb2016-03-28 17:12:19 -0400733VLIB_CLI_COMMAND (elog_restart_cli, static) = {
734 .path = "event-logger restart",
735 .short_help = "Restart the event-logger",
736 .function = elog_restart,
737};
Dave Barach9b8ffd92016-07-08 08:13:45 -0400738/* *INDENT-ON* */
Dave Barache5389bb2016-03-28 17:12:19 -0400739
740static clib_error_t *
Dave Barachbc867c32020-11-25 10:07:09 -0500741elog_resize_command_fn (vlib_main_t * vm,
742 unformat_input_t * input, vlib_cli_command_t * cmd)
Dave Barache5389bb2016-03-28 17:12:19 -0400743{
Damjan Marionf553a2c2021-03-26 13:45:37 +0100744 elog_main_t *em = &vlib_global_main.elog_main;
Dave Barache5389bb2016-03-28 17:12:19 -0400745 u32 tmp;
746
747 /* Stop the parade */
Damjan Marionf553a2c2021-03-26 13:45:37 +0100748 elog_reset_buffer (em);
Dave Barache5389bb2016-03-28 17:12:19 -0400749
750 if (unformat (input, "%d", &tmp))
751 {
752 elog_alloc (em, tmp);
753 em->n_total_events_disable_limit = ~0;
754 }
Dave Barach9b8ffd92016-07-08 08:13:45 -0400755 else
Dave Barache5389bb2016-03-28 17:12:19 -0400756 return clib_error_return (0, "Must specify how many events in the ring");
757
758 vlib_cli_output (vm, "Resized ring and restarted the event logger...");
759 return 0;
760}
761
Dave Barach9b8ffd92016-07-08 08:13:45 -0400762/* *INDENT-OFF* */
Dave Barache5389bb2016-03-28 17:12:19 -0400763VLIB_CLI_COMMAND (elog_resize_cli, static) = {
764 .path = "event-logger resize",
765 .short_help = "event-logger resize <nnn>",
Dave Barachbc867c32020-11-25 10:07:09 -0500766 .function = elog_resize_command_fn,
Dave Barache5389bb2016-03-28 17:12:19 -0400767};
Dave Barach9b8ffd92016-07-08 08:13:45 -0400768/* *INDENT-ON* */
Dave Barache5389bb2016-03-28 17:12:19 -0400769
Ed Warnickecb9cada2015-12-08 15:45:58 -0700770#endif /* CLIB_UNIX */
771
Dave Barach9b8ffd92016-07-08 08:13:45 -0400772static void
773elog_show_buffer_internal (vlib_main_t * vm, u32 n_events_to_show)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700774{
Damjan Marionf553a2c2021-03-26 13:45:37 +0100775 elog_main_t *em = &vlib_global_main.elog_main;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400776 elog_event_t *e, *es;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700777 f64 dt;
778
779 /* Show events in VLIB time since log clock starts after VLIB clock. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400780 dt = (em->init_time.cpu - vm->clib_time.init_cpu_time)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700781 * vm->clib_time.seconds_per_clock;
782
783 es = elog_peek_events (em);
Dave Barach9b8ffd92016-07-08 08:13:45 -0400784 vlib_cli_output (vm, "%d of %d events in buffer, logger %s", vec_len (es),
785 em->event_ring_size,
786 em->n_total_events < em->n_total_events_disable_limit ?
787 "running" : "stopped");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700788 vec_foreach (e, es)
Dave Barach9b8ffd92016-07-08 08:13:45 -0400789 {
790 vlib_cli_output (vm, "%18.9f: %U",
791 e->time + dt, format_elog_event, em, e);
792 n_events_to_show--;
793 if (n_events_to_show == 0)
794 break;
795 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700796 vec_free (es);
Dave Barach9b8ffd92016-07-08 08:13:45 -0400797
Ed Warnickecb9cada2015-12-08 15:45:58 -0700798}
799
800static clib_error_t *
801elog_show_buffer (vlib_main_t * vm,
Dave Barach9b8ffd92016-07-08 08:13:45 -0400802 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700803{
804 u32 n_events_to_show;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400805 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700806
807 n_events_to_show = 250;
808 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
809 {
810 if (unformat (input, "%d", &n_events_to_show))
811 ;
812 else if (unformat (input, "all"))
813 n_events_to_show = ~0;
814 else
815 return unformat_parse_error (input);
816 }
817 elog_show_buffer_internal (vm, n_events_to_show);
818 return error;
819}
820
Dave Barach9b8ffd92016-07-08 08:13:45 -0400821/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700822VLIB_CLI_COMMAND (elog_show_cli, static) = {
823 .path = "show event-logger",
824 .short_help = "Show event logger info",
825 .function = elog_show_buffer,
826};
Dave Barach9b8ffd92016-07-08 08:13:45 -0400827/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700828
Dave Barach9b8ffd92016-07-08 08:13:45 -0400829void
830vlib_gdb_show_event_log (void)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700831{
Dave Barach9b8ffd92016-07-08 08:13:45 -0400832 elog_show_buffer_internal (vlib_get_main (), (u32) ~ 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700833}
834
Dave Barachfb6e59d2016-03-26 18:45:42 -0400835static inline void
Ed Warnickecb9cada2015-12-08 15:45:58 -0700836vlib_elog_main_loop_event (vlib_main_t * vm,
837 u32 node_index,
Dave Barach9b8ffd92016-07-08 08:13:45 -0400838 u64 time, u32 n_vectors, u32 is_return)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700839{
Damjan Marionfd8deb42021-03-06 12:26:28 +0100840 vlib_main_t *evm = vlib_get_first_main ();
Damjan Marionf553a2c2021-03-26 13:45:37 +0100841 elog_main_t *em = vlib_get_elog_main ();
Dave Barach900cbad2019-01-31 19:12:51 -0500842 int enabled = evm->elog_trace_graph_dispatch |
843 evm->elog_trace_graph_circuit;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700844
Dave Barach900cbad2019-01-31 19:12:51 -0500845 if (PREDICT_FALSE (enabled && n_vectors))
846 {
847 if (PREDICT_FALSE (!elog_is_enabled (em)))
848 {
849 evm->elog_trace_graph_dispatch = 0;
850 evm->elog_trace_graph_circuit = 0;
851 return;
852 }
853 if (PREDICT_TRUE
854 (evm->elog_trace_graph_dispatch ||
855 (evm->elog_trace_graph_circuit &&
856 node_index == evm->elog_trace_graph_circuit_node_index)))
857 {
858 elog_track (em,
859 /* event type */
860 vec_elt_at_index (is_return
861 ? evm->node_return_elog_event_types
862 : evm->node_call_elog_event_types,
863 node_index),
864 /* track */
865 (vm->thread_index ?
866 &vlib_worker_threads[vm->thread_index].elog_track
867 : &em->default_track),
868 /* data to log */ n_vectors);
869 }
870 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700871}
872
Dave Barach7bee7732017-10-18 18:48:11 -0400873static inline void
874add_trajectory_trace (vlib_buffer_t * b, u32 node_index)
875{
876#if VLIB_BUFFER_TRACE_TRAJECTORY > 0
Benoît Gannef89bbbe2021-03-04 14:31:03 +0100877 if (PREDICT_FALSE (b->trajectory_nb >= VLIB_BUFFER_TRACE_TRAJECTORY_MAX))
878 return;
879 b->trajectory_trace[b->trajectory_nb] = node_index;
880 b->trajectory_nb++;
Dave Barach7bee7732017-10-18 18:48:11 -0400881#endif
882}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700883
Damjan Marion9a332e12017-03-28 15:11:20 +0200884static_always_inline u64
Ed Warnickecb9cada2015-12-08 15:45:58 -0700885dispatch_node (vlib_main_t * vm,
886 vlib_node_runtime_t * node,
887 vlib_node_type_t type,
888 vlib_node_state_t dispatch_state,
Dave Barach9b8ffd92016-07-08 08:13:45 -0400889 vlib_frame_t * frame, u64 last_time_stamp)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700890{
891 uword n, v;
892 u64 t;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400893 vlib_node_main_t *nm = &vm->node_main;
894 vlib_next_frame_t *nf;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700895
896 if (CLIB_DEBUG > 0)
897 {
Dave Barach9b8ffd92016-07-08 08:13:45 -0400898 vlib_node_t *n = vlib_get_node (vm, node->node_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700899 ASSERT (n->type == type);
900 }
901
902 /* Only non-internal nodes may be disabled. */
903 if (type != VLIB_NODE_TYPE_INTERNAL && node->state != dispatch_state)
904 {
905 ASSERT (type != VLIB_NODE_TYPE_INTERNAL);
906 return last_time_stamp;
907 }
908
909 if ((type == VLIB_NODE_TYPE_PRE_INPUT || type == VLIB_NODE_TYPE_INPUT)
910 && dispatch_state != VLIB_NODE_STATE_INTERRUPT)
911 {
912 u32 c = node->input_main_loops_per_call;
913 /* Only call node when count reaches zero. */
914 if (c)
915 {
916 node->input_main_loops_per_call = c - 1;
917 return last_time_stamp;
918 }
919 }
920
921 /* Speculatively prefetch next frames. */
922 if (node->n_next_nodes > 0)
923 {
924 nf = vec_elt_at_index (nm->next_frames, node->next_frame_index);
925 CLIB_PREFETCH (nf, 4 * sizeof (nf[0]), WRITE);
926 }
927
928 vm->cpu_time_last_node_dispatch = last_time_stamp;
929
Dave Barach900cbad2019-01-31 19:12:51 -0500930 vlib_elog_main_loop_event (vm, node->node_index,
931 last_time_stamp, frame ? frame->n_vectors : 0,
932 /* is_after */ 0);
933
Tom Seidenberg6c81f5a2020-07-10 15:49:03 +0000934 vlib_node_runtime_perf_counter (vm, node, frame, 0, last_time_stamp,
935 VLIB_NODE_RUNTIME_PERF_BEFORE);
Dave Barach900cbad2019-01-31 19:12:51 -0500936
937 /*
938 * Turn this on if you run into
939 * "bad monkey" contexts, and you want to know exactly
940 * which nodes they've visited... See ixge.c...
941 */
942 if (VLIB_BUFFER_TRACE_TRAJECTORY && frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700943 {
Dave Barach900cbad2019-01-31 19:12:51 -0500944 int i;
945 u32 *from;
946 from = vlib_frame_vector_args (frame);
947 for (i = 0; i < frame->n_vectors; i++)
Dave Barach9b8ffd92016-07-08 08:13:45 -0400948 {
Dave Barach900cbad2019-01-31 19:12:51 -0500949 vlib_buffer_t *b = vlib_get_buffer (vm, from[i]);
950 add_trajectory_trace (b, node->node_index);
Dave Barach9b8ffd92016-07-08 08:13:45 -0400951 }
Damjan Marion8b60fb02020-11-27 20:15:17 +0100952 if (PREDICT_TRUE (vm->dispatch_wrapper_fn == 0))
953 n = node->function (vm, node, frame);
954 else
955 n = vm->dispatch_wrapper_fn (vm, node, frame);
Dave Barach900cbad2019-01-31 19:12:51 -0500956 }
957 else
958 {
Damjan Marion8b60fb02020-11-27 20:15:17 +0100959 if (PREDICT_TRUE (vm->dispatch_wrapper_fn == 0))
960 n = node->function (vm, node, frame);
961 else
962 n = vm->dispatch_wrapper_fn (vm, node, frame);
Dave Barach900cbad2019-01-31 19:12:51 -0500963 }
964
965 t = clib_cpu_time_now ();
966
Tom Seidenberg6c81f5a2020-07-10 15:49:03 +0000967 vlib_node_runtime_perf_counter (vm, node, frame, n, t,
968 VLIB_NODE_RUNTIME_PERF_AFTER);
Dave Barach900cbad2019-01-31 19:12:51 -0500969
970 vlib_elog_main_loop_event (vm, node->node_index, t, n, 1 /* is_after */ );
971
972 vm->main_loop_vectors_processed += n;
973 vm->main_loop_nodes_processed += n > 0;
974
975 v = vlib_node_runtime_update_stats (vm, node,
976 /* n_calls */ 1,
977 /* n_vectors */ n,
Tom Seidenberg6c81f5a2020-07-10 15:49:03 +0000978 /* n_clocks */ t - last_time_stamp);
Dave Barach900cbad2019-01-31 19:12:51 -0500979
Florin Coras982e44f2021-03-19 13:12:41 -0700980 /* When in adaptive mode and vector rate crosses threshold switch to
981 polling mode and vice versa. */
982 if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_ADAPTIVE_MODE))
Dave Barach900cbad2019-01-31 19:12:51 -0500983 {
984 /* *INDENT-OFF* */
985 ELOG_TYPE_DECLARE (e) =
986 {
987 .function = (char *) __FUNCTION__,
988 .format = "%s vector length %d, switching to %s",
989 .format_args = "T4i4t4",
990 .n_enum_strings = 2,
991 .enum_strings = {
992 "interrupt", "polling",
993 },
994 };
995 /* *INDENT-ON* */
996 struct
997 {
998 u32 node_name, vector_length, is_polling;
999 } *ed;
1000
1001 if ((dispatch_state == VLIB_NODE_STATE_INTERRUPT
1002 && v >= nm->polling_threshold_vector_length) &&
1003 !(node->flags &
1004 VLIB_NODE_FLAG_SWITCH_FROM_INTERRUPT_TO_POLLING_MODE))
Dave Barach3ae28732018-11-16 17:19:00 -05001005 {
Dave Barach900cbad2019-01-31 19:12:51 -05001006 vlib_node_t *n = vlib_get_node (vm, node->node_index);
1007 n->state = VLIB_NODE_STATE_POLLING;
1008 node->state = VLIB_NODE_STATE_POLLING;
1009 node->flags &=
1010 ~VLIB_NODE_FLAG_SWITCH_FROM_POLLING_TO_INTERRUPT_MODE;
1011 node->flags |= VLIB_NODE_FLAG_SWITCH_FROM_INTERRUPT_TO_POLLING_MODE;
1012 nm->input_node_counts_by_state[VLIB_NODE_STATE_INTERRUPT] -= 1;
1013 nm->input_node_counts_by_state[VLIB_NODE_STATE_POLLING] += 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001014
Damjan Marionfd8deb42021-03-06 12:26:28 +01001015 if (PREDICT_FALSE (
1016 vlib_get_first_main ()->elog_trace_graph_dispatch))
Dave Barach9b8ffd92016-07-08 08:13:45 -04001017 {
Dave Barach900cbad2019-01-31 19:12:51 -05001018 vlib_worker_thread_t *w = vlib_worker_threads
1019 + vm->thread_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001020
Steven6aa75af2017-02-24 10:03:22 -08001021 ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main, e,
1022 w->elog_track);
Dave Barach9b8ffd92016-07-08 08:13:45 -04001023 ed->node_name = n->name_elog_string;
1024 ed->vector_length = v;
1025 ed->is_polling = 1;
1026 }
Dave Barach900cbad2019-01-31 19:12:51 -05001027 }
1028 else if (dispatch_state == VLIB_NODE_STATE_POLLING
1029 && v <= nm->interrupt_threshold_vector_length)
1030 {
1031 vlib_node_t *n = vlib_get_node (vm, node->node_index);
1032 if (node->flags &
1033 VLIB_NODE_FLAG_SWITCH_FROM_POLLING_TO_INTERRUPT_MODE)
Dave Barach9b8ffd92016-07-08 08:13:45 -04001034 {
Dave Barach900cbad2019-01-31 19:12:51 -05001035 /* Switch to interrupt mode after dispatch in polling one more time.
1036 This allows driver to re-enable interrupts. */
1037 n->state = VLIB_NODE_STATE_INTERRUPT;
1038 node->state = VLIB_NODE_STATE_INTERRUPT;
1039 node->flags &=
1040 ~VLIB_NODE_FLAG_SWITCH_FROM_INTERRUPT_TO_POLLING_MODE;
1041 nm->input_node_counts_by_state[VLIB_NODE_STATE_POLLING] -= 1;
1042 nm->input_node_counts_by_state[VLIB_NODE_STATE_INTERRUPT] += 1;
Dave Barach9b8ffd92016-07-08 08:13:45 -04001043
Dave Barach900cbad2019-01-31 19:12:51 -05001044 }
1045 else
1046 {
1047 vlib_worker_thread_t *w = vlib_worker_threads
1048 + vm->thread_index;
1049 node->flags |=
1050 VLIB_NODE_FLAG_SWITCH_FROM_POLLING_TO_INTERRUPT_MODE;
Damjan Marionfd8deb42021-03-06 12:26:28 +01001051 if (PREDICT_FALSE (
1052 vlib_get_first_main ()->elog_trace_graph_dispatch))
Dave Barach9b8ffd92016-07-08 08:13:45 -04001053 {
Steven6aa75af2017-02-24 10:03:22 -08001054 ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main, e,
1055 w->elog_track);
Dave Barach9b8ffd92016-07-08 08:13:45 -04001056 ed->node_name = n->name_elog_string;
1057 ed->vector_length = v;
1058 ed->is_polling = 0;
1059 }
1060 }
1061 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001062 }
1063
1064 return t;
1065}
1066
Damjan Marion9a332e12017-03-28 15:11:20 +02001067static u64
Dave Baracha6269992017-06-07 08:18:49 -04001068dispatch_pending_node (vlib_main_t * vm, uword pending_frame_index,
1069 u64 last_time_stamp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001070{
Dave Barach9b8ffd92016-07-08 08:13:45 -04001071 vlib_node_main_t *nm = &vm->node_main;
1072 vlib_frame_t *f;
Dave Barach11fb09e2020-08-06 12:10:09 -04001073 vlib_next_frame_t *nf, nf_placeholder;
Dave Barach9b8ffd92016-07-08 08:13:45 -04001074 vlib_node_runtime_t *n;
Andreas Schultz58b2eb12019-07-15 15:40:56 +02001075 vlib_frame_t *restore_frame;
Dave Baracha6269992017-06-07 08:18:49 -04001076 vlib_pending_frame_t *p;
1077
1078 /* See comment below about dangling references to nm->pending_frames */
1079 p = nm->pending_frames + pending_frame_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001080
1081 n = vec_elt_at_index (nm->nodes_by_type[VLIB_NODE_TYPE_INTERNAL],
1082 p->node_runtime_index);
1083
Andreas Schultz58b2eb12019-07-15 15:40:56 +02001084 f = vlib_get_frame (vm, p->frame);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001085 if (p->next_frame_index == VLIB_PENDING_FRAME_NO_NEXT_FRAME)
1086 {
Dave Barach11fb09e2020-08-06 12:10:09 -04001087 /* No next frame: so use placeholder on stack. */
1088 nf = &nf_placeholder;
Damjan Marion633b6fd2018-09-14 14:38:53 +02001089 nf->flags = f->frame_flags & VLIB_NODE_FLAG_TRACE;
Andreas Schultz58b2eb12019-07-15 15:40:56 +02001090 nf->frame = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001091 }
1092 else
1093 nf = vec_elt_at_index (nm->next_frames, p->next_frame_index);
1094
Damjan Marion633b6fd2018-09-14 14:38:53 +02001095 ASSERT (f->frame_flags & VLIB_FRAME_IS_ALLOCATED);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001096
1097 /* Force allocation of new frame while current frame is being
1098 dispatched. */
Andreas Schultz58b2eb12019-07-15 15:40:56 +02001099 restore_frame = NULL;
1100 if (nf->frame == p->frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001101 {
Andreas Schultz58b2eb12019-07-15 15:40:56 +02001102 nf->frame = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001103 nf->flags &= ~VLIB_FRAME_IS_ALLOCATED;
Dave Barach9b8ffd92016-07-08 08:13:45 -04001104 if (!(n->flags & VLIB_NODE_FLAG_FRAME_NO_FREE_AFTER_DISPATCH))
Andreas Schultz58b2eb12019-07-15 15:40:56 +02001105 restore_frame = p->frame;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001106 }
1107
1108 /* Frame must be pending. */
Damjan Marion633b6fd2018-09-14 14:38:53 +02001109 ASSERT (f->frame_flags & VLIB_FRAME_PENDING);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001110 ASSERT (f->n_vectors > 0);
1111
1112 /* Copy trace flag from next frame to node.
1113 Trace flag indicates that at least one vector in the dispatched
1114 frame is traced. */
1115 n->flags &= ~VLIB_NODE_FLAG_TRACE;
1116 n->flags |= (nf->flags & VLIB_FRAME_TRACE) ? VLIB_NODE_FLAG_TRACE : 0;
1117 nf->flags &= ~VLIB_FRAME_TRACE;
1118
1119 last_time_stamp = dispatch_node (vm, n,
1120 VLIB_NODE_TYPE_INTERNAL,
1121 VLIB_NODE_STATE_POLLING,
1122 f, last_time_stamp);
Dave Baracha8df85c2019-10-01 13:34:23 -04001123 /* Internal node vector-rate accounting, for summary stats */
1124 vm->internal_node_vectors += f->n_vectors;
1125 vm->internal_node_calls++;
1126 vm->internal_node_last_vectors_per_main_loop =
1127 (f->n_vectors > vm->internal_node_last_vectors_per_main_loop) ?
1128 f->n_vectors : vm->internal_node_last_vectors_per_main_loop;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001129
Damjan Marion296988d2019-02-21 20:24:54 +01001130 f->frame_flags &= ~(VLIB_FRAME_PENDING | VLIB_FRAME_NO_APPEND);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001131
1132 /* Frame is ready to be used again, so restore it. */
Andreas Schultz58b2eb12019-07-15 15:40:56 +02001133 if (restore_frame != NULL)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001134 {
Dave Baracha6269992017-06-07 08:18:49 -04001135 /*
1136 * We musn't restore a frame that is flagged to be freed. This
1137 * shouldn't happen since frames to be freed post dispatch are
1138 * those used when the to-node frame becomes full i.e. they form a
1139 * sort of queue of frames to a single node. If we get here then
1140 * the to-node frame and the pending frame *were* the same, and so
1141 * we removed the to-node frame. Therefore this frame is no
1142 * longer part of the queue for that node and hence it cannot be
1143 * it's overspill.
Neale Ranns88170612016-11-22 08:29:51 +00001144 */
Damjan Marion633b6fd2018-09-14 14:38:53 +02001145 ASSERT (!(f->frame_flags & VLIB_FRAME_FREE_AFTER_DISPATCH));
Neale Ranns88170612016-11-22 08:29:51 +00001146
Dave Baracha6269992017-06-07 08:18:49 -04001147 /*
1148 * NB: dispatching node n can result in the creation and scheduling
1149 * of new frames, and hence in the reallocation of nm->pending_frames.
1150 * Recompute p, or no supper. This was broken for more than 10 years.
1151 */
1152 p = nm->pending_frames + pending_frame_index;
1153
1154 /*
1155 * p->next_frame_index can change during node dispatch if node
1156 * function decides to change graph hook up.
1157 */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001158 nf = vec_elt_at_index (nm->next_frames, p->next_frame_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001159 nf->flags |= VLIB_FRAME_IS_ALLOCATED;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001160
Andreas Schultz58b2eb12019-07-15 15:40:56 +02001161 if (NULL == nf->frame)
Neale Ranns88170612016-11-22 08:29:51 +00001162 {
1163 /* no new frame has been assigned to this node, use the saved one */
Andreas Schultz58b2eb12019-07-15 15:40:56 +02001164 nf->frame = restore_frame;
Neale Ranns88170612016-11-22 08:29:51 +00001165 f->n_vectors = 0;
Stanislav Zaikin3791a032022-03-31 14:16:28 +02001166 f->flags = 0;
Neale Ranns88170612016-11-22 08:29:51 +00001167 }
1168 else
1169 {
1170 /* The node has gained a frame, implying packets from the current frame
1171 were re-queued to this same node. we don't need the saved one
1172 anymore */
Dmitry Valter9f5b3692022-09-05 15:30:18 +00001173 vlib_frame_free (vm, f);
Neale Ranns88170612016-11-22 08:29:51 +00001174 }
1175 }
1176 else
Ed Warnickecb9cada2015-12-08 15:45:58 -07001177 {
Damjan Marion633b6fd2018-09-14 14:38:53 +02001178 if (f->frame_flags & VLIB_FRAME_FREE_AFTER_DISPATCH)
Neale Ranns88170612016-11-22 08:29:51 +00001179 {
1180 ASSERT (!(n->flags & VLIB_NODE_FLAG_FRAME_NO_FREE_AFTER_DISPATCH));
Dmitry Valter9f5b3692022-09-05 15:30:18 +00001181 vlib_frame_free (vm, f);
Neale Ranns88170612016-11-22 08:29:51 +00001182 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001183 }
1184
1185 return last_time_stamp;
1186}
1187
1188always_inline uword
1189vlib_process_stack_is_valid (vlib_process_t * p)
Dave Barach9b8ffd92016-07-08 08:13:45 -04001190{
1191 return p->stack[0] == VLIB_PROCESS_STACK_MAGIC;
1192}
Ed Warnickecb9cada2015-12-08 15:45:58 -07001193
Dave Barach9b8ffd92016-07-08 08:13:45 -04001194typedef struct
1195{
1196 vlib_main_t *vm;
1197 vlib_process_t *process;
1198 vlib_frame_t *frame;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001199} vlib_process_bootstrap_args_t;
1200
1201/* Called in process stack. */
Dave Barach9b8ffd92016-07-08 08:13:45 -04001202static uword
1203vlib_process_bootstrap (uword _a)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001204{
Dave Barach9b8ffd92016-07-08 08:13:45 -04001205 vlib_process_bootstrap_args_t *a;
1206 vlib_main_t *vm;
1207 vlib_node_runtime_t *node;
1208 vlib_frame_t *f;
1209 vlib_process_t *p;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001210 uword n;
1211
1212 a = uword_to_pointer (_a, vlib_process_bootstrap_args_t *);
1213
1214 vm = a->vm;
1215 p = a->process;
Damjan Marioncea46522020-05-21 16:47:05 +02001216 vlib_process_finish_switch_stack (vm);
1217
Ed Warnickecb9cada2015-12-08 15:45:58 -07001218 f = a->frame;
1219 node = &p->node_runtime;
1220
1221 n = node->function (vm, node, f);
1222
1223 ASSERT (vlib_process_stack_is_valid (p));
1224
Damjan Marioncea46522020-05-21 16:47:05 +02001225 vlib_process_start_switch_stack (vm, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001226 clib_longjmp (&p->return_longjmp, n);
1227
1228 return n;
1229}
1230
1231/* Called in main stack. */
1232static_always_inline uword
Dave Barach9b8ffd92016-07-08 08:13:45 -04001233vlib_process_startup (vlib_main_t * vm, vlib_process_t * p, vlib_frame_t * f)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001234{
1235 vlib_process_bootstrap_args_t a;
1236 uword r;
1237
1238 a.vm = vm;
1239 a.process = p;
1240 a.frame = f;
1241
1242 r = clib_setjmp (&p->return_longjmp, VLIB_PROCESS_RETURN_LONGJMP_RETURN);
1243 if (r == VLIB_PROCESS_RETURN_LONGJMP_RETURN)
Damjan Marioncea46522020-05-21 16:47:05 +02001244 {
1245 vlib_process_start_switch_stack (vm, p);
1246 r = clib_calljmp (vlib_process_bootstrap, pointer_to_uword (&a),
1247 (void *) p->stack + (1 << p->log2_n_stack_bytes));
1248 }
1249 else
1250 vlib_process_finish_switch_stack (vm);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001251
1252 return r;
1253}
1254
1255static_always_inline uword
Damjan Marioncea46522020-05-21 16:47:05 +02001256vlib_process_resume (vlib_main_t * vm, vlib_process_t * p)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001257{
1258 uword r;
1259 p->flags &= ~(VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK
1260 | VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT
1261 | VLIB_PROCESS_RESUME_PENDING);
1262 r = clib_setjmp (&p->return_longjmp, VLIB_PROCESS_RETURN_LONGJMP_RETURN);
1263 if (r == VLIB_PROCESS_RETURN_LONGJMP_RETURN)
Damjan Marioncea46522020-05-21 16:47:05 +02001264 {
1265 vlib_process_start_switch_stack (vm, p);
1266 clib_longjmp (&p->resume_longjmp, VLIB_PROCESS_RESUME_LONGJMP_RESUME);
1267 }
1268 else
1269 vlib_process_finish_switch_stack (vm);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001270 return r;
1271}
1272
1273static u64
1274dispatch_process (vlib_main_t * vm,
Dave Barach9b8ffd92016-07-08 08:13:45 -04001275 vlib_process_t * p, vlib_frame_t * f, u64 last_time_stamp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001276{
Dave Barach9b8ffd92016-07-08 08:13:45 -04001277 vlib_node_main_t *nm = &vm->node_main;
1278 vlib_node_runtime_t *node_runtime = &p->node_runtime;
1279 vlib_node_t *node = vlib_get_node (vm, node_runtime->node_index);
Florin Corasfd542f12018-05-16 19:28:24 -07001280 u32 old_process_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001281 u64 t;
1282 uword n_vectors, is_suspend;
1283
1284 if (node->state != VLIB_NODE_STATE_POLLING
1285 || (p->flags & (VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK
1286 | VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT)))
1287 return last_time_stamp;
1288
1289 p->flags |= VLIB_PROCESS_IS_RUNNING;
1290
1291 t = last_time_stamp;
1292 vlib_elog_main_loop_event (vm, node_runtime->node_index, t,
1293 f ? f->n_vectors : 0, /* is_after */ 0);
1294
1295 /* Save away current process for suspend. */
Florin Corasfd542f12018-05-16 19:28:24 -07001296 old_process_index = nm->current_process_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001297 nm->current_process_index = node->runtime_index;
1298
Tom Seidenberg6c81f5a2020-07-10 15:49:03 +00001299 vlib_node_runtime_perf_counter (vm, node_runtime, f, 0, last_time_stamp,
1300 VLIB_NODE_RUNTIME_PERF_BEFORE);
1301
Ed Warnickecb9cada2015-12-08 15:45:58 -07001302 n_vectors = vlib_process_startup (vm, p, f);
1303
Florin Corasfd542f12018-05-16 19:28:24 -07001304 nm->current_process_index = old_process_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001305
1306 ASSERT (n_vectors != VLIB_PROCESS_RETURN_LONGJMP_RETURN);
1307 is_suspend = n_vectors == VLIB_PROCESS_RETURN_LONGJMP_SUSPEND;
1308 if (is_suspend)
1309 {
Dave Barach9b8ffd92016-07-08 08:13:45 -04001310 vlib_pending_frame_t *pf;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001311
1312 n_vectors = 0;
1313 pool_get (nm->suspended_process_frames, pf);
1314 pf->node_runtime_index = node->runtime_index;
Andreas Schultz58b2eb12019-07-15 15:40:56 +02001315 pf->frame = f;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001316 pf->next_frame_index = ~0;
1317
1318 p->n_suspends += 1;
1319 p->suspended_process_frame_index = pf - nm->suspended_process_frames;
1320
1321 if (p->flags & VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK)
Dave Barach5c20a012017-06-13 08:48:31 -04001322 {
1323 TWT (tw_timer_wheel) * tw =
1324 (TWT (tw_timer_wheel) *) nm->timing_wheel;
1325 p->stop_timer_handle =
1326 TW (tw_timer_start) (tw,
1327 vlib_timing_wheel_data_set_suspended_process
1328 (node->runtime_index) /* [sic] pool idex */ ,
1329 0 /* timer_id */ ,
1330 p->resume_clock_interval);
1331 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001332 }
1333 else
1334 p->flags &= ~VLIB_PROCESS_IS_RUNNING;
1335
1336 t = clib_cpu_time_now ();
1337
Dave Barach9b8ffd92016-07-08 08:13:45 -04001338 vlib_elog_main_loop_event (vm, node_runtime->node_index, t, is_suspend,
1339 /* is_after */ 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001340
Tom Seidenberg6c81f5a2020-07-10 15:49:03 +00001341 vlib_node_runtime_perf_counter (vm, node_runtime, f, n_vectors, t,
1342 VLIB_NODE_RUNTIME_PERF_AFTER);
1343
Ed Warnickecb9cada2015-12-08 15:45:58 -07001344 vlib_process_update_stats (vm, p,
Dave Barach9b8ffd92016-07-08 08:13:45 -04001345 /* n_calls */ !is_suspend,
Ed Warnickecb9cada2015-12-08 15:45:58 -07001346 /* n_vectors */ n_vectors,
Dave Barachec595ef2019-01-24 10:34:24 -05001347 /* n_clocks */ t - last_time_stamp);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001348
1349 return t;
1350}
1351
Dave Barach9b8ffd92016-07-08 08:13:45 -04001352void
1353vlib_start_process (vlib_main_t * vm, uword process_index)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001354{
Dave Barach9b8ffd92016-07-08 08:13:45 -04001355 vlib_node_main_t *nm = &vm->node_main;
1356 vlib_process_t *p = vec_elt (nm->processes, process_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001357 dispatch_process (vm, p, /* frame */ 0, /* cpu_time_now */ 0);
1358}
1359
1360static u64
1361dispatch_suspended_process (vlib_main_t * vm,
Dave Barach9b8ffd92016-07-08 08:13:45 -04001362 uword process_index, u64 last_time_stamp)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001363{
Dave Barach9b8ffd92016-07-08 08:13:45 -04001364 vlib_node_main_t *nm = &vm->node_main;
1365 vlib_node_runtime_t *node_runtime;
1366 vlib_node_t *node;
1367 vlib_frame_t *f;
1368 vlib_process_t *p;
1369 vlib_pending_frame_t *pf;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001370 u64 t, n_vectors, is_suspend;
Dave Barach9b8ffd92016-07-08 08:13:45 -04001371
Ed Warnickecb9cada2015-12-08 15:45:58 -07001372 t = last_time_stamp;
1373
1374 p = vec_elt (nm->processes, process_index);
Dave Barach9b8ffd92016-07-08 08:13:45 -04001375 if (PREDICT_FALSE (!(p->flags & VLIB_PROCESS_IS_RUNNING)))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001376 return last_time_stamp;
1377
1378 ASSERT (p->flags & (VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK
1379 | VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT));
1380
Florin Coras221d6f12018-11-07 20:46:38 -08001381 pf = pool_elt_at_index (nm->suspended_process_frames,
1382 p->suspended_process_frame_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001383
1384 node_runtime = &p->node_runtime;
1385 node = vlib_get_node (vm, node_runtime->node_index);
Andreas Schultz58b2eb12019-07-15 15:40:56 +02001386 f = pf->frame;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001387
Dave Barach9b8ffd92016-07-08 08:13:45 -04001388 vlib_elog_main_loop_event (vm, node_runtime->node_index, t,
1389 f ? f->n_vectors : 0, /* is_after */ 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001390
1391 /* Save away current process for suspend. */
1392 nm->current_process_index = node->runtime_index;
1393
Tom Seidenberg6c81f5a2020-07-10 15:49:03 +00001394 vlib_node_runtime_perf_counter (vm, node_runtime, f, 0, last_time_stamp,
1395 VLIB_NODE_RUNTIME_PERF_BEFORE);
1396
Damjan Marioncea46522020-05-21 16:47:05 +02001397 n_vectors = vlib_process_resume (vm, p);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001398 t = clib_cpu_time_now ();
1399
1400 nm->current_process_index = ~0;
1401
1402 is_suspend = n_vectors == VLIB_PROCESS_RETURN_LONGJMP_SUSPEND;
1403 if (is_suspend)
1404 {
1405 /* Suspend it again. */
1406 n_vectors = 0;
1407 p->n_suspends += 1;
1408 if (p->flags & VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK)
Dave Barach5c20a012017-06-13 08:48:31 -04001409 {
1410 p->stop_timer_handle =
1411 TW (tw_timer_start) ((TWT (tw_timer_wheel) *) nm->timing_wheel,
1412 vlib_timing_wheel_data_set_suspended_process
1413 (node->runtime_index) /* [sic] pool idex */ ,
1414 0 /* timer_id */ ,
1415 p->resume_clock_interval);
1416 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001417 }
1418 else
1419 {
1420 p->flags &= ~VLIB_PROCESS_IS_RUNNING;
Florin Coras221d6f12018-11-07 20:46:38 -08001421 pool_put_index (nm->suspended_process_frames,
1422 p->suspended_process_frame_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001423 p->suspended_process_frame_index = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001424 }
1425
1426 t = clib_cpu_time_now ();
Dave Barach9b8ffd92016-07-08 08:13:45 -04001427 vlib_elog_main_loop_event (vm, node_runtime->node_index, t, !is_suspend,
1428 /* is_after */ 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001429
Tom Seidenberg6c81f5a2020-07-10 15:49:03 +00001430 vlib_node_runtime_perf_counter (vm, node_runtime, f, n_vectors, t,
1431 VLIB_NODE_RUNTIME_PERF_AFTER);
1432
Ed Warnickecb9cada2015-12-08 15:45:58 -07001433 vlib_process_update_stats (vm, p,
Dave Barach9b8ffd92016-07-08 08:13:45 -04001434 /* n_calls */ !is_suspend,
Ed Warnickecb9cada2015-12-08 15:45:58 -07001435 /* n_vectors */ n_vectors,
Dave Barachec595ef2019-01-24 10:34:24 -05001436 /* n_clocks */ t - last_time_stamp);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001437
1438 return t;
1439}
1440
Dave Barach2877eee2017-12-15 12:22:57 -05001441void vl_api_send_pending_rpc_requests (vlib_main_t *) __attribute__ ((weak));
1442void
1443vl_api_send_pending_rpc_requests (vlib_main_t * vm)
1444{
1445}
1446
Damjan Marione9d52d52017-03-09 15:42:26 +01001447static_always_inline void
1448vlib_main_or_worker_loop (vlib_main_t * vm, int is_main)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001449{
Dave Barach9b8ffd92016-07-08 08:13:45 -04001450 vlib_node_main_t *nm = &vm->node_main;
Damjan Marione9d52d52017-03-09 15:42:26 +01001451 vlib_thread_main_t *tm = vlib_get_thread_main ();
Ed Warnickecb9cada2015-12-08 15:45:58 -07001452 uword i;
1453 u64 cpu_time_now;
Dave Barach000a0292020-02-17 17:07:12 -05001454 f64 now;
Damjan Marione9d52d52017-03-09 15:42:26 +01001455 vlib_frame_queue_main_t *fqm;
Dave Barach80965f52019-03-11 09:57:38 -04001456 u32 frame_queue_check_counter = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001457
1458 /* Initialize pending node vector. */
Damjan Marione9d52d52017-03-09 15:42:26 +01001459 if (is_main)
1460 {
1461 vec_resize (nm->pending_frames, 32);
Damjan Marion8bea5892022-04-04 22:40:45 +02001462 vec_set_len (nm->pending_frames, 0);
Damjan Marione9d52d52017-03-09 15:42:26 +01001463 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001464
1465 /* Mark time of main loop start. */
Damjan Marione9d52d52017-03-09 15:42:26 +01001466 if (is_main)
1467 {
1468 cpu_time_now = vm->clib_time.last_cpu_time;
1469 vm->cpu_time_main_loop_start = cpu_time_now;
1470 }
1471 else
1472 cpu_time_now = clib_cpu_time_now ();
Ed Warnickecb9cada2015-12-08 15:45:58 -07001473
Damjan Marion2c2b6402017-03-28 14:16:15 +02001474 /* Pre-allocate interupt runtime indices and lock. */
Benoît Ganne6a782ca2023-01-20 09:52:01 +01001475 vec_validate_aligned (nm->pending_interrupts, 0, CLIB_CACHE_LINE_BYTES);
Damjan Marion2c2b6402017-03-28 14:16:15 +02001476
1477 /* Pre-allocate expired nodes. */
Steven7312cc72017-03-15 21:18:55 -07001478 if (!nm->polling_threshold_vector_length)
1479 nm->polling_threshold_vector_length = 10;
1480 if (!nm->interrupt_threshold_vector_length)
1481 nm->interrupt_threshold_vector_length = 5;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001482
Damjan Marion29c0b332019-01-28 13:41:27 +01001483 vm->cpu_id = clib_get_current_cpu_id ();
1484 vm->numa_node = clib_get_current_numa_node ();
Florin Coras4c959952020-02-09 18:09:31 +00001485 os_set_numa_index (vm->numa_node);
Damjan Marion29c0b332019-01-28 13:41:27 +01001486
Ed Warnickecb9cada2015-12-08 15:45:58 -07001487 /* Start all processes. */
Damjan Marione9d52d52017-03-09 15:42:26 +01001488 if (is_main)
1489 {
1490 uword i;
Dave Barachc602b382019-06-03 19:48:22 -04001491
1492 /*
1493 * Perform an initial barrier sync. Pays no attention to
1494 * the barrier sync hold-down timer scheme, which won't work
1495 * at this point in time.
1496 */
1497 vlib_worker_thread_initial_barrier_sync_and_release (vm);
1498
Stevenf3b53642017-05-01 14:03:02 -07001499 nm->current_process_index = ~0;
Damjan Marione9d52d52017-03-09 15:42:26 +01001500 for (i = 0; i < vec_len (nm->processes); i++)
1501 cpu_time_now = dispatch_process (vm, nm->processes[i], /* frame */ 0,
1502 cpu_time_now);
1503 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001504
1505 while (1)
1506 {
Dave Barach9b8ffd92016-07-08 08:13:45 -04001507 vlib_node_runtime_t *n;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001508
Dave Barach2877eee2017-12-15 12:22:57 -05001509 if (PREDICT_FALSE (_vec_len (vm->pending_rpc_requests) > 0))
Dave Barachf6c68d72018-11-01 08:12:52 -04001510 {
1511 if (!is_main)
1512 vl_api_send_pending_rpc_requests (vm);
1513 }
Dave Barach2877eee2017-12-15 12:22:57 -05001514
Damjan Marione9d52d52017-03-09 15:42:26 +01001515 if (!is_main)
Damjan Marionf6e6c782020-09-17 09:54:07 +02001516 vlib_worker_thread_barrier_check ();
1517
1518 if (PREDICT_FALSE (vm->check_frame_queues + frame_queue_check_counter))
Damjan Marione9d52d52017-03-09 15:42:26 +01001519 {
Damjan Marionf6e6c782020-09-17 09:54:07 +02001520 u32 processed = 0;
Mohammed Hawarie7149262022-05-18 10:08:47 +02001521 vlib_frame_queue_dequeue_fn_t *fn;
Damjan Marionf6e6c782020-09-17 09:54:07 +02001522
1523 if (vm->check_frame_queues)
Dave Barach80965f52019-03-11 09:57:38 -04001524 {
Damjan Marionf6e6c782020-09-17 09:54:07 +02001525 frame_queue_check_counter = 100;
1526 vm->check_frame_queues = 0;
Dave Barach80965f52019-03-11 09:57:38 -04001527 }
Damjan Marionf6e6c782020-09-17 09:54:07 +02001528
1529 vec_foreach (fqm, tm->frame_queue_mains)
Mohammed Hawarie7149262022-05-18 10:08:47 +02001530 {
1531 fn = fqm->frame_queue_dequeue_fn;
1532 processed += (fn) (vm, fqm);
1533 }
Damjan Marionf6e6c782020-09-17 09:54:07 +02001534
1535 /* No handoff queue work found? */
1536 if (processed)
1537 frame_queue_check_counter = 100;
1538 else
1539 frame_queue_check_counter--;
Damjan Marione9d52d52017-03-09 15:42:26 +01001540 }
1541
Tom Seidenberg6c81f5a2020-07-10 15:49:03 +00001542 if (PREDICT_FALSE (vec_len (vm->worker_thread_main_loop_callbacks)))
1543 clib_call_callbacks (vm->worker_thread_main_loop_callbacks, vm,
1544 cpu_time_now);
1545
Ed Warnickecb9cada2015-12-08 15:45:58 -07001546 /* Process pre-input nodes. */
Tom Seidenberg6c81f5a2020-07-10 15:49:03 +00001547 cpu_time_now = clib_cpu_time_now ();
Damjan Marionceab7882018-01-19 20:56:12 +01001548 vec_foreach (n, nm->nodes_by_type[VLIB_NODE_TYPE_PRE_INPUT])
1549 cpu_time_now = dispatch_node (vm, n,
1550 VLIB_NODE_TYPE_PRE_INPUT,
1551 VLIB_NODE_STATE_POLLING,
1552 /* frame */ 0,
1553 cpu_time_now);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001554
1555 /* Next process input nodes. */
1556 vec_foreach (n, nm->nodes_by_type[VLIB_NODE_TYPE_INPUT])
1557 cpu_time_now = dispatch_node (vm, n,
1558 VLIB_NODE_TYPE_INPUT,
1559 VLIB_NODE_STATE_POLLING,
1560 /* frame */ 0,
1561 cpu_time_now);
1562
Damjan Marione9d52d52017-03-09 15:42:26 +01001563 if (PREDICT_TRUE (is_main && vm->queue_signal_pending == 0))
Dave Barach9b8ffd92016-07-08 08:13:45 -04001564 vm->queue_signal_callback (vm);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001565
Damjan Marion94100532020-11-06 23:25:57 +01001566 if (__atomic_load_n (nm->pending_interrupts, __ATOMIC_ACQUIRE))
Damjan Marion0b316302020-09-09 18:55:16 +02001567 {
Damjan Marion94100532020-11-06 23:25:57 +01001568 int int_num = -1;
1569 *nm->pending_interrupts = 0;
Dave Barachd47c5092018-01-19 13:09:20 -05001570
Damjan Marion94100532020-11-06 23:25:57 +01001571 while ((int_num =
1572 clib_interrupt_get_next (nm->interrupts, int_num)) != -1)
1573 {
1574 vlib_node_runtime_t *n;
1575 clib_interrupt_clear (nm->interrupts, int_num);
1576 n = vec_elt_at_index (nm->nodes_by_type[VLIB_NODE_TYPE_INPUT],
1577 int_num);
1578 cpu_time_now = dispatch_node (vm, n, VLIB_NODE_TYPE_INPUT,
1579 VLIB_NODE_STATE_INTERRUPT,
1580 /* frame */ 0, cpu_time_now);
1581 }
Damjan Marion1033b492020-06-03 12:20:41 +02001582 }
1583
Dave Barache3248982018-08-14 13:47:58 -04001584 /* Input nodes may have added work to the pending vector.
1585 Process pending vector until there is nothing left.
1586 All pending vectors will be processed from input -> output. */
1587 for (i = 0; i < _vec_len (nm->pending_frames); i++)
1588 cpu_time_now = dispatch_pending_node (vm, i, cpu_time_now);
1589 /* Reset pending vector for next iteration. */
Damjan Marion8bea5892022-04-04 22:40:45 +02001590 vec_set_len (nm->pending_frames, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001591
Damjan Marione9d52d52017-03-09 15:42:26 +01001592 if (is_main)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001593 {
Dave Barach900cbad2019-01-31 19:12:51 -05001594 /* *INDENT-OFF* */
1595 ELOG_TYPE_DECLARE (es) =
1596 {
1597 .format = "process tw start",
1598 .format_args = "",
1599 };
1600 ELOG_TYPE_DECLARE (ee) =
1601 {
1602 .format = "process tw end: %d",
1603 .format_args = "i4",
1604 };
1605 /* *INDENT-ON* */
1606
1607 struct
1608 {
1609 int nready_procs;
1610 } *ed;
1611
Damjan Marione9d52d52017-03-09 15:42:26 +01001612 /* Check if process nodes have expired from timing wheel. */
Dave Barach5c20a012017-06-13 08:48:31 -04001613 ASSERT (nm->data_from_advancing_timing_wheel != 0);
1614
Dave Barach900cbad2019-01-31 19:12:51 -05001615 if (PREDICT_FALSE (vm->elog_trace_graph_dispatch))
1616 ed = ELOG_DATA (&vlib_global_main.elog_main, es);
1617
Dave Barach5c20a012017-06-13 08:48:31 -04001618 nm->data_from_advancing_timing_wheel =
1619 TW (tw_timer_expire_timers_vec)
1620 ((TWT (tw_timer_wheel) *) nm->timing_wheel, vlib_time_now (vm),
1621 nm->data_from_advancing_timing_wheel);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001622
Damjan Marione9d52d52017-03-09 15:42:26 +01001623 ASSERT (nm->data_from_advancing_timing_wheel != 0);
Dave Barach5c20a012017-06-13 08:48:31 -04001624
Dave Barach900cbad2019-01-31 19:12:51 -05001625 if (PREDICT_FALSE (vm->elog_trace_graph_dispatch))
1626 {
1627 ed = ELOG_DATA (&vlib_global_main.elog_main, ee);
1628 ed->nready_procs =
1629 _vec_len (nm->data_from_advancing_timing_wheel);
1630 }
1631
Damjan Marione9d52d52017-03-09 15:42:26 +01001632 if (PREDICT_FALSE
1633 (_vec_len (nm->data_from_advancing_timing_wheel) > 0))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001634 {
Damjan Marione9d52d52017-03-09 15:42:26 +01001635 uword i;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001636
Damjan Marione9d52d52017-03-09 15:42:26 +01001637 for (i = 0; i < _vec_len (nm->data_from_advancing_timing_wheel);
1638 i++)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001639 {
Damjan Marione9d52d52017-03-09 15:42:26 +01001640 u32 d = nm->data_from_advancing_timing_wheel[i];
1641 u32 di = vlib_timing_wheel_data_get_index (d);
1642
1643 if (vlib_timing_wheel_data_is_timed_event (d))
1644 {
1645 vlib_signal_timed_event_data_t *te =
1646 pool_elt_at_index (nm->signal_timed_event_data_pool,
1647 di);
1648 vlib_node_t *n =
1649 vlib_get_node (vm, te->process_node_index);
1650 vlib_process_t *p =
1651 vec_elt (nm->processes, n->runtime_index);
1652 void *data;
1653 data =
1654 vlib_process_signal_event_helper (nm, n, p,
1655 te->event_type_index,
1656 te->n_data_elts,
1657 te->n_data_elt_bytes);
1658 if (te->n_data_bytes < sizeof (te->inline_event_data))
Dave Barach178cf492018-11-13 16:34:13 -05001659 clib_memcpy_fast (data, te->inline_event_data,
1660 te->n_data_bytes);
Damjan Marione9d52d52017-03-09 15:42:26 +01001661 else
1662 {
Dave Barach178cf492018-11-13 16:34:13 -05001663 clib_memcpy_fast (data, te->event_data_as_vector,
1664 te->n_data_bytes);
Damjan Marione9d52d52017-03-09 15:42:26 +01001665 vec_free (te->event_data_as_vector);
1666 }
1667 pool_put (nm->signal_timed_event_data_pool, te);
1668 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001669 else
1670 {
Damjan Marione9d52d52017-03-09 15:42:26 +01001671 cpu_time_now = clib_cpu_time_now ();
1672 cpu_time_now =
1673 dispatch_suspended_process (vm, di, cpu_time_now);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001674 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001675 }
Damjan Marion8bea5892022-04-04 22:40:45 +02001676 vec_set_len (nm->data_from_advancing_timing_wheel, 0);
Damjan Marione9d52d52017-03-09 15:42:26 +01001677 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001678 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001679 vlib_increment_main_loop_counter (vm);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001680 /* Record time stamp in case there are no enabled nodes and above
Dave Barach9b8ffd92016-07-08 08:13:45 -04001681 calls do not update time stamp. */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001682 cpu_time_now = clib_cpu_time_now ();
Dave Barach000a0292020-02-17 17:07:12 -05001683 vm->loops_this_reporting_interval++;
1684 now = clib_time_now_internal (&vm->clib_time, cpu_time_now);
1685 /* Time to update loops_per_second? */
1686 if (PREDICT_FALSE (now >= vm->loop_interval_end))
1687 {
1688 /* Next sample ends in 20ms */
1689 if (vm->loop_interval_start)
1690 {
1691 f64 this_loops_per_second;
1692
1693 this_loops_per_second =
1694 ((f64) vm->loops_this_reporting_interval) / (now -
1695 vm->loop_interval_start);
1696
1697 vm->loops_per_second =
1698 vm->loops_per_second * vm->damping_constant +
1699 (1.0 - vm->damping_constant) * this_loops_per_second;
1700 if (vm->loops_per_second != 0.0)
1701 vm->seconds_per_loop = 1.0 / vm->loops_per_second;
1702 else
1703 vm->seconds_per_loop = 0.0;
1704 }
1705 /* New interval starts now, and ends in 20ms */
1706 vm->loop_interval_start = now;
1707 vm->loop_interval_end = now + 2e-4;
1708 vm->loops_this_reporting_interval = 0;
1709 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001710 }
1711}
Dave Barach9b8ffd92016-07-08 08:13:45 -04001712
Damjan Marione9d52d52017-03-09 15:42:26 +01001713static void
1714vlib_main_loop (vlib_main_t * vm)
1715{
1716 vlib_main_or_worker_loop (vm, /* is_main */ 1);
1717}
1718
1719void
1720vlib_worker_loop (vlib_main_t * vm)
1721{
1722 vlib_main_or_worker_loop (vm, /* is_main */ 0);
1723}
1724
Damjan Marionfd8deb42021-03-06 12:26:28 +01001725vlib_global_main_t vlib_global_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001726
Damjan Marion25ab6c52021-03-05 14:41:25 +01001727void
1728vlib_add_del_post_mortem_callback (void *cb, int is_add)
1729{
Damjan Marionfd8deb42021-03-06 12:26:28 +01001730 vlib_global_main_t *vgm = vlib_get_global_main ();
Damjan Marion25ab6c52021-03-05 14:41:25 +01001731 int i;
1732
1733 if (is_add == 0)
1734 {
Damjan Marionfd8deb42021-03-06 12:26:28 +01001735 for (i = vec_len (vgm->post_mortem_callbacks) - 1; i >= 0; i--)
1736 if (vgm->post_mortem_callbacks[i] == cb)
1737 vec_del1 (vgm->post_mortem_callbacks, i);
Damjan Marion25ab6c52021-03-05 14:41:25 +01001738 return;
1739 }
1740
Damjan Marionfd8deb42021-03-06 12:26:28 +01001741 for (i = 0; i < vec_len (vgm->post_mortem_callbacks); i++)
1742 if (vgm->post_mortem_callbacks[i] == cb)
Damjan Marion25ab6c52021-03-05 14:41:25 +01001743 return;
Damjan Marionfd8deb42021-03-06 12:26:28 +01001744 vec_add1 (vgm->post_mortem_callbacks, cb);
Damjan Marion25ab6c52021-03-05 14:41:25 +01001745}
1746
1747static void
1748elog_post_mortem_dump (void)
1749{
Damjan Marionf553a2c2021-03-26 13:45:37 +01001750 elog_main_t *em = vlib_get_elog_main ();
Damjan Marion25ab6c52021-03-05 14:41:25 +01001751
1752 u8 *filename;
1753 clib_error_t *error;
1754
1755 filename = format (0, "/tmp/elog_post_mortem.%d%c", getpid (), 0);
1756 error = elog_write_file (em, (char *) filename, 1 /* flush ring */);
1757 if (error)
1758 clib_error_report (error);
1759 /*
1760 * We're in the middle of crashing. Don't try to free the filename.
1761 */
1762}
1763
Ed Warnickecb9cada2015-12-08 15:45:58 -07001764static clib_error_t *
1765vlib_main_configure (vlib_main_t * vm, unformat_input_t * input)
1766{
Damjan Marionfd8deb42021-03-06 12:26:28 +01001767 vlib_global_main_t *vgm = vlib_get_global_main ();
Ed Warnickecb9cada2015-12-08 15:45:58 -07001768 int turn_on_mem_trace = 0;
1769
1770 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1771 {
1772 if (unformat (input, "memory-trace"))
1773 turn_on_mem_trace = 1;
1774
1775 else if (unformat (input, "elog-events %d",
Damjan Marionfd8deb42021-03-06 12:26:28 +01001776 &vgm->configured_elog_ring_size))
1777 vgm->configured_elog_ring_size =
1778 1 << max_log2 (vgm->configured_elog_ring_size);
Dave Barach81481312017-05-16 09:08:14 -04001779 else if (unformat (input, "elog-post-mortem-dump"))
Damjan Marion25ab6c52021-03-05 14:41:25 +01001780 vlib_add_del_post_mortem_callback (elog_post_mortem_dump,
1781 /* is_add */ 1);
Dave Barachc74b43c2020-04-09 17:24:07 -04001782 else if (unformat (input, "buffer-alloc-success-rate %f",
1783 &vm->buffer_alloc_success_rate))
1784 {
1785 if (VLIB_BUFFER_ALLOC_FAULT_INJECTOR == 0)
1786 return clib_error_return
1787 (0, "Buffer fault injection not configured");
1788 }
1789 else if (unformat (input, "buffer-alloc-success-seed %u",
1790 &vm->buffer_alloc_success_seed))
1791 {
1792 if (VLIB_BUFFER_ALLOC_FAULT_INJECTOR == 0)
1793 return clib_error_return
1794 (0, "Buffer fault injection not configured");
1795 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001796 else
1797 return unformat_parse_error (input);
1798 }
1799
1800 unformat_free (input);
1801
1802 /* Enable memory trace as early as possible. */
1803 if (turn_on_mem_trace)
1804 clib_mem_trace (1);
1805
1806 return 0;
1807}
1808
1809VLIB_EARLY_CONFIG_FUNCTION (vlib_main_configure, "vlib");
1810
Dave Barach9b8ffd92016-07-08 08:13:45 -04001811static void
Dave Barach11fb09e2020-08-06 12:10:09 -04001812placeholder_queue_signal_callback (vlib_main_t * vm)
Dave Barach9b8ffd92016-07-08 08:13:45 -04001813{
1814}
Dave Barach16c75df2016-05-31 14:05:46 -04001815
Dave Barach1f806582018-06-14 09:18:21 -04001816#define foreach_weak_reference_stub \
Dave Barach1f806582018-06-14 09:18:21 -04001817_(vpe_api_init) \
1818_(vlibmemory_init) \
1819_(map_api_segment_init)
1820
1821#define _(name) \
1822clib_error_t *name (vlib_main_t *vm) __attribute__((weak)); \
1823clib_error_t *name (vlib_main_t *vm) { return 0; }
1824foreach_weak_reference_stub;
1825#undef _
1826
Dave Barachb09f4d02019-07-15 16:00:03 -04001827void vl_api_set_elog_main (elog_main_t * m) __attribute__ ((weak));
1828void
1829vl_api_set_elog_main (elog_main_t * m)
1830{
1831 clib_warning ("STUB");
1832}
1833
1834int vl_api_set_elog_trace_api_messages (int enable) __attribute__ ((weak));
1835int
1836vl_api_set_elog_trace_api_messages (int enable)
1837{
1838 clib_warning ("STUB");
1839 return 0;
1840}
1841
1842int vl_api_get_elog_trace_api_messages (void) __attribute__ ((weak));
1843int
1844vl_api_get_elog_trace_api_messages (void)
1845{
1846 clib_warning ("STUB");
1847 return 0;
1848}
1849
Ed Warnickecb9cada2015-12-08 15:45:58 -07001850/* Main function. */
Dave Barach9b8ffd92016-07-08 08:13:45 -04001851int
Eyal Barid334a6b2016-09-19 10:23:39 +03001852vlib_main (vlib_main_t * volatile vm, unformat_input_t * input)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001853{
Damjan Marionfd8deb42021-03-06 12:26:28 +01001854 vlib_global_main_t *vgm = vlib_get_global_main ();
Eyal Barid334a6b2016-09-19 10:23:39 +03001855 clib_error_t *volatile error;
Dave Barach5c20a012017-06-13 08:48:31 -04001856 vlib_node_main_t *nm = &vm->node_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001857
Dave Barach11fb09e2020-08-06 12:10:09 -04001858 vm->queue_signal_callback = placeholder_queue_signal_callback;
Dave Barach16c75df2016-05-31 14:05:46 -04001859
Dave Barachbc867c32020-11-25 10:07:09 -05001860 /* Reconfigure event log which is enabled very early */
Damjan Marionfd8deb42021-03-06 12:26:28 +01001861 if (vgm->configured_elog_ring_size &&
1862 vgm->configured_elog_ring_size != vgm->elog_main.event_ring_size)
1863 elog_resize (&vgm->elog_main, vgm->configured_elog_ring_size);
Damjan Marionf553a2c2021-03-26 13:45:37 +01001864 vl_api_set_elog_main (vlib_get_elog_main ());
Dave Barachb09f4d02019-07-15 16:00:03 -04001865 (void) vl_api_set_elog_trace_api_messages (1);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001866
1867 /* Default name. */
Damjan Marionfd8deb42021-03-06 12:26:28 +01001868 if (!vgm->name)
1869 vgm->name = "VLIB";
Ed Warnickecb9cada2015-12-08 15:45:58 -07001870
Damjan Marion68b4da62018-09-30 18:26:20 +02001871 if ((error = vlib_physmem_init (vm)))
Damjan Marion04a7f052017-07-10 15:06:17 +02001872 {
Damjan Marion49d66f12017-07-20 18:10:35 +02001873 clib_error_report (error);
1874 goto done;
Damjan Marion04a7f052017-07-10 15:06:17 +02001875 }
Damjan Marion49d66f12017-07-20 18:10:35 +02001876
Damjan Marion62d656a2022-03-09 16:10:54 +01001877 if ((error = vlib_log_init (vm)))
1878 {
1879 clib_error_report (error);
1880 goto done;
1881 }
1882
Damjan Marion8973b072022-03-01 15:51:18 +01001883 if ((error = vlib_stats_init (vm)))
Filip Tehlard2bbdef2019-02-22 05:05:53 -08001884 {
1885 clib_error_report (error);
1886 goto done;
1887 }
1888
Damjan Marion49d66f12017-07-20 18:10:35 +02001889 if ((error = vlib_buffer_main_init (vm)))
Damjan Marion04a7f052017-07-10 15:06:17 +02001890 {
Damjan Marion49d66f12017-07-20 18:10:35 +02001891 clib_error_report (error);
1892 goto done;
Damjan Marion04a7f052017-07-10 15:06:17 +02001893 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001894
1895 if ((error = vlib_thread_init (vm)))
1896 {
1897 clib_error_report (error);
1898 goto done;
1899 }
1900
Damjan Mariona31698b2021-03-10 14:35:28 +01001901 /* Register node ifunction variants */
1902 vlib_register_all_node_march_variants (vm);
1903
Ed Warnickecb9cada2015-12-08 15:45:58 -07001904 /* Register static nodes so that init functions may use them. */
1905 vlib_register_all_static_nodes (vm);
1906
1907 /* Set seed for random number generator.
1908 Allow user to specify seed to make random sequence deterministic. */
Dave Barach9b8ffd92016-07-08 08:13:45 -04001909 if (!unformat (input, "seed %wd", &vm->random_seed))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001910 vm->random_seed = clib_cpu_time_now ();
1911 clib_random_buffer_init (&vm->random_buffer, vm->random_seed);
1912
Ed Warnickecb9cada2015-12-08 15:45:58 -07001913 /* Initialize node graph. */
1914 if ((error = vlib_node_main_init (vm)))
1915 {
1916 /* Arrange for graph hook up error to not be fatal when debugging. */
1917 if (CLIB_DEBUG > 0)
1918 clib_error_report (error);
1919 else
1920 goto done;
1921 }
1922
Dave Barach1f806582018-06-14 09:18:21 -04001923 /* Direct call / weak reference, for vlib standalone use-cases */
1924 if ((error = vpe_api_init (vm)))
Dave Barach048a4e52018-06-01 18:52:25 -04001925 {
1926 clib_error_report (error);
1927 goto done;
1928 }
1929
Dave Barach1f806582018-06-14 09:18:21 -04001930 if ((error = vlibmemory_init (vm)))
Dave Barach048a4e52018-06-01 18:52:25 -04001931 {
1932 clib_error_report (error);
1933 goto done;
1934 }
1935
Dave Barach1f806582018-06-14 09:18:21 -04001936 if ((error = map_api_segment_init (vm)))
Dave Barach048a4e52018-06-01 18:52:25 -04001937 {
1938 clib_error_report (error);
1939 goto done;
1940 }
1941
Ole Troan964f93e2016-06-10 13:22:36 +02001942 /* See unix/main.c; most likely already set up */
Damjan Marionfd8deb42021-03-06 12:26:28 +01001943 if (vgm->init_functions_called == 0)
1944 vgm->init_functions_called = hash_create (0, /* value bytes */ 0);
Ole Troan964f93e2016-06-10 13:22:36 +02001945 if ((error = vlib_call_all_init_functions (vm)))
1946 goto done;
1947
Dave Barach5c20a012017-06-13 08:48:31 -04001948 nm->timing_wheel = clib_mem_alloc_aligned (sizeof (TWT (tw_timer_wheel)),
1949 CLIB_CACHE_LINE_BYTES);
1950
1951 vec_validate (nm->data_from_advancing_timing_wheel, 10);
Damjan Marion8bea5892022-04-04 22:40:45 +02001952 vec_set_len (nm->data_from_advancing_timing_wheel, 0);
Dave Barach5c20a012017-06-13 08:48:31 -04001953
1954 /* Create the process timing wheel */
1955 TW (tw_timer_wheel_init) ((TWT (tw_timer_wheel) *) nm->timing_wheel,
1956 0 /* no callback */ ,
1957 10e-6 /* timer period 10us */ ,
1958 ~0 /* max expirations per call */ );
1959
Dave Barach2877eee2017-12-15 12:22:57 -05001960 vec_validate (vm->pending_rpc_requests, 0);
Damjan Marion8bea5892022-04-04 22:40:45 +02001961 vec_set_len (vm->pending_rpc_requests, 0);
Dave Barachf6c68d72018-11-01 08:12:52 -04001962 vec_validate (vm->processing_rpc_requests, 0);
Damjan Marion8bea5892022-04-04 22:40:45 +02001963 vec_set_len (vm->processing_rpc_requests, 0);
Dave Barach2877eee2017-12-15 12:22:57 -05001964
Dave Barachc74b43c2020-04-09 17:24:07 -04001965 /* Default params for the buffer allocator fault injector, if configured */
1966 if (VLIB_BUFFER_ALLOC_FAULT_INJECTOR > 0)
1967 {
1968 vm->buffer_alloc_success_seed = 0xdeaddabe;
1969 vm->buffer_alloc_success_rate = 0.80;
1970 }
1971
Dave Barachd1e17d02019-03-21 18:01:48 -04001972 if ((error = vlib_call_all_config_functions (vm, input, 0 /* is_early */ )))
1973 goto done;
1974
Dave Barach000a0292020-02-17 17:07:12 -05001975 /*
1976 * Use exponential smoothing, with a half-life of 1 second
1977 * reported_rate(t) = reported_rate(t-1) * K + rate(t)*(1-K)
1978 *
1979 * Sample every 20ms, aka 50 samples per second
1980 * K = exp (-1.0/20.0);
1981 * K = 0.95
1982 */
1983 vm->damping_constant = exp (-1.0 / 20.0);
1984
Dave Barachc602b382019-06-03 19:48:22 -04001985 /* Sort per-thread init functions before we start threads */
Damjan Marionfd8deb42021-03-06 12:26:28 +01001986 vlib_sort_init_exit_functions (&vgm->worker_init_function_registrations);
Dave Barachc602b382019-06-03 19:48:22 -04001987
Dave Barachd1e17d02019-03-21 18:01:48 -04001988 /* Call all main loop enter functions. */
1989 {
1990 clib_error_t *sub_error;
1991 sub_error = vlib_call_all_main_loop_enter_functions (vm);
1992 if (sub_error)
1993 clib_error_report (sub_error);
1994 }
1995
Ed Warnickecb9cada2015-12-08 15:45:58 -07001996 switch (clib_setjmp (&vm->main_loop_exit, VLIB_MAIN_LOOP_EXIT_NONE))
1997 {
1998 case VLIB_MAIN_LOOP_EXIT_NONE:
1999 vm->main_loop_exit_set = 1;
2000 break;
2001
2002 case VLIB_MAIN_LOOP_EXIT_CLI:
2003 goto done;
2004
2005 default:
2006 error = vm->main_loop_error;
2007 goto done;
2008 }
2009
Ed Warnickecb9cada2015-12-08 15:45:58 -07002010 vlib_main_loop (vm);
2011
Dave Barach9b8ffd92016-07-08 08:13:45 -04002012done:
Kommula Shiva Shankarced43e22021-01-28 13:05:59 +05302013 vlib_worker_thread_barrier_sync (vm);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002014 /* Call all exit functions. */
2015 {
Dave Barach9b8ffd92016-07-08 08:13:45 -04002016 clib_error_t *sub_error;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002017 sub_error = vlib_call_all_main_loop_exit_functions (vm);
2018 if (sub_error)
2019 clib_error_report (sub_error);
2020 }
Kommula Shiva Shankarced43e22021-01-28 13:05:59 +05302021 vlib_worker_thread_barrier_release (vm);
Ed Warnickecb9cada2015-12-08 15:45:58 -07002022
2023 if (error)
2024 clib_error_report (error);
2025
Pierre Pfisterc26cc722021-09-10 16:38:03 +02002026 return vm->main_loop_exit_status;
Ed Warnickecb9cada2015-12-08 15:45:58 -07002027}
Dave Barach9b8ffd92016-07-08 08:13:45 -04002028
Dave Barachab1a50c2020-10-06 14:08:16 -04002029vlib_main_t *
2030vlib_get_main_not_inline (void)
2031{
2032 return vlib_get_main ();
2033}
2034
2035elog_main_t *
2036vlib_get_elog_main_not_inline ()
2037{
2038 return &vlib_global_main.elog_main;
2039}
2040
Pierre Pfisterc26cc722021-09-10 16:38:03 +02002041void
2042vlib_exit_with_status (vlib_main_t *vm, int status)
2043{
2044 vm->main_loop_exit_status = status;
2045 __atomic_store_n (&vm->main_loop_exit_now, 1, __ATOMIC_RELEASE);
2046}
2047
Dave Barach9b8ffd92016-07-08 08:13:45 -04002048/*
2049 * fd.io coding-style-patch-verification: ON
2050 *
2051 * Local Variables:
2052 * eval: (c-set-style "gnu")
2053 * End:
2054 */