27 #define FRAME_QUEUE_NELTS 32 76 int pthread_setname_np (pthread_t __target_thread,
const char *__name);
78 pthread_t thread = pthread_self ();
82 rv = pthread_setname_np (thread, name);
94 return ((
i32) ((*tr0)->no_data_structure_clone)
95 - ((
i32) ((*tr1)->no_data_structure_clone)));
104 fp = fopen (filename,
"r");
110 if (fgets ((
char *) buffer, 256, fp))
114 strlen ((
char *) buffer));
134 u32 n_vlib_mains = 1;
187 pthread_setaffinity_np (pthread_self (),
sizeof (cpu_set_t), &cpuset);
195 _vec_len (vlib_worker_threads) = 1;
200 w->
lwp = syscall (SYS_gettid);
206 struct sched_param sched_param;
207 if (!sched_getparam (w->
lwp, &sched_param))
231 first_index += tr->
count;
243 if (clib_bitmap_get(avail_cpu, c) == 0)
244 return clib_error_return (0,
"cpu %u is not available to be used" 245 " for the '%s' thread",c, tr->name);
247 avail_cpu = clib_bitmap_set(avail_cpu, c, 0);
254 for (j = 0; j < tr->
count; j++)
259 "no available cpus to be used for" 260 " the '%s' thread", tr->
name);
288 vec_add2 (vlib_worker_threads, w, 1);
299 memset (fq, 0,
sizeof (*fq));
307 fformat (stderr,
"WARNING: fq->tail unaligned\n");
309 fformat (stderr,
"WARNING: fq->head unaligned\n");
311 fformat (stderr,
"WARNING: fq->elts unaligned\n");
314 fformat (stderr,
"WARNING: fq->elts[0] size %d\n",
315 sizeof (fq->
elts[0]));
316 if (nelts & (nelts - 1))
318 fformat (stderr,
"FATAL: nelts MUST be a power of 2\n");
335 vlib_frame_queue_dequeue_internal (
int thread_id,
343 u32 node_runtime_index;
363 node_runtime_index = elt->node_runtime_index;
368 case VLIB_FRAME_QUEUE_ELT_FREE_BUFFERS:
371 case VLIB_FRAME_QUEUE_ELT_FREE_FRAME:
384 case VLIB_FRAME_QUEUE_ELT_API_MSG:
388 clib_warning (
"bogus frame queue message, type %d", msg_type);
406 return vlib_frame_queue_dequeue_internal (thread_id, vm, nm);
422 new_tail = __sync_add_and_fetch (&fq->
tail, 1);
433 elt = fq->
elts + (new_tail & (fq->
nelts - 1));
444 elt->node_runtime_index = node_runtime_index;
497 w->
lwp = syscall (SYS_gettid);
511 void *(*fp_arg) (
void *) = fp;
521 CPU_SET (lcore_id, &cpuset);
523 if (pthread_create (&worker,
NULL , fp_arg, (
void *) w))
526 if (pthread_setaffinity_np (worker,
sizeof (cpu_set_t), &cpuset))
544 u32 worker_thread_index;
571 if (n_vlib_mains > 1)
590 worker_thread_index = 1;
605 for (k = 0; k < tr->
count; k++)
607 vec_add2 (vlib_worker_threads, w, 1);
620 (
char *)
format (0,
"%s %d", tr->
name, k + 1);
633 vm_clone->
cpu_index = worker_thread_index;
648 u32 save_node_runtime_index;
655 nf->
flags = save_flags;
731 ASSERT (fl_orig - orig_freelist_pool
734 fl_clone[0] = fl_orig[0];
740 worker_thread_index++;
751 for (j = 0; j < tr->
count; j++)
753 vec_add2 (vlib_worker_threads, w, 1);
764 (
char *)
format (0,
"%s %d", tr->
name, j + 1);
772 worker_thread_index = 1;
783 for (j = 0; j < tr->
count; j++)
785 w = vlib_worker_threads + worker_thread_index++;
797 w = vlib_worker_threads + worker_thread_index++;
798 err = vlib_launch_thread_int (vlib_worker_thread_bootstrap_fn,
801 clib_error_report (err);
861 n = nm_clone->
nodes[j];
871 w = vlib_worker_threads +
i;
894 u32 save_node_runtime_index;
901 nf->
flags = save_flags;
904 old_nodes_clone = nm_clone->
nodes;
913 new_n = nm->
nodes[j];
914 old_n_clone = old_nodes_clone[j];
921 if (j >= vec_len (old_nodes_clone))
945 for (j = 0; j <
vec_len (old_nodes_clone); j++)
966 for (j = 0; j <
vec_len (old_rt); j++)
992 for (j = 0; j <
vec_len (old_rt); j++)
1013 u32 *r = va_arg (*args,
u32 *);
1016 #define _(v,f,s) else if (unformat (input, s)) *r = SCHED_POLICY_##f; 1051 if (
unformat (input,
"use-pthreads"))
1059 else if (
unformat (input,
"coremask-%s %llx", &name, &coremask))
1069 "coremask cannot be set for '%s' threads",
1087 "corelist cannot be set for '%s' threads",
1100 else if (
unformat (input,
"%s %u", &name, &count))
1109 (0,
"number of %s threads not configurable", tr->
name);
1131 "scheduling priority (%d) is not allowed for `normal` scheduling policy",
1153 #if !defined (__x86_64__) && !defined (__aarch64__) && !defined (__powerpc64__) && !defined(__arm__) 1155 __sync_fetch_and_add_8 (
void)
1157 fformat (stderr,
"%s called\n", __FUNCTION__);
1162 __sync_add_and_fetch_8 (
void)
1164 fformat (stderr,
"%s called\n", __FUNCTION__);
1210 if (++vlib_worker_threads[0].recursion_level > 1)
1224 fformat (stderr,
"%s: worker thread deadlock\n", __FUNCTION__);
1238 if (--vlib_worker_threads[0].recursion_level > 0)
1249 fformat (stderr,
"%s: worker thread deadlock\n", __FUNCTION__);
1306 for (elix = 0; elix < fqt->
nelts; elix++)
1309 if (1 || elt->
valid)
1345 while (n_left_to_node >= 4)
1353 n_left_to_node -= 4;
1356 while (n_left_to_node > 0)
1430 if (frame_queue_nelts == 0)
_vlib_init_function_list_elt_t * worker_init_function_registrations
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
vlib_frame_t * vlib_get_frame_to_node(vlib_main_t *vm, u32 to_node_index)
sll srl srl sll sra u16x4 i
clib_error_t *(* vlib_thread_set_lcore_cb)(u32 thread, u16 lcore)
vlib_process_t ** processes
static void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
u8 runtime_data[0]
Function dependent node-runtime data.
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)
#define VLIB_MAIN_LOOP_ENTER_FUNCTION(x)
word elog_track_register(elog_main_t *em, elog_track_t *t)
void * mheap_alloc(void *memory, uword size)
static f64 vlib_time_now(vlib_main_t *vm)
#define vec_add2_aligned(V, P, N, A)
Add N elements to end of vector V, return pointer to new elements in P.
clib_error_t * threads_init(vlib_main_t *vm)
u32 vlib_frame_queue_main_init(u32 node_index, u32 frame_queue_nelts)
void * thread_function_arg
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
static int sort_registrations_by_no_clone(void *a0, void *a1)
static u64 clib_cpu_time_now(void)
frame_queue_trace_t * frame_queue_traces
#define VLIB_FRAME_NO_FREE_AFTER_DISPATCH
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
static mheap_t * mheap_header(u8 *v)
vlib_buffer_main_t * buffer_main
void vnet_main_fixup(vlib_fork_fixup_t which)
static uword * clib_bitmap_set(uword *ai, uword i, uword value)
Sets the ith bit of a bitmap to new_value Removes trailing zeros from the bitmap. ...
#define hash_set_mem(h, key, value)
void vlib_worker_thread_fn(void *arg)
u32 unformat_sched_policy(unformat_input_t *input, va_list *args)
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
struct vlib_thread_registration_ * next
#define MHEAP_FLAG_THREAD_SAFE
u32 buffer_index[VLIB_FRAME_SIZE]
vlib_main_t ** vlib_mains
#define clib_bitmap_dup(v)
Duplicate a bitmap.
void vlib_frame_free(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_frame_t *f)
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
u64 * counters_last_clear
static void vlib_worker_thread_barrier_check(void)
#define VLIB_LOG2_THREAD_STACK_SIZE
vlib_thread_registration_t * next
#define vec_add1_aligned(V, E, A)
Add 1 element to end of vector (alignment specified).
vlib_node_stats_t stats_last_clear
#define clib_smp_atomic_add(addr, increment)
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
void vlib_worker_thread_node_runtime_update(void)
u64 count[FRAME_QUEUE_MAX_NELTS]
#define VLIB_INIT_FUNCTION(x)
never_inline void vlib_node_runtime_sync_stats(vlib_main_t *vm, vlib_node_runtime_t *r, uword n_calls, uword n_vectors, uword n_clocks)
vlib_worker_thread_t * vlib_alloc_thread(vlib_main_t *vm)
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.
#define clib_error_return(e, args...)
clib_error_t * vlib_call_init_exit_functions(vlib_main_t *vm, _vlib_init_function_list_elt_t *head, int call_once)
vlib_frame_queue_elt_t * elts
vlib_node_runtime_t * nodes_by_type[VLIB_N_NODE_TYPE]
void vlib_set_thread_name(char *name)
void vl_msg_api_handler_no_free(void *)
#define hash_create_string(elts, value_bytes)
#define BARRIER_SYNC_TIMEOUT
#define VLIB_NODE_RUNTIME_DATA_SIZE
VLIB_REGISTER_THREAD(worker_thread_reg, static)
vlib_worker_thread_t * vlib_worker_threads
#define clib_bitmap_foreach(i, ai, body)
Macro to iterate across set bits in a bitmap.
vlib_node_stats_t stats_total
u16 state
Input node state.
void vlib_node_sync_stats(vlib_main_t *vm, vlib_node_t *n)
static uword clib_bitmap_first_set(uword *ai)
Return the lowest numbered set bit in a bitmap.
vlib_error_main_t error_main
static u32 vlib_frame_index(vlib_main_t *vm, vlib_frame_t *f)
vlib_thread_callbacks_t cb
int vlib_thread_cb_register(struct vlib_main_t *vm, vlib_thread_callbacks_t *cb)
#define clib_error_return_unix(e, args...)
#define vec_dup(V)
Return copy of vector (no header, no alignment)
static void * clib_mem_get_per_cpu_heap(void)
static clib_error_t * vlib_launch_thread_int(void *fp, vlib_worker_thread_t *w, unsigned lcore_id)
#define VLIB_FRAME_PENDING
u32 node_index
Node index.
uword * init_functions_called
#define VLIB_FRAME_FREE_AFTER_DISPATCH
void clib_time_init(clib_time_t *c)
vlib_thread_main_t vlib_thread_main
void(* thread_function)(void *)
static clib_error_t * cpu_config(vlib_main_t *vm, unformat_input_t *input)
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P (general version).
i32 n_vectors[FRAME_QUEUE_MAX_NELTS]
vlib_frame_queue_t * vlib_frame_queue_alloc(int nelts)
#define clib_mem_alloc_no_fail(size)
#define VLIB_EARLY_CONFIG_FUNCTION(x, n,...)
vlib_frame_queue_t ** vlib_frame_queues
vlib_pending_frame_t * pending_frames
vlib_thread_function_t * function
int vlib_frame_queue_dequeue(vlib_main_t *vm, vlib_frame_queue_main_t *fqm)
#define vec_free(V)
Free vector's memory (no header).
static void * clib_mem_set_heap(void *heap)
#define clib_warning(format, args...)
static vlib_node_runtime_t * vlib_node_get_runtime(vlib_main_t *vm, u32 node_index)
Get node runtime by node index.
#define clib_memcpy(a, b, c)
void vlib_worker_loop(vlib_main_t *vm)
frame_queue_nelt_counter_t * frame_queue_histogram
static uword * clib_bitmap_set_multiple(uword *bitmap, uword i, uword value, uword n_bits)
sets the ith through ith + n_bits bits in a bitmap
void vlib_worker_thread_barrier_sync(vlib_main_t *vm)
static uword clib_bitmap_get(uword *ai, uword i)
Gets the ith bit value from a bitmap.
u16 cpu_index
CPU this node runs on.
static void vlib_next_frame_init(vlib_next_frame_t *nf)
void vlib_worker_thread_init(vlib_worker_thread_t *w)
static void * clib_mem_get_heap(void)
volatile u32 * wait_at_barrier
#define FRAME_QUEUE_NELTS
#define hash_create(elts, value_bytes)
vlib_frame_queue_main_t * frame_queue_mains
static void clib_mem_free(void *p)
#define clib_error_report(e)
#define clib_bitmap_free(v)
Free a bitmap.
uword * thread_registrations_by_name
static void * clib_mem_alloc(uword size)
static vlib_main_t * vlib_get_main(void)
static uword clib_bitmap_count_set_bits(uword *ai)
Return the number of set bits in a bitmap.
static clib_error_t * start_workers(vlib_main_t *vm)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define VLIB_PENDING_FRAME_NO_NEXT_FRAME
vlib_node_main_t node_main
static uword unformat_bitmap_list(unformat_input_t *input, va_list *va)
unformat a list of bit ranges into a bitmap (eg "0-3,5-7,11" )
vlib_buffer_free_list_t * buffer_free_list_pool
vlib_next_frame_t * next_frames
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
int no_data_structure_clone
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
uword os_get_cpu_number(void)
#define VLIB_THREAD_STACK_SIZE
vlib_frame_size_t * frame_sizes
clib_error_t *(* vlib_launch_thread_cb)(void *fp, vlib_worker_thread_t *w, unsigned lcore_id)
#define hash_get_mem(h, key)
static void * clib_mem_alloc_aligned(uword size, uword align)
volatile u32 * workers_at_barrier
uword clib_calljmp(uword(*func)(uword func_arg), uword func_arg, void *stack)
void vlib_worker_thread_barrier_release(vlib_main_t *vm)
#define VLIB_INVALID_NODE_INDEX
static vlib_thread_main_t * vlib_get_thread_main()
static f64 vlib_time_now_ticks(vlib_main_t *vm, u64 n)
static vlib_node_t * vlib_get_node(vlib_main_t *vm, u32 i)
Get vlib node by index.
#define vec_foreach(var, vec)
Vector iterator.
void * vlib_worker_thread_bootstrap_fn(void *arg)
#define CLIB_MEMORY_BARRIER()
uword * cpu_socket_bitmap
static uword * vlib_sysfs_list_to_bitmap(char *filename)
#define foreach_sched_policy
void vlib_put_frame_to_node(vlib_main_t *vm, u32 to_node_index, vlib_frame_t *f)
vlib_thread_registration_t ** registrations
#define CLIB_CACHE_LINE_BYTES
vlib_thread_registration_t * registration
volatile u32 worker_thread_release
void vlib_worker_thread_fork_fixup(vlib_fork_fixup_t which)
clib_random_buffer_t random_buffer
clib_error_t * vlib_thread_init(vlib_main_t *vm)