b927f95f17b30c157a881992f6f2532c2303c4c3
[vpp.git] / src / vlibmemory / memory_shared.c
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 <vppinfra/elog.h>
33 #include <svm/queue.h>
34 #include <vlib/vlib.h>
35 #include <vlib/unix/unix.h>
36 #include <vlibmemory/memory_api.h>
37 #include <vlibmemory/vl_memory_msg_enum.h>
38
39 #define vl_typedefs
40 #include <vlibmemory/vl_memory_api_h.h>
41 #undef vl_typedefs
42
43 #define DEBUG_MESSAGE_BUFFER_OVERRUN 0
44
45 CLIB_NOSANITIZE_ADDR static inline void *
46 vl_msg_api_alloc_internal (svm_region_t * vlib_rp, int nbytes, int pool,
47                            int may_return_null)
48 {
49   int i;
50   msgbuf_t *rv;
51   ring_alloc_t *ap;
52   svm_queue_t *q;
53   void *oldheap;
54   vl_shmem_hdr_t *shmem_hdr;
55   api_main_t *am = &api_main;
56
57   shmem_hdr = (void *) vlib_rp->user_ctx;
58
59 #if DEBUG_MESSAGE_BUFFER_OVERRUN > 0
60   nbytes += 4;
61 #endif
62
63   ASSERT (pool == 0 || vlib_get_thread_index () == 0);
64
65   if (shmem_hdr == 0)
66     {
67       clib_warning ("shared memory header NULL");
68       return 0;
69     }
70
71   /* account for the msgbuf_t header */
72   nbytes += sizeof (msgbuf_t);
73
74   if (shmem_hdr->vl_rings == 0)
75     {
76       clib_warning ("vl_rings NULL");
77       ASSERT (0);
78       abort ();
79     }
80
81   if (shmem_hdr->client_rings == 0)
82     {
83       clib_warning ("client_rings NULL");
84       ASSERT (0);
85       abort ();
86     }
87
88   ap = pool ? shmem_hdr->vl_rings : shmem_hdr->client_rings;
89   for (i = 0; i < vec_len (ap); i++)
90     {
91       /* Too big? */
92       if (nbytes > ap[i].size)
93         {
94           continue;
95         }
96
97       q = ap[i].rp;
98       if (pool == 0)
99         {
100           pthread_mutex_lock (&q->mutex);
101         }
102       rv = (msgbuf_t *) (&q->data[0] + q->head * q->elsize);
103       /*
104        * Is this item still in use?
105        */
106       if (rv->q)
107         {
108           u32 now = (u32) time (0);
109
110           if (PREDICT_TRUE (rv->gc_mark_timestamp == 0))
111             rv->gc_mark_timestamp = now;
112           else
113             {
114               if (now - rv->gc_mark_timestamp > 10)
115                 {
116                   if (CLIB_DEBUG > 0)
117                     {
118                       u16 *msg_idp, msg_id;
119                       clib_warning
120                         ("garbage collect pool %d ring %d index %d", pool, i,
121                          q->head);
122                       msg_idp = (u16 *) (rv->data);
123                       msg_id = clib_net_to_host_u16 (*msg_idp);
124                       if (msg_id < vec_len (api_main.msg_names))
125                         clib_warning ("msg id %d name %s", (u32) msg_id,
126                                       api_main.msg_names[msg_id]);
127                     }
128                   shmem_hdr->garbage_collects++;
129                   goto collected;
130                 }
131             }
132
133
134           /* yes, loser; try next larger pool */
135           ap[i].misses++;
136           if (pool == 0)
137             pthread_mutex_unlock (&q->mutex);
138           continue;
139         }
140     collected:
141
142       /* OK, we have a winner */
143       ap[i].hits++;
144       /*
145        * Remember the source queue, although we
146        * don't need to know the queue to free the item.
147        */
148       rv->q = q;
149       rv->gc_mark_timestamp = 0;
150       q->head++;
151       if (q->head == q->maxsize)
152         q->head = 0;
153
154       if (pool == 0)
155         pthread_mutex_unlock (&q->mutex);
156       goto out;
157     }
158
159   /*
160    * Request too big, or head element of all size-compatible rings
161    * still in use. Fall back to shared-memory malloc.
162    */
163   am->ring_misses++;
164
165   pthread_mutex_lock (&vlib_rp->mutex);
166   oldheap = svm_push_data_heap (vlib_rp);
167   if (may_return_null)
168     {
169       rv = clib_mem_alloc_or_null (nbytes);
170       if (PREDICT_FALSE (rv == 0))
171         {
172           svm_pop_heap (oldheap);
173           pthread_mutex_unlock (&vlib_rp->mutex);
174           return 0;
175         }
176     }
177   else
178     rv = clib_mem_alloc (nbytes);
179
180   rv->q = 0;
181   rv->gc_mark_timestamp = 0;
182   svm_pop_heap (oldheap);
183   pthread_mutex_unlock (&vlib_rp->mutex);
184
185 out:
186 #if DEBUG_MESSAGE_BUFFER_OVERRUN > 0
187   {
188     nbytes -= 4;
189     u32 *overrun;
190     overrun = (u32 *) (rv->data + nbytes - sizeof (msgbuf_t));
191     *overrun = 0x1badbabe;
192   }
193 #endif
194   rv->data_len = htonl (nbytes - sizeof (msgbuf_t));
195
196   VL_MSG_API_UNPOISON (rv->data);
197   return (rv->data);
198 }
199
200 void *
201 vl_msg_api_alloc (int nbytes)
202 {
203   int pool;
204   api_main_t *am = &api_main;
205   vl_shmem_hdr_t *shmem_hdr = am->shmem_hdr;
206
207   /*
208    * Clients use pool-0, vlib proc uses pool 1
209    */
210   pool = (am->our_pid == shmem_hdr->vl_pid);
211   return vl_msg_api_alloc_internal (am->vlib_rp, nbytes, pool,
212                                     0 /* may_return_null */ );
213 }
214
215 void *
216 vl_msg_api_alloc_zero (int nbytes)
217 {
218   void *ret;
219
220   ret = vl_msg_api_alloc (nbytes);
221   clib_memset (ret, 0, nbytes);
222   return ret;
223 }
224
225 void *
226 vl_msg_api_alloc_or_null (int nbytes)
227 {
228   int pool;
229   api_main_t *am = &api_main;
230   vl_shmem_hdr_t *shmem_hdr = am->shmem_hdr;
231
232   pool = (am->our_pid == shmem_hdr->vl_pid);
233   return vl_msg_api_alloc_internal (am->vlib_rp, nbytes, pool,
234                                     1 /* may_return_null */ );
235 }
236
237 void *
238 vl_msg_api_alloc_as_if_client (int nbytes)
239 {
240   return vl_msg_api_alloc_internal (api_main.vlib_rp, nbytes, 0,
241                                     0 /* may_return_null */ );
242 }
243
244 void *
245 vl_msg_api_alloc_zero_as_if_client (int nbytes)
246 {
247   void *ret;
248
249   ret = vl_msg_api_alloc_as_if_client (nbytes);
250   clib_memset (ret, 0, nbytes);
251   return ret;
252 }
253
254 void *
255 vl_msg_api_alloc_as_if_client_or_null (int nbytes)
256 {
257   return vl_msg_api_alloc_internal (api_main.vlib_rp, nbytes, 0,
258                                     1 /* may_return_null */ );
259 }
260
261 void *
262 vl_mem_api_alloc_as_if_client_w_reg (vl_api_registration_t * reg, int nbytes)
263 {
264   return vl_msg_api_alloc_internal (reg->vlib_rp, nbytes, 0,
265                                     0 /* may_return_null */ );
266 }
267
268 void
269 vl_msg_api_free_w_region (svm_region_t * vlib_rp, void *a)
270 {
271   msgbuf_t *rv;
272   void *oldheap;
273
274   rv = (msgbuf_t *) (((u8 *) a) - offsetof (msgbuf_t, data));
275
276   /*
277    * Here's the beauty of the scheme.  Only one proc/thread has
278    * control of a given message buffer. To free a buffer, we just clear the
279    * queue field, and leave. No locks, no hits, no errors...
280    */
281   if (rv->q)
282     {
283       rv->q = 0;
284       rv->gc_mark_timestamp = 0;
285 #if DEBUG_MESSAGE_BUFFER_OVERRUN > 0
286       {
287         u32 *overrun;
288         overrun = (u32 *) (rv->data + ntohl (rv->data_len));
289         ASSERT (*overrun == 0x1badbabe);
290       }
291 #endif
292       VL_MSG_API_POISON (rv->data);
293       return;
294     }
295
296   pthread_mutex_lock (&vlib_rp->mutex);
297   oldheap = svm_push_data_heap (vlib_rp);
298
299 #if DEBUG_MESSAGE_BUFFER_OVERRUN > 0
300   {
301     u32 *overrun;
302     overrun = (u32 *) (rv->data + ntohl (rv->data_len));
303     ASSERT (*overrun == 0x1badbabe);
304   }
305 #endif
306
307   clib_mem_free (rv);
308   svm_pop_heap (oldheap);
309   pthread_mutex_unlock (&vlib_rp->mutex);
310 }
311
312 void
313 vl_msg_api_free (void *a)
314 {
315   vl_msg_api_free_w_region (api_main.vlib_rp, a);
316 }
317
318 static void
319 vl_msg_api_free_nolock (void *a)
320 {
321   msgbuf_t *rv;
322   void *oldheap;
323   api_main_t *am = &api_main;
324
325   rv = (msgbuf_t *) (((u8 *) a) - offsetof (msgbuf_t, data));
326   /*
327    * Here's the beauty of the scheme.  Only one proc/thread has
328    * control of a given message buffer. To free a buffer, we just clear the
329    * queue field, and leave. No locks, no hits, no errors...
330    */
331   if (rv->q)
332     {
333       rv->q = 0;
334       VL_MSG_API_POISON (rv->data);
335       return;
336     }
337
338   oldheap = svm_push_data_heap (am->vlib_rp);
339   clib_mem_free (rv);
340   svm_pop_heap (oldheap);
341 }
342
343 void
344 vl_set_memory_root_path (const char *name)
345 {
346   api_main_t *am = &api_main;
347
348   am->root_path = name;
349 }
350
351 void
352 vl_set_memory_uid (int uid)
353 {
354   api_main_t *am = &api_main;
355
356   am->api_uid = uid;
357 }
358
359 void
360 vl_set_memory_gid (int gid)
361 {
362   api_main_t *am = &api_main;
363
364   am->api_gid = gid;
365 }
366
367 void
368 vl_set_global_memory_baseva (u64 baseva)
369 {
370   api_main_t *am = &api_main;
371
372   am->global_baseva = baseva;
373 }
374
375 void
376 vl_set_global_memory_size (u64 size)
377 {
378   api_main_t *am = &api_main;
379
380   am->global_size = size;
381 }
382
383 void
384 vl_set_api_memory_size (u64 size)
385 {
386   api_main_t *am = &api_main;
387
388   am->api_size = size;
389 }
390
391 void
392 vl_set_global_pvt_heap_size (u64 size)
393 {
394   api_main_t *am = &api_main;
395
396   am->global_pvt_heap_size = size;
397 }
398
399 void
400 vl_set_api_pvt_heap_size (u64 size)
401 {
402   api_main_t *am = &api_main;
403
404   am->api_pvt_heap_size = size;
405 }
406
407 static void
408 vl_api_default_mem_config (vl_shmem_hdr_t * shmem_hdr)
409 {
410   api_main_t *am = &api_main;
411   u32 vlib_input_queue_length;
412
413   /* vlib main input queue */
414   vlib_input_queue_length = 1024;
415   if (am->vlib_input_queue_length)
416     vlib_input_queue_length = am->vlib_input_queue_length;
417
418   shmem_hdr->vl_input_queue =
419     svm_queue_alloc_and_init (vlib_input_queue_length, sizeof (uword),
420                               getpid ());
421
422 #define _(sz,n)                                                 \
423     do {                                                        \
424         ring_alloc_t _rp;                                       \
425         _rp.rp = svm_queue_alloc_and_init ((n), (sz), 0);       \
426         _rp.size = (sz);                                        \
427         _rp.nitems = n;                                         \
428         _rp.hits = 0;                                           \
429         _rp.misses = 0;                                         \
430         vec_add1(shmem_hdr->vl_rings, _rp);                     \
431     } while (0);
432
433   foreach_vl_aring_size;
434 #undef _
435
436 #define _(sz,n)                                                 \
437     do {                                                        \
438         ring_alloc_t _rp;                                       \
439         _rp.rp = svm_queue_alloc_and_init ((n), (sz), 0);       \
440         _rp.size = (sz);                                        \
441         _rp.nitems = n;                                         \
442         _rp.hits = 0;                                           \
443         _rp.misses = 0;                                         \
444         vec_add1(shmem_hdr->client_rings, _rp);                 \
445     } while (0);
446
447   foreach_clnt_aring_size;
448 #undef _
449 }
450
451 void
452 vl_api_mem_config (vl_shmem_hdr_t * hdr, vl_api_shm_elem_config_t * config)
453 {
454   vl_api_shm_elem_config_t *c;
455   ring_alloc_t *rp;
456   u32 size;
457
458   if (!config)
459     {
460       vl_api_default_mem_config (hdr);
461       return;
462     }
463
464   vec_foreach (c, config)
465   {
466     switch (c->type)
467       {
468       case VL_API_QUEUE:
469         hdr->vl_input_queue = svm_queue_alloc_and_init (c->count, c->size,
470                                                         getpid ());
471         continue;
472       case VL_API_VLIB_RING:
473         vec_add2 (hdr->vl_rings, rp, 1);
474         break;
475       case VL_API_CLIENT_RING:
476         vec_add2 (hdr->client_rings, rp, 1);
477         break;
478       default:
479         clib_warning ("unknown config type: %d", c->type);
480         continue;
481       }
482
483     size = sizeof (ring_alloc_t) + c->size;
484     rp->rp = svm_queue_alloc_and_init (c->count, size, 0);
485     rp->size = size;
486     rp->nitems = c->count;
487     rp->hits = 0;
488     rp->misses = 0;
489   }
490 }
491
492 void
493 vl_init_shmem (svm_region_t * vlib_rp, vl_api_shm_elem_config_t * config,
494                int is_vlib, int is_private_region)
495 {
496   api_main_t *am = &api_main;
497   vl_shmem_hdr_t *shmem_hdr = 0;
498   void *oldheap;
499   ASSERT (vlib_rp);
500
501   /* $$$$ need private region config parameters */
502
503   oldheap = svm_push_data_heap (vlib_rp);
504
505   vec_validate (shmem_hdr, 0);
506   shmem_hdr->version = VL_SHM_VERSION;
507   shmem_hdr->clib_file_index = VL_API_INVALID_FI;
508
509   /* Set up the queue and msg ring allocator */
510   vl_api_mem_config (shmem_hdr, config);
511
512   if (is_private_region == 0)
513     {
514       am->shmem_hdr = shmem_hdr;
515       am->vlib_rp = vlib_rp;
516       am->our_pid = getpid ();
517       if (is_vlib)
518         am->shmem_hdr->vl_pid = am->our_pid;
519     }
520   else
521     shmem_hdr->vl_pid = am->our_pid;
522
523   svm_pop_heap (oldheap);
524
525   /*
526    * After absolutely everything that a client might see is set up,
527    * declare the shmem region valid
528    */
529   vlib_rp->user_ctx = shmem_hdr;
530
531   pthread_mutex_unlock (&vlib_rp->mutex);
532 }
533
534 int
535 vl_map_shmem (const char *region_name, int is_vlib)
536 {
537   svm_map_region_args_t _a, *a = &_a;
538   svm_region_t *vlib_rp, *root_rp;
539   api_main_t *am = &api_main;
540   int i;
541   struct timespec ts, tsrem;
542   char *vpe_api_region_suffix = "-vpe-api";
543
544   clib_memset (a, 0, sizeof (*a));
545
546   if (strstr (region_name, vpe_api_region_suffix))
547     {
548       u8 *root_path = format (0, "%s", region_name);
549       _vec_len (root_path) = (vec_len (root_path) -
550                               strlen (vpe_api_region_suffix));
551       vec_terminate_c_string (root_path);
552       a->root_path = (const char *) root_path;
553       am->root_path = (const char *) root_path;
554     }
555
556   if (is_vlib == 0)
557     {
558       int tfd;
559       u8 *api_name;
560       /*
561        * Clients wait for vpp to set up the root / API regioins
562        */
563       if (am->root_path)
564         api_name = format (0, "/dev/shm/%s-%s%c", am->root_path,
565                            region_name + 1, 0);
566       else
567         api_name = format (0, "/dev/shm%s%c", region_name, 0);
568
569       /* Wait up to 100 seconds... */
570       for (i = 0; i < 10000; i++)
571         {
572           ts.tv_sec = 0;
573           ts.tv_nsec = 10000 * 1000;    /* 10 ms */
574           while (nanosleep (&ts, &tsrem) < 0)
575             ts = tsrem;
576           tfd = open ((char *) api_name, O_RDWR);
577           if (tfd >= 0)
578             break;
579         }
580       vec_free (api_name);
581       if (tfd < 0)
582         {
583           clib_warning ("region init fail");
584           return -2;
585         }
586       close (tfd);
587       svm_region_init_chroot_uid_gid (am->root_path, getuid (), getgid ());
588     }
589
590   if (a->root_path != NULL)
591     {
592       a->name = "/vpe-api";
593     }
594   else
595     a->name = region_name;
596   a->size = am->api_size ? am->api_size : (16 << 20);
597   a->flags = SVM_FLAGS_MHEAP;
598   a->uid = am->api_uid;
599   a->gid = am->api_gid;
600   a->pvt_heap_size = am->api_pvt_heap_size;
601
602   vlib_rp = svm_region_find_or_create (a);
603
604   if (vlib_rp == 0)
605     return (-2);
606
607   pthread_mutex_lock (&vlib_rp->mutex);
608   /* Has someone else set up the shared-memory variable table? */
609   if (vlib_rp->user_ctx)
610     {
611       am->shmem_hdr = (void *) vlib_rp->user_ctx;
612       am->our_pid = getpid ();
613       if (is_vlib)
614         {
615           svm_queue_t *q;
616           uword old_msg;
617           /*
618            * application restart. Reset cached pids, API message
619            * rings, list of clients; otherwise, various things
620            * fail. (e.g. queue non-empty notification)
621            */
622
623           /* ghosts keep the region from disappearing properly */
624           svm_client_scan_this_region_nolock (vlib_rp);
625           am->shmem_hdr->application_restarts++;
626           q = am->shmem_hdr->vl_input_queue;
627           am->shmem_hdr->vl_pid = getpid ();
628           q->consumer_pid = am->shmem_hdr->vl_pid;
629           /* Drain the input queue, freeing msgs */
630           for (i = 0; i < 10; i++)
631             {
632               if (pthread_mutex_trylock (&q->mutex) == 0)
633                 {
634                   pthread_mutex_unlock (&q->mutex);
635                   goto mutex_ok;
636                 }
637               ts.tv_sec = 0;
638               ts.tv_nsec = 10000 * 1000;        /* 10 ms */
639               while (nanosleep (&ts, &tsrem) < 0)
640                 ts = tsrem;
641             }
642           /* Mutex buggered, "fix" it */
643           clib_memset (&q->mutex, 0, sizeof (q->mutex));
644           clib_warning ("forcibly release main input queue mutex");
645
646         mutex_ok:
647           am->vlib_rp = vlib_rp;
648           while (svm_queue_sub (q, (u8 *) & old_msg, SVM_Q_NOWAIT, 0)
649                  != -2 /* queue underflow */ )
650             {
651               vl_msg_api_free_nolock ((void *) old_msg);
652               am->shmem_hdr->restart_reclaims++;
653             }
654           pthread_mutex_unlock (&vlib_rp->mutex);
655           root_rp = svm_get_root_rp ();
656           ASSERT (root_rp);
657           /* Clean up the root region client list */
658           pthread_mutex_lock (&root_rp->mutex);
659           svm_client_scan_this_region_nolock (root_rp);
660           pthread_mutex_unlock (&root_rp->mutex);
661         }
662       else
663         {
664           pthread_mutex_unlock (&vlib_rp->mutex);
665         }
666       am->vlib_rp = vlib_rp;
667       vec_add1 (am->mapped_shmem_regions, vlib_rp);
668       return 0;
669     }
670   /* Clients simply have to wait... */
671   if (!is_vlib)
672     {
673       pthread_mutex_unlock (&vlib_rp->mutex);
674
675       /* Wait up to 100 seconds... */
676       for (i = 0; i < 10000; i++)
677         {
678           ts.tv_sec = 0;
679           ts.tv_nsec = 10000 * 1000;    /* 10 ms */
680           while (nanosleep (&ts, &tsrem) < 0)
681             ts = tsrem;
682           if (vlib_rp->user_ctx)
683             goto ready;
684         }
685       /* Clean up and leave... */
686       svm_region_unmap (vlib_rp);
687       clib_warning ("region init fail");
688       return (-2);
689
690     ready:
691       am->shmem_hdr = (void *) vlib_rp->user_ctx;
692       am->our_pid = getpid ();
693       am->vlib_rp = vlib_rp;
694       vec_add1 (am->mapped_shmem_regions, vlib_rp);
695       return 0;
696     }
697
698   /* Nope, it's our problem... */
699   vl_init_shmem (vlib_rp, 0 /* default config */ , 1 /* is vlib */ ,
700                  0 /* is_private_region */ );
701
702   vec_add1 (am->mapped_shmem_regions, vlib_rp);
703   return 0;
704 }
705
706 void
707 vl_register_mapped_shmem_region (svm_region_t * rp)
708 {
709   api_main_t *am = &api_main;
710
711   vec_add1 (am->mapped_shmem_regions, rp);
712 }
713
714 static void
715 vl_unmap_shmem_internal (u8 is_client)
716 {
717   svm_region_t *rp;
718   int i;
719   api_main_t *am = &api_main;
720
721   if (!svm_get_root_rp ())
722     return;
723
724   for (i = 0; i < vec_len (am->mapped_shmem_regions); i++)
725     {
726       rp = am->mapped_shmem_regions[i];
727       is_client ? svm_region_unmap_client (rp) : svm_region_unmap (rp);
728     }
729
730   vec_free (am->mapped_shmem_regions);
731   am->shmem_hdr = 0;
732
733   is_client ? svm_region_exit_client () : svm_region_exit ();
734
735   /* $$$ more careful cleanup, valgrind run... */
736   vec_free (am->msg_handlers);
737   vec_free (am->msg_endian_handlers);
738   vec_free (am->msg_print_handlers);
739 }
740
741 void
742 vl_unmap_shmem (void)
743 {
744   vl_unmap_shmem_internal (0);
745 }
746
747 void
748 vl_unmap_shmem_client (void)
749 {
750   vl_unmap_shmem_internal (1);
751 }
752
753 void
754 vl_msg_api_send_shmem (svm_queue_t * q, u8 * elem)
755 {
756   api_main_t *am = &api_main;
757   void *msg = (void *) *(uword *) elem;
758
759   if (am->tx_trace && am->tx_trace->enabled)
760     vl_msg_api_trace (am, am->tx_trace, msg);
761
762   /*
763    * Announce a probable binary API client bug:
764    * some client's input queue is stuffed.
765    * The situation may be recoverable, or not.
766    */
767   if (PREDICT_FALSE
768       (am->vl_clients /* vpp side */  && (q->cursize == q->maxsize)))
769     {
770       if (PREDICT_FALSE (am->elog_trace_api_messages))
771         {
772           /* *INDENT-OFF* */
773           ELOG_TYPE_DECLARE (e) =
774             {
775               .format = "api-client-queue-stuffed: %x%x",
776               .format_args = "i4i4",
777             };
778           /* *INDENT-ON* */
779           struct
780           {
781             u32 hi, low;
782           } *ed;
783           ed = ELOG_DATA (am->elog_main, e);
784           ed->hi = (uword) q >> 32;
785           ed->low = (uword) q & 0xFFFFFFFF;
786           clib_warning ("WARNING: client input queue at %llx is stuffed...",
787                         q);
788         }
789     }
790   VL_MSG_API_POISON (msg);
791   (void) svm_queue_add (q, elem, 0 /* nowait */ );
792 }
793
794 int
795 vl_mem_api_can_send (svm_queue_t * q)
796 {
797   return (q->cursize < q->maxsize);
798 }
799
800 void
801 vl_msg_api_send_shmem_nolock (svm_queue_t * q, u8 * elem)
802 {
803   api_main_t *am = &api_main;
804   void *msg = (void *) *(uword *) elem;
805
806   if (am->tx_trace && am->tx_trace->enabled)
807     vl_msg_api_trace (am, am->tx_trace, msg);
808
809   (void) svm_queue_add_nolock (q, elem);
810   VL_MSG_API_POISON (msg);
811 }
812
813 /*
814  * fd.io coding-style-patch-verification: ON
815  *
816  * Local Variables:
817  * eval: (c-set-style "gnu")
818  * End:
819  */