blob: 636212c939e5fb55ffc39e4bfc5147a62c6c9cab [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
Florin Coras93992a92017-05-24 18:03:56 -070048#define VLIB_LOG2_THREAD_STACK_SIZE (21)
Ed Warnickecb9cada2015-12-08 15:45:58 -070049#define VLIB_THREAD_STACK_SIZE (1<<VLIB_LOG2_THREAD_STACK_SIZE)
50
Dave Barach9b8ffd92016-07-08 08:13:45 -040051typedef struct
52{
Damjan Marionb0d680b2016-11-04 14:41:44 +010053 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070054 volatile u32 valid;
Damjan Marionc0d9ca72021-05-11 09:39:24 +020055 u32 maybe_trace : 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -070056 u32 n_vectors;
Damjan Marionc0d9ca72021-05-11 09:39:24 +020057 u32 offset;
58 STRUCT_MARK (end_of_reset);
Ed Warnickecb9cada2015-12-08 15:45:58 -070059
Damjan Marionc0d9ca72021-05-11 09:39:24 +020060 CLIB_CACHE_LINE_ALIGN_MARK (cacheline1);
Ed Warnickecb9cada2015-12-08 15:45:58 -070061 u32 buffer_index[VLIB_FRAME_SIZE];
Mohammed Hawarie7149262022-05-18 10:08:47 +020062 u32 aux_data[VLIB_FRAME_SIZE];
Dave Barach9b8ffd92016-07-08 08:13:45 -040063}
64vlib_frame_queue_elt_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -070065
Dave Barach9b8ffd92016-07-08 08:13:45 -040066typedef struct
67{
Ed Warnickecb9cada2015-12-08 15:45:58 -070068 /* First cache line */
Damjan Marionb0d680b2016-11-04 14:41:44 +010069 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070070 volatile u32 *wait_at_barrier;
71 volatile u32 *workers_at_barrier;
Ed Warnickecb9cada2015-12-08 15:45:58 -070072
73 /* Second Cache Line */
Damjan Marionb0d680b2016-11-04 14:41:44 +010074 CLIB_CACHE_LINE_ALIGN_MARK (cacheline1);
Ed Warnickecb9cada2015-12-08 15:45:58 -070075 void *thread_mheap;
Dave Barach9b8ffd92016-07-08 08:13:45 -040076 u8 *thread_stack;
77 void (*thread_function) (void *);
78 void *thread_function_arg;
79 i64 recursion_level;
80 elog_track_t elog_track;
Ed Warnickecb9cada2015-12-08 15:45:58 -070081 u32 instance_id;
82 vlib_thread_registration_t *registration;
83 u8 *name;
Bud Grise42f20062016-03-16 13:09:46 -040084 u64 barrier_sync_count;
Dave Barach88c6e002018-09-30 15:54:06 -040085 u8 barrier_elog_enabled;
Colin Tregenza Dancereb1ac172017-09-06 20:23:24 +010086 const char *barrier_caller;
87 const char *barrier_context;
Colin Tregenza Dancer21596182017-09-04 15:27:49 +010088 volatile u32 *node_reforks_required;
Florin Coras4b208302022-03-30 13:50:19 -070089 volatile u32 wait_before_barrier;
90 volatile u32 workers_before_barrier;
91 volatile u32 done_work_before_barrier;
Ed Warnickecb9cada2015-12-08 15:45:58 -070092
93 long lwp;
Mohsin Kazmi5d64c782018-09-11 20:27:09 +020094 int cpu_id;
95 int core_id;
Dave Baracha690fdb2020-01-21 12:34:55 -050096 int numa_id;
Pavel Kotucek98765202016-10-07 08:37:28 +020097 pthread_t thread_id;
Ed Warnickecb9cada2015-12-08 15:45:58 -070098} vlib_worker_thread_t;
99
Damjan Marion6a7acc22016-12-19 16:28:36 +0100100extern vlib_worker_thread_t *vlib_worker_threads;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700101
Dave Barach9b8ffd92016-07-08 08:13:45 -0400102typedef struct
103{
Damjan Marionc0d9ca72021-05-11 09:39:24 +0200104 /* static data */
Damjan Marionb0d680b2016-11-04 14:41:44 +0100105 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700106 vlib_frame_queue_elt_t *elts;
Damjan Marionc0d9ca72021-05-11 09:39:24 +0200107 u64 vector_threshold;
108 u64 trace;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700109 u32 nelts;
Damjan Marionc0d9ca72021-05-11 09:39:24 +0200110
111 /* modified by enqueue side */
112 CLIB_CACHE_LINE_ALIGN_MARK (cacheline1);
113 volatile u64 tail;
114
115 /* modified by dequeue side */
116 CLIB_CACHE_LINE_ALIGN_MARK (cacheline2);
117 volatile u64 head;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400118}
119vlib_frame_queue_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700120
Mohammed Hawarie7149262022-05-18 10:08:47 +0200121struct vlib_frame_queue_main_t_;
122typedef u32 (vlib_frame_queue_dequeue_fn_t) (
123 vlib_main_t *vm, struct vlib_frame_queue_main_t_ *fqm);
124typedef struct vlib_frame_queue_main_t_
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100125{
126 u32 node_index;
Damjan Marion78fd7e82018-07-20 18:47:05 +0200127 u32 frame_queue_nelts;
Damjan Marion78fd7e82018-07-20 18:47:05 +0200128
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100129 vlib_frame_queue_t **vlib_frame_queues;
130
131 /* for frame queue tracing */
132 frame_queue_trace_t *frame_queue_traces;
133 frame_queue_nelt_counter_t *frame_queue_histogram;
Mohammed Hawarie7149262022-05-18 10:08:47 +0200134 vlib_frame_queue_dequeue_fn_t *frame_queue_dequeue_fn;
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100135} vlib_frame_queue_main_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700136
Dave Barach69128d02017-09-26 10:54:34 -0400137typedef struct
138{
139 uword node_index;
140 uword type_opaque;
141 uword data;
142} vlib_process_signal_event_mt_args_t;
143
Ed Warnickecb9cada2015-12-08 15:45:58 -0700144/* Called early, in thread 0's context */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400145clib_error_t *vlib_thread_init (vlib_main_t * vm);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700146
Dave Barach9b8ffd92016-07-08 08:13:45 -0400147void vlib_worker_thread_node_runtime_update (void);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700148
Dave Barach9b8ffd92016-07-08 08:13:45 -0400149void vlib_create_worker_threads (vlib_main_t * vm, int n,
150 void (*thread_function) (void *));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700151
152void vlib_worker_thread_init (vlib_worker_thread_t * w);
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100153u32 vlib_frame_queue_main_init (u32 node_index, u32 frame_queue_nelts);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700154
155/* Check for a barrier sync request every 30ms */
156#define BARRIER_SYNC_DELAY (0.030000)
157
158#if CLIB_DEBUG > 0
159/* long barrier timeout, for gdb... */
160#define BARRIER_SYNC_TIMEOUT (600.1)
161#else
162#define BARRIER_SYNC_TIMEOUT (1.0)
163#endif
164
Damjan Marion8343ee52019-02-26 17:15:48 +0100165#define vlib_worker_thread_barrier_sync(X) {vlib_worker_thread_barrier_sync_int(X, __FUNCTION__);}
Colin Tregenza Dancereb1ac172017-09-06 20:23:24 +0100166
Damjan Marion8343ee52019-02-26 17:15:48 +0100167void vlib_worker_thread_barrier_sync_int (vlib_main_t * vm,
168 const char *func_name);
Dave Barach9b8ffd92016-07-08 08:13:45 -0400169void vlib_worker_thread_barrier_release (vlib_main_t * vm);
Neale Ranns42845dd2020-05-26 13:12:17 +0000170u8 vlib_worker_thread_barrier_held (void);
Dave Barachc602b382019-06-03 19:48:22 -0400171void vlib_worker_thread_initial_barrier_sync_and_release (vlib_main_t * vm);
Colin Tregenza Dancer21596182017-09-04 15:27:49 +0100172void vlib_worker_thread_node_refork (void);
Neale Ranns42845dd2020-05-26 13:12:17 +0000173/**
174 * Wait until each of the workers has been once around the track
175 */
176void vlib_worker_wait_one_loop (void);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700177
Damjan Marion586afd72017-04-05 19:18:20 +0200178static_always_inline uword
179vlib_get_thread_index (void)
180{
Damjan Marionf55f9b82017-05-10 21:06:28 +0200181 return __os_thread_index;
Damjan Marion586afd72017-04-05 19:18:20 +0200182}
183
Dave Barach9b8ffd92016-07-08 08:13:45 -0400184always_inline void
185vlib_smp_unsafe_warning (void)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700186{
187 if (CLIB_DEBUG > 0)
188 {
Damjan Marion586afd72017-04-05 19:18:20 +0200189 if (vlib_get_thread_index ())
Dave Barach9b8ffd92016-07-08 08:13:45 -0400190 fformat (stderr, "%s: SMP unsafe warning...\n", __FUNCTION__);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700191 }
192}
193
Damjan Marion1d429df2021-04-14 19:07:13 +0200194always_inline int
195__foreach_vlib_main_helper (vlib_main_t *ii, vlib_main_t **p)
196{
197 vlib_main_t *vm;
198 u32 index = ii - (vlib_main_t *) 0;
199
200 if (index >= vec_len (vlib_global_main.vlib_mains))
201 return 0;
202
203 *p = vm = vlib_global_main.vlib_mains[index];
204 ASSERT (index == 0 || vm->parked_at_barrier == 1);
205 return 1;
206}
207
Damjan Marion92ccf9b2021-03-26 11:38:01 +0100208#define foreach_vlib_main() \
Damjan Marion1d429df2021-04-14 19:07:13 +0200209 for (vlib_main_t *ii = 0, *this_vlib_main; \
210 __foreach_vlib_main_helper (ii, &this_vlib_main); ii++) \
211 if (this_vlib_main)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700212
Pavel Kotucek1e765832016-09-23 08:54:14 +0200213#define foreach_sched_policy \
214 _(SCHED_OTHER, OTHER, "other") \
215 _(SCHED_BATCH, BATCH, "batch") \
216 _(SCHED_IDLE, IDLE, "idle") \
217 _(SCHED_FIFO, FIFO, "fifo") \
218 _(SCHED_RR, RR, "rr")
219
220typedef enum
221{
222#define _(v,f,s) SCHED_POLICY_##f = v,
223 foreach_sched_policy
224#undef _
225 SCHED_POLICY_N,
226} sched_policy_t;
227
Dave Barach9b8ffd92016-07-08 08:13:45 -0400228typedef struct
229{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700230 /* Link list of registrations, built by constructors */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400231 vlib_thread_registration_t *next;
232
Ed Warnickecb9cada2015-12-08 15:45:58 -0700233 /* Vector of registrations, w/ non-data-structure clones at the top */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400234 vlib_thread_registration_t **registrations;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700235
Dave Barach9b8ffd92016-07-08 08:13:45 -0400236 uword *thread_registrations_by_name;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700237
Dave Barach9b8ffd92016-07-08 08:13:45 -0400238 vlib_worker_thread_t *worker_threads;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700239
Ed Warnickecb9cada2015-12-08 15:45:58 -0700240 int use_pthreads;
241
242 /* Number of vlib_main / vnet_main clones */
243 u32 n_vlib_mains;
244
245 /* Number of thread stacks to create */
246 u32 n_thread_stacks;
247
248 /* Number of pthreads */
249 u32 n_pthreads;
250
Damjan Marion878c6092017-01-04 13:19:27 +0100251 /* Number of threads */
252 u32 n_threads;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700253
254 /* Number of cores to skip, must match the core mask */
255 u32 skip_cores;
256
257 /* Thread prefix name */
258 u8 *thread_prefix;
259
260 /* main thread lcore */
Damjan Marion858151f2018-07-11 10:51:00 +0200261 u32 main_lcore;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700262
263 /* Bitmap of available CPU cores */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400264 uword *cpu_core_bitmap;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700265
266 /* Bitmap of available CPU sockets (NUMA nodes) */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400267 uword *cpu_socket_bitmap;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700268
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100269 /* Worker handoff queues */
270 vlib_frame_queue_main_t *frame_queue_mains;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200271
272 /* worker thread initialization barrier */
273 volatile u32 worker_thread_release;
274
Pavel Kotucek1e765832016-09-23 08:54:14 +0200275 /* scheduling policy */
276 u32 sched_policy;
277
278 /* scheduling policy priority */
279 u32 sched_priority;
280
Dave Baracha690fdb2020-01-21 12:34:55 -0500281 /* NUMA-bound heap size */
282 uword numa_heap_size;
283
Ed Warnickecb9cada2015-12-08 15:45:58 -0700284} vlib_thread_main_t;
285
Damjan Marion6a7acc22016-12-19 16:28:36 +0100286extern vlib_thread_main_t vlib_thread_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700287
Damjan Marionce359db2017-03-16 16:15:38 +0100288#include <vlib/global_funcs.h>
289
Ed Warnickecb9cada2015-12-08 15:45:58 -0700290#define VLIB_REGISTER_THREAD(x,...) \
291 __VA_ARGS__ vlib_thread_registration_t x; \
292static void __vlib_add_thread_registration_##x (void) \
293 __attribute__((__constructor__)) ; \
294static void __vlib_add_thread_registration_##x (void) \
295{ \
296 vlib_thread_main_t * tm = &vlib_thread_main; \
297 x.next = tm->next; \
298 tm->next = &x; \
299} \
Damjan Marion72d2c4f2018-04-05 21:32:29 +0200300static void __vlib_rm_thread_registration_##x (void) \
301 __attribute__((__destructor__)) ; \
302static void __vlib_rm_thread_registration_##x (void) \
303{ \
304 vlib_thread_main_t * tm = &vlib_thread_main; \
305 VLIB_REMOVE_FROM_LINKED_LIST (tm->next, &x, next); \
306} \
Dave Barach9b8ffd92016-07-08 08:13:45 -0400307__VA_ARGS__ vlib_thread_registration_t x
Ed Warnickecb9cada2015-12-08 15:45:58 -0700308
Damjan Marion64034362016-11-07 22:19:55 +0100309always_inline u32
310vlib_num_workers ()
311{
312 return vlib_thread_main.n_vlib_mains - 1;
313}
314
315always_inline u32
Damjan Marion586afd72017-04-05 19:18:20 +0200316vlib_get_worker_thread_index (u32 worker_index)
Damjan Marion64034362016-11-07 22:19:55 +0100317{
318 return worker_index + 1;
319}
320
Damjan Marion3a4ed392016-11-08 13:20:42 +0100321always_inline u32
Damjan Marion586afd72017-04-05 19:18:20 +0200322vlib_get_worker_index (u32 thread_index)
Damjan Marion3a4ed392016-11-08 13:20:42 +0100323{
Damjan Marion586afd72017-04-05 19:18:20 +0200324 return thread_index - 1;
Damjan Marion3a4ed392016-11-08 13:20:42 +0100325}
326
327always_inline u32
328vlib_get_current_worker_index ()
329{
Damjan Marion586afd72017-04-05 19:18:20 +0200330 return vlib_get_thread_index () - 1;
Damjan Marion3a4ed392016-11-08 13:20:42 +0100331}
332
Damjan Marionce359db2017-03-16 16:15:38 +0100333static inline void
334vlib_worker_thread_barrier_check (void)
335{
336 if (PREDICT_FALSE (*vlib_worker_threads->wait_at_barrier))
337 {
Damjan Marionfd8deb42021-03-06 12:26:28 +0100338 vlib_global_main_t *vgm = vlib_get_global_main ();
Dave Barach88c6e002018-09-30 15:54:06 -0400339 vlib_main_t *vm = vlib_get_main ();
340 u32 thread_index = vm->thread_index;
341 f64 t = vlib_time_now (vm);
342
Tom Seidenberg6c81f5a2020-07-10 15:49:03 +0000343 if (PREDICT_FALSE (vec_len (vm->barrier_perf_callbacks) != 0))
344 clib_call_callbacks (vm->barrier_perf_callbacks, vm,
345 vm->clib_time.last_cpu_time, 0 /* enter */ );
346
Dave Barach88c6e002018-09-30 15:54:06 -0400347 if (PREDICT_FALSE (vlib_worker_threads->barrier_elog_enabled))
348 {
349 vlib_worker_thread_t *w = vlib_worker_threads + thread_index;
350 /* *INDENT-OFF* */
351 ELOG_TYPE_DECLARE (e) = {
352 .format = "barrier-wait-thread-%d",
353 .format_args = "i4",
354 };
355 /* *INDENT-ON* */
356
357 struct
358 {
359 u32 thread_index;
360 } __clib_packed *ed;
361
Damjan Marionf553a2c2021-03-26 13:45:37 +0100362 ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main, e, w->elog_track);
Dave Barach88c6e002018-09-30 15:54:06 -0400363 ed->thread_index = thread_index;
364 }
365
Damjan Marionce359db2017-03-16 16:15:38 +0100366 if (CLIB_DEBUG > 0)
367 {
368 vm = vlib_get_main ();
369 vm->parked_at_barrier = 1;
370 }
Alexander Kabaevfeda5452019-11-01 18:26:20 -0400371 clib_atomic_fetch_add (vlib_worker_threads->workers_at_barrier, 1);
Damjan Marionce359db2017-03-16 16:15:38 +0100372 while (*vlib_worker_threads->wait_at_barrier)
373 ;
Dave Baracha4324a92019-02-19 17:05:30 -0500374
375 /*
376 * Recompute the offset from thread-0 time.
377 * Note that vlib_time_now adds vm->time_offset, so
378 * clear it first. Save the resulting idea of "now", to
379 * see how well we're doing. See show_clock_command_fn(...)
380 */
381 {
382 f64 now;
383 vm->time_offset = 0.0;
384 now = vlib_time_now (vm);
Damjan Marionfd8deb42021-03-06 12:26:28 +0100385 vm->time_offset = vgm->vlib_mains[0]->time_last_barrier_release - now;
Dave Baracha4324a92019-02-19 17:05:30 -0500386 vm->time_last_barrier_release = vlib_time_now (vm);
387 }
388
Damjan Marionce359db2017-03-16 16:15:38 +0100389 if (CLIB_DEBUG > 0)
390 vm->parked_at_barrier = 0;
Sirshak Das2f6d7bb2018-10-03 22:53:51 +0000391 clib_atomic_fetch_add (vlib_worker_threads->workers_at_barrier, -1);
Colin Tregenza Dancer21596182017-09-04 15:27:49 +0100392
393 if (PREDICT_FALSE (*vlib_worker_threads->node_reforks_required))
394 {
Dave Barach88c6e002018-09-30 15:54:06 -0400395 if (PREDICT_FALSE (vlib_worker_threads->barrier_elog_enabled))
396 {
397 t = vlib_time_now (vm) - t;
398 vlib_worker_thread_t *w = vlib_worker_threads + thread_index;
399 /* *INDENT-OFF* */
400 ELOG_TYPE_DECLARE (e) = {
401 .format = "barrier-refork-thread-%d",
402 .format_args = "i4",
403 };
404 /* *INDENT-ON* */
405
406 struct
407 {
408 u32 thread_index;
409 } __clib_packed *ed;
410
411 ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main, e,
412 w->elog_track);
413 ed->thread_index = thread_index;
414 }
415
Colin Tregenza Dancer21596182017-09-04 15:27:49 +0100416 vlib_worker_thread_node_refork ();
Sirshak Das2f6d7bb2018-10-03 22:53:51 +0000417 clib_atomic_fetch_add (vlib_worker_threads->node_reforks_required,
418 -1);
Colin Tregenza Dancer21596182017-09-04 15:27:49 +0100419 while (*vlib_worker_threads->node_reforks_required)
420 ;
421 }
Dave Barach88c6e002018-09-30 15:54:06 -0400422 if (PREDICT_FALSE (vlib_worker_threads->barrier_elog_enabled))
423 {
424 t = vlib_time_now (vm) - t;
425 vlib_worker_thread_t *w = vlib_worker_threads + thread_index;
426 /* *INDENT-OFF* */
427 ELOG_TYPE_DECLARE (e) = {
428 .format = "barrier-released-thread-%d: %dus",
429 .format_args = "i4i4",
430 };
431 /* *INDENT-ON* */
432
433 struct
434 {
435 u32 thread_index;
436 u32 duration;
437 } __clib_packed *ed;
438
Damjan Marionf553a2c2021-03-26 13:45:37 +0100439 ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main, e, w->elog_track);
Dave Barach88c6e002018-09-30 15:54:06 -0400440 ed->thread_index = thread_index;
441 ed->duration = (int) (1000000.0 * t);
442 }
Tom Seidenberg6c81f5a2020-07-10 15:49:03 +0000443
444 if (PREDICT_FALSE (vec_len (vm->barrier_perf_callbacks) != 0))
445 clib_call_callbacks (vm->barrier_perf_callbacks, vm,
446 vm->clib_time.last_cpu_time, 1 /* leave */ );
Damjan Marionce359db2017-03-16 16:15:38 +0100447 }
448}
449
Damjan Marion64034362016-11-07 22:19:55 +0100450always_inline vlib_main_t *
451vlib_get_worker_vlib_main (u32 worker_index)
452{
453 vlib_main_t *vm;
454 vlib_thread_main_t *tm = &vlib_thread_main;
455 ASSERT (worker_index < tm->n_vlib_mains - 1);
Damjan Marion6ffb7c62021-03-26 13:06:13 +0100456 vm = vlib_get_main_by_index (worker_index + 1);
Damjan Marion64034362016-11-07 22:19:55 +0100457 ASSERT (vm);
458 return vm;
459}
460
Florin Coras568ebc72018-09-18 16:12:50 -0700461static inline u8
462vlib_thread_is_main_w_barrier (void)
463{
464 return (!vlib_num_workers ()
465 || ((vlib_get_thread_index () == 0
466 && vlib_worker_threads->wait_at_barrier[0])));
467}
468
Damjan Marion586afd72017-04-05 19:18:20 +0200469u8 *vlib_thread_stack_init (uword thread_index);
Dave Barach69128d02017-09-26 10:54:34 -0400470extern void *rpc_call_main_thread_cb_fn;
471
472void
473vlib_process_signal_event_mt_helper (vlib_process_signal_event_mt_args_t *
474 args);
475void vlib_rpc_call_main_thread (void *function, u8 * args, u32 size);
Dave Baracha690fdb2020-01-21 12:34:55 -0500476void vlib_get_thread_core_numa (vlib_worker_thread_t * w, unsigned cpu_id);
Dave Barachab1a50c2020-10-06 14:08:16 -0400477vlib_thread_main_t *vlib_get_thread_main_not_inline (void);
Dave Baracha690fdb2020-01-21 12:34:55 -0500478
Florin Coras4b208302022-03-30 13:50:19 -0700479/**
480 * Force workers sync from within worker
481 *
482 * Must be paired with @ref vlib_workers_continue
483 */
484void vlib_workers_sync (void);
485/**
486 * Release barrier after workers sync
487 */
488void vlib_workers_continue (void);
489
Ed Warnickecb9cada2015-12-08 15:45:58 -0700490#endif /* included_vlib_threads_h */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400491
492/*
493 * fd.io coding-style-patch-verification: ON
494 *
495 * Local Variables:
496 * eval: (c-set-style "gnu")
497 * End:
498 */