FD.io VPP  v17.01-9-ge7dcee4
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 #include <vppinfra/format.h>
29 #include <vppinfra/byte_order.h>
30 #include <vppinfra/error.h>
31 #include <vlib/vlib.h>
32 #include <vlib/unix/unix.h>
33 #include <vlibmemory/api.h>
35 
37 
38 #define vl_typedefs
40 #undef vl_typedefs
41 
42 static inline void *
43 vl_msg_api_alloc_internal (int nbytes, int pool, int may_return_null)
44 {
45  int i;
46  msgbuf_t *rv;
47  ring_alloc_t *ap;
49  void *oldheap;
51  api_main_t *am = &api_main;
52 
53  shmem_hdr = am->shmem_hdr;
54 
55  if (shmem_hdr == 0)
56  {
57  clib_warning ("shared memory header NULL");
58  return 0;
59  }
60 
61  /* account for the msgbuf_t header */
62  nbytes += sizeof (msgbuf_t);
63 
64  if (shmem_hdr->vl_rings == 0)
65  {
66  clib_warning ("vl_rings NULL");
67  ASSERT (0);
68  abort ();
69  }
70 
71  if (shmem_hdr->client_rings == 0)
72  {
73  clib_warning ("client_rings NULL");
74  ASSERT (0);
75  abort ();
76  }
77 
78  ap = pool ? shmem_hdr->vl_rings : shmem_hdr->client_rings;
79  for (i = 0; i < vec_len (ap); i++)
80  {
81  /* Too big? */
82  if (nbytes > ap[i].size)
83  {
84  continue;
85  }
86 
87  q = ap[i].rp;
88  if (pool == 0)
89  {
90  pthread_mutex_lock (&q->mutex);
91  }
92  rv = (msgbuf_t *) (&q->data[0] + q->head * q->elsize);
93  /*
94  * Is this item still in use?
95  */
96  if (rv->q)
97  {
98  /* yes, loser; try next larger pool */
99  ap[i].misses++;
100  if (pool == 0)
101  pthread_mutex_unlock (&q->mutex);
102  continue;
103  }
104  /* OK, we have a winner */
105  ap[i].hits++;
106  /*
107  * Remember the source queue, although we
108  * don't need to know the queue to free the item.
109  */
110  rv->q = q;
111  q->head++;
112  if (q->head == q->maxsize)
113  q->head = 0;
114 
115  if (pool == 0)
116  pthread_mutex_unlock (&q->mutex);
117  goto out;
118  }
119 
120  /*
121  * Request too big, or head element of all size-compatible rings
122  * still in use. Fall back to shared-memory malloc.
123  */
124  am->ring_misses++;
125 
126  pthread_mutex_lock (&am->vlib_rp->mutex);
127  oldheap = svm_push_data_heap (am->vlib_rp);
128  if (may_return_null)
129  {
130  rv = clib_mem_alloc_or_null (nbytes);
131  if (PREDICT_FALSE (rv == 0))
132  {
133  svm_pop_heap (oldheap);
134  pthread_mutex_unlock (&am->vlib_rp->mutex);
135  return 0;
136  }
137  }
138  else
139  rv = clib_mem_alloc (nbytes);
140 
141  rv->q = 0;
142  svm_pop_heap (oldheap);
143  pthread_mutex_unlock (&am->vlib_rp->mutex);
144 
145 out:
146  rv->data_len = htonl (nbytes - sizeof (msgbuf_t));
147  return (rv->data);
148 }
149 
150 void *
151 vl_msg_api_alloc (int nbytes)
152 {
153  int pool;
154  api_main_t *am = &api_main;
156 
157  /*
158  * Clients use pool-0, vlib proc uses pool 1
159  */
160  pool = (am->our_pid == shmem_hdr->vl_pid);
161  return vl_msg_api_alloc_internal (nbytes, pool, 0 /* may_return_null */ );
162 }
163 
164 void *
166 {
167  int pool;
168  api_main_t *am = &api_main;
170 
171  pool = (am->our_pid == shmem_hdr->vl_pid);
172  return vl_msg_api_alloc_internal (nbytes, pool, 1 /* may_return_null */ );
173 }
174 
175 void *
177 {
178  return vl_msg_api_alloc_internal (nbytes, 0, 0 /* may_return_null */ );
179 }
180 
181 void *
183 {
184  return vl_msg_api_alloc_internal (nbytes, 0, 1 /* may_return_null */ );
185 }
186 
187 void
189 {
190  msgbuf_t *rv;
191  void *oldheap;
192  api_main_t *am = &api_main;
193 
194  rv = (msgbuf_t *) (((u8 *) a) - offsetof (msgbuf_t, data));
195 
196  /*
197  * Here's the beauty of the scheme. Only one proc/thread has
198  * control of a given message buffer. To free a buffer, we just clear the
199  * queue field, and leave. No locks, no hits, no errors...
200  */
201  if (rv->q)
202  {
203  rv->q = 0;
204  return;
205  }
206 
207  pthread_mutex_lock (&am->vlib_rp->mutex);
208  oldheap = svm_push_data_heap (am->vlib_rp);
209  clib_mem_free (rv);
210  svm_pop_heap (oldheap);
211  pthread_mutex_unlock (&am->vlib_rp->mutex);
212 }
213 
214 static void
216 {
217  msgbuf_t *rv;
218  void *oldheap;
219  api_main_t *am = &api_main;
220 
221  rv = (msgbuf_t *) (((u8 *) a) - offsetof (msgbuf_t, data));
222  /*
223  * Here's the beauty of the scheme. Only one proc/thread has
224  * control of a given message buffer. To free a buffer, we just clear the
225  * queue field, and leave. No locks, no hits, no errors...
226  */
227  if (rv->q)
228  {
229  rv->q = 0;
230  return;
231  }
232 
233  oldheap = svm_push_data_heap (am->vlib_rp);
234  clib_mem_free (rv);
235  svm_pop_heap (oldheap);
236 }
237 
238 void
240 {
241  api_main_t *am = &api_main;
242 
243  am->root_path = name;
244 }
245 
246 void
248 {
249  api_main_t *am = &api_main;
250 
251  am->api_uid = uid;
252 }
253 
254 void
256 {
257  api_main_t *am = &api_main;
258 
259  am->api_gid = gid;
260 }
261 
262 void
264 {
265  api_main_t *am = &api_main;
266 
267  am->global_baseva = baseva;
268 }
269 
270 void
272 {
273  api_main_t *am = &api_main;
274 
275  am->global_size = size;
276 }
277 
278 void
280 {
281  api_main_t *am = &api_main;
282 
283  am->api_size = size;
284 }
285 
286 void
288 {
289  api_main_t *am = &api_main;
290 
292 }
293 
294 void
296 {
297  api_main_t *am = &api_main;
298 
299  am->api_pvt_heap_size = size;
300 }
301 
302 int
303 vl_map_shmem (char *region_name, int is_vlib)
304 {
305  svm_map_region_args_t _a, *a = &_a;
306  svm_region_t *vlib_rp, *root_rp;
307  void *oldheap;
309  api_main_t *am = &api_main;
310  int i;
311  struct timespec ts, tsrem;
312 
313  if (is_vlib == 0)
315 
316  memset (a, 0, sizeof (*a));
317 
318  a->name = region_name;
319  a->size = am->api_size ? am->api_size : (16 << 20);
320  a->flags = SVM_FLAGS_MHEAP;
321  a->uid = am->api_uid;
322  a->gid = am->api_gid;
324 
325  vlib_rp = svm_region_find_or_create (a);
326 
327  if (vlib_rp == 0)
328  return (-2);
329 
330  pthread_mutex_lock (&vlib_rp->mutex);
331  /* Has someone else set up the shared-memory variable table? */
332  if (vlib_rp->user_ctx)
333  {
334  am->shmem_hdr = (void *) vlib_rp->user_ctx;
335  am->our_pid = getpid ();
336  if (is_vlib)
337  {
339  uword old_msg;
340  /*
341  * application restart. Reset cached pids, API message
342  * rings, list of clients; otherwise, various things
343  * fail. (e.g. queue non-empty notification)
344  */
345 
346  /* ghosts keep the region from disappearing properly */
349  q = am->shmem_hdr->vl_input_queue;
350  am->shmem_hdr->vl_pid = getpid ();
351  q->consumer_pid = am->shmem_hdr->vl_pid;
352  /* Drain the input queue, freeing msgs */
353  for (i = 0; i < 10; i++)
354  {
355  if (pthread_mutex_trylock (&q->mutex) == 0)
356  {
357  pthread_mutex_unlock (&q->mutex);
358  goto mutex_ok;
359  }
360  ts.tv_sec = 0;
361  ts.tv_nsec = 10000 * 1000; /* 10 ms */
362  while (nanosleep (&ts, &tsrem) < 0)
363  ts = tsrem;
364  }
365  /* Mutex buggered, "fix" it */
366  memset (&q->mutex, 0, sizeof (q->mutex));
367  clib_warning ("forcibly release main input queue mutex");
368 
369  mutex_ok:
370  am->vlib_rp = vlib_rp;
372  (u8 *) & old_msg,
373  1 /* nowait */ )
374  != -2 /* queue underflow */ )
375  {
376  vl_msg_api_free_nolock ((void *) old_msg);
378  }
379  pthread_mutex_unlock (&vlib_rp->mutex);
380  root_rp = svm_get_root_rp ();
381  ASSERT (root_rp);
382  /* Clean up the root region client list */
383  pthread_mutex_lock (&root_rp->mutex);
385  pthread_mutex_unlock (&root_rp->mutex);
386  }
387  else
388  {
389  pthread_mutex_unlock (&vlib_rp->mutex);
390  }
391  am->vlib_rp = vlib_rp;
392  vec_add1 (am->mapped_shmem_regions, vlib_rp);
393  return 0;
394  }
395  /* Clients simply have to wait... */
396  if (!is_vlib)
397  {
398  pthread_mutex_unlock (&vlib_rp->mutex);
399 
400  /* Wait up to 100 seconds... */
401  for (i = 0; i < 10000; i++)
402  {
403  ts.tv_sec = 0;
404  ts.tv_nsec = 10000 * 1000; /* 10 ms */
405  while (nanosleep (&ts, &tsrem) < 0)
406  ts = tsrem;
407  if (vlib_rp->user_ctx)
408  goto ready;
409  }
410  /* Clean up and leave... */
411  svm_region_unmap (vlib_rp);
412  clib_warning ("region init fail");
413  return (-2);
414 
415  ready:
416  am->shmem_hdr = (void *) vlib_rp->user_ctx;
417  am->our_pid = getpid ();
418  am->vlib_rp = vlib_rp;
419  vec_add1 (am->mapped_shmem_regions, vlib_rp);
420  return 0;
421  }
422 
423  /* Nope, it's our problem... */
424 
425  oldheap = svm_push_data_heap (vlib_rp);
426 
427  vec_validate (shmem_hdr, 0);
428  shmem_hdr->version = VL_SHM_VERSION;
429 
430  /* vlib main input queue */
431  shmem_hdr->vl_input_queue =
432  unix_shared_memory_queue_init (1024, sizeof (uword), getpid (),
433  am->vlib_signal);
434 
435  /* Set up the msg ring allocator */
436 #define _(sz,n) \
437  do { \
438  ring_alloc_t _rp; \
439  _rp.rp = unix_shared_memory_queue_init ((n), (sz), 0, 0); \
440  _rp.size = (sz); \
441  _rp.nitems = n; \
442  _rp.hits = 0; \
443  _rp.misses = 0; \
444  vec_add1(shmem_hdr->vl_rings, _rp); \
445  } while (0);
446 
448 #undef _
449 
450 #define _(sz,n) \
451  do { \
452  ring_alloc_t _rp; \
453  _rp.rp = unix_shared_memory_queue_init ((n), (sz), 0, 0); \
454  _rp.size = (sz); \
455  _rp.nitems = n; \
456  _rp.hits = 0; \
457  _rp.misses = 0; \
458  vec_add1(shmem_hdr->client_rings, _rp); \
459  } while (0);
460 
462 #undef _
463 
464  am->shmem_hdr = shmem_hdr;
465  am->vlib_rp = vlib_rp;
466  am->our_pid = getpid ();
467  if (is_vlib)
468  am->shmem_hdr->vl_pid = am->our_pid;
469 
470  svm_pop_heap (oldheap);
471 
472  /*
473  * After absolutely everything that a client might see is set up,
474  * declare the shmem region valid
475  */
476  vlib_rp->user_ctx = shmem_hdr;
477 
478  pthread_mutex_unlock (&vlib_rp->mutex);
479  vec_add1 (am->mapped_shmem_regions, vlib_rp);
480  return 0;
481 }
482 
483 void
485 {
486  api_main_t *am = &api_main;
487 
488  vec_add1 (am->mapped_shmem_regions, rp);
489 }
490 
491 void
493 {
494  svm_region_t *rp;
495  int i;
496  api_main_t *am = &api_main;
497 
498  if (!svm_get_root_rp ())
499  return;
500 
501  for (i = 0; i < vec_len (am->mapped_shmem_regions); i++)
502  {
503  rp = am->mapped_shmem_regions[i];
504  svm_region_unmap (rp);
505  }
506 
508  am->shmem_hdr = 0;
509 
510  svm_region_exit ();
511  /* $$$ more careful cleanup, valgrind run... */
512  vec_free (am->msg_handlers);
515 }
516 
517 void
519 {
520  api_main_t *am = &api_main;
521  uword *trace = (uword *) elem;
522 
523  if (am->tx_trace && am->tx_trace->enabled)
524  vl_msg_api_trace (am, am->tx_trace, (void *) trace[0]);
525 
526  (void) unix_shared_memory_queue_add (q, elem, 0 /* nowait */ );
527 }
528 
529 void
531 {
532  api_main_t *am = &api_main;
533  uword *trace = (uword *) elem;
534 
535  if (am->tx_trace && am->tx_trace->enabled)
536  vl_msg_api_trace (am, am->tx_trace, (void *) trace[0]);
537 
538  (void) unix_shared_memory_queue_add_nolock (q, elem);
539 }
540 
541 static void
543 {
544  serialize_main_t _sm, *sm = &_sm;
545  api_main_t *am = &api_main;
546  u8 *tblv;
547  u32 nmsgs;
548  int i;
549  u8 *name_and_crc;
550  u32 msg_index;
551 
552  am->my_client_index = mp->index;
554 
555  /* Clean out any previous hash table (unlikely) */
557  {
558  int i;
559  u8 **keys = 0;
560  hash_pair_t *hp;
561  /* *INDENT-OFF* */
563  ({
564  vec_add1 (keys, (u8 *) hp->key);
565  }));
566  /* *INDENT-ON* */
567  for (i = 0; i < vec_len (keys); i++)
568  vec_free (keys[i]);
569  vec_free (keys);
570  }
571 
573 
574  /* Recreate the vnet-side API message handler table */
575  tblv = (u8 *) mp->message_table;
576  serialize_open_vector (sm, tblv);
577  unserialize_integer (sm, &nmsgs, sizeof (u32));
578 
579  for (i = 0; i < nmsgs; i++)
580  {
582  unserialize_cstring (sm, (char **) &name_and_crc);
583  hash_set_mem (am->msg_index_by_name_and_crc, name_and_crc, msg_index);
584  }
585 }
586 
587 u32
588 vl_api_get_msg_index (u8 * name_and_crc)
589 {
590  api_main_t *am = &api_main;
591  uword *p;
592 
594  {
595  p = hash_get_mem (am->msg_index_by_name_and_crc, name_and_crc);
596  if (p)
597  return p[0];
598  }
599  return ~0;
600 }
601 
602 int
603 vl_client_connect (char *name, int ctx_quota, int input_queue_size)
604 {
605  svm_region_t *svm;
608  unix_shared_memory_queue_t *vl_input_queue;
610  int rv = 0;
611  void *oldheap;
612  api_main_t *am = &api_main;
613 
614  if (am->my_registration)
615  {
616  clib_warning ("client %s already connected...", name);
617  return -1;
618  }
619 
620  if (am->vlib_rp == 0)
621  {
622  clib_warning ("am->vlib_rp NULL");
623  return -1;
624  }
625 
626  svm = am->vlib_rp;
627  shmem_hdr = am->shmem_hdr;
628 
629  if (shmem_hdr == 0 || shmem_hdr->vl_input_queue == 0)
630  {
631  clib_warning ("shmem_hdr / input queue NULL");
632  return -1;
633  }
634 
635  pthread_mutex_lock (&svm->mutex);
636  oldheap = svm_push_data_heap (svm);
637  vl_input_queue =
638  unix_shared_memory_queue_init (input_queue_size, sizeof (uword),
639  getpid (), 0);
640  pthread_mutex_unlock (&svm->mutex);
641  svm_pop_heap (oldheap);
642 
643  am->my_client_index = ~0;
644  am->my_registration = 0;
645  am->vl_input_queue = vl_input_queue;
646 
648  memset (mp, 0, sizeof (*mp));
649  mp->_vl_msg_id = ntohs (VL_API_MEMCLNT_CREATE);
650  mp->ctx_quota = ctx_quota;
651  mp->input_queue = (uword) vl_input_queue;
652  strncpy ((char *) mp->name, name, sizeof (mp->name) - 1);
653 
654  vl_msg_api_send_shmem (shmem_hdr->vl_input_queue, (u8 *) & mp);
655 
656  while (1)
657  {
658  int qstatus;
659  struct timespec ts, tsrem;
660  int i;
661 
662  /* Wait up to 10 seconds */
663  for (i = 0; i < 1000; i++)
664  {
665  qstatus = unix_shared_memory_queue_sub (vl_input_queue, (u8 *) & rp,
666  1 /* nowait */ );
667  if (qstatus == 0)
668  goto read_one_msg;
669  ts.tv_sec = 0;
670  ts.tv_nsec = 10000 * 1000; /* 10 ms */
671  while (nanosleep (&ts, &tsrem) < 0)
672  ts = tsrem;
673  }
674  /* Timeout... */
675  clib_warning ("memclnt_create_reply timeout");
676  return -1;
677 
678  read_one_msg:
679  if (ntohs (rp->_vl_msg_id) != VL_API_MEMCLNT_CREATE_REPLY)
680  {
681  clib_warning ("unexpected reply: id %d", ntohs (rp->_vl_msg_id));
682  continue;
683  }
684  rv = clib_net_to_host_u32 (rp->response);
685 
686  vl_msg_api_handler ((void *) rp);
687  break;
688  }
689  return (rv);
690 }
691 
692 static void
694 {
695  void *oldheap;
696  api_main_t *am = &api_main;
697 
698  pthread_mutex_lock (&am->vlib_rp->mutex);
699  oldheap = svm_push_data_heap (am->vlib_rp);
701  pthread_mutex_unlock (&am->vlib_rp->mutex);
702  svm_pop_heap (oldheap);
703 
704  am->my_client_index = ~0;
705  am->my_registration = 0;
706  am->vl_input_queue = 0;
707 }
708 
709 void
711 {
714  unix_shared_memory_queue_t *vl_input_queue;
716  time_t begin;
717  api_main_t *am = &api_main;
718 
719  ASSERT (am->vlib_rp);
720  shmem_hdr = am->shmem_hdr;
721  ASSERT (shmem_hdr && shmem_hdr->vl_input_queue);
722 
723  vl_input_queue = am->vl_input_queue;
724 
726  memset (mp, 0, sizeof (*mp));
727  mp->_vl_msg_id = ntohs (VL_API_MEMCLNT_DELETE);
728  mp->index = am->my_client_index;
729  mp->handle = (uword) am->my_registration;
730 
731  vl_msg_api_send_shmem (shmem_hdr->vl_input_queue, (u8 *) & mp);
732 
733  /*
734  * Have to be careful here, in case the client is disconnecting
735  * because e.g. the vlib process died, or is unresponsive.
736  */
737 
738  begin = time (0);
739  while (1)
740  {
741  time_t now;
742 
743  now = time (0);
744 
745  if (now >= (begin + 2))
746  {
747  clib_warning ("peer unresponsive, give up");
748  am->my_client_index = ~0;
749  am->my_registration = 0;
750  am->shmem_hdr = 0;
751  break;
752  }
753  if (unix_shared_memory_queue_sub (vl_input_queue, (u8 *) & rp, 1) < 0)
754  continue;
755 
756  /* drain the queue */
757  if (ntohs (rp->_vl_msg_id) != VL_API_MEMCLNT_DELETE_REPLY)
758  {
759  vl_msg_api_handler ((void *) rp);
760  continue;
761  }
762  vl_msg_api_handler ((void *) rp);
763  break;
764  }
765 }
766 
767 static inline vl_api_registration_t *
769 {
770  vl_api_registration_t **regpp;
771  vl_api_registration_t *regp;
772  api_main_t *am = &api_main;
773  u32 index;
774 
775  index = vl_msg_api_handle_get_index (handle);
777  != vl_msg_api_handle_get_epoch (handle))
778  {
780  return 0;
781  }
782 
783  regpp = am->vl_clients + index;
784 
785  if (pool_is_free (am->vl_clients, regpp))
786  {
788  return 0;
789  }
790  regp = *regpp;
791  return (regp);
792 }
793 
796 {
798 }
799 
802 {
803  vl_api_registration_t *regp;
804 
806  if (!regp)
807  return 0;
808  return (regp->vl_input_queue);
809 }
810 
811 #define foreach_api_client_msg \
812 _(MEMCLNT_CREATE_REPLY, memclnt_create_reply) \
813 _(MEMCLNT_DELETE_REPLY, memclnt_delete_reply)
814 
815 int
816 vl_client_api_map (char *region_name)
817 {
818  int rv;
819 
820  if ((rv = vl_map_shmem (region_name, 0 /* is_vlib */ )) < 0)
821  {
822  return rv;
823  }
824 
825 #define _(N,n) \
826  vl_msg_api_set_handlers(VL_API_##N, 0 /* name */, \
827  vl_api_##n##_t_handler, \
828  0/* cleanup */, 0/* endian */, 0/* print */, \
829  sizeof(vl_api_##n##_t), 1);
831 #undef _
832  return 0;
833 }
834 
835 void
837 {
838  vl_unmap_shmem ();
839 }
840 
841 /*
842  * fd.io coding-style-patch-verification: ON
843  *
844  * Local Variables:
845  * eval: (c-set-style "gnu")
846  * End:
847  */
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:396
u64 pvt_heap_size
Definition: svm.h:76
u64 api_pvt_heap_size
Definition: api.h:167
void vl_client_api_unmap(void)
svm_region_t * svm_get_root_rp(void)
Definition: svm.c:54
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:343
int vl_client_api_map(char *region_name)
static void svm_pop_heap(void *oldheap)
Definition: svm.h:190
static u64 unserialize_likely_small_unsigned_integer(serialize_main_t *m)
Definition: serialize.h:254
a
Definition: bitmap.h:516
void vl_set_global_memory_baseva(u64 baseva)
static vlib_cli_command_t trace
(constructor) VLIB_CLI_COMMAND (trace)
Definition: memory_vlib.c:1115
#define foreach_clnt_aring_size
Definition: api.h:60
u64 api_size
Definition: api.h:161
u32 application_restarts
Definition: api.h:84
void vl_set_memory_uid(int uid)
unix_shared_memory_queue_t * vl_input_queue
Definition: api.h:73
int my_client_index
Definition: api.h:176
void unix_shared_memory_queue_free(unix_shared_memory_queue_t *q)
void vl_set_global_pvt_heap_size(u64 size)
void vl_unmap_shmem(void)
int vl_client_connect(char *name, int ctx_quota, int input_queue_size)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:482
int api_uid
Definition: api.h:150
#define hash_set_mem(h, key, value)
Definition: hash.h:274
ring_alloc_t * client_rings
Definition: api.h:81
u8 data[0]
Definition: api.h:216
#define pool_is_free(P, E)
Use free bitmap to query whether given element is free.
Definition: pool.h:203
static vl_api_registration_t * vl_api_client_index_to_registration_internal(u32 handle)
void * vl_msg_api_alloc(int nbytes)
int api_gid
Definition: api.h:152
void vl_set_memory_root_path(char *name)
unix_shared_memory_queue_t * vl_input_queue
Definition: api.h:170
void vl_set_global_memory_size(u64 size)
#define SVM_FLAGS_MHEAP
Definition: svm.h:32
u32 vl_api_get_msg_index(u8 *name_and_crc)
api_main_t api_main
Definition: api_shared.c:39
int our_pid
Definition: api.h:132
vl_api_registration_t * my_registration
Definition: api.h:182
u32 ring_misses
Definition: api.h:126
static void * svm_push_data_heap(svm_region_t *rp)
Definition: svm.h:182
vl_api_registration_t ** vl_clients
Definition: api.h:136
void * svm_region_find_or_create(svm_map_region_args_t *a)
Definition: svm.c:839
volatile void * user_ctx
Definition: svm.h:52
char * name
Definition: svm.h:73
int vl_map_shmem(char *region_name, int is_vlib)
svm_region_t * vlib_rp
Definition: api.h:133
int unix_shared_memory_queue_add_nolock(unix_shared_memory_queue_t *q, u8 *elem)
#define clib_warning(format, args...)
Definition: error.h:59
unsigned long u64
Definition: types.h:89
struct vl_shmem_hdr_ * shmem_hdr
Definition: api.h:135
#define hash_create_string(elts, value_bytes)
Definition: hash.h:652
vl_shmem_hdr_t * shmem_hdr
int unix_shared_memory_queue_add(unix_shared_memory_queue_t *q, u8 *elem, int nowait)
volatile int vl_pid
Definition: api.h:70
void vl_register_mapped_shmem_region(svm_region_t *rp)
vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
void(** msg_print_handlers)(void *, void *)
Definition: api.h:121
void vl_msg_api_send_shmem_nolock(unix_shared_memory_queue_t *q, u8 *elem)
void vl_msg_api_send_shmem(unix_shared_memory_queue_t *q, u8 *elem)
#define PREDICT_FALSE(x)
Definition: clib.h:97
void svm_region_exit()
Definition: svm.c:1078
static u32 vl_msg_api_handle_get_index(u32 index)
Definition: api.h:103
struct msgbuf_ msgbuf_t
void vl_set_api_pvt_heap_size(u64 size)
void unserialize_cstring(serialize_main_t *m, char **s)
Definition: serialize.c:178
u64 global_size
Definition: api.h:158
u8 enabled
Definition: api.h:82
int unix_shared_memory_queue_sub(unix_shared_memory_queue_t *q, u8 *elem, int nowait)
ring_alloc_t * vl_rings
Definition: api.h:78
static void * clib_mem_alloc_or_null(uword size)
Definition: mem.h:125
void serialize_open_vector(serialize_main_t *m, u8 *vector)
Definition: serialize.c:908
u64 global_baseva
Definition: api.h:155
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:300
unix_shared_memory_queue_t * vl_input_queue
Definition: api.h:53
unix_shared_memory_queue_t * q
Definition: api.h:213
void vl_msg_api_trace(api_main_t *am, vl_api_trace_t *tp, void *msg)
Definition: api_shared.c:84
void vl_set_memory_gid(int gid)
static void vl_msg_api_free_nolock(void *a)
static void unserialize_integer(serialize_main_t *m, void *x, u32 n_bytes)
Definition: serialize.h:201
void vl_msg_api_free(void *a)
#define VL_SHM_VERSION
Definition: api.h:91
#define foreach_vl_aring_size
Definition: api.h:55
int version
Definition: api.h:67
vl_api_trace_t * tx_trace
Definition: api.h:129
#define ASSERT(truth)
#define VL_API_EPOCH_MASK
Definition: api.h:93
unsigned int u32
Definition: types.h:88
void svm_region_init_chroot(char *root_path)
Definition: svm.c:799
static void vl_api_memclnt_create_reply_t_handler(vl_api_memclnt_create_reply_t *mp)
u32 data_len
Definition: api.h:214
Definition: api.h:211
unix_shared_memory_queue_t * unix_shared_memory_queue_init(int nels, int elsize, int consumer_pid, int signal_when_queue_non_empty)
u64 size
Definition: vhost-user.h:74
static void clib_mem_free(void *p)
Definition: mem.h:176
u32 misses
Definition: api.h:47
u64 global_pvt_heap_size
Definition: api.h:164
static void * clib_mem_alloc(uword size)
Definition: mem.h:109
u32 restart_reclaims
Definition: api.h:87
i32 vlib_signal
Definition: api.h:184
u64 uword
Definition: types.h:112
char * root_path
Definition: api.h:190
#define foreach_api_client_msg
void(** msg_endian_handlers)(void *)
Definition: api.h:120
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
unsigned char u8
Definition: types.h:56
#define hash_foreach_pair(p, v, body)
Iterate over hash pairs.
Definition: hash.h:349
void vl_msg_api_handler(void *the_msg)
Definition: api_shared.c:549
void svm_region_unmap(void *rp_arg)
Definition: svm.c:958
void svm_client_scan_this_region_nolock(svm_region_t *rp)
Definition: svm.c:1126
unix_shared_memory_queue_t * vl_api_client_index_to_input_queue(u32 index)
static void vl_api_memclnt_delete_reply_t_handler(vl_api_memclnt_delete_reply_t *mp)
static void * vl_msg_api_alloc_internal(int nbytes, int pool, int may_return_null)
Definition: memory_shared.c:43
unix_shared_memory_queue_t * rp
Definition: api.h:43
void * vl_msg_api_alloc_as_if_client_or_null(int nbytes)
#define hash_get_mem(h, key)
Definition: hash.h:268
void vl_msg_api_increment_missing_client_counter(void)
Definition: api_shared.c:54
void(** msg_handlers)(void *)
Definition: api.h:117
void vl_set_api_memory_size(u64 size)
void * vl_msg_api_alloc_as_if_client(int nbytes)
static u32 vl_msg_api_handle_get_epoch(u32 index)
Definition: api.h:97
void * vl_msg_api_alloc_or_null(int nbytes)
svm_region_t ** mapped_shmem_regions
Definition: api.h:134
uword * msg_index_by_name_and_crc
Definition: api.h:187
u32 hits
Definition: api.h:46
void vl_client_disconnect(void)
pthread_mutex_t mutex
Definition: svm.h:42
struct _unix_shared_memory_queue unix_shared_memory_queue_t
static svm_region_t * root_rp
Definition: svm.c:46