2 *------------------------------------------------------------------
3 * Copyright (c) 2018 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *------------------------------------------------------------------
19 #include <vlib/vlib.h>
20 #include <vlibapi/api.h>
21 #include <vlibmemory/api.h>
22 #include <vlibmemory/memory_api.h>
24 #include <vlibmemory/vl_memory_msg_enum.h> /* enumerate all vlib messages */
26 #define vl_typedefs /* define message structures */
27 #include <vlibmemory/vl_memory_api_h.h>
30 /* instantiate all the print functions we know about */
31 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
33 #include <vlibmemory/vl_memory_api_h.h>
36 /* instantiate all the endian swap functions we know about */
38 #include <vlibmemory/vl_memory_api_h.h>
42 vl_api_memclnt_create_t_print (vl_api_memclnt_create_t * a, void *handle)
44 vl_print (handle, "vl_api_memclnt_create_t:\n");
45 vl_print (handle, "name: %s\n", a->name);
46 vl_print (handle, "input_queue: 0x%wx\n", a->input_queue);
47 vl_print (handle, "context: %u\n", (unsigned) a->context);
48 vl_print (handle, "ctx_quota: %ld\n", (long) a->ctx_quota);
53 vl_api_memclnt_delete_t_print (vl_api_memclnt_delete_t * a, void *handle)
55 vl_print (handle, "vl_api_memclnt_delete_t:\n");
56 vl_print (handle, "index: %u\n", (unsigned) a->index);
57 vl_print (handle, "handle: 0x%wx\n", a->handle);
61 volatile int **vl_api_queue_cursizes;
64 memclnt_queue_callback (vlib_main_t * vm)
67 api_main_t *am = &api_main;
69 if (PREDICT_FALSE (vec_len (vl_api_queue_cursizes) !=
70 1 + vec_len (am->vlib_private_rps)))
72 vl_shmem_hdr_t *shmem_hdr = am->shmem_hdr;
78 q = shmem_hdr->vl_input_queue;
82 vec_add1 (vl_api_queue_cursizes, &q->cursize);
84 for (i = 0; i < vec_len (am->vlib_private_rps); i++)
86 svm_region_t *vlib_rp = am->vlib_private_rps[i];
88 shmem_hdr = (void *) vlib_rp->user_ctx;
89 q = shmem_hdr->vl_input_queue;
90 vec_add1 (vl_api_queue_cursizes, &q->cursize);
94 for (i = 0; i < vec_len (vl_api_queue_cursizes); i++)
96 if (*vl_api_queue_cursizes[i])
98 vm->queue_signal_pending = 1;
99 vm->api_queue_nonempty = 1;
100 vlib_process_signal_event (vm, vl_api_clnt_node.index,
101 /* event_type */ QUEUE_SIGNAL_EVENT,
109 * vl_api_memclnt_create_internal
112 vl_api_memclnt_create_internal (char *name, svm_queue_t * q)
114 vl_api_registration_t **regpp;
115 vl_api_registration_t *regp;
118 api_main_t *am = &api_main;
120 ASSERT (vlib_get_thread_index () == 0);
121 pool_get (am->vl_clients, regpp);
125 pthread_mutex_lock (&svm->mutex);
126 oldheap = svm_push_data_heap (svm);
127 *regpp = clib_mem_alloc (sizeof (vl_api_registration_t));
130 memset (regp, 0, sizeof (*regp));
131 regp->registration_type = REGISTRATION_TYPE_SHMEM;
132 regp->vl_api_registration_pool_index = regpp - am->vl_clients;
134 regp->shmem_hdr = am->shmem_hdr;
136 regp->vl_input_queue = q;
137 regp->name = format (0, "%s%c", name, 0);
139 pthread_mutex_unlock (&svm->mutex);
140 svm_pop_heap (oldheap);
141 return vl_msg_api_handle_from_index_and_epoch
142 (regp->vl_api_registration_pool_index,
143 am->shmem_hdr->application_restarts);
147 * vl_api_memclnt_create_t_handler
150 vl_api_memclnt_create_t_handler (vl_api_memclnt_create_t * mp)
152 vl_api_registration_t **regpp;
153 vl_api_registration_t *regp;
154 vl_api_memclnt_create_reply_t *rp;
159 api_main_t *am = &api_main;
163 * This is tortured. Maintain a vlib-address-space private
164 * pool of client registrations. We use the shared-memory virtual
165 * address of client structure as a handle, to allow direct
166 * manipulation of context quota vbls from the client library.
168 * This scheme causes trouble w/ API message trace replay, since
169 * some random VA from clib_mem_alloc() certainly won't
170 * occur in the Linux sim. The (very) few places
171 * that care need to use the pool index.
173 * Putting the registration object(s) into a pool in shared memory and
174 * using the pool index as a handle seems like a great idea.
175 * Unfortunately, each and every reference to that pool would need
176 * to be protected by a mutex:
180 * convert pool index to
188 pool_get (am->vl_clients, regpp);
192 pthread_mutex_lock (&svm->mutex);
193 oldheap = svm_push_data_heap (svm);
194 *regpp = clib_mem_alloc (sizeof (vl_api_registration_t));
197 memset (regp, 0, sizeof (*regp));
198 regp->registration_type = REGISTRATION_TYPE_SHMEM;
199 regp->vl_api_registration_pool_index = regpp - am->vl_clients;
201 regp->shmem_hdr = am->shmem_hdr;
202 regp->clib_file_index = am->shmem_hdr->clib_file_index;
204 q = regp->vl_input_queue = (svm_queue_t *) (uword) mp->input_queue;
206 regp->name = format (0, "%s", mp->name);
207 vec_add1 (regp->name, 0);
209 if (am->serialized_message_table_in_shmem == 0)
210 am->serialized_message_table_in_shmem =
211 vl_api_serialize_message_table (am, 0);
213 if (am->vlib_rp != am->vlib_primary_rp)
214 msg_table = vl_api_serialize_message_table (am, 0);
216 msg_table = am->serialized_message_table_in_shmem;
218 pthread_mutex_unlock (&svm->mutex);
219 svm_pop_heap (oldheap);
221 rp = vl_msg_api_alloc (sizeof (*rp));
222 rp->_vl_msg_id = ntohs (VL_API_MEMCLNT_CREATE_REPLY);
223 rp->handle = (uword) regp;
224 rp->index = vl_msg_api_handle_from_index_and_epoch
225 (regp->vl_api_registration_pool_index,
226 am->shmem_hdr->application_restarts);
227 rp->context = mp->context;
228 rp->response = ntohl (rv);
229 rp->message_table = pointer_to_uword (msg_table);
231 vl_msg_api_send_shmem (q, (u8 *) & rp);
235 vl_api_call_reaper_functions (u32 client_index)
237 clib_error_t *error = 0;
238 _vl_msg_api_function_list_elt_t *i;
240 i = api_main.reaper_function_registrations;
243 error = i->f (client_index);
245 clib_error_report (error);
246 i = i->next_init_function;
252 * vl_api_memclnt_delete_t_handler
255 vl_api_memclnt_delete_t_handler (vl_api_memclnt_delete_t * mp)
257 vl_api_registration_t **regpp;
258 vl_api_registration_t *regp;
259 vl_api_memclnt_delete_reply_t *rp;
262 api_main_t *am = &api_main;
263 u32 handle, client_index, epoch;
267 if (vl_api_call_reaper_functions (handle))
270 epoch = vl_msg_api_handle_get_epoch (handle);
271 client_index = vl_msg_api_handle_get_index (handle);
273 if (epoch != (am->shmem_hdr->application_restarts & VL_API_EPOCH_MASK))
276 ("Stale clnt delete index %d old epoch %d cur epoch %d",
278 (am->shmem_hdr->application_restarts & VL_API_EPOCH_MASK));
282 regpp = pool_elt_at_index (am->vl_clients, client_index);
284 if (!pool_is_free (am->vl_clients, regpp))
289 int private_registration = 0;
292 * Note: the API message handling path will set am->vlib_rp
293 * as appropriate for pairwise / private memory segments
295 rp = vl_msg_api_alloc (sizeof (*rp));
296 rp->_vl_msg_id = ntohs (VL_API_MEMCLNT_DELETE_REPLY);
297 rp->handle = mp->handle;
300 vl_msg_api_send_shmem (regp->vl_input_queue, (u8 *) & rp);
302 if (client_index != regp->vl_api_registration_pool_index)
304 clib_warning ("mismatch client_index %d pool_index %d",
305 client_index, regp->vl_api_registration_pool_index);
306 vl_msg_api_free (rp);
310 /* For horizontal scaling, add a hash table... */
311 for (i = 0; i < vec_len (am->vlib_private_rps); i++)
313 /* Is this a pairwise / private API segment? */
314 if (am->vlib_private_rps[i] == svm)
316 /* Note: account for the memfd header page */
317 u64 virtual_base = svm->virtual_base - MMAP_PAGESIZE;
318 u64 virtual_size = svm->virtual_size + MMAP_PAGESIZE;
321 * Kill the registration pool element before we make
322 * the index vanish forever
324 pool_put_index (am->vl_clients,
325 regp->vl_api_registration_pool_index);
327 vec_delete (am->vlib_private_rps, 1, i);
328 /* Kill it, accounting for the memfd header page */
329 if (munmap ((void *) virtual_base, virtual_size) < 0)
330 clib_unix_warning ("munmap");
331 /* Reset the queue-length-address cache */
332 vec_reset_length (vl_api_queue_cursizes);
333 private_registration = 1;
338 /* No dangling references, please */
341 if (private_registration == 0)
343 pool_put_index (am->vl_clients,
344 regp->vl_api_registration_pool_index);
345 pthread_mutex_lock (&svm->mutex);
346 oldheap = svm_push_data_heap (svm);
347 vec_free (regp->name);
348 /* Poison the old registration */
349 memset (regp, 0xF1, sizeof (*regp));
350 clib_mem_free (regp);
351 pthread_mutex_unlock (&svm->mutex);
352 svm_pop_heap (oldheap);
354 * These messages must be freed manually, since they're set up
355 * as "bounce" messages. In the private_registration == 1 case,
356 * we kill the shared-memory segment which contains the message
359 vl_msg_api_free (mp);
364 clib_warning ("unknown client ID %d", mp->index);
369 * client answered a ping, stave off the grim reaper...
372 vl_api_memclnt_keepalive_reply_t_handler
373 (vl_api_memclnt_keepalive_reply_t * mp)
375 vl_api_registration_t *regp;
376 vlib_main_t *vm = vlib_get_main ();
378 regp = vl_api_client_index_to_registration (mp->context);
381 regp->last_heard = vlib_time_now (vm);
382 regp->unanswered_pings = 0;
385 clib_warning ("BUG: anonymous memclnt_keepalive_reply");
389 * We can send ourselves these messages if someone uses the
390 * builtin binary api test tool...
393 vl_api_memclnt_keepalive_t_handler (vl_api_memclnt_keepalive_t * mp)
395 vl_api_memclnt_keepalive_reply_t *rmp;
397 vl_shmem_hdr_t *shmem_hdr;
400 shmem_hdr = am->shmem_hdr;
402 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp));
403 memset (rmp, 0, sizeof (*rmp));
404 rmp->_vl_msg_id = ntohs (VL_API_MEMCLNT_KEEPALIVE_REPLY);
405 rmp->context = mp->context;
406 vl_msg_api_send_shmem (shmem_hdr->vl_input_queue, (u8 *) & rmp);
409 #define foreach_vlib_api_msg \
410 _(MEMCLNT_CREATE, memclnt_create) \
411 _(MEMCLNT_DELETE, memclnt_delete) \
412 _(MEMCLNT_KEEPALIVE, memclnt_keepalive) \
413 _(MEMCLNT_KEEPALIVE_REPLY, memclnt_keepalive_reply) \
419 vl_mem_api_init (const char *region_name)
422 api_main_t *am = &api_main;
423 vl_msg_api_msg_config_t cfg;
424 vl_msg_api_msg_config_t *c = &cfg;
426 vlib_main_t *vm = vlib_get_main ();
428 memset (c, 0, sizeof (*c));
430 if ((rv = vl_map_shmem (region_name, 1 /* is_vlib */ )) < 0)
433 #define _(N,n) do { \
434 c->id = VL_API_##N; \
436 c->handler = vl_api_##n##_t_handler; \
437 c->cleanup = vl_noop_handler; \
438 c->endian = vl_api_##n##_t_endian; \
439 c->print = vl_api_##n##_t_print; \
440 c->size = sizeof(vl_api_##n##_t); \
441 c->traced = 1; /* trace, so these msgs print */ \
442 c->replay = 0; /* don't replay client create/delete msgs */ \
443 c->message_bounce = 0; /* don't bounce this message */ \
444 vl_msg_api_config(c);} while (0);
446 foreach_vlib_api_msg;
450 * special-case freeing of memclnt_delete messages, so we can
451 * simply munmap pairwise / private API segments...
453 am->message_bounce[VL_API_MEMCLNT_DELETE] = 1;
454 am->is_mp_safe[VL_API_MEMCLNT_KEEPALIVE_REPLY] = 1;
456 vlib_set_queue_signal_callback (vm, memclnt_queue_callback);
459 ASSERT (shm && shm->vl_input_queue);
461 /* Make a note so we can always find the primary region easily */
462 am->vlib_primary_rp = am->vlib_rp;
468 map_api_segment_init (vlib_main_t * vm)
470 api_main_t *am = &api_main;
473 if ((rv = vl_mem_api_init (am->region_name)) < 0)
475 return clib_error_return (0, "vl_mem_api_init (%s) failed",
482 send_memclnt_keepalive (vl_api_registration_t * regp, f64 now)
484 vl_api_memclnt_keepalive_t *mp;
486 api_main_t *am = &api_main;
487 svm_region_t *save_vlib_rp = am->vlib_rp;
488 vl_shmem_hdr_t *save_shmem_hdr = am->shmem_hdr;
490 q = regp->vl_input_queue;
493 * If the queue head is moving, assume that the client is processing
494 * messages and skip the ping. This heuristic may fail if the queue
495 * is in the same position as last time, net of wrapping; in which
496 * case, the client will receive a keepalive.
498 if (regp->last_queue_head != q->head)
500 regp->last_heard = now;
501 regp->unanswered_pings = 0;
502 regp->last_queue_head = q->head;
507 * push/pop shared memory segment, so this routine
508 * will work with "normal" as well as "private segment"
512 am->vlib_rp = regp->vlib_rp;
513 am->shmem_hdr = regp->shmem_hdr;
515 mp = vl_msg_api_alloc (sizeof (*mp));
516 memset (mp, 0, sizeof (*mp));
517 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_MEMCLNT_KEEPALIVE);
518 mp->context = mp->client_index =
519 vl_msg_api_handle_from_index_and_epoch
520 (regp->vl_api_registration_pool_index,
521 am->shmem_hdr->application_restarts);
523 regp->unanswered_pings++;
525 /* Failure-to-send due to a stuffed queue is absolutely expected */
526 if (svm_queue_add (q, (u8 *) & mp, 1 /* nowait */ ))
527 vl_msg_api_free (mp);
529 am->vlib_rp = save_vlib_rp;
530 am->shmem_hdr = save_shmem_hdr;
534 vl_mem_send_client_keepalive_w_reg (api_main_t * am, f64 now,
535 vl_api_registration_t ** regpp,
537 u32 ** confused_indices)
539 vl_api_registration_t *regp = *regpp;
542 /* If we haven't heard from this client recently... */
543 if (regp->last_heard < (now - 10.0))
545 if (regp->unanswered_pings == 2)
548 q = regp->vl_input_queue;
549 if (kill (q->consumer_pid, 0) >= 0)
551 clib_warning ("REAPER: lazy binary API client '%s'",
553 regp->unanswered_pings = 0;
554 regp->last_heard = now;
558 clib_warning ("REAPER: binary API client '%s' died",
560 vec_add1 (*dead_indices, regpp - am->vl_clients);
564 send_memclnt_keepalive (regp, now);
567 regp->unanswered_pings = 0;
571 clib_warning ("NULL client registration index %d",
572 regpp - am->vl_clients);
573 vec_add1 (*confused_indices, regpp - am->vl_clients);
578 vl_mem_api_dead_client_scan (api_main_t * am, vl_shmem_hdr_t * shm, f64 now)
580 vl_api_registration_t **regpp;
581 static u32 *dead_indices;
582 static u32 *confused_indices;
584 vec_reset_length (dead_indices);
585 vec_reset_length (confused_indices);
588 pool_foreach (regpp, am->vl_clients, ({
589 vl_mem_send_client_keepalive_w_reg (am, now, regpp, &dead_indices,
594 /* This should "never happen," but if it does, fix it... */
595 if (PREDICT_FALSE (vec_len (confused_indices) > 0))
598 for (i = 0; i < vec_len (confused_indices); i++)
600 pool_put_index (am->vl_clients, confused_indices[i]);
604 if (PREDICT_FALSE (vec_len (dead_indices) > 0))
610 /* Allow the application to clean up its registrations */
611 for (i = 0; i < vec_len (dead_indices); i++)
613 regpp = pool_elt_at_index (am->vl_clients, dead_indices[i]);
618 handle = vl_msg_api_handle_from_index_and_epoch
619 (dead_indices[i], shm->application_restarts);
620 (void) vl_api_call_reaper_functions (handle);
625 pthread_mutex_lock (&svm->mutex);
626 oldheap = svm_push_data_heap (svm);
628 for (i = 0; i < vec_len (dead_indices); i++)
630 regpp = pool_elt_at_index (am->vl_clients, dead_indices[i]);
633 /* Is this a pairwise SVM segment? */
634 if ((*regpp)->vlib_rp != svm)
637 svm_region_t *dead_rp = (*regpp)->vlib_rp;
638 /* Note: account for the memfd header page */
639 u64 virtual_base = dead_rp->virtual_base - MMAP_PAGESIZE;
640 u64 virtual_size = dead_rp->virtual_size + MMAP_PAGESIZE;
642 /* For horizontal scaling, add a hash table... */
643 for (i = 0; i < vec_len (am->vlib_private_rps); i++)
644 if (am->vlib_private_rps[i] == dead_rp)
646 vec_delete (am->vlib_private_rps, 1, i);
649 clib_warning ("private rp %llx AWOL", dead_rp);
652 /* Kill it, accounting for the memfd header page */
653 if (munmap ((void *) virtual_base, virtual_size) < 0)
654 clib_unix_warning ("munmap");
655 /* Reset the queue-length-address cache */
656 vec_reset_length (vl_api_queue_cursizes);
660 /* Poison the old registration */
661 memset (*regpp, 0xF3, sizeof (**regpp));
662 clib_mem_free (*regpp);
664 /* no dangling references, please */
669 svm_pop_heap (oldheap);
670 clib_warning ("Duplicate free, client index %d",
671 regpp - am->vl_clients);
672 oldheap = svm_push_data_heap (svm);
676 svm_client_scan_this_region_nolock (am->vlib_rp);
678 pthread_mutex_unlock (&svm->mutex);
679 svm_pop_heap (oldheap);
680 for (i = 0; i < vec_len (dead_indices); i++)
681 pool_put_index (am->vl_clients, dead_indices[i]);
686 void_mem_api_handle_msg_i (api_main_t * am, vlib_main_t * vm,
687 vlib_node_runtime_t * node, svm_queue_t * q)
690 if (!svm_queue_sub2 (q, (u8 *) & mp))
692 vl_msg_api_handler_with_vm_node (am, (void *) mp, vm, node);
699 vl_mem_api_handle_msg_main (vlib_main_t * vm, vlib_node_runtime_t * node)
701 api_main_t *am = &api_main;
702 return void_mem_api_handle_msg_i (am, vm, node,
703 am->shmem_hdr->vl_input_queue);
707 vl_mem_api_handle_msg_private (vlib_main_t * vm, vlib_node_runtime_t * node,
710 api_main_t *am = &api_main;
711 vl_shmem_hdr_t *save_shmem_hdr = am->shmem_hdr;
712 svm_region_t *vlib_rp, *save_vlib_rp = am->vlib_rp;
716 vlib_rp = am->vlib_rp = am->vlib_private_rps[reg_index];
718 am->shmem_hdr = (void *) vlib_rp->user_ctx;
719 q = am->shmem_hdr->vl_input_queue;
721 rv = void_mem_api_handle_msg_i (am, vm, node, q);
723 am->shmem_hdr = save_shmem_hdr;
724 am->vlib_rp = save_vlib_rp;
729 vl_api_registration_t *
730 vl_mem_api_client_index_to_registration (u32 handle)
732 vl_api_registration_t **regpp;
733 vl_api_registration_t *regp;
734 api_main_t *am = &api_main;
735 vl_shmem_hdr_t *shmem_hdr;
738 index = vl_msg_api_handle_get_index (handle);
739 regpp = am->vl_clients + index;
741 if (pool_is_free (am->vl_clients, regpp))
743 vl_msg_api_increment_missing_client_counter ();
748 shmem_hdr = (vl_shmem_hdr_t *) regp->shmem_hdr;
749 if (!vl_msg_api_handle_is_valid (handle, shmem_hdr->application_restarts))
751 vl_msg_api_increment_missing_client_counter ();
759 vl_api_client_index_to_input_queue (u32 index)
761 vl_api_registration_t *regp;
762 api_main_t *am = &api_main;
764 /* Special case: vlib trying to send itself a message */
765 if (index == (u32) ~ 0)
766 return (am->shmem_hdr->vl_input_queue);
768 regp = vl_mem_api_client_index_to_registration (index);
771 return (regp->vl_input_queue);
774 static clib_error_t *
775 setup_memclnt_exit (vlib_main_t * vm)
777 atexit (vl_unmap_shmem);
781 VLIB_INIT_FUNCTION (setup_memclnt_exit);
784 format_api_message_rings (u8 * s, va_list * args)
786 api_main_t *am = va_arg (*args, api_main_t *);
787 vl_shmem_hdr_t *shmem_hdr = va_arg (*args, vl_shmem_hdr_t *);
788 int main_segment = va_arg (*args, int);
793 return format (s, "%8s %8s %8s %8s %8s\n",
794 "Owner", "Size", "Nitems", "Hits", "Misses");
796 ap = shmem_hdr->vl_rings;
798 for (i = 0; i < vec_len (shmem_hdr->vl_rings); i++)
800 s = format (s, "%8s %8d %8d %8d %8d\n",
801 "vlib", ap->size, ap->nitems, ap->hits, ap->misses);
805 ap = shmem_hdr->client_rings;
807 for (i = 0; i < vec_len (shmem_hdr->client_rings); i++)
809 s = format (s, "%8s %8d %8d %8d %8d\n",
810 "clnt", ap->size, ap->nitems, ap->hits, ap->misses);
816 s = format (s, "%d ring miss fallback allocations\n", am->ring_misses);
819 "%d application restarts, %d reclaimed msgs, %d garbage collects\n",
820 shmem_hdr->application_restarts, shmem_hdr->restart_reclaims,
821 shmem_hdr->garbage_collects);
826 static clib_error_t *
827 vl_api_ring_command (vlib_main_t * vm,
828 unformat_input_t * input, vlib_cli_command_t * cli_cmd)
831 vl_shmem_hdr_t *shmem_hdr;
832 api_main_t *am = &api_main;
834 /* First, dump the primary region rings.. */
836 if (am->vlib_primary_rp == 0 || am->vlib_primary_rp->user_ctx == 0)
838 vlib_cli_output (vm, "Shared memory segment not initialized...\n");
842 shmem_hdr = (void *) am->vlib_primary_rp->user_ctx;
844 vlib_cli_output (vm, "Main API segment rings:");
846 vlib_cli_output (vm, "%U", format_api_message_rings, am,
847 0 /* print header */ , 0 /* notused */ );
849 vlib_cli_output (vm, "%U", format_api_message_rings, am,
850 shmem_hdr, 1 /* main segment */ );
852 for (i = 0; i < vec_len (am->vlib_private_rps); i++)
854 svm_region_t *vlib_rp = am->vlib_private_rps[i];
855 shmem_hdr = (void *) vlib_rp->user_ctx;
856 vl_api_registration_t **regpp;
857 vl_api_registration_t *regp = 0;
859 /* For horizontal scaling, add a hash table... */
861 pool_foreach (regpp, am->vl_clients,
864 if (regp && regp->vlib_rp == vlib_rp)
866 vlib_cli_output (vm, "%s segment rings:", regp->name);
870 vlib_cli_output (vm, "regp %llx not found?", regp);
874 vlib_cli_output (vm, "%U", format_api_message_rings, am,
875 0 /* print header */ , 0 /* notused */ );
876 vlib_cli_output (vm, "%U", format_api_message_rings, am,
877 shmem_hdr, 0 /* main segment */ );
884 * Display binary api message allocation ring statistics
887 VLIB_CLI_COMMAND (cli_show_api_ring_command, static) =
889 .path = "show api ring-stats",
890 .short_help = "Message ring statistics",
891 .function = vl_api_ring_command,
896 vlibmemory_init (vlib_main_t * vm)
898 api_main_t *am = &api_main;
899 svm_map_region_args_t _a, *a = &_a;
902 memset (a, 0, sizeof (*a));
903 a->root_path = am->root_path;
904 a->name = SVM_GLOBAL_REGION_NAME;
905 a->baseva = (am->global_baseva != 0) ?
906 am->global_baseva : +svm_get_global_region_base_va ();
907 a->size = (am->global_size != 0) ? am->global_size : SVM_GLOBAL_REGION_SIZE;
908 a->flags = SVM_FLAGS_NODATA;
909 a->uid = am->api_uid;
910 a->gid = am->api_gid;
912 (am->global_pvt_heap_size !=
913 0) ? am->global_pvt_heap_size : SVM_PVT_MHEAP_SIZE;
915 svm_region_init_args (a);
917 error = vlib_call_init_function (vm, vlibsocket_init);
923 vl_set_memory_region_name (const char *name)
925 api_main_t *am = &api_main;
926 am->region_name = name;
930 * fd.io coding-style-patch-verification: ON
933 * eval: (c-set-style "gnu")