FD.io VPP  v18.07-34-g55fbdb9
Vector Packet Processing
memory_shared.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * memclnt_shared.c - API message handling, common code for both clients
4  * and the vlib process itself.
5  *
6  *
7  * Copyright (c) 2009 Cisco and/or its affiliates.
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at:
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *------------------------------------------------------------------
20  */
21 
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <stddef.h>
25 #include <string.h>
26 #include <unistd.h>
27 #include <signal.h>
28 
29 #include <vppinfra/format.h>
30 #include <vppinfra/byte_order.h>
31 #include <vppinfra/error.h>
32 #include <svm/queue.h>
33 #include <vlib/vlib.h>
34 #include <vlib/unix/unix.h>
35 #include <vlibmemory/memory_api.h>
37 
38 #define vl_typedefs
40 #undef vl_typedefs
41 
42 #define DEBUG_MESSAGE_BUFFER_OVERRUN 0
43 
44 static inline void *
45 vl_msg_api_alloc_internal (int nbytes, int pool, int may_return_null)
46 {
47  int i;
48  msgbuf_t *rv;
49  ring_alloc_t *ap;
50  svm_queue_t *q;
51  void *oldheap;
53  api_main_t *am = &api_main;
54 
55  shmem_hdr = am->shmem_hdr;
56 
57 #if DEBUG_MESSAGE_BUFFER_OVERRUN > 0
58  nbytes += 4;
59 #endif
60 
61  ASSERT (pool == 0 || vlib_get_thread_index () == 0);
62 
63  if (shmem_hdr == 0)
64  {
65  clib_warning ("shared memory header NULL");
66  return 0;
67  }
68 
69  /* account for the msgbuf_t header */
70  nbytes += sizeof (msgbuf_t);
71 
72  if (shmem_hdr->vl_rings == 0)
73  {
74  clib_warning ("vl_rings NULL");
75  ASSERT (0);
76  abort ();
77  }
78 
79  if (shmem_hdr->client_rings == 0)
80  {
81  clib_warning ("client_rings NULL");
82  ASSERT (0);
83  abort ();
84  }
85 
86  ap = pool ? shmem_hdr->vl_rings : shmem_hdr->client_rings;
87  for (i = 0; i < vec_len (ap); i++)
88  {
89  /* Too big? */
90  if (nbytes > ap[i].size)
91  {
92  continue;
93  }
94 
95  q = ap[i].rp;
96  if (pool == 0)
97  {
98  pthread_mutex_lock (&q->mutex);
99  }
100  rv = (msgbuf_t *) (&q->data[0] + q->head * q->elsize);
101  /*
102  * Is this item still in use?
103  */
104  if (rv->q)
105  {
106  u32 now = (u32) time (0);
107 
108  if (PREDICT_TRUE (rv->gc_mark_timestamp == 0))
109  rv->gc_mark_timestamp = now;
110  else
111  {
112  if (now - rv->gc_mark_timestamp > 10)
113  {
114  if (CLIB_DEBUG > 0)
115  {
116  u16 *msg_idp, msg_id;
118  ("garbage collect pool %d ring %d index %d", pool, i,
119  q->head);
120  msg_idp = (u16 *) (rv->data);
121  msg_id = clib_net_to_host_u16 (*msg_idp);
122  if (msg_id < vec_len (api_main.msg_names))
123  clib_warning ("msg id %d name %s", (u32) msg_id,
124  api_main.msg_names[msg_id]);
125  }
126  shmem_hdr->garbage_collects++;
127  goto collected;
128  }
129  }
130 
131 
132  /* yes, loser; try next larger pool */
133  ap[i].misses++;
134  if (pool == 0)
135  pthread_mutex_unlock (&q->mutex);
136  continue;
137  }
138  collected:
139 
140  /* OK, we have a winner */
141  ap[i].hits++;
142  /*
143  * Remember the source queue, although we
144  * don't need to know the queue to free the item.
145  */
146  rv->q = q;
147  rv->gc_mark_timestamp = 0;
148  q->head++;
149  if (q->head == q->maxsize)
150  q->head = 0;
151 
152  if (pool == 0)
153  pthread_mutex_unlock (&q->mutex);
154  goto out;
155  }
156 
157  /*
158  * Request too big, or head element of all size-compatible rings
159  * still in use. Fall back to shared-memory malloc.
160  */
161  am->ring_misses++;
162 
163  pthread_mutex_lock (&am->vlib_rp->mutex);
164  oldheap = svm_push_data_heap (am->vlib_rp);
165  if (may_return_null)
166  {
167  rv = clib_mem_alloc_or_null (nbytes);
168  if (PREDICT_FALSE (rv == 0))
169  {
170  svm_pop_heap (oldheap);
171  pthread_mutex_unlock (&am->vlib_rp->mutex);
172  return 0;
173  }
174  }
175  else
176  rv = clib_mem_alloc (nbytes);
177 
178  rv->q = 0;
179  svm_pop_heap (oldheap);
180  pthread_mutex_unlock (&am->vlib_rp->mutex);
181 
182 out:
183 #if DEBUG_MESSAGE_BUFFER_OVERRUN > 0
184  {
185  nbytes -= 4;
186  u32 *overrun;
187  overrun = (u32 *) (rv->data + nbytes - sizeof (msgbuf_t));
188  *overrun = 0x1badbabe;
189  }
190 #endif
191  rv->data_len = htonl (nbytes - sizeof (msgbuf_t));
192 
193  return (rv->data);
194 }
195 
196 void *
197 vl_msg_api_alloc (int nbytes)
198 {
199  int pool;
200  api_main_t *am = &api_main;
202 
203  /*
204  * Clients use pool-0, vlib proc uses pool 1
205  */
206  pool = (am->our_pid == shmem_hdr->vl_pid);
207  return vl_msg_api_alloc_internal (nbytes, pool, 0 /* may_return_null */ );
208 }
209 
210 void *
212 {
213  int pool;
214  api_main_t *am = &api_main;
216 
217  pool = (am->our_pid == shmem_hdr->vl_pid);
218  return vl_msg_api_alloc_internal (nbytes, pool, 1 /* may_return_null */ );
219 }
220 
221 void *
223 {
224  return vl_msg_api_alloc_internal (nbytes, 0, 0 /* may_return_null */ );
225 }
226 
227 void *
229 {
230  return vl_msg_api_alloc_internal (nbytes, 0, 1 /* may_return_null */ );
231 }
232 
233 void *
235 {
236  api_main_t *am = &api_main;
237  vl_shmem_hdr_t *save_shmem_hdr = am->shmem_hdr;
238  svm_region_t *vlib_rp, *save_vlib_rp = am->vlib_rp;
239  void *msg;
240 
241  vlib_rp = am->vlib_rp = reg->vlib_rp;
242  am->shmem_hdr = (void *) vlib_rp->user_ctx;
243 
244  msg = vl_msg_api_alloc_internal (nbytes, 0, 0 /* may_return_null */ );
245 
246  am->shmem_hdr = save_shmem_hdr;
247  am->vlib_rp = save_vlib_rp;
248 
249  return msg;
250 }
251 
252 void
254 {
255  msgbuf_t *rv;
256  void *oldheap;
257  api_main_t *am = &api_main;
258 
259  rv = (msgbuf_t *) (((u8 *) a) - offsetof (msgbuf_t, data));
260 
261  /*
262  * Here's the beauty of the scheme. Only one proc/thread has
263  * control of a given message buffer. To free a buffer, we just clear the
264  * queue field, and leave. No locks, no hits, no errors...
265  */
266  if (rv->q)
267  {
268  rv->q = 0;
269  rv->gc_mark_timestamp = 0;
270 #if DEBUG_MESSAGE_BUFFER_OVERRUN > 0
271  {
272  u32 *overrun;
273  overrun = (u32 *) (rv->data + ntohl (rv->data_len));
274  ASSERT (*overrun == 0x1badbabe);
275  }
276 #endif
277  return;
278  }
279 
280  pthread_mutex_lock (&am->vlib_rp->mutex);
281  oldheap = svm_push_data_heap (am->vlib_rp);
282 
283 #if DEBUG_MESSAGE_BUFFER_OVERRUN > 0
284  {
285  u32 *overrun;
286  overrun = (u32 *) (rv->data + ntohl (rv->data_len));
287  ASSERT (*overrun == 0x1badbabe);
288  }
289 #endif
290 
291  clib_mem_free (rv);
292  svm_pop_heap (oldheap);
293  pthread_mutex_unlock (&am->vlib_rp->mutex);
294 }
295 
296 static void
298 {
299  msgbuf_t *rv;
300  void *oldheap;
301  api_main_t *am = &api_main;
302 
303  rv = (msgbuf_t *) (((u8 *) a) - offsetof (msgbuf_t, data));
304  /*
305  * Here's the beauty of the scheme. Only one proc/thread has
306  * control of a given message buffer. To free a buffer, we just clear the
307  * queue field, and leave. No locks, no hits, no errors...
308  */
309  if (rv->q)
310  {
311  rv->q = 0;
312  return;
313  }
314 
315  oldheap = svm_push_data_heap (am->vlib_rp);
316  clib_mem_free (rv);
317  svm_pop_heap (oldheap);
318 }
319 
320 void
321 vl_set_memory_root_path (const char *name)
322 {
323  api_main_t *am = &api_main;
324 
325  am->root_path = name;
326 }
327 
328 void
330 {
331  api_main_t *am = &api_main;
332 
333  am->api_uid = uid;
334 }
335 
336 void
338 {
339  api_main_t *am = &api_main;
340 
341  am->api_gid = gid;
342 }
343 
344 void
346 {
347  api_main_t *am = &api_main;
348 
349  am->global_baseva = baseva;
350 }
351 
352 void
354 {
355  api_main_t *am = &api_main;
356 
357  am->global_size = size;
358 }
359 
360 void
362 {
363  api_main_t *am = &api_main;
364 
365  am->api_size = size;
366 }
367 
368 void
370 {
371  api_main_t *am = &api_main;
372 
374 }
375 
376 void
378 {
379  api_main_t *am = &api_main;
380 
381  am->api_pvt_heap_size = size;
382 }
383 
384 static void
386 {
387  api_main_t *am = &api_main;
388  u32 vlib_input_queue_length;
389 
390  /* vlib main input queue */
391  vlib_input_queue_length = 1024;
392  if (am->vlib_input_queue_length)
393  vlib_input_queue_length = am->vlib_input_queue_length;
394 
395  shmem_hdr->vl_input_queue =
396  svm_queue_init (vlib_input_queue_length, sizeof (uword),
397  getpid (), am->vlib_signal);
398 
399 #define _(sz,n) \
400  do { \
401  ring_alloc_t _rp; \
402  _rp.rp = svm_queue_init ((n), (sz), 0, 0); \
403  _rp.size = (sz); \
404  _rp.nitems = n; \
405  _rp.hits = 0; \
406  _rp.misses = 0; \
407  vec_add1(shmem_hdr->vl_rings, _rp); \
408  } while (0);
409 
411 #undef _
412 
413 #define _(sz,n) \
414  do { \
415  ring_alloc_t _rp; \
416  _rp.rp = svm_queue_init ((n), (sz), 0, 0); \
417  _rp.size = (sz); \
418  _rp.nitems = n; \
419  _rp.hits = 0; \
420  _rp.misses = 0; \
421  vec_add1(shmem_hdr->client_rings, _rp); \
422  } while (0);
423 
425 #undef _
426 }
427 
428 void
430 {
431  api_main_t *am = &api_main;
433  ring_alloc_t *rp;
434  u32 size;
435 
436  if (!config)
437  {
439  return;
440  }
441 
442  vec_foreach (c, config)
443  {
444  switch (c->type)
445  {
446  case VL_API_QUEUE:
448  c->size,
449  getpid (), am->vlib_signal);
450  continue;
451  case VL_API_VLIB_RING:
452  vec_add2 (hdr->vl_rings, rp, 1);
453  break;
454  case VL_API_CLIENT_RING:
455  vec_add2 (hdr->client_rings, rp, 1);
456  break;
457  default:
458  clib_warning ("unknown config type: %d", c->type);
459  continue;
460  }
461 
462  size = sizeof (ring_alloc_t) + c->size;
463  rp->rp = svm_queue_init (c->count, size, 0, 0);
464  rp->size = size;
465  rp->nitems = c->count;
466  rp->hits = 0;
467  rp->misses = 0;
468  }
469 }
470 
471 void
473  int is_vlib, int is_private_region)
474 {
475  api_main_t *am = &api_main;
477  void *oldheap;
478  ASSERT (vlib_rp);
479 
480  /* $$$$ need private region config parameters */
481 
482  oldheap = svm_push_data_heap (vlib_rp);
483 
484  vec_validate (shmem_hdr, 0);
485  shmem_hdr->version = VL_SHM_VERSION;
486  shmem_hdr->clib_file_index = VL_API_INVALID_FI;
487 
488  /* Set up the queue and msg ring allocator */
489  vl_api_mem_config (shmem_hdr, config);
490 
491  if (is_private_region == 0)
492  {
493  am->shmem_hdr = shmem_hdr;
494  am->vlib_rp = vlib_rp;
495  am->our_pid = getpid ();
496  if (is_vlib)
497  am->shmem_hdr->vl_pid = am->our_pid;
498  }
499  else
500  shmem_hdr->vl_pid = am->our_pid;
501 
502  svm_pop_heap (oldheap);
503 
504  /*
505  * After absolutely everything that a client might see is set up,
506  * declare the shmem region valid
507  */
508  vlib_rp->user_ctx = shmem_hdr;
509 
510  pthread_mutex_unlock (&vlib_rp->mutex);
511 }
512 
513 int
514 vl_map_shmem (const char *region_name, int is_vlib)
515 {
516  svm_map_region_args_t _a, *a = &_a;
517  svm_region_t *vlib_rp, *root_rp;
518  api_main_t *am = &api_main;
519  int i, rv;
520  struct timespec ts, tsrem;
521  char *vpe_api_region_suffix = "-vpe-api";
522 
523  memset (a, 0, sizeof (*a));
524 
525  if (strstr (region_name, vpe_api_region_suffix))
526  {
527  u8 *root_path = format (0, "%s", region_name);
528  _vec_len (root_path) = (vec_len (root_path) -
529  strlen (vpe_api_region_suffix));
530  vec_terminate_c_string (root_path);
531  a->root_path = (const char *) root_path;
532  am->root_path = (const char *) root_path;
533  }
534 
535  if (is_vlib == 0)
536  {
538  if (rv)
539  return rv;
540  }
541 
542  if (a->root_path != NULL)
543  {
544  a->name = "/vpe-api";
545  }
546  else
547  a->name = region_name;
548  a->size = am->api_size ? am->api_size : (16 << 20);
549  a->flags = SVM_FLAGS_MHEAP;
550  a->uid = am->api_uid;
551  a->gid = am->api_gid;
553 
554  vlib_rp = svm_region_find_or_create (a);
555 
556  if (vlib_rp == 0)
557  return (-2);
558 
559  pthread_mutex_lock (&vlib_rp->mutex);
560  /* Has someone else set up the shared-memory variable table? */
561  if (vlib_rp->user_ctx)
562  {
563  am->shmem_hdr = (void *) vlib_rp->user_ctx;
564  am->our_pid = getpid ();
565  if (is_vlib)
566  {
567  svm_queue_t *q;
568  uword old_msg;
569  /*
570  * application restart. Reset cached pids, API message
571  * rings, list of clients; otherwise, various things
572  * fail. (e.g. queue non-empty notification)
573  */
574 
575  /* ghosts keep the region from disappearing properly */
578  q = am->shmem_hdr->vl_input_queue;
579  am->shmem_hdr->vl_pid = getpid ();
580  q->consumer_pid = am->shmem_hdr->vl_pid;
581  /* Drain the input queue, freeing msgs */
582  for (i = 0; i < 10; i++)
583  {
584  if (pthread_mutex_trylock (&q->mutex) == 0)
585  {
586  pthread_mutex_unlock (&q->mutex);
587  goto mutex_ok;
588  }
589  ts.tv_sec = 0;
590  ts.tv_nsec = 10000 * 1000; /* 10 ms */
591  while (nanosleep (&ts, &tsrem) < 0)
592  ts = tsrem;
593  }
594  /* Mutex buggered, "fix" it */
595  memset (&q->mutex, 0, sizeof (q->mutex));
596  clib_warning ("forcibly release main input queue mutex");
597 
598  mutex_ok:
599  am->vlib_rp = vlib_rp;
600  while (svm_queue_sub (q, (u8 *) & old_msg, SVM_Q_NOWAIT, 0)
601  != -2 /* queue underflow */ )
602  {
603  vl_msg_api_free_nolock ((void *) old_msg);
605  }
606  pthread_mutex_unlock (&vlib_rp->mutex);
607  root_rp = svm_get_root_rp ();
608  ASSERT (root_rp);
609  /* Clean up the root region client list */
610  pthread_mutex_lock (&root_rp->mutex);
612  pthread_mutex_unlock (&root_rp->mutex);
613  }
614  else
615  {
616  pthread_mutex_unlock (&vlib_rp->mutex);
617  }
618  am->vlib_rp = vlib_rp;
619  vec_add1 (am->mapped_shmem_regions, vlib_rp);
620  return 0;
621  }
622  /* Clients simply have to wait... */
623  if (!is_vlib)
624  {
625  pthread_mutex_unlock (&vlib_rp->mutex);
626 
627  /* Wait up to 100 seconds... */
628  for (i = 0; i < 10000; i++)
629  {
630  ts.tv_sec = 0;
631  ts.tv_nsec = 10000 * 1000; /* 10 ms */
632  while (nanosleep (&ts, &tsrem) < 0)
633  ts = tsrem;
634  if (vlib_rp->user_ctx)
635  goto ready;
636  }
637  /* Clean up and leave... */
638  svm_region_unmap (vlib_rp);
639  clib_warning ("region init fail");
640  return (-2);
641 
642  ready:
643  am->shmem_hdr = (void *) vlib_rp->user_ctx;
644  am->our_pid = getpid ();
645  am->vlib_rp = vlib_rp;
646  vec_add1 (am->mapped_shmem_regions, vlib_rp);
647  return 0;
648  }
649 
650  /* Nope, it's our problem... */
651  vl_init_shmem (vlib_rp, 0 /* default config */ , 1 /* is vlib */ ,
652  0 /* is_private_region */ );
653 
654  vec_add1 (am->mapped_shmem_regions, vlib_rp);
655  return 0;
656 }
657 
658 void
660 {
661  api_main_t *am = &api_main;
662 
663  vec_add1 (am->mapped_shmem_regions, rp);
664 }
665 
666 static void
668 {
669  svm_region_t *rp;
670  int i;
671  api_main_t *am = &api_main;
672 
673  if (!svm_get_root_rp ())
674  return;
675 
676  for (i = 0; i < vec_len (am->mapped_shmem_regions); i++)
677  {
678  rp = am->mapped_shmem_regions[i];
679  is_client ? svm_region_unmap_client (rp) : svm_region_unmap (rp);
680  }
681 
683  am->shmem_hdr = 0;
684 
685  is_client ? svm_region_exit_client () : svm_region_exit ();
686 
687  /* $$$ more careful cleanup, valgrind run... */
688  vec_free (am->msg_handlers);
691 }
692 
693 void
695 {
697 }
698 
699 void
701 {
703 }
704 
705 void
707 {
708  api_main_t *am = &api_main;
709  uword *trace = (uword *) elem;
710 
711  if (am->tx_trace && am->tx_trace->enabled)
712  vl_msg_api_trace (am, am->tx_trace, (void *) trace[0]);
713 
714  (void) svm_queue_add (q, elem, 0 /* nowait */ );
715 }
716 
717 int
719 {
720  return (q->cursize < q->maxsize);
721 }
722 
723 void
725 {
726  api_main_t *am = &api_main;
727  uword *trace = (uword *) elem;
728 
729  if (am->tx_trace && am->tx_trace->enabled)
730  vl_msg_api_trace (am, am->tx_trace, (void *) trace[0]);
731 
732  (void) svm_queue_add_nolock (q, elem);
733 }
734 
735 /*
736  * fd.io coding-style-patch-verification: ON
737  *
738  * Local Variables:
739  * eval: (c-set-style "gnu")
740  * End:
741  */
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:437
u64 api_pvt_heap_size
size of the api private mheap
Definition: api_common.h:300
static vlib_cli_command_t trace
(constructor) VLIB_CLI_COMMAND (trace)
Definition: vlib_api_cli.c:862
svm_region_t * svm_get_root_rp(void)
Definition: svm.c:54
const char * root_path
Definition: svm_common.h:67
static void svm_pop_heap(void *oldheap)
Definition: svm.h:94
int svm_queue_add(svm_queue_t *q, u8 *elem, int nowait)
Definition: queue.c:184
a
Definition: bitmap.h:538
void vl_set_global_memory_baseva(u64 baseva)
int vl_map_shmem(const char *region_name, int is_vlib)
u64 api_size
size of the API region
Definition: api_common.h:294
u32 application_restarts
Definition: memory_shared.h:95
#define PREDICT_TRUE(x)
Definition: clib.h:106
void vl_set_memory_uid(int uid)
unsigned long u64
Definition: types.h:89
void vl_set_global_pvt_heap_size(u64 size)
#define NULL
Definition: clib.h:55
void vl_unmap_shmem(void)
u32 gc_mark_timestamp
message garbage collector mark TS
Definition: api_common.h:139
#define vec_terminate_c_string(V)
(If necessary) NULL terminate a vector containing a c-string.
Definition: vec.h:1016
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:523
static void vl_unmap_shmem_internal(u8 is_client)
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:562
int i
int api_uid
uid for the api shared memory region
Definition: api_common.h:282
void svm_region_unmap_client(void *rp_arg)
Definition: svm.c:1172
ring_alloc_t * client_rings
Definition: memory_shared.h:92
svm_queue_t * q
message allocated in this shmem ring
Definition: api_common.h:137
int vl_mem_api_can_send(svm_queue_t *q)
void svm_region_exit_client(void)
Definition: svm.c:1238
u8 data[0]
actual message begins here
Definition: api_common.h:140
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
struct msgbuf_ msgbuf_t
Message header structure.
void * vl_msg_api_alloc(int nbytes)
int api_gid
gid for the api shared memory region
Definition: api_common.h:285
unsigned char u8
Definition: types.h:56
void vl_set_global_memory_size(u64 size)
svm_queue_t * svm_queue_init(int nels, int elsize, int consumer_pid, int signal_when_queue_non_empty)
Definition: queue.c:51
int our_pid
Current process PID.
Definition: api_common.h:251
void svm_region_exit(void)
Definition: svm.c:1232
int svm_queue_sub(svm_queue_t *q, u8 *elem, svm_q_conditional_wait_t cond, u32 time)
Definition: queue.c:303
#define foreach_clnt_aring_size
Definition: memory_shared.h:71
static void * svm_push_data_heap(svm_region_t *rp)
Definition: svm.h:86
void * svm_region_find_or_create(svm_map_region_args_t *a)
Definition: svm.c:904
volatile void * user_ctx
Definition: svm_common.h:47
const char * root_path
Chroot path to the shared memory API files.
Definition: api_common.h:333
svm_region_t * vlib_rp
Current binary api segment descriptor.
Definition: api_common.h:254
struct vl_shmem_hdr_ * shmem_hdr
Binary API shared-memory segment header pointer.
Definition: api_common.h:264
unsigned int u32
Definition: types.h:88
svm_queue_t * rp
Definition: memory_shared.h:37
vl_shmem_hdr_t * shmem_hdr
struct ring_alloc_ ring_alloc_t
void vl_set_memory_root_path(const char *name)
#define SVM_FLAGS_MHEAP
Definition: svm_common.h:27
volatile int vl_pid
Definition: memory_shared.h:81
uword size
void vl_register_mapped_shmem_region(svm_region_t *rp)
void vl_init_shmem(svm_region_t *vlib_rp, vl_api_shm_elem_config_t *config, int is_vlib, int is_private_region)
#define VL_API_INVALID_FI
Definition: api_common.h:75
void(** msg_print_handlers)(void *, void *)
Message print function vector.
Definition: api_common.h:215
unsigned short u16
Definition: types.h:57
#define PREDICT_FALSE(x)
Definition: clib.h:105
#define VL_SHM_VERSION
void vl_set_api_pvt_heap_size(u64 size)
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:201
u64 global_size
size of the global VM region
Definition: api_common.h:291
u8 enabled
trace is enabled
Definition: api_common.h:91
An API client registration, only in vpp/vlib.
Definition: api_common.h:44
void vl_msg_api_send_shmem(svm_queue_t *q, u8 *elem)
ring_alloc_t * vl_rings
Definition: memory_shared.h:89
svmdb_client_t * c
static_always_inline uword vlib_get_thread_index(void)
Definition: threads.h:221
static void * clib_mem_alloc_or_null(uword size)
Definition: mem.h:128
u64 global_baseva
base virtual address for global VM region
Definition: api_common.h:288
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:339
#define clib_warning(format, args...)
Definition: error.h:59
void vl_msg_api_trace(api_main_t *am, vl_api_trace_t *tp, void *msg)
Definition: api_shared.c:66
void vl_set_memory_gid(int gid)
static void vl_msg_api_free_nolock(void *a)
void vl_msg_api_free(void *a)
const char ** msg_names
Message name vector.
Definition: api_common.h:218
svm_queue_t * vl_input_queue
Definition: memory_shared.h:84
void vl_unmap_shmem_client(void)
vl_api_trace_t * tx_trace
Sent message trace configuration.
Definition: api_common.h:242
#define ASSERT(truth)
u32 data_len
message length not including header
Definition: api_common.h:138
Message header structure.
Definition: api_common.h:135
static void clib_mem_free(void *p)
Definition: mem.h:179
u64 global_pvt_heap_size
size of the global VM private mheap
Definition: api_common.h:297
static void vl_api_default_mem_config(vl_shmem_hdr_t *shmem_hdr)
static void * clib_mem_alloc(uword size)
Definition: mem.h:112
i32 vlib_signal
(Historical) signal-based queue non-empty signal, to be removed
Definition: api_common.h:318
#define foreach_vl_aring_size
Definition: memory_shared.h:66
void vl_api_mem_config(vl_shmem_hdr_t *hdr, vl_api_shm_elem_config_t *config)
void(** msg_endian_handlers)(void *)
Message endian handler vector.
Definition: api_common.h:212
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
const char * name
Definition: svm_common.h:68
u64 uword
Definition: types.h:112
void svm_region_unmap(void *rp_arg)
Definition: svm.c:1166
void svm_client_scan_this_region_nolock(svm_region_t *rp)
Definition: svm.c:1244
int svm_queue_add_nolock(svm_queue_t *q, u8 *elem)
Definition: queue.c:124
static void * vl_msg_api_alloc_internal(int nbytes, int pool, int may_return_null)
Definition: memory_shared.c:45
struct _svm_queue svm_queue_t
void * vl_msg_api_alloc_as_if_client_or_null(int nbytes)
void * vl_mem_api_alloc_as_if_client_w_reg(vl_api_registration_t *reg, int nbytes)
void(** msg_handlers)(void *)
Message handler vector.
Definition: api_common.h:204
void vl_set_api_memory_size(u64 size)
#define vec_foreach(var, vec)
Vector iterator.
void * vl_msg_api_alloc_as_if_client(int nbytes)
void * vl_msg_api_alloc_or_null(int nbytes)
svm_region_t ** mapped_shmem_regions
Definition: api_common.h:261
api_main_t api_main
Definition: api_shared.c:35
void vl_msg_api_send_shmem_nolock(svm_queue_t *q, u8 *elem)
svm_region_t * vlib_rp
Definition: api_common.h:60
u32 vlib_input_queue_length
vpp/vlib input queue length
Definition: api_common.h:321
pthread_mutex_t mutex
Definition: svm_common.h:37
non-blocking call
Definition: queue.h:49
static svm_region_t * root_rp
Definition: svm.c:46
int svm_region_init_chroot(const char *root_path)
Definition: svm.c:864