X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvlibmemory%2Fmemory_shared.c;h=703db9da4ec72ae3de9f71d05d20b09305689c9a;hb=49c1bc845d0bc77542982f85cc64f57e2b5b70f6;hp=c8c071f9a45a0bf377b9e5db1987a224f5d42806;hpb=d6c30d9cae3ec8946c75d9ed87d40c053e2c083a;p=vpp.git diff --git a/src/vlibmemory/memory_shared.c b/src/vlibmemory/memory_shared.c index c8c071f9a45..703db9da4ec 100644 --- a/src/vlibmemory/memory_shared.c +++ b/src/vlibmemory/memory_shared.c @@ -176,6 +176,7 @@ vl_msg_api_alloc_internal (int nbytes, int pool, int may_return_null) rv = clib_mem_alloc (nbytes); rv->q = 0; + rv->gc_mark_timestamp = 0; svm_pop_heap (oldheap); pthread_mutex_unlock (&am->vlib_rp->mutex); @@ -393,13 +394,13 @@ vl_api_default_mem_config (vl_shmem_hdr_t * shmem_hdr) vlib_input_queue_length = am->vlib_input_queue_length; shmem_hdr->vl_input_queue = - svm_queue_init (vlib_input_queue_length, sizeof (uword), - getpid (), am->vlib_signal); + svm_queue_alloc_and_init (vlib_input_queue_length, sizeof (uword), + getpid ()); #define _(sz,n) \ do { \ ring_alloc_t _rp; \ - _rp.rp = svm_queue_init ((n), (sz), 0, 0); \ + _rp.rp = svm_queue_alloc_and_init ((n), (sz), 0); \ _rp.size = (sz); \ _rp.nitems = n; \ _rp.hits = 0; \ @@ -413,7 +414,7 @@ vl_api_default_mem_config (vl_shmem_hdr_t * shmem_hdr) #define _(sz,n) \ do { \ ring_alloc_t _rp; \ - _rp.rp = svm_queue_init ((n), (sz), 0, 0); \ + _rp.rp = svm_queue_alloc_and_init ((n), (sz), 0); \ _rp.size = (sz); \ _rp.nitems = n; \ _rp.hits = 0; \ @@ -428,7 +429,6 @@ vl_api_default_mem_config (vl_shmem_hdr_t * shmem_hdr) void vl_api_mem_config (vl_shmem_hdr_t * hdr, vl_api_shm_elem_config_t * config) { - api_main_t *am = &api_main; vl_api_shm_elem_config_t *c; ring_alloc_t *rp; u32 size; @@ -444,9 +444,8 @@ vl_api_mem_config (vl_shmem_hdr_t * hdr, vl_api_shm_elem_config_t * config) switch (c->type) { case VL_API_QUEUE: - hdr->vl_input_queue = svm_queue_init (c->count, - c->size, - getpid (), am->vlib_signal); + hdr->vl_input_queue = svm_queue_alloc_and_init (c->count, c->size, + getpid ()); continue; case VL_API_VLIB_RING: vec_add2 (hdr->vl_rings, rp, 1); @@ -460,7 +459,7 @@ vl_api_mem_config (vl_shmem_hdr_t * hdr, vl_api_shm_elem_config_t * config) } size = sizeof (ring_alloc_t) + c->size; - rp->rp = svm_queue_init (c->count, size, 0, 0); + rp->rp = svm_queue_alloc_and_init (c->count, size, 0); rp->size = size; rp->nitems = c->count; rp->hits = 0; @@ -516,11 +515,11 @@ vl_map_shmem (const char *region_name, int is_vlib) svm_map_region_args_t _a, *a = &_a; svm_region_t *vlib_rp, *root_rp; api_main_t *am = &api_main; - int i, rv; + int i; struct timespec ts, tsrem; char *vpe_api_region_suffix = "-vpe-api"; - memset (a, 0, sizeof (*a)); + clib_memset (a, 0, sizeof (*a)); if (strstr (region_name, vpe_api_region_suffix)) { @@ -534,9 +533,36 @@ vl_map_shmem (const char *region_name, int is_vlib) if (is_vlib == 0) { - rv = svm_region_init_chroot (am->root_path); - if (rv) - return rv; + int tfd; + u8 *api_name; + /* + * Clients wait for vpp to set up the root / API regioins + */ + if (am->root_path) + api_name = format (0, "/dev/shm/%s-%s%c", am->root_path, + region_name + 1, 0); + else + api_name = format (0, "/dev/shm%s%c", region_name, 0); + + /* Wait up to 100 seconds... */ + for (i = 0; i < 10000; i++) + { + ts.tv_sec = 0; + ts.tv_nsec = 10000 * 1000; /* 10 ms */ + while (nanosleep (&ts, &tsrem) < 0) + ts = tsrem; + tfd = open ((char *) api_name, O_RDWR); + if (tfd >= 0) + break; + } + vec_free (api_name); + if (tfd < 0) + { + clib_warning ("region init fail"); + return -2; + } + close (tfd); + svm_region_init_chroot_uid_gid (am->root_path, getuid (), getgid ()); } if (a->root_path != NULL) @@ -592,7 +618,7 @@ vl_map_shmem (const char *region_name, int is_vlib) ts = tsrem; } /* Mutex buggered, "fix" it */ - memset (&q->mutex, 0, sizeof (q->mutex)); + clib_memset (&q->mutex, 0, sizeof (q->mutex)); clib_warning ("forcibly release main input queue mutex"); mutex_ok: @@ -711,6 +737,14 @@ vl_msg_api_send_shmem (svm_queue_t * q, u8 * elem) if (am->tx_trace && am->tx_trace->enabled) vl_msg_api_trace (am, am->tx_trace, (void *) trace[0]); + /* + * Announce a probable binary API client bug: + * some client's input queue is stuffed. + * The situation may be recoverable, or not. + */ + if (PREDICT_FALSE + (am->vl_clients /* vpp side */ && (q->cursize == q->maxsize))) + clib_warning ("WARNING: client input queue at %llx is stuffed...", q); (void) svm_queue_add (q, elem, 0 /* nowait */ ); }