15 #ifndef included_vlib_threads_h 16 #define included_vlib_threads_h 19 #include <linux/sched.h> 55 #define VLIB_MAX_CPUS 256 58 #if VLIB_MAX_CPUS > CLIB_MAX_MHEAPS 59 #error Please increase number of per-cpu mheaps 62 #define VLIB_CPU_MASK (VLIB_MAX_CPUS - 1) 63 #define VLIB_OFFSET_MASK (~VLIB_CPU_MASK) 65 #define VLIB_LOG2_THREAD_STACK_SIZE (20) 66 #define VLIB_THREAD_STACK_SIZE (1<<VLIB_LOG2_THREAD_STACK_SIZE) 97 void (*thread_function) (
void *);
160 vlib_frame_queue_msg_type_t type);
177 void (*thread_function) (
void *));
183 #define BARRIER_SYNC_DELAY (0.030000) 187 #define BARRIER_SYNC_TIMEOUT (600.1) 189 #define BARRIER_SYNC_TIMEOUT (1.0) 201 fformat (stderr,
"%s: SMP unsafe warning...\n", __FUNCTION__);
225 #define foreach_vlib_main(body) \ 227 vlib_main_t ** __vlib_mains = 0, *this_vlib_main; \ 230 for (ii = 0; ii < vec_len (vlib_mains); ii++) \ 232 this_vlib_main = vlib_mains[ii]; \ 233 if (this_vlib_main) \ 234 vec_add1 (__vlib_mains, this_vlib_main); \ 237 for (ii = 0; ii < vec_len (__vlib_mains); ii++) \ 239 this_vlib_main = __vlib_mains[ii]; \ 243 vec_free (__vlib_mains); \ 246 #define foreach_sched_policy \ 247 _(SCHED_OTHER, OTHER, "other") \ 248 _(SCHED_BATCH, BATCH, "batch") \ 249 _(SCHED_IDLE, IDLE, "idle") \ 250 _(SCHED_FIFO, FIFO, "fifo") \ 251 _(SCHED_RR, RR, "rr") 255 #define _(v,f,s) SCHED_POLICY_##f = v, 266 } vlib_thread_callbacks_t;
326 vlib_thread_callbacks_t
cb;
332 #define VLIB_REGISTER_THREAD(x,...) \ 333 __VA_ARGS__ vlib_thread_registration_t x; \ 334 static void __vlib_add_thread_registration_##x (void) \ 335 __attribute__((__constructor__)) ; \ 336 static void __vlib_add_thread_registration_##x (void) \ 338 vlib_thread_main_t * tm = &vlib_thread_main; \ 342 __VA_ARGS__ vlib_thread_registration_t x 353 return worker_index + 1;
359 return cpu_index - 1;
373 ASSERT (worker_index < tm->n_vlib_mains - 1);
374 vm = vlib_mains[worker_index + 1];
399 new_tail = __sync_add_and_fetch (&fq->
tail, 1);
405 elt = fq->
elts + (new_tail & (fq->
nelts - 1));
422 handoff_queue_by_worker_index)
429 fq = handoff_queue_by_worker_index[index];
441 handoff_queue_by_worker_index[index] = fq;
451 u32 vlib_worker_index,
453 handoff_queue_elt_by_worker_index)
457 if (handoff_queue_elt_by_worker_index[vlib_worker_index])
458 return handoff_queue_elt_by_worker_index[vlib_worker_index];
462 handoff_queue_elt_by_worker_index[vlib_worker_index] = elt;
468 vlib_thread_callbacks_t * cb);
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
void vlib_worker_thread_init(vlib_worker_thread_t *w)
int vlib_frame_queue_enqueue(vlib_main_t *vm, u32 node_runtime_index, u32 frame_queue_index, vlib_frame_t *frame, vlib_frame_queue_msg_type_t type)
vlib_worker_thread_t * vlib_alloc_thread(vlib_main_t *vm)
void vlib_set_thread_name(char *name)
void * thread_function_arg
frame_queue_trace_t * frame_queue_traces
vlib_worker_thread_t * vlib_worker_threads
struct vlib_thread_registration_ * next
int vlib_thread_cb_register(struct vlib_main_t *vm, vlib_thread_callbacks_t *cb)
static vlib_frame_queue_t * is_vlib_frame_queue_congested(u32 frame_queue_index, u32 index, u32 queue_hi_thresh, vlib_frame_queue_t **handoff_queue_by_worker_index)
static void vlib_smp_unsafe_warning(void)
static void vlib_worker_thread_barrier_check(void)
vlib_thread_registration_t * next
u64 dispatch_node(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_node_type_t type, vlib_node_state_t dispatch_state, vlib_frame_t *frame, u64 last_time_stamp)
#define clib_smp_atomic_add(addr, increment)
vlib_frame_queue_msg_type_t
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
int vlib_frame_queue_dequeue(vlib_main_t *vm, vlib_frame_queue_main_t *fqm)
vlib_frame_queue_elt_t * elts
static u32 vlib_get_current_worker_index()
vlib_thread_callbacks_t cb
uword os_get_cpu_number(void)
void vlib_worker_thread_barrier_release(vlib_main_t *vm)
static vlib_frame_queue_elt_t * vlib_get_worker_handoff_queue_elt(u32 frame_queue_index, u32 vlib_worker_index, vlib_frame_queue_elt_t **handoff_queue_elt_by_worker_index)
void vlib_worker_thread_node_runtime_update(void)
void vlib_worker_thread_fork_fixup(vlib_fork_fixup_t which)
vlib_frame_queue_t ** vlib_frame_queues
static u32 vlib_get_worker_index(u32 cpu_index)
frame_queue_nelt_counter_t * frame_queue_histogram
vlib_worker_thread_t * worker_threads
static vlib_frame_queue_elt_t * vlib_get_frame_queue_elt(u32 frame_queue_index, u32 index)
volatile u32 * wait_at_barrier
vlib_frame_queue_main_t * frame_queue_mains
struct vlib_thread_registration_ vlib_thread_registration_t
uword * thread_registrations_by_name
u32 vlib_frame_queue_main_init(u32 node_index, u32 frame_queue_nelts)
clib_error_t * vlib_thread_init(vlib_main_t *vm)
int no_data_structure_clone
vlib_main_t ** vlib_mains
void vlib_create_worker_threads(vlib_main_t *vm, int n, void(*thread_function)(void *))
static void vlib_put_frame_queue_elt(vlib_frame_queue_elt_t *hf)
static u32 vlib_get_worker_cpu_index(u32 worker_index)
void vlib_worker_thread_barrier_sync(vlib_main_t *vm)
volatile u32 * workers_at_barrier
static u32 vlib_num_workers()
u64 dispatch_pending_node(vlib_main_t *vm, vlib_pending_frame_t *p, u64 last_time_stamp)
#define CLIB_MEMORY_BARRIER()
uword * cpu_socket_bitmap
#define foreach_sched_policy
void( vlib_thread_function_t)(void *arg)
vlib_thread_registration_t ** registrations
vlib_thread_main_t vlib_thread_main
vlib_thread_registration_t * registration
volatile u32 worker_thread_release
static vlib_main_t * vlib_get_worker_vlib_main(u32 worker_index)