blob: 91727bacc23bf32a35ab9cb041dcb35a814e000c [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];
Dave Barach9b8ffd92016-07-08 08:13:45 -040078}
79vlib_frame_queue_elt_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -070080
Dave Barach9b8ffd92016-07-08 08:13:45 -040081typedef struct
82{
Ed Warnickecb9cada2015-12-08 15:45:58 -070083 /* First cache line */
Damjan Marionb0d680b2016-11-04 14:41:44 +010084 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070085 volatile u32 *wait_at_barrier;
86 volatile u32 *workers_at_barrier;
Ed Warnickecb9cada2015-12-08 15:45:58 -070087
88 /* Second Cache Line */
Damjan Marionb0d680b2016-11-04 14:41:44 +010089 CLIB_CACHE_LINE_ALIGN_MARK (cacheline1);
Ed Warnickecb9cada2015-12-08 15:45:58 -070090 void *thread_mheap;
Dave Barach9b8ffd92016-07-08 08:13:45 -040091 u8 *thread_stack;
92 void (*thread_function) (void *);
93 void *thread_function_arg;
94 i64 recursion_level;
95 elog_track_t elog_track;
Ed Warnickecb9cada2015-12-08 15:45:58 -070096 u32 instance_id;
97 vlib_thread_registration_t *registration;
98 u8 *name;
Bud Grise42f20062016-03-16 13:09:46 -040099 u64 barrier_sync_count;
Dave Barach88c6e002018-09-30 15:54:06 -0400100 u8 barrier_elog_enabled;
Colin Tregenza Dancereb1ac172017-09-06 20:23:24 +0100101 const char *barrier_caller;
102 const char *barrier_context;
Colin Tregenza Dancer21596182017-09-04 15:27:49 +0100103 volatile u32 *node_reforks_required;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700104
105 long lwp;
Mohsin Kazmi5d64c782018-09-11 20:27:09 +0200106 int cpu_id;
107 int core_id;
Dave Baracha690fdb2020-01-21 12:34:55 -0500108 int numa_id;
Pavel Kotucek98765202016-10-07 08:37:28 +0200109 pthread_t thread_id;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700110} vlib_worker_thread_t;
111
Damjan Marion6a7acc22016-12-19 16:28:36 +0100112extern vlib_worker_thread_t *vlib_worker_threads;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700113
Dave Barach9b8ffd92016-07-08 08:13:45 -0400114typedef struct
115{
Damjan Marionc0d9ca72021-05-11 09:39:24 +0200116 /* static data */
Damjan Marionb0d680b2016-11-04 14:41:44 +0100117 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700118 vlib_frame_queue_elt_t *elts;
Damjan Marionc0d9ca72021-05-11 09:39:24 +0200119 u64 vector_threshold;
120 u64 trace;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700121 u32 nelts;
Damjan Marionc0d9ca72021-05-11 09:39:24 +0200122
123 /* modified by enqueue side */
124 CLIB_CACHE_LINE_ALIGN_MARK (cacheline1);
125 volatile u64 tail;
126
127 /* modified by dequeue side */
128 CLIB_CACHE_LINE_ALIGN_MARK (cacheline2);
129 volatile u64 head;
Dave Barach9b8ffd92016-07-08 08:13:45 -0400130}
131vlib_frame_queue_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700132
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100133typedef struct
134{
135 u32 node_index;
Damjan Marion78fd7e82018-07-20 18:47:05 +0200136 u32 frame_queue_nelts;
Damjan Marion78fd7e82018-07-20 18:47:05 +0200137
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100138 vlib_frame_queue_t **vlib_frame_queues;
139
140 /* for frame queue tracing */
141 frame_queue_trace_t *frame_queue_traces;
142 frame_queue_nelt_counter_t *frame_queue_histogram;
143} vlib_frame_queue_main_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700144
Dave Barach69128d02017-09-26 10:54:34 -0400145typedef struct
146{
147 uword node_index;
148 uword type_opaque;
149 uword data;
150} vlib_process_signal_event_mt_args_t;
151
Ed Warnickecb9cada2015-12-08 15:45:58 -0700152/* Called early, in thread 0's context */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400153clib_error_t *vlib_thread_init (vlib_main_t * vm);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700154
Dave Barach9b8ffd92016-07-08 08:13:45 -0400155void vlib_worker_thread_node_runtime_update (void);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700156
Dave Barach9b8ffd92016-07-08 08:13:45 -0400157void vlib_create_worker_threads (vlib_main_t * vm, int n,
158 void (*thread_function) (void *));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700159
160void vlib_worker_thread_init (vlib_worker_thread_t * w);
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100161u32 vlib_frame_queue_main_init (u32 node_index, u32 frame_queue_nelts);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700162
163/* Check for a barrier sync request every 30ms */
164#define BARRIER_SYNC_DELAY (0.030000)
165
166#if CLIB_DEBUG > 0
167/* long barrier timeout, for gdb... */
168#define BARRIER_SYNC_TIMEOUT (600.1)
169#else
170#define BARRIER_SYNC_TIMEOUT (1.0)
171#endif
172
Damjan Marion8343ee52019-02-26 17:15:48 +0100173#define vlib_worker_thread_barrier_sync(X) {vlib_worker_thread_barrier_sync_int(X, __FUNCTION__);}
Colin Tregenza Dancereb1ac172017-09-06 20:23:24 +0100174
Damjan Marion8343ee52019-02-26 17:15:48 +0100175void vlib_worker_thread_barrier_sync_int (vlib_main_t * vm,
176 const char *func_name);
Dave Barach9b8ffd92016-07-08 08:13:45 -0400177void vlib_worker_thread_barrier_release (vlib_main_t * vm);
Neale Ranns42845dd2020-05-26 13:12:17 +0000178u8 vlib_worker_thread_barrier_held (void);
Dave Barachc602b382019-06-03 19:48:22 -0400179void vlib_worker_thread_initial_barrier_sync_and_release (vlib_main_t * vm);
Colin Tregenza Dancer21596182017-09-04 15:27:49 +0100180void vlib_worker_thread_node_refork (void);
Neale Ranns42845dd2020-05-26 13:12:17 +0000181/**
182 * Wait until each of the workers has been once around the track
183 */
184void vlib_worker_wait_one_loop (void);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700185
Damjan Marion586afd72017-04-05 19:18:20 +0200186static_always_inline uword
187vlib_get_thread_index (void)
188{
Damjan Marionf55f9b82017-05-10 21:06:28 +0200189 return __os_thread_index;
Damjan Marion586afd72017-04-05 19:18:20 +0200190}
191
Dave Barach9b8ffd92016-07-08 08:13:45 -0400192always_inline void
193vlib_smp_unsafe_warning (void)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700194{
195 if (CLIB_DEBUG > 0)
196 {
Damjan Marion586afd72017-04-05 19:18:20 +0200197 if (vlib_get_thread_index ())
Dave Barach9b8ffd92016-07-08 08:13:45 -0400198 fformat (stderr, "%s: SMP unsafe warning...\n", __FUNCTION__);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700199 }
200}
201
Damjan Marion1d429df2021-04-14 19:07:13 +0200202always_inline int
203__foreach_vlib_main_helper (vlib_main_t *ii, vlib_main_t **p)
204{
205 vlib_main_t *vm;
206 u32 index = ii - (vlib_main_t *) 0;
207
208 if (index >= vec_len (vlib_global_main.vlib_mains))
209 return 0;
210
211 *p = vm = vlib_global_main.vlib_mains[index];
212 ASSERT (index == 0 || vm->parked_at_barrier == 1);
213 return 1;
214}
215
Damjan Marion92ccf9b2021-03-26 11:38:01 +0100216#define foreach_vlib_main() \
Damjan Marion1d429df2021-04-14 19:07:13 +0200217 for (vlib_main_t *ii = 0, *this_vlib_main; \
218 __foreach_vlib_main_helper (ii, &this_vlib_main); ii++) \
219 if (this_vlib_main)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700220
Pavel Kotucek1e765832016-09-23 08:54:14 +0200221#define foreach_sched_policy \
222 _(SCHED_OTHER, OTHER, "other") \
223 _(SCHED_BATCH, BATCH, "batch") \
224 _(SCHED_IDLE, IDLE, "idle") \
225 _(SCHED_FIFO, FIFO, "fifo") \
226 _(SCHED_RR, RR, "rr")
227
228typedef enum
229{
230#define _(v,f,s) SCHED_POLICY_##f = v,
231 foreach_sched_policy
232#undef _
233 SCHED_POLICY_N,
234} sched_policy_t;
235
Dave Barach9b8ffd92016-07-08 08:13:45 -0400236typedef struct
237{
Damjan Marion878c6092017-01-04 13:19:27 +0100238 clib_error_t *(*vlib_launch_thread_cb) (void *fp, vlib_worker_thread_t * w,
Mohsin Kazmi5d64c782018-09-11 20:27:09 +0200239 unsigned cpu_id);
240 clib_error_t *(*vlib_thread_set_lcore_cb) (u32 thread, u16 cpu);
Damjan Marion878c6092017-01-04 13:19:27 +0100241} vlib_thread_callbacks_t;
242
243typedef struct
244{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700245 /* Link list of registrations, built by constructors */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400246 vlib_thread_registration_t *next;
247
Ed Warnickecb9cada2015-12-08 15:45:58 -0700248 /* Vector of registrations, w/ non-data-structure clones at the top */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400249 vlib_thread_registration_t **registrations;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700250
Dave Barach9b8ffd92016-07-08 08:13:45 -0400251 uword *thread_registrations_by_name;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700252
Dave Barach9b8ffd92016-07-08 08:13:45 -0400253 vlib_worker_thread_t *worker_threads;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700254
Dave Barach9b8ffd92016-07-08 08:13:45 -0400255 /*
256 * Launch all threads as pthreads,
257 * not eal_rte_launch (strict affinity) threads
Ed Warnickecb9cada2015-12-08 15:45:58 -0700258 */
259 int use_pthreads;
260
261 /* Number of vlib_main / vnet_main clones */
262 u32 n_vlib_mains;
263
264 /* Number of thread stacks to create */
265 u32 n_thread_stacks;
266
267 /* Number of pthreads */
268 u32 n_pthreads;
269
Damjan Marion878c6092017-01-04 13:19:27 +0100270 /* Number of threads */
271 u32 n_threads;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700272
273 /* Number of cores to skip, must match the core mask */
274 u32 skip_cores;
275
276 /* Thread prefix name */
277 u8 *thread_prefix;
278
279 /* main thread lcore */
Damjan Marion858151f2018-07-11 10:51:00 +0200280 u32 main_lcore;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700281
282 /* Bitmap of available CPU cores */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400283 uword *cpu_core_bitmap;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700284
285 /* Bitmap of available CPU sockets (NUMA nodes) */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400286 uword *cpu_socket_bitmap;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700287
Damjan Marionaaef1eb2016-11-08 17:37:01 +0100288 /* Worker handoff queues */
289 vlib_frame_queue_main_t *frame_queue_mains;
Damjan Marion0f8ecf02016-06-27 08:30:30 +0200290
291 /* worker thread initialization barrier */
292 volatile u32 worker_thread_release;
293
Pavel Kotucek1e765832016-09-23 08:54:14 +0200294 /* scheduling policy */
295 u32 sched_policy;
296
297 /* scheduling policy priority */
298 u32 sched_priority;
299
Damjan Marion878c6092017-01-04 13:19:27 +0100300 /* callbacks */
301 vlib_thread_callbacks_t cb;
302 int extern_thread_mgmt;
Dave Baracha690fdb2020-01-21 12:34:55 -0500303
304 /* NUMA-bound heap size */
305 uword numa_heap_size;
306
Ed Warnickecb9cada2015-12-08 15:45:58 -0700307} vlib_thread_main_t;
308
Damjan Marion6a7acc22016-12-19 16:28:36 +0100309extern vlib_thread_main_t vlib_thread_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700310
Damjan Marionce359db2017-03-16 16:15:38 +0100311#include <vlib/global_funcs.h>
312
Ed Warnickecb9cada2015-12-08 15:45:58 -0700313#define VLIB_REGISTER_THREAD(x,...) \
314 __VA_ARGS__ vlib_thread_registration_t x; \
315static void __vlib_add_thread_registration_##x (void) \
316 __attribute__((__constructor__)) ; \
317static void __vlib_add_thread_registration_##x (void) \
318{ \
319 vlib_thread_main_t * tm = &vlib_thread_main; \
320 x.next = tm->next; \
321 tm->next = &x; \
322} \
Damjan Marion72d2c4f2018-04-05 21:32:29 +0200323static void __vlib_rm_thread_registration_##x (void) \
324 __attribute__((__destructor__)) ; \
325static void __vlib_rm_thread_registration_##x (void) \
326{ \
327 vlib_thread_main_t * tm = &vlib_thread_main; \
328 VLIB_REMOVE_FROM_LINKED_LIST (tm->next, &x, next); \
329} \
Dave Barach9b8ffd92016-07-08 08:13:45 -0400330__VA_ARGS__ vlib_thread_registration_t x
Ed Warnickecb9cada2015-12-08 15:45:58 -0700331
Damjan Marion64034362016-11-07 22:19:55 +0100332always_inline u32
333vlib_num_workers ()
334{
335 return vlib_thread_main.n_vlib_mains - 1;
336}
337
338always_inline u32
Damjan Marion586afd72017-04-05 19:18:20 +0200339vlib_get_worker_thread_index (u32 worker_index)
Damjan Marion64034362016-11-07 22:19:55 +0100340{
341 return worker_index + 1;
342}
343
Damjan Marion3a4ed392016-11-08 13:20:42 +0100344always_inline u32
Damjan Marion586afd72017-04-05 19:18:20 +0200345vlib_get_worker_index (u32 thread_index)
Damjan Marion3a4ed392016-11-08 13:20:42 +0100346{
Damjan Marion586afd72017-04-05 19:18:20 +0200347 return thread_index - 1;
Damjan Marion3a4ed392016-11-08 13:20:42 +0100348}
349
350always_inline u32
351vlib_get_current_worker_index ()
352{
Damjan Marion586afd72017-04-05 19:18:20 +0200353 return vlib_get_thread_index () - 1;
Damjan Marion3a4ed392016-11-08 13:20:42 +0100354}
355
Damjan Marionce359db2017-03-16 16:15:38 +0100356static inline void
357vlib_worker_thread_barrier_check (void)
358{
359 if (PREDICT_FALSE (*vlib_worker_threads->wait_at_barrier))
360 {
Damjan Marionfd8deb42021-03-06 12:26:28 +0100361 vlib_global_main_t *vgm = vlib_get_global_main ();
Dave Barach88c6e002018-09-30 15:54:06 -0400362 vlib_main_t *vm = vlib_get_main ();
363 u32 thread_index = vm->thread_index;
364 f64 t = vlib_time_now (vm);
365
Tom Seidenberg6c81f5a2020-07-10 15:49:03 +0000366 if (PREDICT_FALSE (vec_len (vm->barrier_perf_callbacks) != 0))
367 clib_call_callbacks (vm->barrier_perf_callbacks, vm,
368 vm->clib_time.last_cpu_time, 0 /* enter */ );
369
Dave Barach88c6e002018-09-30 15:54:06 -0400370 if (PREDICT_FALSE (vlib_worker_threads->barrier_elog_enabled))
371 {
372 vlib_worker_thread_t *w = vlib_worker_threads + thread_index;
373 /* *INDENT-OFF* */
374 ELOG_TYPE_DECLARE (e) = {
375 .format = "barrier-wait-thread-%d",
376 .format_args = "i4",
377 };
378 /* *INDENT-ON* */
379
380 struct
381 {
382 u32 thread_index;
383 } __clib_packed *ed;
384
Damjan Marionf553a2c2021-03-26 13:45:37 +0100385 ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main, e, w->elog_track);
Dave Barach88c6e002018-09-30 15:54:06 -0400386 ed->thread_index = thread_index;
387 }
388
Damjan Marionce359db2017-03-16 16:15:38 +0100389 if (CLIB_DEBUG > 0)
390 {
391 vm = vlib_get_main ();
392 vm->parked_at_barrier = 1;
393 }
Alexander Kabaevfeda5452019-11-01 18:26:20 -0400394 clib_atomic_fetch_add (vlib_worker_threads->workers_at_barrier, 1);
Damjan Marionce359db2017-03-16 16:15:38 +0100395 while (*vlib_worker_threads->wait_at_barrier)
396 ;
Dave Baracha4324a92019-02-19 17:05:30 -0500397
398 /*
399 * Recompute the offset from thread-0 time.
400 * Note that vlib_time_now adds vm->time_offset, so
401 * clear it first. Save the resulting idea of "now", to
402 * see how well we're doing. See show_clock_command_fn(...)
403 */
404 {
405 f64 now;
406 vm->time_offset = 0.0;
407 now = vlib_time_now (vm);
Damjan Marionfd8deb42021-03-06 12:26:28 +0100408 vm->time_offset = vgm->vlib_mains[0]->time_last_barrier_release - now;
Dave Baracha4324a92019-02-19 17:05:30 -0500409 vm->time_last_barrier_release = vlib_time_now (vm);
410 }
411
Damjan Marionce359db2017-03-16 16:15:38 +0100412 if (CLIB_DEBUG > 0)
413 vm->parked_at_barrier = 0;
Sirshak Das2f6d7bb2018-10-03 22:53:51 +0000414 clib_atomic_fetch_add (vlib_worker_threads->workers_at_barrier, -1);
Colin Tregenza Dancer21596182017-09-04 15:27:49 +0100415
416 if (PREDICT_FALSE (*vlib_worker_threads->node_reforks_required))
417 {
Dave Barach88c6e002018-09-30 15:54:06 -0400418 if (PREDICT_FALSE (vlib_worker_threads->barrier_elog_enabled))
419 {
420 t = vlib_time_now (vm) - t;
421 vlib_worker_thread_t *w = vlib_worker_threads + thread_index;
422 /* *INDENT-OFF* */
423 ELOG_TYPE_DECLARE (e) = {
424 .format = "barrier-refork-thread-%d",
425 .format_args = "i4",
426 };
427 /* *INDENT-ON* */
428
429 struct
430 {
431 u32 thread_index;
432 } __clib_packed *ed;
433
434 ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main, e,
435 w->elog_track);
436 ed->thread_index = thread_index;
437 }
438
Colin Tregenza Dancer21596182017-09-04 15:27:49 +0100439 vlib_worker_thread_node_refork ();
Sirshak Das2f6d7bb2018-10-03 22:53:51 +0000440 clib_atomic_fetch_add (vlib_worker_threads->node_reforks_required,
441 -1);
Colin Tregenza Dancer21596182017-09-04 15:27:49 +0100442 while (*vlib_worker_threads->node_reforks_required)
443 ;
444 }
Dave Barach88c6e002018-09-30 15:54:06 -0400445 if (PREDICT_FALSE (vlib_worker_threads->barrier_elog_enabled))
446 {
447 t = vlib_time_now (vm) - t;
448 vlib_worker_thread_t *w = vlib_worker_threads + thread_index;
449 /* *INDENT-OFF* */
450 ELOG_TYPE_DECLARE (e) = {
451 .format = "barrier-released-thread-%d: %dus",
452 .format_args = "i4i4",
453 };
454 /* *INDENT-ON* */
455
456 struct
457 {
458 u32 thread_index;
459 u32 duration;
460 } __clib_packed *ed;
461
Damjan Marionf553a2c2021-03-26 13:45:37 +0100462 ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main, e, w->elog_track);
Dave Barach88c6e002018-09-30 15:54:06 -0400463 ed->thread_index = thread_index;
464 ed->duration = (int) (1000000.0 * t);
465 }
Tom Seidenberg6c81f5a2020-07-10 15:49:03 +0000466
467 if (PREDICT_FALSE (vec_len (vm->barrier_perf_callbacks) != 0))
468 clib_call_callbacks (vm->barrier_perf_callbacks, vm,
469 vm->clib_time.last_cpu_time, 1 /* leave */ );
Damjan Marionce359db2017-03-16 16:15:38 +0100470 }
471}
472
Damjan Marion64034362016-11-07 22:19:55 +0100473always_inline vlib_main_t *
474vlib_get_worker_vlib_main (u32 worker_index)
475{
476 vlib_main_t *vm;
477 vlib_thread_main_t *tm = &vlib_thread_main;
478 ASSERT (worker_index < tm->n_vlib_mains - 1);
Damjan Marion6ffb7c62021-03-26 13:06:13 +0100479 vm = vlib_get_main_by_index (worker_index + 1);
Damjan Marion64034362016-11-07 22:19:55 +0100480 ASSERT (vm);
481 return vm;
482}
483
Florin Coras568ebc72018-09-18 16:12:50 -0700484static inline u8
485vlib_thread_is_main_w_barrier (void)
486{
487 return (!vlib_num_workers ()
488 || ((vlib_get_thread_index () == 0
489 && vlib_worker_threads->wait_at_barrier[0])));
490}
491
Damjan Marion586afd72017-04-05 19:18:20 +0200492u8 *vlib_thread_stack_init (uword thread_index);
Damjan Marion878c6092017-01-04 13:19:27 +0100493int vlib_thread_cb_register (struct vlib_main_t *vm,
494 vlib_thread_callbacks_t * cb);
Dave Barach69128d02017-09-26 10:54:34 -0400495extern void *rpc_call_main_thread_cb_fn;
496
497void
498vlib_process_signal_event_mt_helper (vlib_process_signal_event_mt_args_t *
499 args);
500void vlib_rpc_call_main_thread (void *function, u8 * args, u32 size);
Dave Baracha690fdb2020-01-21 12:34:55 -0500501void vlib_get_thread_core_numa (vlib_worker_thread_t * w, unsigned cpu_id);
Dave Barachab1a50c2020-10-06 14:08:16 -0400502vlib_thread_main_t *vlib_get_thread_main_not_inline (void);
Dave Baracha690fdb2020-01-21 12:34:55 -0500503
Ed Warnickecb9cada2015-12-08 15:45:58 -0700504#endif /* included_vlib_threads_h */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400505
506/*
507 * fd.io coding-style-patch-verification: ON
508 *
509 * Local Variables:
510 * eval: (c-set-style "gnu")
511 * End:
512 */