blob: 97df3d253a0792af68229888e84d7596d13d49c0 [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#ifndef included_vlib_threads_h
16#define included_vlib_threads_h
17
18#include <vlib/main.h>
Tom Seidenberg6c81f5a2020-07-10 15:49:03 +000019#include <vppinfra/callback.h>
Pavel Kotucek1e765832016-09-23 08:54:14 +020020#include <linux/sched.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070021
Dave Barach9b8ffd92016-07-08 08:13:45 -040022void vlib_set_thread_name (char *name);
Ed Warnickecb9cada2015-12-08 15:45:58 -070023
24/* arg is actually a vlib__thread_t * */
Dave Barach9b8ffd92016-07-08 08:13:45 -040025typedef void (vlib_thread_function_t) (void *arg);
Ed Warnickecb9cada2015-12-08 15:45:58 -070026
Dave Barach9b8ffd92016-07-08 08:13:45 -040027typedef struct vlib_thread_registration_
28{
Ed Warnickecb9cada2015-12-08 15:45:58 -070029 /* constructor generated list of thread registrations */
Dave Barach9b8ffd92016-07-08 08:13:45 -040030 struct vlib_thread_registration_ *next;
Ed Warnickecb9cada2015-12-08 15:45:58 -070031
32 /* config parameters */
Dave Barach9b8ffd92016-07-08 08:13:45 -040033 char *name;
34 char *short_name;
35 vlib_thread_function_t *function;
Ed Warnickecb9cada2015-12-08 15:45:58 -070036 uword mheap_size;
37 int fixed_count;
38 u32 count;
39 int no_data_structure_clone;
Bud Grise68adab92016-02-12 10:36:11 -050040 u32 frame_queue_nelts;
41
Ed Warnickecb9cada2015-12-08 15:45:58 -070042 /* All threads of this type run on pthreads */
43 int use_pthreads;
44 u32 first_index;
Dave Barach9b8ffd92016-07-08 08:13:45 -040045 uword *coremask;
Ed Warnickecb9cada2015-12-08 15:45:58 -070046} vlib_thread_registration_t;
47
Damjan Marion3f46baf2016-02-06 19:16:21 +010048/*
49 * Frames have their cpu / vlib_main_t index in the low-order N bits
50 * Make VLIB_MAX_CPUS a power-of-two, please...
Ed Warnickecb9cada2015-12-08 15:45:58 -070051 */
Damjan Marion3f46baf2016-02-06 19:16:21 +010052
Christophe Fontainefef15b42016-04-09 12:38:49 +090053#ifndef VLIB_MAX_CPUS
Damjan Marion3f46baf2016-02-06 19:16:21 +010054#define VLIB_MAX_CPUS 256
Christophe Fontainefef15b42016-04-09 12:38:49 +090055#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -070056
Damjan Marionce8debf2016-02-06 19:16:21 +010057#if VLIB_MAX_CPUS > CLIB_MAX_MHEAPS
58#error Please increase number of per-cpu mheaps
59#endif
60
Dave Barach9b8ffd92016-07-08 08:13:45 -040061#define VLIB_CPU_MASK (VLIB_MAX_CPUS - 1) /* 0x3f, max */
Ed Warnickecb9cada2015-12-08 15:45:58 -070062#define VLIB_OFFSET_MASK (~VLIB_CPU_MASK)
63
Florin Coras93992a92017-05-24 18:03:56 -070064#define VLIB_LOG2_THREAD_STACK_SIZE (21)
Ed Warnickecb9cada2015-12-08 15:45:58 -070065#define VLIB_THREAD_STACK_SIZE (1<<VLIB_LOG2_THREAD_STACK_SIZE)
66
Dave Barach9b8ffd92016-07-08 08:13:45 -040067typedef struct
68{
Damjan Marionb0d680b2016-11-04 14:41:44 +010069 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070070 volatile u32 valid;
Damjan Marionc0d9ca72021-05-11 09:39:24 +020071 u32 maybe_trace : 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070072 u32 n_vectors;
Damjan Marionc0d9ca72021-05-11 09:39:24 +020073 u32 offset;
74 STRUCT_MARK (end_of_reset);
Ed Warnickecb9cada2015-12-08 15:45:58 -070075
Damjan Marionc0d9ca72021-05-11 09:39:24 +020076 CLIB_CACHE_LINE_ALIGN_MARK (cacheline1);
Ed Warnickecb9cada2015-12-08 15:45:58 -070077 u32 buffer_index[VLIB_FRAME_SIZE];
Mohammed Hawarie7149262022-05-18 10:08:47 +020078 u32 aux_data[VLIB_FRAME_SIZE];
Dave Barach9b8ffd92016-07-08 08:13:45 -040079}
80vlib_frame_queue_elt_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -070081
Dave Barach9b8ffd92016-07-08 08:13:45 -040082typedef struct
83{
Ed Warnickecb9cada2015-12-08 15:45:58 -070084 /* First cache line */
Damjan Marionb0d680b2016-11-04 14:41:44 +010085 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070086 volatile u32 *wait_at_barrier;
87 volatile u32 *workers_at_barrier;
Ed Warnickecb9cada2015-12-08 15:45:58 -070088
89 /* Second Cache Line */
Damjan Marionb0d680b2016-11-04 14:41:44 +010090 CLIB_CACHE_LINE_ALIGN_MARK (cacheline1);
Ed Warnickecb9cada2015-12-08 15:45:58 -070091 void *thread_mheap;
Dave Barach9b8ffd92016-07-08 08:13:45 -040092 u8 *thread_stack;
93 void (*thread_function) (void *);
94 void *thread_function_arg;
95 i64 recursion_level;
96 elog_track_t elog_track;
Ed Warnickecb9cada2015-12-08 15:45:58 -070097 u32 instance_id;
98 vlib_thread_registration_t *registration;
99 u8 *name;
Bud Grise42f20062016-03-16 13:09:46 -0400100 u64 barrier_sync_count;
Dave Barach88c6e002018-09-30 15:54:06 -0400101 u8 barrier_elog_enabled;
Colin Tregenza Dancereb1ac172017-09-06 20:23:24 +0100102 const char *barrier_caller;
103 const char *barrier_context;
Colin Tregenza Dancer21596182017-09-04 15:27:49 +0100104 volatile u32 *node_reforks_required;
Florin Coras4b208302022-03-30 13:50:19 -0700105 volatile u32 wait_before_barrier;
106 volatile u32 workers_before_barrier;
107 volatile u32 done_work_before_barrier;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700108
109 long lwp;
Mohsin Kazmi5d64c782018-09-11 20:27:09 +0200110 int cpu_id;
111 int core_id;
Dave Baracha690fdb2020-01-21 12:34:55 -0500112 int numa_id;
Pavel Kotucek98765202016-10-07 08:37:28 +0200113 pthread_t thread_id;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700114} vlib_worker_thread_t;
115
Damjan Marion6a7acc22016-12-19 16:28:36 +0100116extern vlib_worker_thread_t *vlib_worker_threads;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700117
Dave Barach9b8ffd92016-07-08 08:13:45 -0400118typedef struct
119{
Damjan Marionc0d9ca72021-05-11 09:39:24 +0200120 /* static data */
Damjan Marionb0d680b2016-11-04 14:41:44 +0100121 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700122 vlib_frame_queue_elt_t *elts;
Damjan Marionc0d9ca72021-05-11 09:39:24 +0200123 u64 vector_threshold;
124 u64 trace;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700125 u32 nelts;
Damjan Marionc0d9ca72021-05-11 09:39:24 +0200126
127 /* modified by enqueue side */
128 CLIB_CACHE_LINE_ALIGN_MARK (cacheline1);
129 volatile u64 tail;
130
131 /* modified by dequeue side */
132 CLIB_CACHE_LINE_ALIGN_MARK (cacheline2);
133 volatile u64 head;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400134}
135vlib_frame_queue_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700136
Mohammed Hawarie7149262022-05-18 10:08:47 +0200137struct vlib_frame_queue_main_t_;
138typedef u32 (vlib_frame_queue_dequeue_fn_t) (
139 vlib_main_t *vm, struct vlib_frame_queue_main_t_ *fqm);
140typedef struct vlib_frame_queue_main_t_
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100141{
142 u32 node_index;
Damjan Marion78fd7e82018-07-20 18:47:05 +0200143 u32 frame_queue_nelts;
Damjan Marion78fd7e82018-07-20 18:47:05 +0200144
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100145 vlib_frame_queue_t **vlib_frame_queues;
146
147 /* for frame queue tracing */
148 frame_queue_trace_t *frame_queue_traces;
149 frame_queue_nelt_counter_t *frame_queue_histogram;
Mohammed Hawarie7149262022-05-18 10:08:47 +0200150 vlib_frame_queue_dequeue_fn_t *frame_queue_dequeue_fn;
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100151} vlib_frame_queue_main_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700152
Dave Barach69128d02017-09-26 10:54:34 -0400153typedef struct
154{
155 uword node_index;
156 uword type_opaque;
157 uword data;
158} vlib_process_signal_event_mt_args_t;
159
Ed Warnickecb9cada2015-12-08 15:45:58 -0700160/* Called early, in thread 0's context */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400161clib_error_t *vlib_thread_init (vlib_main_t * vm);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700162
Dave Barach9b8ffd92016-07-08 08:13:45 -0400163void vlib_worker_thread_node_runtime_update (void);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700164
Dave Barach9b8ffd92016-07-08 08:13:45 -0400165void vlib_create_worker_threads (vlib_main_t * vm, int n,
166 void (*thread_function) (void *));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700167
168void vlib_worker_thread_init (vlib_worker_thread_t * w);
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100169u32 vlib_frame_queue_main_init (u32 node_index, u32 frame_queue_nelts);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700170
171/* Check for a barrier sync request every 30ms */
172#define BARRIER_SYNC_DELAY (0.030000)
173
174#if CLIB_DEBUG > 0
175/* long barrier timeout, for gdb... */
176#define BARRIER_SYNC_TIMEOUT (600.1)
177#else
178#define BARRIER_SYNC_TIMEOUT (1.0)
179#endif
180
Damjan Marion8343ee52019-02-26 17:15:48 +0100181#define vlib_worker_thread_barrier_sync(X) {vlib_worker_thread_barrier_sync_int(X, __FUNCTION__);}
Colin Tregenza Dancereb1ac172017-09-06 20:23:24 +0100182
Damjan Marion8343ee52019-02-26 17:15:48 +0100183void vlib_worker_thread_barrier_sync_int (vlib_main_t * vm,
184 const char *func_name);
Dave Barach9b8ffd92016-07-08 08:13:45 -0400185void vlib_worker_thread_barrier_release (vlib_main_t * vm);
Neale Ranns42845dd2020-05-26 13:12:17 +0000186u8 vlib_worker_thread_barrier_held (void);
Dave Barachc602b382019-06-03 19:48:22 -0400187void vlib_worker_thread_initial_barrier_sync_and_release (vlib_main_t * vm);
Colin Tregenza Dancer21596182017-09-04 15:27:49 +0100188void vlib_worker_thread_node_refork (void);
Neale Ranns42845dd2020-05-26 13:12:17 +0000189/**
190 * Wait until each of the workers has been once around the track
191 */
192void vlib_worker_wait_one_loop (void);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700193
Damjan Marion586afd72017-04-05 19:18:20 +0200194static_always_inline uword
195vlib_get_thread_index (void)
196{
Damjan Marionf55f9b82017-05-10 21:06:28 +0200197 return __os_thread_index;
Damjan Marion586afd72017-04-05 19:18:20 +0200198}
199
Dave Barach9b8ffd92016-07-08 08:13:45 -0400200always_inline void
201vlib_smp_unsafe_warning (void)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700202{
203 if (CLIB_DEBUG > 0)
204 {
Damjan Marion586afd72017-04-05 19:18:20 +0200205 if (vlib_get_thread_index ())
Dave Barach9b8ffd92016-07-08 08:13:45 -0400206 fformat (stderr, "%s: SMP unsafe warning...\n", __FUNCTION__);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700207 }
208}
209
Damjan Marion1d429df2021-04-14 19:07:13 +0200210always_inline int
211__foreach_vlib_main_helper (vlib_main_t *ii, vlib_main_t **p)
212{
213 vlib_main_t *vm;
214 u32 index = ii - (vlib_main_t *) 0;
215
216 if (index >= vec_len (vlib_global_main.vlib_mains))
217 return 0;
218
219 *p = vm = vlib_global_main.vlib_mains[index];
220 ASSERT (index == 0 || vm->parked_at_barrier == 1);
221 return 1;
222}
223
Damjan Marion92ccf9b2021-03-26 11:38:01 +0100224#define foreach_vlib_main() \
Damjan Marion1d429df2021-04-14 19:07:13 +0200225 for (vlib_main_t *ii = 0, *this_vlib_main; \
226 __foreach_vlib_main_helper (ii, &this_vlib_main); ii++) \
227 if (this_vlib_main)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700228
Pavel Kotucek1e765832016-09-23 08:54:14 +0200229#define foreach_sched_policy \
230 _(SCHED_OTHER, OTHER, "other") \
231 _(SCHED_BATCH, BATCH, "batch") \
232 _(SCHED_IDLE, IDLE, "idle") \
233 _(SCHED_FIFO, FIFO, "fifo") \
234 _(SCHED_RR, RR, "rr")
235
236typedef enum
237{
238#define _(v,f,s) SCHED_POLICY_##f = v,
239 foreach_sched_policy
240#undef _
241 SCHED_POLICY_N,
242} sched_policy_t;
243
Dave Barach9b8ffd92016-07-08 08:13:45 -0400244typedef struct
245{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700246 /* Link list of registrations, built by constructors */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400247 vlib_thread_registration_t *next;
248
Ed Warnickecb9cada2015-12-08 15:45:58 -0700249 /* Vector of registrations, w/ non-data-structure clones at the top */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400250 vlib_thread_registration_t **registrations;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700251
Dave Barach9b8ffd92016-07-08 08:13:45 -0400252 uword *thread_registrations_by_name;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700253
Dave Barach9b8ffd92016-07-08 08:13:45 -0400254 vlib_worker_thread_t *worker_threads;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700255
Ed Warnickecb9cada2015-12-08 15:45:58 -0700256 int use_pthreads;
257
258 /* Number of vlib_main / vnet_main clones */
259 u32 n_vlib_mains;
260
261 /* Number of thread stacks to create */
262 u32 n_thread_stacks;
263
264 /* Number of pthreads */
265 u32 n_pthreads;
266
Damjan Marion878c6092017-01-04 13:19:27 +0100267 /* Number of threads */
268 u32 n_threads;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700269
270 /* Number of cores to skip, must match the core mask */
271 u32 skip_cores;
272
273 /* Thread prefix name */
274 u8 *thread_prefix;
275
276 /* main thread lcore */
Damjan Marion858151f2018-07-11 10:51:00 +0200277 u32 main_lcore;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700278
279 /* Bitmap of available CPU cores */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400280 uword *cpu_core_bitmap;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700281
282 /* Bitmap of available CPU sockets (NUMA nodes) */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400283 uword *cpu_socket_bitmap;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700284
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100285 /* Worker handoff queues */
286 vlib_frame_queue_main_t *frame_queue_mains;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200287
288 /* worker thread initialization barrier */
289 volatile u32 worker_thread_release;
290
Pavel Kotucek1e765832016-09-23 08:54:14 +0200291 /* scheduling policy */
292 u32 sched_policy;
293
294 /* scheduling policy priority */
295 u32 sched_priority;
296
Dave Baracha690fdb2020-01-21 12:34:55 -0500297 /* NUMA-bound heap size */
298 uword numa_heap_size;
299
Ed Warnickecb9cada2015-12-08 15:45:58 -0700300} vlib_thread_main_t;
301
Damjan Marion6a7acc22016-12-19 16:28:36 +0100302extern vlib_thread_main_t vlib_thread_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700303
Damjan Marionce359db2017-03-16 16:15:38 +0100304#include <vlib/global_funcs.h>
305
Ed Warnickecb9cada2015-12-08 15:45:58 -0700306#define VLIB_REGISTER_THREAD(x,...) \
307 __VA_ARGS__ vlib_thread_registration_t x; \
308static void __vlib_add_thread_registration_##x (void) \
309 __attribute__((__constructor__)) ; \
310static void __vlib_add_thread_registration_##x (void) \
311{ \
312 vlib_thread_main_t * tm = &vlib_thread_main; \
313 x.next = tm->next; \
314 tm->next = &x; \
315} \
Damjan Marion72d2c4f2018-04-05 21:32:29 +0200316static void __vlib_rm_thread_registration_##x (void) \
317 __attribute__((__destructor__)) ; \
318static void __vlib_rm_thread_registration_##x (void) \
319{ \
320 vlib_thread_main_t * tm = &vlib_thread_main; \
321 VLIB_REMOVE_FROM_LINKED_LIST (tm->next, &x, next); \
322} \
Dave Barach9b8ffd92016-07-08 08:13:45 -0400323__VA_ARGS__ vlib_thread_registration_t x
Ed Warnickecb9cada2015-12-08 15:45:58 -0700324
Damjan Marion64034362016-11-07 22:19:55 +0100325always_inline u32
326vlib_num_workers ()
327{
328 return vlib_thread_main.n_vlib_mains - 1;
329}
330
331always_inline u32
Damjan Marion586afd72017-04-05 19:18:20 +0200332vlib_get_worker_thread_index (u32 worker_index)
Damjan Marion64034362016-11-07 22:19:55 +0100333{
334 return worker_index + 1;
335}
336
Damjan Marion3a4ed392016-11-08 13:20:42 +0100337always_inline u32
Damjan Marion586afd72017-04-05 19:18:20 +0200338vlib_get_worker_index (u32 thread_index)
Damjan Marion3a4ed392016-11-08 13:20:42 +0100339{
Damjan Marion586afd72017-04-05 19:18:20 +0200340 return thread_index - 1;
Damjan Marion3a4ed392016-11-08 13:20:42 +0100341}
342
343always_inline u32
344vlib_get_current_worker_index ()
345{
Damjan Marion586afd72017-04-05 19:18:20 +0200346 return vlib_get_thread_index () - 1;
Damjan Marion3a4ed392016-11-08 13:20:42 +0100347}
348
Damjan Marionce359db2017-03-16 16:15:38 +0100349static inline void
350vlib_worker_thread_barrier_check (void)
351{
352 if (PREDICT_FALSE (*vlib_worker_threads->wait_at_barrier))
353 {
Damjan Marionfd8deb42021-03-06 12:26:28 +0100354 vlib_global_main_t *vgm = vlib_get_global_main ();
Dave Barach88c6e002018-09-30 15:54:06 -0400355 vlib_main_t *vm = vlib_get_main ();
356 u32 thread_index = vm->thread_index;
357 f64 t = vlib_time_now (vm);
358
Tom Seidenberg6c81f5a2020-07-10 15:49:03 +0000359 if (PREDICT_FALSE (vec_len (vm->barrier_perf_callbacks) != 0))
360 clib_call_callbacks (vm->barrier_perf_callbacks, vm,
361 vm->clib_time.last_cpu_time, 0 /* enter */ );
362
Dave Barach88c6e002018-09-30 15:54:06 -0400363 if (PREDICT_FALSE (vlib_worker_threads->barrier_elog_enabled))
364 {
365 vlib_worker_thread_t *w = vlib_worker_threads + thread_index;
366 /* *INDENT-OFF* */
367 ELOG_TYPE_DECLARE (e) = {
368 .format = "barrier-wait-thread-%d",
369 .format_args = "i4",
370 };
371 /* *INDENT-ON* */
372
373 struct
374 {
375 u32 thread_index;
376 } __clib_packed *ed;
377
Damjan Marionf553a2c2021-03-26 13:45:37 +0100378 ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main, e, w->elog_track);
Dave Barach88c6e002018-09-30 15:54:06 -0400379 ed->thread_index = thread_index;
380 }
381
Damjan Marionce359db2017-03-16 16:15:38 +0100382 if (CLIB_DEBUG > 0)
383 {
384 vm = vlib_get_main ();
385 vm->parked_at_barrier = 1;
386 }
Alexander Kabaevfeda5452019-11-01 18:26:20 -0400387 clib_atomic_fetch_add (vlib_worker_threads->workers_at_barrier, 1);
Damjan Marionce359db2017-03-16 16:15:38 +0100388 while (*vlib_worker_threads->wait_at_barrier)
389 ;
Dave Baracha4324a92019-02-19 17:05:30 -0500390
391 /*
392 * Recompute the offset from thread-0 time.
393 * Note that vlib_time_now adds vm->time_offset, so
394 * clear it first. Save the resulting idea of "now", to
395 * see how well we're doing. See show_clock_command_fn(...)
396 */
397 {
398 f64 now;
399 vm->time_offset = 0.0;
400 now = vlib_time_now (vm);
Damjan Marionfd8deb42021-03-06 12:26:28 +0100401 vm->time_offset = vgm->vlib_mains[0]->time_last_barrier_release - now;
Dave Baracha4324a92019-02-19 17:05:30 -0500402 vm->time_last_barrier_release = vlib_time_now (vm);
403 }
404
Damjan Marionce359db2017-03-16 16:15:38 +0100405 if (CLIB_DEBUG > 0)
406 vm->parked_at_barrier = 0;
Sirshak Das2f6d7bb2018-10-03 22:53:51 +0000407 clib_atomic_fetch_add (vlib_worker_threads->workers_at_barrier, -1);
Colin Tregenza Dancer21596182017-09-04 15:27:49 +0100408
409 if (PREDICT_FALSE (*vlib_worker_threads->node_reforks_required))
410 {
Dave Barach88c6e002018-09-30 15:54:06 -0400411 if (PREDICT_FALSE (vlib_worker_threads->barrier_elog_enabled))
412 {
413 t = vlib_time_now (vm) - t;
414 vlib_worker_thread_t *w = vlib_worker_threads + thread_index;
415 /* *INDENT-OFF* */
416 ELOG_TYPE_DECLARE (e) = {
417 .format = "barrier-refork-thread-%d",
418 .format_args = "i4",
419 };
420 /* *INDENT-ON* */
421
422 struct
423 {
424 u32 thread_index;
425 } __clib_packed *ed;
426
427 ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main, e,
428 w->elog_track);
429 ed->thread_index = thread_index;
430 }
431
Colin Tregenza Dancer21596182017-09-04 15:27:49 +0100432 vlib_worker_thread_node_refork ();
Sirshak Das2f6d7bb2018-10-03 22:53:51 +0000433 clib_atomic_fetch_add (vlib_worker_threads->node_reforks_required,
434 -1);
Colin Tregenza Dancer21596182017-09-04 15:27:49 +0100435 while (*vlib_worker_threads->node_reforks_required)
436 ;
437 }
Dave Barach88c6e002018-09-30 15:54:06 -0400438 if (PREDICT_FALSE (vlib_worker_threads->barrier_elog_enabled))
439 {
440 t = vlib_time_now (vm) - t;
441 vlib_worker_thread_t *w = vlib_worker_threads + thread_index;
442 /* *INDENT-OFF* */
443 ELOG_TYPE_DECLARE (e) = {
444 .format = "barrier-released-thread-%d: %dus",
445 .format_args = "i4i4",
446 };
447 /* *INDENT-ON* */
448
449 struct
450 {
451 u32 thread_index;
452 u32 duration;
453 } __clib_packed *ed;
454
Damjan Marionf553a2c2021-03-26 13:45:37 +0100455 ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main, e, w->elog_track);
Dave Barach88c6e002018-09-30 15:54:06 -0400456 ed->thread_index = thread_index;
457 ed->duration = (int) (1000000.0 * t);
458 }
Tom Seidenberg6c81f5a2020-07-10 15:49:03 +0000459
460 if (PREDICT_FALSE (vec_len (vm->barrier_perf_callbacks) != 0))
461 clib_call_callbacks (vm->barrier_perf_callbacks, vm,
462 vm->clib_time.last_cpu_time, 1 /* leave */ );
Damjan Marionce359db2017-03-16 16:15:38 +0100463 }
464}
465
Damjan Marion64034362016-11-07 22:19:55 +0100466always_inline vlib_main_t *
467vlib_get_worker_vlib_main (u32 worker_index)
468{
469 vlib_main_t *vm;
470 vlib_thread_main_t *tm = &vlib_thread_main;
471 ASSERT (worker_index < tm->n_vlib_mains - 1);
Damjan Marion6ffb7c62021-03-26 13:06:13 +0100472 vm = vlib_get_main_by_index (worker_index + 1);
Damjan Marion64034362016-11-07 22:19:55 +0100473 ASSERT (vm);
474 return vm;
475}
476
Florin Coras568ebc72018-09-18 16:12:50 -0700477static inline u8
478vlib_thread_is_main_w_barrier (void)
479{
480 return (!vlib_num_workers ()
481 || ((vlib_get_thread_index () == 0
482 && vlib_worker_threads->wait_at_barrier[0])));
483}
484
Damjan Marion586afd72017-04-05 19:18:20 +0200485u8 *vlib_thread_stack_init (uword thread_index);
Dave Barach69128d02017-09-26 10:54:34 -0400486extern void *rpc_call_main_thread_cb_fn;
487
488void
489vlib_process_signal_event_mt_helper (vlib_process_signal_event_mt_args_t *
490 args);
491void vlib_rpc_call_main_thread (void *function, u8 * args, u32 size);
Dave Baracha690fdb2020-01-21 12:34:55 -0500492void vlib_get_thread_core_numa (vlib_worker_thread_t * w, unsigned cpu_id);
Dave Barachab1a50c2020-10-06 14:08:16 -0400493vlib_thread_main_t *vlib_get_thread_main_not_inline (void);
Dave Baracha690fdb2020-01-21 12:34:55 -0500494
Florin Coras4b208302022-03-30 13:50:19 -0700495/**
496 * Force workers sync from within worker
497 *
498 * Must be paired with @ref vlib_workers_continue
499 */
500void vlib_workers_sync (void);
501/**
502 * Release barrier after workers sync
503 */
504void vlib_workers_continue (void);
505
Ed Warnickecb9cada2015-12-08 15:45:58 -0700506#endif /* included_vlib_threads_h */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400507
508/*
509 * fd.io coding-style-patch-verification: ON
510 *
511 * Local Variables:
512 * eval: (c-set-style "gnu")
513 * End:
514 */