FD.io VPP  v16.09
Vector Packet Processing
threads.c
Go to the documentation of this file.
1 /*
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 #define _GNU_SOURCE
16 #include <sched.h>
17 
18 #include <signal.h>
19 #include <math.h>
20 #include <vppinfra/format.h>
21 #include <vlib/vlib.h>
22 
23 #include <vlib/threads.h>
24 #include <vlib/unix/cj.h>
25 
26 
27 #if DPDK==1
28 #include <rte_config.h>
29 #include <rte_common.h>
30 #include <rte_eal.h>
31 #include <rte_launch.h>
32 #include <rte_lcore.h>
33 #endif
35 
36 #define FRAME_QUEUE_NELTS 32
37 
38 
39 #if DPDK==1
40 /*
41  * Weak definitions of DPDK symbols used in this file.
42  * Needed for linking test programs without DPDK libs.
43  */
44 unsigned __thread __attribute__ ((weak)) RTE_PER_LCORE (_lcore_id);
45 struct lcore_config __attribute__ ((weak)) lcore_config[];
46 unsigned __attribute__ ((weak)) rte_socket_id ();
47 int __attribute__ ((weak)) rte_eal_remote_launch ();
48 #endif
49 u32
50 vl (void *p)
51 {
52  return vec_len (p);
53 }
54 
56 
57 uword
59 {
60  void *sp;
61  uword n;
62  u32 len;
63 
65  if (len == 0)
66  return 0;
67 
68  /* Get any old stack address. */
69  sp = &sp;
70 
71  n = ((uword) sp - (uword) vlib_thread_stacks[0])
73 
74  /* "processes" have their own stacks, and they always run in thread 0 */
75  n = n >= len ? 0 : n;
76 
77  return n;
78 }
79 
80 uword
82 {
83  u32 len;
84 
86  if (len == 0)
87  return 1;
88  else
89  return len;
90 }
91 
92 void
94 {
95  int pthread_setname_np (pthread_t __target_thread, const char *__name);
96  int rv;
97  pthread_t thread = pthread_self ();
98 
99  if (thread)
100  {
101  rv = pthread_setname_np (thread, name);
102  if (rv)
103  clib_warning ("pthread_setname_np returned %d", rv);
104  }
105 }
106 
107 static int
108 sort_registrations_by_no_clone (void *a0, void *a1)
109 {
110  vlib_thread_registration_t **tr0 = a0;
111  vlib_thread_registration_t **tr1 = a1;
112 
113  return ((i32) ((*tr0)->no_data_structure_clone)
114  - ((i32) ((*tr1)->no_data_structure_clone)));
115 }
116 
117 static uword *
119 {
120  FILE *fp;
121  uword *r = 0;
122 
123  fp = fopen (filename, "r");
124 
125  if (fp != NULL)
126  {
127  u8 *buffer = 0;
128  vec_validate (buffer, 256 - 1);
129  if (fgets ((char *) buffer, 256, fp))
130  {
131  unformat_input_t in;
132  unformat_init_string (&in, (char *) buffer,
133  strlen ((char *) buffer));
134  if (unformat (&in, "%U", unformat_bitmap_list, &r) != 1)
135  clib_warning ("unformat_bitmap_list failed");
136  unformat_free (&in);
137  }
138  vec_free (buffer);
139  fclose (fp);
140  }
141  return r;
142 }
143 
144 
145 /* Called early in the init sequence */
146 
147 clib_error_t *
149 {
153  u32 n_vlib_mains = 1;
154  u32 first_index = 1;
155  u32 i;
156  uword *avail_cpu;
157 
158  /* get bitmaps of active cpu cores and sockets */
159  tm->cpu_core_bitmap =
160  vlib_sysfs_list_to_bitmap ("/sys/devices/system/cpu/online");
161  tm->cpu_socket_bitmap =
162  vlib_sysfs_list_to_bitmap ("/sys/devices/system/node/online");
163 
164  avail_cpu = clib_bitmap_dup (tm->cpu_core_bitmap);
165 
166  /* skip cores */
167  for (i = 0; i < tm->skip_cores; i++)
168  {
169  uword c = clib_bitmap_first_set (avail_cpu);
170  if (c == ~0)
171  return clib_error_return (0, "no available cpus to skip");
172 
173  avail_cpu = clib_bitmap_set (avail_cpu, c, 0);
174  }
175 
176  /* grab cpu for main thread */
177  if (!tm->main_lcore)
178  {
179  tm->main_lcore = clib_bitmap_first_set (avail_cpu);
180  if (tm->main_lcore == (u8) ~ 0)
181  return clib_error_return (0, "no available cpus to be used for the"
182  " main thread");
183  }
184  else
185  {
186  if (clib_bitmap_get (avail_cpu, tm->main_lcore) == 0)
187  return clib_error_return (0, "cpu %u is not available to be used"
188  " for the main thread", tm->main_lcore);
189  }
190  avail_cpu = clib_bitmap_set (avail_cpu, tm->main_lcore, 0);
191 
192  /* assume that there is socket 0 only if there is no data from sysfs */
193  if (!tm->cpu_socket_bitmap)
194  tm->cpu_socket_bitmap = clib_bitmap_set (0, 0, 1);
195 
196  /* pin main thread to main_lcore */
197 #if DPDK==0
198  {
199  cpu_set_t cpuset;
200  CPU_ZERO (&cpuset);
201  CPU_SET (tm->main_lcore, &cpuset);
202  pthread_setaffinity_np (pthread_self (), sizeof (cpu_set_t), &cpuset);
203  }
204 #endif
205 
206  /* as many threads as stacks... */
209 
210  /* Preallocate thread 0 */
211  _vec_len (vlib_worker_threads) = 1;
215  w->dpdk_lcore_id = -1;
216  w->lwp = syscall (SYS_gettid);
217  tm->n_vlib_mains = 1;
218 
219  /* assign threads to cores and set n_vlib_mains */
220  tr = tm->next;
221 
222  while (tr)
223  {
224  vec_add1 (tm->registrations, tr);
225  tr = tr->next;
226  }
227 
229 
230  for (i = 0; i < vec_len (tm->registrations); i++)
231  {
232  int j;
233  tr = tm->registrations[i];
234  tr->first_index = first_index;
235  first_index += tr->count;
236  n_vlib_mains += (tr->no_data_structure_clone == 0) ? tr->count : 0;
237 
238  /* construct coremask */
239  if (tr->use_pthreads || !tr->count)
240  continue;
241 
242  if (tr->coremask)
243  {
244  uword c;
245  /* *INDENT-OFF* */
246  clib_bitmap_foreach (c, tr->coremask, ({
247  if (clib_bitmap_get(avail_cpu, c) == 0)
248  return clib_error_return (0, "cpu %u is not available to be used"
249  " for the '%s' thread",c, tr->name);
250 
251  avail_cpu = clib_bitmap_set(avail_cpu, c, 0);
252  }));
253 /* *INDENT-ON* */
254 
255  }
256  else
257  {
258  for (j = 0; j < tr->count; j++)
259  {
260  uword c = clib_bitmap_first_set (avail_cpu);
261  if (c == ~0)
262  return clib_error_return (0,
263  "no available cpus to be used for"
264  " the '%s' thread", tr->name);
265 
266  avail_cpu = clib_bitmap_set (avail_cpu, c, 0);
267  tr->coremask = clib_bitmap_set (tr->coremask, c, 1);
268  }
269  }
270  }
271 
272  clib_bitmap_free (avail_cpu);
273 
274  tm->n_vlib_mains = n_vlib_mains;
275 
276  vec_validate_aligned (vlib_worker_threads, first_index - 1,
278 
279 
282  FRAME_QUEUE_NELTS) / 100);
283  return 0;
284 }
285 
288 {
290 
292  {
293  clib_warning ("out of worker threads... Quitting...");
294  exit (1);
295  }
298  return w;
299 }
300 
303 {
304  vlib_frame_queue_t *fq;
305 
306  fq = clib_mem_alloc_aligned (sizeof (*fq), CLIB_CACHE_LINE_BYTES);
307  memset (fq, 0, sizeof (*fq));
308  fq->nelts = nelts;
309  fq->vector_threshold = 128; // packets
311 
312  if (1)
313  {
314  if (((uword) & fq->tail) & (CLIB_CACHE_LINE_BYTES - 1))
315  fformat (stderr, "WARNING: fq->tail unaligned\n");
316  if (((uword) & fq->head) & (CLIB_CACHE_LINE_BYTES - 1))
317  fformat (stderr, "WARNING: fq->head unaligned\n");
318  if (((uword) fq->elts) & (CLIB_CACHE_LINE_BYTES - 1))
319  fformat (stderr, "WARNING: fq->elts unaligned\n");
320 
321  if (sizeof (fq->elts[0]) % CLIB_CACHE_LINE_BYTES)
322  fformat (stderr, "WARNING: fq->elts[0] size %d\n",
323  sizeof (fq->elts[0]));
324  if (nelts & (nelts - 1))
325  {
326  fformat (stderr, "FATAL: nelts MUST be a power of 2\n");
327  abort ();
328  }
329  }
330 
331  return (fq);
332 }
333 
334 void vl_msg_api_handler_no_free (void *) __attribute__ ((weak));
335 void
337 {
338 }
339 
340 /* Turned off, save as reference material... */
341 #if 0
342 static inline int
343 vlib_frame_queue_dequeue_internal (int thread_id,
344  vlib_main_t * vm, vlib_node_main_t * nm)
345 {
346  vlib_frame_queue_t *fq = vlib_frame_queues[thread_id];
348  vlib_frame_t *f;
351  u32 node_runtime_index;
352  int msg_type;
353  u64 before;
354  int processed = 0;
355 
356  ASSERT (vm == vlib_mains[thread_id]);
357 
358  while (1)
359  {
360  if (fq->head == fq->tail)
361  return processed;
362 
363  elt = fq->elts + ((fq->head + 1) & (fq->nelts - 1));
364 
365  if (!elt->valid)
366  return processed;
367 
368  before = clib_cpu_time_now ();
369 
370  f = elt->frame;
371  node_runtime_index = elt->node_runtime_index;
372  msg_type = elt->msg_type;
373 
374  switch (msg_type)
375  {
376  case VLIB_FRAME_QUEUE_ELT_FREE_BUFFERS:
378  /* note fallthrough... */
379  case VLIB_FRAME_QUEUE_ELT_FREE_FRAME:
381  node_runtime_index);
382  vlib_frame_free (vm, r, f);
383  break;
385  vec_add2 (vm->node_main.pending_frames, p, 1);
387  p->node_runtime_index = elt->node_runtime_index;
388  p->frame_index = vlib_frame_index (vm, f);
390  fq->dequeue_vectors += (u64) f->n_vectors;
391  break;
392  case VLIB_FRAME_QUEUE_ELT_API_MSG:
394  break;
395  default:
396  clib_warning ("bogus frame queue message, type %d", msg_type);
397  break;
398  }
399  elt->valid = 0;
400  fq->dequeues++;
401  fq->dequeue_ticks += clib_cpu_time_now () - before;
403  fq->head++;
404  processed++;
405  }
406  ASSERT (0);
407  return processed;
408 }
409 
410 int
411 vlib_frame_queue_dequeue (int thread_id,
412  vlib_main_t * vm, vlib_node_main_t * nm)
413 {
414  return vlib_frame_queue_dequeue_internal (thread_id, vm, nm);
415 }
416 
417 int
418 vlib_frame_queue_enqueue (vlib_main_t * vm, u32 node_runtime_index,
419  u32 frame_queue_index, vlib_frame_t * frame,
421 {
422  vlib_frame_queue_t *fq = vlib_frame_queues[frame_queue_index];
424  u32 save_count;
425  u64 new_tail;
426  u64 before = clib_cpu_time_now ();
427 
428  ASSERT (fq);
429 
430  new_tail = __sync_add_and_fetch (&fq->tail, 1);
431 
432  /* Wait until a ring slot is available */
433  while (new_tail >= fq->head + fq->nelts)
434  {
435  f64 b4 = vlib_time_now_ticks (vm, before);
437  /* Bad idea. Dequeue -> enqueue -> dequeue -> trouble */
438  // vlib_frame_queue_dequeue (vm->cpu_index, vm, nm);
439  }
440 
441  elt = fq->elts + (new_tail & (fq->nelts - 1));
442 
443  /* this would be very bad... */
444  while (elt->valid)
445  {
446  }
447 
448  /* Once we enqueue the frame, frame->n_vectors is owned elsewhere... */
449  save_count = frame->n_vectors;
450 
451  elt->frame = frame;
452  elt->node_runtime_index = node_runtime_index;
453  elt->msg_type = type;
455  elt->valid = 1;
456 
457  return save_count;
458 }
459 #endif /* 0 */
460 
461 /* To be called by vlib worker threads upon startup */
462 void
464 {
466 
467  /* worker threads wants no signals. */
468  {
469  sigset_t s;
470  sigfillset (&s);
471  pthread_sigmask (SIG_SETMASK, &s, 0);
472  }
473 
475 
476  if (vec_len (tm->thread_prefix) && w->registration->short_name)
477  {
478  w->name = format (0, "%v_%s_%d%c", tm->thread_prefix,
479  w->registration->short_name, w->instance_id, '\0');
480  vlib_set_thread_name ((char *) w->name);
481  }
482 
483  if (!w->registration->use_pthreads)
484  {
485 
486  /* Initial barrier sync, for both worker and i/o threads */
488 
490  ;
491 
493  }
494 }
495 
496 void *
498 {
499  void *rv;
500  vlib_worker_thread_t *w = arg;
501 
502  w->lwp = syscall (SYS_gettid);
503  w->dpdk_lcore_id = -1;
504 #if DPDK==1
505  if (w->registration && !w->registration->use_pthreads && rte_socket_id) /* do we really have dpdk linked */
506  {
507  unsigned lcore = rte_lcore_id ();
508  lcore = lcore < RTE_MAX_LCORE ? lcore : -1;
509  w->dpdk_lcore_id = lcore;
510  }
511 #endif
512 
513  rv = (void *) clib_calljmp
514  ((uword (*)(uword)) w->thread_function,
516  /* NOTREACHED, we hope */
517  return rv;
518 }
519 
520 static int
521 vlib_launch_thread (void *fp, vlib_worker_thread_t * w, unsigned lcore_id)
522 {
523  void *(*fp_arg) (void *) = fp;
524 
525 #if DPDK==1
526  if (!w->registration->use_pthreads)
527  if (rte_eal_remote_launch) /* do we have dpdk linked */
528  return rte_eal_remote_launch (fp, (void *) w, lcore_id);
529  else
530  return -1;
531  else
532 #endif
533  {
534  int ret;
535  pthread_t worker;
536  cpu_set_t cpuset;
537  CPU_ZERO (&cpuset);
538  CPU_SET (lcore_id, &cpuset);
539 
540  ret = pthread_create (&worker, NULL /* attr */ , fp_arg, (void *) w);
541  if (ret == 0)
542  return pthread_setaffinity_np (worker, sizeof (cpu_set_t), &cpuset);
543  else
544  return ret;
545  }
546 }
547 
548 static clib_error_t *
550 {
551  int i, j;
553  vlib_main_t *vm_clone;
554  void *oldheap;
555  vlib_frame_queue_t *fq;
559  u32 n_vlib_mains = tm->n_vlib_mains;
560  u32 worker_thread_index;
561  u8 *main_heap = clib_mem_get_per_cpu_heap ();
562  mheap_t *main_heap_header = mheap_header (main_heap);
563 
565 
566  /* Set up the main thread */
568  w->elog_track.name = "main thread";
570 
571  if (vec_len (tm->thread_prefix))
572  {
573  w->name = format (0, "%v_main%c", tm->thread_prefix, '\0');
574  vlib_set_thread_name ((char *) w->name);
575  }
576 
577 #if DPDK==1
578  w->dpdk_lcore_id = -1;
579  if (rte_socket_id) /* do we really have dpdk linked */
580  {
581  unsigned lcore = rte_lcore_id ();
582  w->dpdk_lcore_id = lcore < RTE_MAX_LCORE ? lcore : -1;;
583  }
584 #endif
585 
586  /*
587  * Truth of the matter: we always use at least two
588  * threads. So, make the main heap thread-safe
589  * and make the event log thread-safe.
590  */
591  main_heap_header->flags |= MHEAP_FLAG_THREAD_SAFE;
592  vm->elog_main.lock =
594  vm->elog_main.lock[0] = 0;
595 
596  if (n_vlib_mains > 1)
597  {
599  _vec_len (vlib_mains) = 0;
600  vec_add1 (vlib_mains, vm);
601 
603  _vec_len (vlib_frame_queues) = 0;
606 
611 
612  /* Ask for an initial barrier sync */
615 
616  worker_thread_index = 1;
617 
618  for (i = 0; i < vec_len (tm->registrations); i++)
619  {
620  vlib_node_main_t *nm, *nm_clone;
621  vlib_buffer_main_t *bm_clone;
622  vlib_buffer_free_list_t *fl_clone, *fl_orig;
623  vlib_buffer_free_list_t *orig_freelist_pool;
624  int k;
625 
626  tr = tm->registrations[i];
627 
628  if (tr->count == 0)
629  continue;
630 
631  for (k = 0; k < tr->count; k++)
632  {
634  if (tr->mheap_size)
635  w->thread_mheap =
636  mheap_alloc (0 /* use VM */ , tr->mheap_size);
637  else
638  w->thread_mheap = main_heap;
640  w->thread_function = tr->function;
641  w->thread_function_arg = w;
642  w->instance_id = k;
643  w->registration = tr;
644 
645  w->elog_track.name =
646  (char *) format (0, "%s %d", tr->name, k + 1);
647  vec_add1 (w->elog_track.name, 0);
649 
650  if (tr->no_data_structure_clone)
651  continue;
652 
653  /* Allocate "to-worker-N" frame queue */
654  if (tr->frame_queue_nelts)
655  {
657  }
658  else
659  {
661  }
662 
663  vec_validate (vlib_frame_queues, worker_thread_index);
664  vlib_frame_queues[worker_thread_index] = fq;
665 
666  /* Fork vlib_global_main et al. Look for bugs here */
667  oldheap = clib_mem_set_heap (w->thread_mheap);
668 
669  vm_clone = clib_mem_alloc (sizeof (*vm_clone));
670  clib_memcpy (vm_clone, vlib_mains[0], sizeof (*vm_clone));
671 
672  vm_clone->cpu_index = worker_thread_index;
673  vm_clone->heap_base = w->thread_mheap;
674  vm_clone->mbuf_alloc_list = 0;
675  memset (&vm_clone->random_buffer, 0,
676  sizeof (vm_clone->random_buffer));
677 
678  nm = &vlib_mains[0]->node_main;
679  nm_clone = &vm_clone->node_main;
680  /* fork next frames array, preserving node runtime indices */
681  nm_clone->next_frames = vec_dup (nm->next_frames);
682  for (j = 0; j < vec_len (nm_clone->next_frames); j++)
683  {
684  vlib_next_frame_t *nf = &nm_clone->next_frames[j];
685  u32 save_node_runtime_index;
686  u32 save_flags;
687 
688  save_node_runtime_index = nf->node_runtime_index;
689  save_flags = nf->flags & VLIB_FRAME_NO_FREE_AFTER_DISPATCH;
691  nf->node_runtime_index = save_node_runtime_index;
692  nf->flags = save_flags;
693  }
694 
695  /* fork the frame dispatch queue */
696  nm_clone->pending_frames = 0;
697  vec_validate (nm_clone->pending_frames, 10); /* $$$$$?????? */
698  _vec_len (nm_clone->pending_frames) = 0;
699 
700  /* fork nodes */
701  nm_clone->nodes = 0;
702  for (j = 0; j < vec_len (nm->nodes); j++)
703  {
704  vlib_node_t *n;
705  n = clib_mem_alloc_no_fail (sizeof (*n));
706  clib_memcpy (n, nm->nodes[j], sizeof (*n));
707  /* none of the copied nodes have enqueue rights given out */
709  memset (&n->stats_total, 0, sizeof (n->stats_total));
710  memset (&n->stats_last_clear, 0,
711  sizeof (n->stats_last_clear));
712  vec_add1 (nm_clone->nodes, n);
713  }
716 
720  rt->cpu_index = vm_clone->cpu_index;
721 
722  nm_clone->processes = vec_dup (nm->processes);
723 
724  /* zap the (per worker) frame freelists, etc */
725  nm_clone->frame_sizes = 0;
726  nm_clone->frame_size_hash = 0;
727 
728  /* Packet trace buffers are guaranteed to be empty, nothing to do here */
729 
730  clib_mem_set_heap (oldheap);
731  vec_add1 (vlib_mains, vm_clone);
732 
733  vm_clone->error_main.counters =
734  vec_dup (vlib_mains[0]->error_main.counters);
735  vm_clone->error_main.counters_last_clear =
736  vec_dup (vlib_mains[0]->error_main.counters_last_clear);
737 
738  /* Fork the vlib_buffer_main_t free lists, etc. */
739  bm_clone = vec_dup (vm_clone->buffer_main);
740  vm_clone->buffer_main = bm_clone;
741 
742  orig_freelist_pool = bm_clone->buffer_free_list_pool;
743  bm_clone->buffer_free_list_pool = 0;
744 
745  /* *INDENT-OFF* */
746  pool_foreach (fl_orig, orig_freelist_pool,
747  ({
749  fl_clone, CLIB_CACHE_LINE_BYTES);
750  ASSERT (fl_orig - orig_freelist_pool
751  == fl_clone - bm_clone->buffer_free_list_pool);
752 
753  fl_clone[0] = fl_orig[0];
754  fl_clone->aligned_buffers = 0;
755  fl_clone->unaligned_buffers = 0;
756  fl_clone->n_alloc = 0;
757  }));
758 /* *INDENT-ON* */
759 
760  worker_thread_index++;
761  }
762  }
763  }
764  else
765  {
766  /* only have non-data-structure copy threads to create... */
767  for (i = 0; i < vec_len (tm->registrations); i++)
768  {
769  tr = tm->registrations[i];
770 
771  for (j = 0; j < tr->count; j++)
772  {
774  if (tr->mheap_size)
775  w->thread_mheap =
776  mheap_alloc (0 /* use VM */ , tr->mheap_size);
777  else
778  w->thread_mheap = main_heap;
780  w->thread_function = tr->function;
781  w->thread_function_arg = w;
782  w->instance_id = j;
783  w->elog_track.name =
784  (char *) format (0, "%s %d", tr->name, j + 1);
785  w->registration = tr;
786  vec_add1 (w->elog_track.name, 0);
788  }
789  }
790  }
791 
792  worker_thread_index = 1;
793 
794  for (i = 0; i < vec_len (tm->registrations); i++)
795  {
796  int j;
797 
798  tr = tm->registrations[i];
799 
800  if (tr->use_pthreads || tm->use_pthreads)
801  {
802  for (j = 0; j < tr->count; j++)
803  {
804  w = vlib_worker_threads + worker_thread_index++;
806  0)
807  clib_warning ("Couldn't start '%s' pthread ", tr->name);
808  }
809  }
810  else
811  {
812  uword c;
813  /* *INDENT-OFF* */
814  clib_bitmap_foreach (c, tr->coremask, ({
815  w = vlib_worker_threads + worker_thread_index++;
816  if (vlib_launch_thread (vlib_worker_thread_bootstrap_fn, w, c) < 0)
817  clib_warning ("Couldn't start DPDK lcore %d", c);
818 
819  }));
820 /* *INDENT-ON* */
821  }
822  }
825  return 0;
826 }
827 
829 
830 void
832 {
833  int i, j;
835  vlib_main_t *vm;
836  vlib_node_main_t *nm, *nm_clone;
837  vlib_node_t **old_nodes_clone;
838  vlib_main_t *vm_clone;
839  vlib_node_runtime_t *rt, *old_rt;
840  void *oldheap;
841  never_inline void
844  uword n_calls,
845  uword n_vectors, uword n_clocks);
846 
847  ASSERT (os_get_cpu_number () == 0);
848 
849  if (vec_len (vlib_mains) == 0)
850  return;
851 
852  vm = vlib_mains[0];
853  nm = &vm->node_main;
854 
855  ASSERT (os_get_cpu_number () == 0);
857 
858  /*
859  * Scrape all runtime stats, so we don't lose node runtime(s) with
860  * pending counts, or throw away worker / io thread counts.
861  */
862  for (j = 0; j < vec_len (nm->nodes); j++)
863  {
864  vlib_node_t *n;
865  n = nm->nodes[j];
866  vlib_node_sync_stats (vm, n);
867  }
868 
869  for (i = 1; i < vec_len (vlib_mains); i++)
870  {
871  vlib_node_t *n;
872 
873  vm_clone = vlib_mains[i];
874  nm_clone = &vm_clone->node_main;
875 
876  for (j = 0; j < vec_len (nm_clone->nodes); j++)
877  {
878  n = nm_clone->nodes[j];
879 
880  rt = vlib_node_get_runtime (vm_clone, n->index);
881  vlib_node_runtime_sync_stats (vm_clone, rt, 0, 0, 0);
882  }
883  }
884 
885  for (i = 1; i < vec_len (vlib_mains); i++)
886  {
888  w = vlib_worker_threads + i;
889  oldheap = clib_mem_set_heap (w->thread_mheap);
890 
891  vm_clone = vlib_mains[i];
892 
893  /* Re-clone error heap */
894  u64 *old_counters = vm_clone->error_main.counters;
895  u64 *old_counters_all_clear = vm_clone->error_main.counters_last_clear;
896  clib_memcpy (&vm_clone->error_main, &vm->error_main,
897  sizeof (vm->error_main));
898  j = vec_len (vm->error_main.counters) - 1;
899  vec_validate_aligned (old_counters, j, CLIB_CACHE_LINE_BYTES);
900  vec_validate_aligned (old_counters_all_clear, j, CLIB_CACHE_LINE_BYTES);
901  vm_clone->error_main.counters = old_counters;
902  vm_clone->error_main.counters_last_clear = old_counters_all_clear;
903 
904  nm_clone = &vm_clone->node_main;
905  vec_free (nm_clone->next_frames);
906  nm_clone->next_frames = vec_dup (nm->next_frames);
907 
908  for (j = 0; j < vec_len (nm_clone->next_frames); j++)
909  {
910  vlib_next_frame_t *nf = &nm_clone->next_frames[j];
911  u32 save_node_runtime_index;
912  u32 save_flags;
913 
914  save_node_runtime_index = nf->node_runtime_index;
915  save_flags = nf->flags & VLIB_FRAME_NO_FREE_AFTER_DISPATCH;
917  nf->node_runtime_index = save_node_runtime_index;
918  nf->flags = save_flags;
919  }
920 
921  old_nodes_clone = nm_clone->nodes;
922  nm_clone->nodes = 0;
923 
924  /* re-fork nodes */
925  for (j = 0; j < vec_len (nm->nodes); j++)
926  {
927  vlib_node_t *old_n_clone;
928  vlib_node_t *new_n, *new_n_clone;
929 
930  new_n = nm->nodes[j];
931  old_n_clone = old_nodes_clone[j];
932 
933  new_n_clone = clib_mem_alloc_no_fail (sizeof (*new_n_clone));
934  clib_memcpy (new_n_clone, new_n, sizeof (*new_n));
935  /* none of the copied nodes have enqueue rights given out */
937 
938  if (j >= vec_len (old_nodes_clone))
939  {
940  /* new node, set to zero */
941  memset (&new_n_clone->stats_total, 0,
942  sizeof (new_n_clone->stats_total));
943  memset (&new_n_clone->stats_last_clear, 0,
944  sizeof (new_n_clone->stats_last_clear));
945  }
946  else
947  {
948  /* Copy stats if the old data is valid */
949  clib_memcpy (&new_n_clone->stats_total,
950  &old_n_clone->stats_total,
951  sizeof (new_n_clone->stats_total));
952  clib_memcpy (&new_n_clone->stats_last_clear,
953  &old_n_clone->stats_last_clear,
954  sizeof (new_n_clone->stats_last_clear));
955 
956  /* keep previous node state */
957  new_n_clone->state = old_n_clone->state;
958  }
959  vec_add1 (nm_clone->nodes, new_n_clone);
960  }
961  /* Free the old node clone */
962  for (j = 0; j < vec_len (old_nodes_clone); j++)
963  clib_mem_free (old_nodes_clone[j]);
964  vec_free (old_nodes_clone);
965 
967 
970 
971  /* clone input node runtime */
972  old_rt = nm_clone->nodes_by_type[VLIB_NODE_TYPE_INPUT];
973 
976 
978  {
979  rt->cpu_index = vm_clone->cpu_index;
980  }
981 
982  for (j = 0; j < vec_len (old_rt); j++)
983  {
984  rt = vlib_node_get_runtime (vm_clone, old_rt[j].node_index);
985  rt->state = old_rt[j].state;
986  }
987 
988  vec_free (old_rt);
989 
990  nm_clone->processes = vec_dup (nm->processes);
991 
992  clib_mem_set_heap (oldheap);
993 
994  // vnet_main_fork_fixup (i);
995  }
996 }
997 
998 static clib_error_t *
1000 {
1002  uword *p;
1004  u8 *name;
1005  u64 coremask;
1006  uword *bitmap;
1007  u32 count;
1008 
1010  tm->n_thread_stacks = 1; /* account for main thread */
1011 
1012  tr = tm->next;
1013 
1014  while (tr)
1015  {
1017  tr = tr->next;
1018  }
1019 
1020  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1021  {
1022  if (unformat (input, "use-pthreads"))
1023  tm->use_pthreads = 1;
1024  else if (unformat (input, "thread-prefix %v", &tm->thread_prefix))
1025  ;
1026  else if (unformat (input, "main-core %u", &tm->main_lcore))
1027  ;
1028  else if (unformat (input, "skip-cores %u", &tm->skip_cores))
1029  ;
1030  else if (unformat (input, "coremask-%s %llx", &name, &coremask))
1031  {
1033  if (p == 0)
1034  return clib_error_return (0, "no such thread type '%s'", name);
1035 
1036  tr = (vlib_thread_registration_t *) p[0];
1037 
1038  if (tr->use_pthreads)
1039  return clib_error_return (0,
1040  "coremask cannot be set for '%s' threads",
1041  name);
1042 
1044  (tr->coremask, 0, coremask, BITS (coremask));
1046  }
1047  else if (unformat (input, "corelist-%s %U", &name, unformat_bitmap_list,
1048  &bitmap))
1049  {
1051  if (p == 0)
1052  return clib_error_return (0, "no such thread type '%s'", name);
1053 
1054  tr = (vlib_thread_registration_t *) p[0];
1055 
1056  if (tr->use_pthreads)
1057  return clib_error_return (0,
1058  "corelist cannot be set for '%s' threads",
1059  name);
1060 
1061  tr->coremask = bitmap;
1063  }
1064  else if (unformat (input, "%s %u", &name, &count))
1065  {
1067  if (p == 0)
1068  return clib_error_return (0, "no such thread type '%s'", name);
1069 
1070  tr = (vlib_thread_registration_t *) p[0];
1071  if (tr->fixed_count)
1072  return clib_error_return
1073  (0, "number of %s threads not configurable", tr->name);
1074  tr->count = count;
1075  }
1076  else
1077  break;
1078  }
1079 
1080  tr = tm->next;
1081 
1082  if (!tm->thread_prefix)
1083  tm->thread_prefix = format (0, "vpp");
1084 
1085  while (tr)
1086  {
1087  tm->n_thread_stacks += tr->count;
1088  tm->n_pthreads += tr->count * tr->use_pthreads;
1089  tm->n_eal_threads += tr->count * (tr->use_pthreads == 0);
1090  tr = tr->next;
1091  }
1092 
1093  return 0;
1094 }
1095 
1097 
1098 #if !defined (__x86_64__) && !defined (__aarch64__) && !defined (__powerpc64__) && !defined(__arm__)
1099 void
1100 __sync_fetch_and_add_8 (void)
1101 {
1102  fformat (stderr, "%s called\n", __FUNCTION__);
1103  abort ();
1104 }
1105 
1106 void
1107 __sync_add_and_fetch_8 (void)
1108 {
1109  fformat (stderr, "%s called\n", __FUNCTION__);
1110  abort ();
1111 }
1112 #endif
1113 
1114 void vnet_main_fixup (vlib_fork_fixup_t which) __attribute__ ((weak));
1115 void
1117 {
1118 }
1119 
1120 void
1122 {
1123  vlib_main_t *vm = vlib_get_main ();
1124 
1125  if (vlib_mains == 0)
1126  return;
1127 
1128  ASSERT (os_get_cpu_number () == 0);
1130 
1131  switch (which)
1132  {
1135  break;
1136 
1137  default:
1138  ASSERT (0);
1139  }
1141 }
1142 
1143 void
1145 {
1146  f64 deadline;
1147  u32 count;
1148 
1149  if (!vlib_mains)
1150  return;
1151 
1152  count = vec_len (vlib_mains) - 1;
1153 
1154  /* Tolerate recursive calls */
1155  if (++vlib_worker_threads[0].recursion_level > 1)
1156  return;
1157 
1159 
1160  ASSERT (os_get_cpu_number () == 0);
1161 
1162  deadline = vlib_time_now (vm) + BARRIER_SYNC_TIMEOUT;
1163 
1165  while (*vlib_worker_threads->workers_at_barrier != count)
1166  {
1167  if (vlib_time_now (vm) > deadline)
1168  {
1169  fformat (stderr, "%s: worker thread deadlock\n", __FUNCTION__);
1170  os_panic ();
1171  }
1172  }
1173 }
1174 
1175 void
1177 {
1178  f64 deadline;
1179 
1180  if (!vlib_mains)
1181  return;
1182 
1183  if (--vlib_worker_threads[0].recursion_level > 0)
1184  return;
1185 
1186  deadline = vlib_time_now (vm) + BARRIER_SYNC_TIMEOUT;
1187 
1189 
1191  {
1192  if (vlib_time_now (vm) > deadline)
1193  {
1194  fformat (stderr, "%s: worker thread deadlock\n", __FUNCTION__);
1195  os_panic ();
1196  }
1197  }
1198 }
1199 
1200 /*
1201  * Check the frame queue to see if any frames are available.
1202  * If so, pull the packets off the frames and put them to
1203  * the handoff node.
1204  */
1205 static inline int
1207 {
1208  u32 thread_id = vm->cpu_index;
1209  vlib_frame_queue_t *fq = vlib_frame_queues[thread_id];
1211  u32 *from, *to;
1212  vlib_frame_t *f;
1213  int msg_type;
1214  int processed = 0;
1215  u32 n_left_to_node;
1216  u32 vectors = 0;
1218 
1219  ASSERT (fq);
1220  ASSERT (vm == vlib_mains[thread_id]);
1221 
1223  return 0;
1224  /*
1225  * Gather trace data for frame queues
1226  */
1227  if (PREDICT_FALSE (fq->trace))
1228  {
1229  frame_queue_trace_t *fqt;
1231  u32 elix;
1232 
1233  fqt = &tm->frame_queue_traces[thread_id];
1234 
1235  fqt->nelts = fq->nelts;
1236  fqt->head = fq->head;
1237  fqt->head_hint = fq->head_hint;
1238  fqt->tail = fq->tail;
1239  fqt->threshold = fq->vector_threshold;
1240  fqt->n_in_use = fqt->tail - fqt->head;
1241  if (fqt->n_in_use >= fqt->nelts)
1242  {
1243  // if beyond max then use max
1244  fqt->n_in_use = fqt->nelts - 1;
1245  }
1246 
1247  /* Record the number of elements in use in the histogram */
1248  fqh = &tm->frame_queue_histogram[thread_id];
1249  fqh->count[fqt->n_in_use]++;
1250 
1251  /* Record a snapshot of the elements in use */
1252  for (elix = 0; elix < fqt->nelts; elix++)
1253  {
1254  elt = fq->elts + ((fq->head + 1 + elix) & (fq->nelts - 1));
1255  if (1 || elt->valid)
1256  {
1257  fqt->n_vectors[elix] = elt->n_vectors;
1258  }
1259  }
1260  fqt->written = 1;
1261  }
1262 
1263  while (1)
1264  {
1265  if (fq->head == fq->tail)
1266  {
1267  fq->head_hint = fq->head;
1268  return processed;
1269  }
1270 
1271  elt = fq->elts + ((fq->head + 1) & (fq->nelts - 1));
1272 
1273  if (!elt->valid)
1274  {
1275  fq->head_hint = fq->head;
1276  return processed;
1277  }
1278 
1279  from = elt->buffer_index;
1280  msg_type = elt->msg_type;
1281 
1283  ASSERT (elt->n_vectors <= VLIB_FRAME_SIZE);
1284 
1286 
1287  to = vlib_frame_vector_args (f);
1288 
1289  n_left_to_node = elt->n_vectors;
1290 
1291  while (n_left_to_node >= 4)
1292  {
1293  to[0] = from[0];
1294  to[1] = from[1];
1295  to[2] = from[2];
1296  to[3] = from[3];
1297  to += 4;
1298  from += 4;
1299  n_left_to_node -= 4;
1300  }
1301 
1302  while (n_left_to_node > 0)
1303  {
1304  to[0] = from[0];
1305  to++;
1306  from++;
1307  n_left_to_node--;
1308  }
1309 
1310  vectors += elt->n_vectors;
1311  f->n_vectors = elt->n_vectors;
1313 
1314  elt->valid = 0;
1315  elt->n_vectors = 0;
1316  elt->msg_type = 0xfefefefe;
1318  fq->head++;
1319  processed++;
1320 
1321  /*
1322  * Limit the number of packets pushed into the graph
1323  */
1324  if (vectors >= fq->vector_threshold)
1325  {
1326  fq->head_hint = fq->head;
1327  return processed;
1328  }
1329  }
1330  ASSERT (0);
1331  return processed;
1332 }
1333 
1336 {
1337  vlib_node_main_t *nm = &vm->node_main;
1338  u64 cpu_time_now = clib_cpu_time_now ();
1339 
1340  while (1)
1341  {
1343 
1345 
1348  {
1349  cpu_time_now = dispatch_node (vm, n, VLIB_NODE_TYPE_INPUT,
1350  VLIB_NODE_STATE_POLLING, /* frame */ 0,
1351  cpu_time_now);
1352  }
1353 
1354  if (_vec_len (nm->pending_frames))
1355  {
1356  int i;
1357  cpu_time_now = clib_cpu_time_now ();
1358  for (i = 0; i < _vec_len (nm->pending_frames); i++)
1359  {
1361 
1362  p = nm->pending_frames + i;
1363 
1364  cpu_time_now = dispatch_pending_node (vm, p, cpu_time_now);
1365  }
1366  _vec_len (nm->pending_frames) = 0;
1367  }
1369 
1370  /* Record time stamp in case there are no enabled nodes and above
1371  calls do not update time stamp. */
1372  cpu_time_now = clib_cpu_time_now ();
1373  }
1374 }
1375 
1376 void
1378 {
1381  vlib_main_t *vm = vlib_get_main ();
1382 
1383  ASSERT (vm->cpu_index == os_get_cpu_number ());
1384 
1386  clib_time_init (&vm->clib_time);
1388 
1389  /* Wait until the dpdk init sequence is complete */
1390  while (tm->worker_thread_release == 0)
1392 
1394 }
1395 
1396 /* *INDENT-OFF* */
1397 VLIB_REGISTER_THREAD (worker_thread_reg, static) = {
1398  .name = "workers",
1399  .short_name = "wk",
1400  .function = vlib_worker_thread_fn,
1401 };
1402 /* *INDENT-ON* */
1403 
1404 clib_error_t *
1406 {
1408 
1409  tm->handoff_dispatch_node_index = ~0;
1410 
1411  return 0;
1412 }
1413 
1415 
1416 /*
1417  * fd.io coding-style-patch-verification: ON
1418  *
1419  * Local Variables:
1420  * eval: (c-set-style "gnu")
1421  * End:
1422  */
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:396
#define VLIB_EFD_DEF_WORKER_HI_THRESH_PCT
Definition: threads.h:247
u32 vl(void *p)
Definition: threads.c:50
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:343
uword unformat(unformat_input_t *i, char *fmt,...)
Definition: unformat.c:966
vlib_process_t ** processes
Definition: node.h:673
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)
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
bad routing header type(not 4)") sr_error (NO_MORE_SEGMENTS
#define VLIB_MAIN_LOOP_ENTER_FUNCTION(x)
Definition: init.h:113
word elog_track_register(elog_main_t *em, elog_track_t *t)
Definition: elog.c:190
void * mheap_alloc(void *memory, uword size)
Definition: mheap.c:953
static void vlib_increment_main_loop_counter(vlib_main_t *vm)
Definition: main.h:284
#define UNFORMAT_END_OF_INPUT
Definition: format.h:143
#define NULL
Definition: clib.h:55
u32 index
Definition: node.h:237
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:182
#define vec_add2_aligned(V, P, N, A)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:533
clib_error_t * threads_init(vlib_main_t *vm)
Definition: threads.c:1405
void os_panic(void)
Definition: unix-misc.c:172
void * thread_function_arg
Definition: threads.h:98
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:482
static int sort_registrations_by_no_clone(void *a0, void *a1)
Definition: threads.c:108
static u64 clib_cpu_time_now(void)
Definition: time.h:73
elog_track_t elog_track
Definition: threads.h:100
frame_queue_trace_t * frame_queue_traces
Definition: threads.h:311
#define VLIB_FRAME_NO_FREE_AFTER_DISPATCH
Definition: node.h:365
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:521
static mheap_t * mheap_header(u8 *v)
vlib_buffer_main_t * buffer_main
Definition: main.h:104
void vnet_main_fixup(vlib_fork_fixup_t which)
Definition: threads.c:1116
vlib_worker_thread_t * vlib_worker_threads
Definition: threads.h:110
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. ...
Definition: bitmap.h:167
#define hash_set_mem(h, key, value)
Definition: hash.h:274
clib_time_t clib_time
Definition: main.h:62
void vlib_worker_thread_fn(void *arg)
Definition: threads.c:1377
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
Definition: vec.h:407
struct vlib_thread_registration_ * next
Definition: threads.h:30
#define MHEAP_FLAG_THREAD_SAFE
u32 buffer_index[VLIB_FRAME_SIZE]
Definition: threads.h:80
volatile u32 valid
Definition: threads.h:74
u32 handoff_dispatch_node_index
Definition: threads.h:308
#define clib_bitmap_dup(v)
Duplicate a bitmap.
Definition: bitmap.h:87
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
u8 state
Definition: node.h:265
u64 * counters_last_clear
Definition: error.h:81
static void vlib_worker_thread_barrier_check(void)
Definition: threads.h:204
#define VLIB_LOG2_THREAD_STACK_SIZE
Definition: threads.h:64
vlib_thread_registration_t * next
Definition: threads.h:263
vlib_node_stats_t stats_last_clear
Definition: node.h:231
#define static_always_inline
Definition: clib.h:85
#define clib_smp_atomic_add(addr, increment)
Definition: smp.h:46
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:348
void vlib_worker_thread_node_runtime_update(void)
Definition: threads.c:831
u64 count[FRAME_QUEUE_MAX_NELTS]
Definition: node.h:717
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:111
u64 dispatch_pending_node(vlib_main_t *vm, vlib_pending_frame_t *p, u64 last_time_stamp)
Definition: main.c:1087
vlib_worker_thread_t * vlib_alloc_thread(vlib_main_t *vm)
Definition: threads.c:287
vlib_frame_queue_msg_type_t
Definition: threads.h:67
u16 queue_hi_thresh
Definition: threads.h:253
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)
Definition: main.c:543
vlib_node_t ** nodes
Definition: node.h:633
int i32
Definition: types.h:81
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
uword * lock
Definition: elog.h:162
uword * cpu_core_bitmap
Definition: threads.h:300
static void unformat_free(unformat_input_t *i)
Definition: format.h:161
u32 cpu_index
Definition: main.h:159
#define clib_warning(format, args...)
Definition: error.h:59
unsigned long u64
Definition: types.h:89
static int vlib_launch_thread(void *fp, vlib_worker_thread_t *w, unsigned lcore_id)
Definition: threads.c:521
vlib_frame_queue_elt_t * elts
Definition: threads.h:137
void unformat_init_string(unformat_input_t *input, char *string, int string_len)
Definition: unformat.c:1017
vlib_node_runtime_t * nodes_by_type[VLIB_N_NODE_TYPE]
Definition: node.h:643
vlib_frame_queue_t ** vlib_frame_queues
Definition: threads.h:142
void vlib_set_thread_name(char *name)
Definition: threads.c:93
void vl_msg_api_handler_no_free(void *)
Definition: threads.c:336
#define hash_create_string(elts, value_bytes)
Definition: hash.h:641
vlib_fork_fixup_t
Definition: threads.h:195
#define BARRIER_SYNC_TIMEOUT
Definition: threads.h:177
vlib_main_t ** vlib_mains
Definition: dpdk_buffer.c:157
VLIB_REGISTER_THREAD(worker_thread_reg, static)
unsigned __thread RTE_PER_LCORE(_lcore_id)
#define clib_bitmap_foreach(i, ai, body)
Macro to iterate across set bits in a bitmap.
Definition: bitmap.h:361
void * thread_mheap
Definition: threads.h:95
u32 next_frame_index
Definition: node.h:406
int rte_eal_remote_launch()
vlib_node_stats_t stats_total
Definition: node.h:227
volatile u64 head
Definition: threads.h:124
static_always_inline void vlib_worker_thread_internal(vlib_main_t *vm)
Definition: threads.c:1335
static uword clib_bitmap_first_set(uword *ai)
Return the lowest numbered set bit in a bitmap.
Definition: bitmap.h:385
vlib_error_main_t error_main
Definition: main.h:124
static u32 vlib_frame_index(vlib_main_t *vm, vlib_frame_t *f)
Definition: node_funcs.h:229
void vlib_frame_free(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_frame_t *f)
Definition: main.c:214
char * name
Definition: elog.h:106
#define vec_dup(V)
Return copy of vector (no header, no alignment)
Definition: vec.h:334
static void * clib_mem_get_per_cpu_heap(void)
Definition: mem.h:55
#define PREDICT_FALSE(x)
Definition: clib.h:97
#define VLIB_FRAME_PENDING
Definition: node.h:376
#define VLIB_FRAME_SIZE
Definition: node.h:328
void vlib_put_frame_to_node(vlib_main_t *vm, u32 to_node_index, vlib_frame_t *f)
Definition: main.c:194
#define VLIB_FRAME_FREE_AFTER_DISPATCH
Definition: node.h:379
void clib_time_init(clib_time_t *c)
Definition: time.c:165
uword * frame_size_hash
Definition: node.h:688
vlib_thread_main_t vlib_thread_main
Definition: threads.c:55
void(* thread_function)(void *)
Definition: threads.h:97
static clib_error_t * cpu_config(vlib_main_t *vm, unformat_input_t *input)
Definition: threads.c:999
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P (general version).
Definition: pool.h:169
i32 n_vectors[FRAME_QUEUE_MAX_NELTS]
Definition: node.h:712
u64 * counters
Definition: error.h:78
u32 owner_node_index
Definition: node.h:308
vlib_frame_queue_t * vlib_frame_queue_alloc(int nelts)
Definition: threads.c:302
uword os_get_ncpus(void)
Definition: threads.c:81
volatile u64 tail
Definition: threads.h:115
#define clib_mem_alloc_no_fail(size)
Definition: mem.h:131
#define VLIB_EARLY_CONFIG_FUNCTION(x, n,...)
Definition: init.h:139
svmdb_client_t * c
u16 n_vectors
Definition: node.h:344
u32 node_runtime_index
Definition: node.h:400
vlib_pending_frame_t * pending_frames
Definition: node.h:658
vlib_thread_function_t * function
Definition: threads.h:35
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:300
void * heap_base
Definition: main.h:101
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:32
static void * clib_mem_set_heap(void *heap)
Definition: mem.h:201
static vlib_node_runtime_t * vlib_node_get_runtime(vlib_main_t *vm, u32 node_index)
Get node runtime by node index.
Definition: node_funcs.h:88
#define clib_memcpy(a, b, c)
Definition: string.h:63
elog_main_t elog_main
Definition: main.h:141
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
Definition: bitmap.h:275
void vlib_worker_thread_barrier_sync(vlib_main_t *vm)
Definition: threads.c:1144
static uword clib_bitmap_get(uword *ai, uword i)
Gets the ith bit value from a bitmap.
Definition: bitmap.h:197
static void vlib_next_frame_init(vlib_next_frame_t *nf)
Definition: node.h:389
void vlib_worker_thread_init(vlib_worker_thread_t *w)
Definition: threads.c:463
static void * clib_mem_get_heap(void)
Definition: mem.h:195
int vlib_frame_queue_dequeue(int thread_id, vlib_main_t *vm, vlib_node_main_t *nm)
volatile u32 * wait_at_barrier
Definition: threads.h:90
#define FRAME_QUEUE_NELTS
Definition: threads.c:36
#define never_inline
Definition: clib.h:81
frame_queue_nelt_counter_t * frame_queue_histogram
Definition: threads.h:312
#define ASSERT(truth)
unsigned int u32
Definition: types.h:88
u8 * format(u8 *s, char *fmt,...)
Definition: format.c:418
void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
Definition: dpdk_buffer.c:766
u16 flags
Definition: node.h:335
static void clib_mem_free(void *p)
Definition: mem.h:154
#define clib_bitmap_free(v)
Free a bitmap.
Definition: bitmap.h:92
uword * thread_registrations_by_name
Definition: threads.h:268
static void * clib_mem_alloc(uword size)
Definition: mem.h:107
#define VLIB_EFD_DISABLED
Definition: threads.h:243
u64 uword
Definition: types.h:112
static uword clib_bitmap_count_set_bits(uword *ai)
Return the number of set bits in a bitmap.
Definition: bitmap.h:441
void ** mbuf_alloc_list
Definition: main.h:161
static clib_error_t * start_workers(vlib_main_t *vm)
Definition: threads.c:549
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
double f64
Definition: types.h:142
unsigned char u8
Definition: types.h:56
#define VLIB_PENDING_FRAME_NO_NEXT_FRAME
Definition: node.h:409
DECLARE_CJ_GLOBAL_LOG
Definition: threads.c:34
vlib_node_main_t node_main
Definition: main.h:115
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" )
Definition: bitmap.h:693
vlib_buffer_free_list_t * buffer_free_list_pool
Definition: buffer.h:302
vlib_next_frame_t * next_frames
Definition: node.h:655
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
Definition: vec.h:900
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:251
uword os_get_cpu_number(void)
Definition: threads.c:58
volatile u64 head_hint
Definition: threads.h:133
word fformat(FILE *f, char *fmt,...)
Definition: format.c:452
#define VLIB_THREAD_STACK_SIZE
Definition: threads.h:65
vlib_frame_size_t * frame_sizes
Definition: node.h:691
void vlib_node_sync_stats(vlib_main_t *vm, vlib_node_t *n)
Definition: main.c:573
#define hash_get_mem(h, key)
Definition: hash.h:268
static void * clib_mem_alloc_aligned(uword size, uword align)
Definition: mem.h:114
volatile u32 * workers_at_barrier
Definition: threads.h:91
uword clib_calljmp(uword(*func)(uword func_arg), uword func_arg, void *stack)
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)
Definition: main.c:919
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:169
void vlib_worker_thread_barrier_release(vlib_main_t *vm)
Definition: threads.c:1176
#define VLIB_INVALID_NODE_INDEX
Definition: node.h:325
static f64 vlib_time_now_ticks(vlib_main_t *vm, u64 n)
Definition: main.h:188
#define vec_foreach(var, vec)
Vector iterator.
void * vlib_worker_thread_bootstrap_fn(void *arg)
Definition: threads.c:497
static int vlib_frame_queue_dequeue_internal(vlib_main_t *vm)
Definition: threads.c:1206
#define CLIB_MEMORY_BARRIER()
Definition: clib.h:101
u32 node_runtime_index
Definition: node.h:359
uword * cpu_socket_bitmap
Definition: threads.h:303
static uword * vlib_sysfs_list_to_bitmap(char *filename)
Definition: threads.c:118
#define clib_error_return(e, args...)
Definition: error.h:111
struct _unformat_input_t unformat_input_t
vlib_thread_registration_t ** registrations
Definition: threads.h:266
vlib_frame_t * vlib_get_frame_to_node(vlib_main_t *vm, u32 to_node_index)
Definition: main.c:185
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:67
u8 ** vlib_thread_stacks
Definition: main.h:318
vlib_thread_registration_t * registration
Definition: threads.h:102
#define BITS(x)
Definition: clib.h:58
volatile u32 worker_thread_release
Definition: threads.h:315
void vlib_worker_thread_fork_fixup(vlib_fork_fixup_t which)
Definition: threads.c:1121
clib_random_buffer_t random_buffer
Definition: main.h:153
u16 enabled
Definition: threads.h:252
vlib_efd_t efd
Definition: threads.h:305
clib_error_t * vlib_thread_init(vlib_main_t *vm)
Definition: threads.c:148