blob: 7177bebeffbd94890571539638093c1037addbb8 [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 * node.h: VLIB processing nodes
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#ifndef included_vlib_node_h
41#define included_vlib_node_h
42
Damjan Marion1c80e832016-05-11 23:07:18 +020043#include <vppinfra/cpu.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070044#include <vppinfra/longjmp.h>
Damjan Marion2c2b6402017-03-28 14:16:15 +020045#include <vppinfra/lock.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070046#include <vlib/trace.h> /* for vlib_trace_filter_t */
47
48/* Forward declaration. */
49struct vlib_node_runtime_t;
50struct vlib_frame_t;
51
52/* Internal nodes (including output nodes) move data from node to
53 node (or out of the graph for output nodes). */
54typedef uword (vlib_node_function_t) (struct vlib_main_t * vm,
55 struct vlib_node_runtime_t * node,
56 struct vlib_frame_t * frame);
57
Dave Barach9b8ffd92016-07-08 08:13:45 -040058typedef enum
59{
Ed Warnickecb9cada2015-12-08 15:45:58 -070060 /* An internal node on the call graph (could be output). */
61 VLIB_NODE_TYPE_INTERNAL,
62
63 /* Nodes which input data into the processing graph.
64 Input nodes are called for each iteration of main loop. */
65 VLIB_NODE_TYPE_INPUT,
66
67 /* Nodes to be called before all input nodes.
68 Used, for example, to clean out driver TX rings before
69 processing input. */
70 VLIB_NODE_TYPE_PRE_INPUT,
71
72 /* "Process" nodes which can be suspended and later resumed. */
73 VLIB_NODE_TYPE_PROCESS,
74
75 VLIB_N_NODE_TYPE,
76} vlib_node_type_t;
77
Dave Barach9b8ffd92016-07-08 08:13:45 -040078typedef struct _vlib_node_registration
79{
Ed Warnickecb9cada2015-12-08 15:45:58 -070080 /* Vector processing function for this node. */
Dave Barach9b8ffd92016-07-08 08:13:45 -040081 vlib_node_function_t *function;
Ed Warnickecb9cada2015-12-08 15:45:58 -070082
83 /* Node name. */
Dave Barach9b8ffd92016-07-08 08:13:45 -040084 char *name;
Ed Warnickecb9cada2015-12-08 15:45:58 -070085
86 /* Name of sibling (if applicable). */
Dave Barach9b8ffd92016-07-08 08:13:45 -040087 char *sibling_of;
Ed Warnickecb9cada2015-12-08 15:45:58 -070088
89 /* Node index filled in by registration. */
90 u32 index;
91
92 /* Type of this node. */
93 vlib_node_type_t type;
94
95 /* Error strings indexed by error code for this node. */
Dave Barach9b8ffd92016-07-08 08:13:45 -040096 char **error_strings;
Ed Warnickecb9cada2015-12-08 15:45:58 -070097
98 /* Buffer format/unformat for this node. */
Dave Barach9b8ffd92016-07-08 08:13:45 -040099 format_function_t *format_buffer;
100 unformat_function_t *unformat_buffer;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700101
102 /* Trace format/unformat for this node. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400103 format_function_t *format_trace;
104 unformat_function_t *unformat_trace;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700105
106 /* Function to validate incoming frames. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400107 u8 *(*validate_frame) (struct vlib_main_t * vm,
108 struct vlib_node_runtime_t *,
109 struct vlib_frame_t * f);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700110
111 /* Per-node runtime data. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400112 void *runtime_data;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700113
114 /* Process stack size. */
115 u16 process_log2_n_stack_bytes;
116
117 /* Number of bytes of per-node run time data. */
118 u8 runtime_data_bytes;
119
120 /* State for input nodes. */
121 u8 state;
122
123 /* Node flags. */
124 u16 flags;
125
126 /* Size of scalar and vector arguments in bytes. */
127 u16 scalar_size, vector_size;
128
129 /* Number of error codes used by this node. */
130 u16 n_errors;
131
132 /* Number of next node names that follow. */
133 u16 n_next_nodes;
134
135 /* Constructor link-list, don't ask... */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400136 struct _vlib_node_registration *next_registration;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700137
138 /* Names of next nodes which this node feeds into. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400139 char *next_nodes[];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700140
141} vlib_node_registration_t;
142
143#define VLIB_REGISTER_NODE(x,...) \
144 __VA_ARGS__ vlib_node_registration_t x; \
145static void __vlib_add_node_registration_##x (void) \
146 __attribute__((__constructor__)) ; \
147static void __vlib_add_node_registration_##x (void) \
148{ \
149 vlib_main_t * vm = vlib_get_main(); \
150 x.next_registration = vm->node_main.node_registrations; \
151 vm->node_main.node_registrations = &x; \
152} \
Damjan Marion72d2c4f2018-04-05 21:32:29 +0200153static void __vlib_rm_node_registration_##x (void) \
154 __attribute__((__destructor__)) ; \
155static void __vlib_rm_node_registration_##x (void) \
156{ \
157 vlib_main_t * vm = vlib_get_main(); \
158 VLIB_REMOVE_FROM_LINKED_LIST (vm->node_main.node_registrations, \
159 &x, next_registration); \
160} \
Dave Barach9b8ffd92016-07-08 08:13:45 -0400161__VA_ARGS__ vlib_node_registration_t x
Ed Warnickecb9cada2015-12-08 15:45:58 -0700162
Damjan Marion1c80e832016-05-11 23:07:18 +0200163#if CLIB_DEBUG > 0
164#define VLIB_NODE_FUNCTION_CLONE_TEMPLATE(arch, fn)
165#define VLIB_NODE_FUNCTION_MULTIARCH_CLONE(fn)
166#define VLIB_NODE_FUNCTION_MULTIARCH(node, fn)
167#else
168#define VLIB_NODE_FUNCTION_CLONE_TEMPLATE(arch, fn, tgt) \
169 uword \
170 __attribute__ ((flatten)) \
171 __attribute__ ((target (tgt))) \
172 CLIB_CPU_OPTIMIZED \
173 fn ## _ ## arch ( struct vlib_main_t * vm, \
174 struct vlib_node_runtime_t * node, \
175 struct vlib_frame_t * frame) \
176 { return fn (vm, node, frame); }
177
178#define VLIB_NODE_FUNCTION_MULTIARCH_CLONE(fn) \
179 foreach_march_variant(VLIB_NODE_FUNCTION_CLONE_TEMPLATE, fn)
180
181#define VLIB_NODE_FUNCTION_MULTIARCH(node, fn) \
182 VLIB_NODE_FUNCTION_MULTIARCH_CLONE(fn) \
183 CLIB_MULTIARCH_SELECT_FN(fn, static inline) \
184 static void __attribute__((__constructor__)) \
185 __vlib_node_function_multiarch_select_##node (void) \
186 { node.function = fn ## _multiarch_select(); }
187#endif
188
Ed Warnickecb9cada2015-12-08 15:45:58 -0700189always_inline vlib_node_registration_t *
190vlib_node_next_registered (vlib_node_registration_t * c)
191{
Dave Barach9b8ffd92016-07-08 08:13:45 -0400192 c =
193 clib_elf_section_data_next (c,
194 c->n_next_nodes * sizeof (c->next_nodes[0]));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700195 return c;
196}
197
Dave Barach9b8ffd92016-07-08 08:13:45 -0400198typedef struct
199{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700200 /* Total calls, clock ticks and vector elements processed for this node. */
201 u64 calls, vectors, clocks, suspends;
202 u64 max_clock;
203 u64 max_clock_n;
204} vlib_node_stats_t;
205
206#define foreach_vlib_node_state \
207 /* Input node is called each iteration of main loop. \
208 This is the default (zero). */ \
209 _ (POLLING) \
210 /* Input node is called when device signals an interrupt. */ \
211 _ (INTERRUPT) \
212 /* Input node is never called. */ \
213 _ (DISABLED)
214
Dave Barach9b8ffd92016-07-08 08:13:45 -0400215typedef enum
216{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700217#define _(f) VLIB_NODE_STATE_##f,
218 foreach_vlib_node_state
219#undef _
Dave Barach9b8ffd92016-07-08 08:13:45 -0400220 VLIB_N_NODE_STATE,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700221} vlib_node_state_t;
222
Dave Barach9b8ffd92016-07-08 08:13:45 -0400223typedef struct vlib_node_t
224{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700225 /* Vector processing function for this node. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400226 vlib_node_function_t *function;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700227
228 /* Node name. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400229 u8 *name;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700230
231 /* Node name index in elog string table. */
232 u32 name_elog_string;
233
234 /* Total statistics for this node. */
235 vlib_node_stats_t stats_total;
236
237 /* Saved values as of last clear (or zero if never cleared).
238 Current values are always stats_total - stats_last_clear. */
239 vlib_node_stats_t stats_last_clear;
240
241 /* Type of this node. */
242 vlib_node_type_t type;
243
244 /* Node index. */
245 u32 index;
246
247 /* Index of corresponding node runtime. */
248 u32 runtime_index;
249
250 /* Runtime data for this node. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400251 void *runtime_data;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700252
253 /* Node flags. */
254 u16 flags;
255
256 /* Processing function keeps frame. Tells node dispatching code not
257 to free frame after dispatch is done. */
258#define VLIB_NODE_FLAG_FRAME_NO_FREE_AFTER_DISPATCH (1 << 0)
259
260 /* Node counts as output/drop/punt node for stats purposes. */
261#define VLIB_NODE_FLAG_IS_OUTPUT (1 << 1)
262#define VLIB_NODE_FLAG_IS_DROP (1 << 2)
263#define VLIB_NODE_FLAG_IS_PUNT (1 << 3)
264#define VLIB_NODE_FLAG_IS_HANDOFF (1 << 4)
265
266 /* Set if current node runtime has traced vectors. */
267#define VLIB_NODE_FLAG_TRACE (1 << 5)
268
269#define VLIB_NODE_FLAG_SWITCH_FROM_INTERRUPT_TO_POLLING_MODE (1 << 6)
270#define VLIB_NODE_FLAG_SWITCH_FROM_POLLING_TO_INTERRUPT_MODE (1 << 7)
271
272 /* State for input nodes. */
273 u8 state;
274
275 /* Number of bytes of run time data. */
276 u8 runtime_data_bytes;
277
278 /* Number of error codes used by this node. */
279 u16 n_errors;
280
281 /* Size of scalar and vector arguments in bytes. */
282 u16 scalar_size, vector_size;
283
284 /* Handle/index in error heap for this node. */
285 u32 error_heap_handle;
286 u32 error_heap_index;
287
288 /* Error strings indexed by error code for this node. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400289 char **error_strings;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700290
291 /* Vector of next node names.
292 Only used before next_nodes array is initialized. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400293 char **next_node_names;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700294
295 /* Next node indices for this node. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400296 u32 *next_nodes;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700297
298 /* Name of node that we are sibling of. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400299 char *sibling_of;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700300
301 /* Bitmap of all of this node's siblings. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400302 uword *sibling_bitmap;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700303
304 /* Total number of vectors sent to each next node. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400305 u64 *n_vectors_by_next_node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700306
307 /* Hash table mapping next node index into slot in
308 next_nodes vector. Quickly determines whether this node
309 is connected to given next node and, if so, with which slot. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400310 uword *next_slot_by_node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700311
312 /* Bitmap of node indices which feed this node. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400313 uword *prev_node_bitmap;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700314
315 /* Node/next-index which own enqueue rights with to this node. */
316 u32 owner_node_index, owner_next_index;
317
318 /* Buffer format/unformat for this node. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400319 format_function_t *format_buffer;
320 unformat_function_t *unformat_buffer;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700321
322 /* Trace buffer format/unformat for this node. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400323 format_function_t *format_trace;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700324
325 /* Function to validate incoming frames. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400326 u8 *(*validate_frame) (struct vlib_main_t * vm,
327 struct vlib_node_runtime_t *,
328 struct vlib_frame_t * f);
Dave Barach6931f592016-05-13 12:55:01 -0400329 /* for pretty-printing, not typically valid */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400330 u8 *state_string;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700331} vlib_node_t;
332
333#define VLIB_INVALID_NODE_INDEX ((u32) ~0)
334
335/* Max number of vector elements to process at once per node. */
336#define VLIB_FRAME_SIZE 256
Dave Barachd84ba852017-08-22 17:56:46 -0400337#define VLIB_FRAME_ALIGN CLIB_CACHE_LINE_BYTES
Ed Warnickecb9cada2015-12-08 15:45:58 -0700338
339/* Calling frame (think stack frame) for a node. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400340typedef struct vlib_frame_t
341{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700342 /* Frame flags. */
343 u16 flags;
344
345 /* Number of scalar bytes in arguments. */
346 u8 scalar_size;
347
348 /* Number of bytes per vector argument. */
349 u8 vector_size;
350
351 /* Number of vector elements currently in frame. */
352 u16 n_vectors;
353
Ed Warnickecb9cada2015-12-08 15:45:58 -0700354 /* Scalar and vector arguments to next node. */
355 u8 arguments[0];
356} vlib_frame_t;
357
Dave Barach9b8ffd92016-07-08 08:13:45 -0400358typedef struct
359{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700360 /* Frame index. */
361 u32 frame_index;
362
363 /* Node runtime for this next. */
364 u32 node_runtime_index;
365
366 /* Next frame flags. */
367 u32 flags;
368
369 /* Reflects node frame-used flag for this next. */
370#define VLIB_FRAME_NO_FREE_AFTER_DISPATCH \
371 VLIB_NODE_FLAG_FRAME_NO_FREE_AFTER_DISPATCH
372
373 /* This next frame owns enqueue to node
374 corresponding to node_runtime_index. */
375#define VLIB_FRAME_OWNER (1 << 15)
376
377 /* Set when frame has been allocated for this next. */
378#define VLIB_FRAME_IS_ALLOCATED VLIB_NODE_FLAG_IS_OUTPUT
379
380 /* Set when frame has been added to pending vector. */
381#define VLIB_FRAME_PENDING VLIB_NODE_FLAG_IS_DROP
382
383 /* Set when frame is to be freed after dispatch. */
384#define VLIB_FRAME_FREE_AFTER_DISPATCH VLIB_NODE_FLAG_IS_PUNT
385
386 /* Set when frame has traced packets. */
387#define VLIB_FRAME_TRACE VLIB_NODE_FLAG_TRACE
388
389 /* Number of vectors enqueue to this next since last overflow. */
390 u32 vectors_since_last_overflow;
391} vlib_next_frame_t;
392
393always_inline void
394vlib_next_frame_init (vlib_next_frame_t * nf)
395{
396 memset (nf, 0, sizeof (nf[0]));
397 nf->frame_index = ~0;
398 nf->node_runtime_index = ~0;
399}
400
401/* A frame pending dispatch by main loop. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400402typedef struct
403{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700404 /* Node and runtime for this frame. */
405 u32 node_runtime_index;
406
407 /* Frame index (in the heap). */
408 u32 frame_index;
409
410 /* Start of next frames for this node. */
411 u32 next_frame_index;
412
413 /* Special value for next_frame_index when there is no next frame. */
414#define VLIB_PENDING_FRAME_NO_NEXT_FRAME ((u32) ~0)
415} vlib_pending_frame_t;
416
Dave Barach9b8ffd92016-07-08 08:13:45 -0400417typedef struct vlib_node_runtime_t
418{
Damjan Marione9f929b2017-03-16 11:32:09 +0100419 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); /**< cacheline mark */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700420
Damjan Marione9f929b2017-03-16 11:32:09 +0100421 vlib_node_function_t *function; /**< Node function to call. */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700422
Damjan Marione9f929b2017-03-16 11:32:09 +0100423 vlib_error_t *errors; /**< Vector of errors for this node. */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700424
Damjan Marion36c13082017-04-24 20:58:29 +0200425#if __SIZEOF_POINTER__ == 4
426 u8 pad[8];
427#endif
428
Damjan Marione9f929b2017-03-16 11:32:09 +0100429 u32 clocks_since_last_overflow; /**< Number of clock cycles. */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700430
Damjan Marione9f929b2017-03-16 11:32:09 +0100431 u32 max_clock; /**< Maximum clock cycle for an
432 invocation. */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700433
Damjan Marione9f929b2017-03-16 11:32:09 +0100434 u32 max_clock_n; /**< Number of vectors in the recorded
435 max_clock. */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700436
Damjan Marione9f929b2017-03-16 11:32:09 +0100437 u32 calls_since_last_overflow; /**< Number of calls. */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700438
Damjan Marione9f929b2017-03-16 11:32:09 +0100439 u32 vectors_since_last_overflow; /**< Number of vector elements
440 processed by this node. */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700441
Damjan Marione9f929b2017-03-16 11:32:09 +0100442 u32 next_frame_index; /**< Start of next frames for this
443 node. */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700444
Damjan Marione9f929b2017-03-16 11:32:09 +0100445 u32 node_index; /**< Node index. */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700446
Damjan Marione9f929b2017-03-16 11:32:09 +0100447 u32 input_main_loops_per_call; /**< For input nodes: decremented
448 on each main loop interation until
449 it reaches zero and function is
450 called. Allows some input nodes to
451 be called more than others. */
452
453 u32 main_loop_count_last_dispatch; /**< Saved main loop counter of last
454 dispatch of this node. */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700455
456 u32 main_loop_vector_stats[2];
457
Damjan Marione9f929b2017-03-16 11:32:09 +0100458 u16 flags; /**< Copy of main node flags. */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700459
Damjan Marione9f929b2017-03-16 11:32:09 +0100460 u16 state; /**< Input node state. */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700461
462 u16 n_next_nodes;
463
Damjan Marione9f929b2017-03-16 11:32:09 +0100464 u16 cached_next_index; /**< Next frame index that vector
465 arguments were last enqueued to
466 last time this node ran. Set to
467 zero before first run of this
468 node. */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700469
Damjan Marion586afd72017-04-05 19:18:20 +0200470 u16 thread_index; /**< thread this node runs on */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700471
Damjan Marione9f929b2017-03-16 11:32:09 +0100472 u8 runtime_data[0]; /**< Function dependent
473 node-runtime data. This data is
474 thread local, and it is not
475 cloned from main thread. It needs
476 to be initialized for each thread
477 before it is used unless
478 runtime_data template exists in
479 vlib_node_t. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400480}
481vlib_node_runtime_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700482
Damjan Marione9f929b2017-03-16 11:32:09 +0100483#define VLIB_NODE_RUNTIME_DATA_SIZE (sizeof (vlib_node_runtime_t) - STRUCT_OFFSET_OF (vlib_node_runtime_t, runtime_data))
484
Dave Barach9b8ffd92016-07-08 08:13:45 -0400485typedef struct
486{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700487 /* Number of allocated frames for this scalar/vector size. */
488 u32 n_alloc_frames;
489
490 /* Vector of free frame indices for this scalar/vector size. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400491 u32 *free_frame_indices;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700492} vlib_frame_size_t;
493
Dave Barach9b8ffd92016-07-08 08:13:45 -0400494typedef struct
495{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700496 /* Users opaque value for event type. */
497 uword opaque;
498} vlib_process_event_type_t;
499
Dave Barach9b8ffd92016-07-08 08:13:45 -0400500typedef struct
501{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700502 /* Node runtime for this process. */
503 vlib_node_runtime_t node_runtime;
504
505 /* Where to longjmp when process is done. */
506 clib_longjmp_t return_longjmp;
507
508#define VLIB_PROCESS_RETURN_LONGJMP_RETURN ((uword) ~0 - 0)
509#define VLIB_PROCESS_RETURN_LONGJMP_SUSPEND ((uword) ~0 - 1)
510
511 /* Where to longjmp to resume node after suspend. */
512 clib_longjmp_t resume_longjmp;
513#define VLIB_PROCESS_RESUME_LONGJMP_SUSPEND 0
514#define VLIB_PROCESS_RESUME_LONGJMP_RESUME 1
515
516 u16 flags;
517#define VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK (1 << 0)
518#define VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT (1 << 1)
519 /* Set to indicate that this process has been added to resume vector. */
520#define VLIB_PROCESS_RESUME_PENDING (1 << 2)
521
522 /* Process function is currently running. */
523#define VLIB_PROCESS_IS_RUNNING (1 << 3)
524
525 /* Size of process stack. */
526 u16 log2_n_stack_bytes;
527
528 u32 suspended_process_frame_index;
529
530 /* Number of times this process was suspended. */
531 u32 n_suspends;
532
533 /* Vectors of pending event data indexed by event type index. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400534 void **pending_event_data_by_type_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700535
536 /* Bitmap of event type-indices with non-empty vectors. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400537 uword *non_empty_event_type_bitmap;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700538
539 /* Bitmap of event type-indices which are one time events. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400540 uword *one_time_event_type_bitmap;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700541
542 /* Type is opaque pointer -- typically a pointer to an event handler
543 function. Hash table to map opaque to a type index. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400544 uword *event_type_index_by_type_opaque;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700545
546 /* Pool of currently valid event types. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400547 vlib_process_event_type_t *event_type_pool;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700548
Dave Barach5c20a012017-06-13 08:48:31 -0400549 /*
550 * When suspending saves clock time (10us ticks) when process
551 * is to be resumed.
552 */
553 u64 resume_clock_interval;
554
555 /* Handle from timer code, to cancel an unexpired timer */
556 u32 stop_timer_handle;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700557
Andrew Yourtchenko716d9592016-05-10 10:51:34 +0000558 /* Default output function and its argument for any CLI outputs
559 within the process. */
560 vlib_cli_output_function_t *output_function;
561 uword output_function_arg;
562
Ed Warnickecb9cada2015-12-08 15:45:58 -0700563#ifdef CLIB_UNIX
564 /* Pad to a multiple of the page size so we can mprotect process stacks */
Andrew Yourtchenko716d9592016-05-10 10:51:34 +0000565#define PAGE_SIZE_MULTIPLE 0x1000
566#define ALIGN_ON_MULTIPLE_PAGE_BOUNDARY_FOR_MPROTECT __attribute__ ((aligned (PAGE_SIZE_MULTIPLE)))
567#else
568#define ALIGN_ON_MULTIPLE_PAGE_BOUNDARY_FOR_MPROTECT
Ed Warnickecb9cada2015-12-08 15:45:58 -0700569#endif
Andrew Yourtchenko716d9592016-05-10 10:51:34 +0000570
Ed Warnickecb9cada2015-12-08 15:45:58 -0700571 /* Process stack. Starts here and extends 2^log2_n_stack_bytes
572 bytes. */
573
574#define VLIB_PROCESS_STACK_MAGIC (0xdead7ead)
Andrew Yourtchenko716d9592016-05-10 10:51:34 +0000575 u32 stack[0] ALIGN_ON_MULTIPLE_PAGE_BOUNDARY_FOR_MPROTECT;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700576} vlib_process_t __attribute__ ((aligned (CLIB_CACHE_LINE_BYTES)));
577
Andrew Yourtchenko716d9592016-05-10 10:51:34 +0000578#ifdef CLIB_UNIX
579 /* Ensure that the stack is aligned on the multiple of the page size */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400580typedef char
581 assert_process_stack_must_be_aligned_exactly_to_page_size_multiple[(sizeof
582 (vlib_process_t)
583 -
584 PAGE_SIZE_MULTIPLE)
585 ==
586 0 ? 0 :
587 -1];
Andrew Yourtchenko716d9592016-05-10 10:51:34 +0000588#endif
589
Dave Barach9b8ffd92016-07-08 08:13:45 -0400590typedef struct
591{
592 u32 node_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700593
Dave Barach9b8ffd92016-07-08 08:13:45 -0400594 u32 one_time_event;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700595} vlib_one_time_waiting_process_t;
596
Dave Barach9b8ffd92016-07-08 08:13:45 -0400597typedef struct
598{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700599 u16 n_data_elts;
600
601 u16 n_data_elt_bytes;
602
603 /* n_data_elts * n_data_elt_bytes */
604 u32 n_data_bytes;
605
606 /* Process node & event type to be used to signal event. */
607 u32 process_node_index;
608
609 u32 event_type_index;
610
Dave Barach9b8ffd92016-07-08 08:13:45 -0400611 union
612 {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700613 u8 inline_event_data[64 - 3 * sizeof (u32) - 2 * sizeof (u16)];
614
615 /* Vector of event data used only when data does not fit inline. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400616 u8 *event_data_as_vector;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700617 };
Dave Barach9b8ffd92016-07-08 08:13:45 -0400618}
619vlib_signal_timed_event_data_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700620
621always_inline uword
622vlib_timing_wheel_data_is_timed_event (u32 d)
Dave Barach9b8ffd92016-07-08 08:13:45 -0400623{
624 return d & 1;
625}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700626
627always_inline u32
628vlib_timing_wheel_data_set_suspended_process (u32 i)
Dave Barach9b8ffd92016-07-08 08:13:45 -0400629{
630 return 0 + 2 * i;
631}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700632
633always_inline u32
634vlib_timing_wheel_data_set_timed_event (u32 i)
Dave Barach9b8ffd92016-07-08 08:13:45 -0400635{
636 return 1 + 2 * i;
637}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700638
639always_inline uword
640vlib_timing_wheel_data_get_index (u32 d)
Dave Barach9b8ffd92016-07-08 08:13:45 -0400641{
642 return d / 2;
643}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700644
Dave Barach9b8ffd92016-07-08 08:13:45 -0400645typedef struct
646{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700647 /* Public nodes. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400648 vlib_node_t **nodes;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700649
650 /* Node index hashed by node name. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400651 uword *node_by_name;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700652
653 u32 flags;
654#define VLIB_NODE_MAIN_RUNTIME_STARTED (1 << 0)
655
656 /* Nodes segregated by type for cache locality.
657 Does not apply to nodes of type VLIB_NODE_TYPE_INTERNAL. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400658 vlib_node_runtime_t *nodes_by_type[VLIB_N_NODE_TYPE];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700659
660 /* Node runtime indices for input nodes with pending interrupts. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400661 u32 *pending_interrupt_node_runtime_indices;
Damjan Marion2c2b6402017-03-28 14:16:15 +0200662 clib_spinlock_t pending_interrupt_lock;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700663
664 /* Input nodes are switched from/to interrupt to/from polling mode
665 when average vector length goes above/below polling/interrupt
666 thresholds. */
667 u32 polling_threshold_vector_length;
668 u32 interrupt_threshold_vector_length;
669
670 /* Vector of next frames. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400671 vlib_next_frame_t *next_frames;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700672
673 /* Vector of internal node's frames waiting to be called. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400674 vlib_pending_frame_t *pending_frames;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700675
676 /* Timing wheel for scheduling time-based node dispatch. */
Dave Barach5c20a012017-06-13 08:48:31 -0400677 void *timing_wheel;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700678
Dave Barach9b8ffd92016-07-08 08:13:45 -0400679 vlib_signal_timed_event_data_t *signal_timed_event_data_pool;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700680
681 /* Opaque data vector added via timing_wheel_advance. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400682 u32 *data_from_advancing_timing_wheel;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700683
684 /* CPU time of next process to be ready on timing wheel. */
Dave Barach5c20a012017-06-13 08:48:31 -0400685 f64 time_next_process_ready;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700686
687 /* Vector of process nodes.
688 One for each node of type VLIB_NODE_TYPE_PROCESS. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400689 vlib_process_t **processes;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700690
691 /* Current running process or ~0 if no process running. */
692 u32 current_process_index;
693
694 /* Pool of pending process frames. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400695 vlib_pending_frame_t *suspended_process_frames;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700696
697 /* Vector of event data vectors pending recycle. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400698 void **recycled_event_data_vectors;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700699
700 /* Current counts of nodes in each state. */
701 u32 input_node_counts_by_state[VLIB_N_NODE_STATE];
702
703 /* Hash of (scalar_size,vector_size) to frame_sizes index. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400704 uword *frame_size_hash;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700705
706 /* Per-size frame allocation information. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400707 vlib_frame_size_t *frame_sizes;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700708
709 /* Time of last node runtime stats clear. */
710 f64 time_last_runtime_stats_clear;
711
712 /* Node registrations added by constructors */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400713 vlib_node_registration_t *node_registrations;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700714} vlib_node_main_t;
715
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200716
717#define FRAME_QUEUE_MAX_NELTS 32
Dave Barach9b8ffd92016-07-08 08:13:45 -0400718typedef struct
719{
720 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200721 u64 head;
722 u64 head_hint;
723 u64 tail;
724 u32 n_in_use;
725 u32 nelts;
726 u32 written;
727 u32 threshold;
728 i32 n_vectors[FRAME_QUEUE_MAX_NELTS];
729} frame_queue_trace_t;
730
Dave Barach9b8ffd92016-07-08 08:13:45 -0400731typedef struct
732{
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200733 u64 count[FRAME_QUEUE_MAX_NELTS];
734} frame_queue_nelt_counter_t;
735
Ed Warnickecb9cada2015-12-08 15:45:58 -0700736#endif /* included_vlib_node_h */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400737
738/*
739 * fd.io coding-style-patch-verification: ON
740 *
741 * Local Variables:
742 * eval: (c-set-style "gnu")
743 * End:
744 */