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;
162 * This is tortured. Maintain a vlib-address-space private
163 * pool of client registrations. We use the shared-memory virtual
164 * address of client structure as a handle, to allow direct
165 * manipulation of context quota vbls from the client library.
167 * This scheme causes trouble w/ API message trace replay, since
168 * some random VA from clib_mem_alloc() certainly won't
169 * occur in the Linux sim. The (very) few places
170 * that care need to use the pool index.
172 * Putting the registration object(s) into a pool in shared memory and
173 * using the pool index as a handle seems like a great idea.
174 * Unfortunately, each and every reference to that pool would need
175 * to be protected by a mutex:
179 * convert pool index to
187 pool_get (am->vl_clients, regpp);
191 pthread_mutex_lock (&svm->mutex);
192 oldheap = svm_push_data_heap (svm);
193 *regpp = clib_mem_alloc (sizeof (vl_api_registration_t));
196 memset (regp, 0, sizeof (*regp));
197 regp->registration_type = REGISTRATION_TYPE_SHMEM;
198 regp->vl_api_registration_pool_index = regpp - am->vl_clients;
200 regp->shmem_hdr = am->shmem_hdr;
201 regp->clib_file_index = am->shmem_hdr->clib_file_index;
203 q = regp->vl_input_queue = (svm_queue_t *) (uword) mp->input_queue;
205 regp->name = format (0, "%s", mp->name);
206 vec_add1 (regp->name, 0);
208 if (am->serialized_message_table_in_shmem == 0)
209 am->serialized_message_table_in_shmem =
210 vl_api_serialize_message_table (am, 0);
212 pthread_mutex_unlock (&svm->mutex);
213 svm_pop_heap (oldheap);
215 rp = vl_msg_api_alloc (sizeof (*rp));
216 rp->_vl_msg_id = ntohs (VL_API_MEMCLNT_CREATE_REPLY);
217 rp->handle = (uword) regp;
218 rp->index = vl_msg_api_handle_from_index_and_epoch
219 (regp->vl_api_registration_pool_index,
220 am->shmem_hdr->application_restarts);
221 rp->context = mp->context;
222 rp->response = ntohl (rv);
224 pointer_to_uword (am->serialized_message_table_in_shmem);
226 vl_msg_api_send_shmem (q, (u8 *) & rp);
230 vl_api_call_reaper_functions (u32 client_index)
232 clib_error_t *error = 0;
233 _vl_msg_api_function_list_elt_t *i;
235 i = api_main.reaper_function_registrations;
238 error = i->f (client_index);
240 clib_error_report (error);
241 i = i->next_init_function;
247 * vl_api_memclnt_delete_t_handler
250 vl_api_memclnt_delete_t_handler (vl_api_memclnt_delete_t * mp)
252 vl_api_registration_t **regpp;
253 vl_api_registration_t *regp;
254 vl_api_memclnt_delete_reply_t *rp;
257 api_main_t *am = &api_main;
258 u32 handle, client_index, epoch;
262 if (vl_api_call_reaper_functions (handle))
265 epoch = vl_msg_api_handle_get_epoch (handle);
266 client_index = vl_msg_api_handle_get_index (handle);
268 if (epoch != (am->shmem_hdr->application_restarts & VL_API_EPOCH_MASK))
271 ("Stale clnt delete index %d old epoch %d cur epoch %d",
273 (am->shmem_hdr->application_restarts & VL_API_EPOCH_MASK));
277 regpp = pool_elt_at_index (am->vl_clients, client_index);
279 if (!pool_is_free (am->vl_clients, regpp))
284 int private_registration = 0;
287 * Note: the API message handling path will set am->vlib_rp
288 * as appropriate for pairwise / private memory segments
290 rp = vl_msg_api_alloc (sizeof (*rp));
291 rp->_vl_msg_id = ntohs (VL_API_MEMCLNT_DELETE_REPLY);
292 rp->handle = mp->handle;
295 vl_msg_api_send_shmem (regp->vl_input_queue, (u8 *) & rp);
297 if (client_index != regp->vl_api_registration_pool_index)
299 clib_warning ("mismatch client_index %d pool_index %d",
300 client_index, regp->vl_api_registration_pool_index);
301 vl_msg_api_free (rp);
305 /* For horizontal scaling, add a hash table... */
306 for (i = 0; i < vec_len (am->vlib_private_rps); i++)
308 /* Is this a pairwise / private API segment? */
309 if (am->vlib_private_rps[i] == svm)
311 /* Note: account for the memfd header page */
312 u64 virtual_base = svm->virtual_base - MMAP_PAGESIZE;
313 u64 virtual_size = svm->virtual_size + MMAP_PAGESIZE;
316 * Kill the registration pool element before we make
317 * the index vanish forever
319 pool_put_index (am->vl_clients,
320 regp->vl_api_registration_pool_index);
322 vec_delete (am->vlib_private_rps, 1, i);
323 /* Kill it, accounting for the memfd header page */
324 if (munmap ((void *) virtual_base, virtual_size) < 0)
325 clib_unix_warning ("munmap");
326 /* Reset the queue-length-address cache */
327 vec_reset_length (vl_api_queue_cursizes);
328 private_registration = 1;
333 /* No dangling references, please */
336 if (private_registration == 0)
338 pool_put_index (am->vl_clients,
339 regp->vl_api_registration_pool_index);
340 pthread_mutex_lock (&svm->mutex);
341 oldheap = svm_push_data_heap (svm);
342 /* Poison the old registration */
343 memset (regp, 0xF1, sizeof (*regp));
344 clib_mem_free (regp);
345 pthread_mutex_unlock (&svm->mutex);
346 svm_pop_heap (oldheap);
348 * These messages must be freed manually, since they're set up
349 * as "bounce" messages. In the private_registration == 1 case,
350 * we kill the shared-memory segment which contains the message
353 vl_msg_api_free (mp);
358 clib_warning ("unknown client ID %d", mp->index);
363 * client answered a ping, stave off the grim reaper...
366 vl_api_memclnt_keepalive_reply_t_handler
367 (vl_api_memclnt_keepalive_reply_t * mp)
369 vl_api_registration_t *regp;
370 vlib_main_t *vm = vlib_get_main ();
372 regp = vl_api_client_index_to_registration (mp->context);
375 regp->last_heard = vlib_time_now (vm);
376 regp->unanswered_pings = 0;
379 clib_warning ("BUG: anonymous memclnt_keepalive_reply");
383 * We can send ourselves these messages if someone uses the
384 * builtin binary api test tool...
387 vl_api_memclnt_keepalive_t_handler (vl_api_memclnt_keepalive_t * mp)
389 vl_api_memclnt_keepalive_reply_t *rmp;
391 vl_shmem_hdr_t *shmem_hdr;
394 shmem_hdr = am->shmem_hdr;
396 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp));
397 memset (rmp, 0, sizeof (*rmp));
398 rmp->_vl_msg_id = ntohs (VL_API_MEMCLNT_KEEPALIVE_REPLY);
399 rmp->context = mp->context;
400 vl_msg_api_send_shmem (shmem_hdr->vl_input_queue, (u8 *) & rmp);
403 #define foreach_vlib_api_msg \
404 _(MEMCLNT_CREATE, memclnt_create) \
405 _(MEMCLNT_DELETE, memclnt_delete) \
406 _(MEMCLNT_KEEPALIVE, memclnt_keepalive) \
407 _(MEMCLNT_KEEPALIVE_REPLY, memclnt_keepalive_reply) \
413 vl_mem_api_init (const char *region_name)
416 api_main_t *am = &api_main;
417 vl_msg_api_msg_config_t cfg;
418 vl_msg_api_msg_config_t *c = &cfg;
420 vlib_main_t *vm = vlib_get_main ();
422 memset (c, 0, sizeof (*c));
424 if ((rv = vl_map_shmem (region_name, 1 /* is_vlib */ )) < 0)
427 #define _(N,n) do { \
428 c->id = VL_API_##N; \
430 c->handler = vl_api_##n##_t_handler; \
431 c->cleanup = vl_noop_handler; \
432 c->endian = vl_api_##n##_t_endian; \
433 c->print = vl_api_##n##_t_print; \
434 c->size = sizeof(vl_api_##n##_t); \
435 c->traced = 1; /* trace, so these msgs print */ \
436 c->replay = 0; /* don't replay client create/delete msgs */ \
437 c->message_bounce = 0; /* don't bounce this message */ \
438 vl_msg_api_config(c);} while (0);
440 foreach_vlib_api_msg;
444 * special-case freeing of memclnt_delete messages, so we can
445 * simply munmap pairwise / private API segments...
447 am->message_bounce[VL_API_MEMCLNT_DELETE] = 1;
448 am->is_mp_safe[VL_API_MEMCLNT_KEEPALIVE_REPLY] = 1;
450 vlib_set_queue_signal_callback (vm, memclnt_queue_callback);
453 ASSERT (shm && shm->vl_input_queue);
455 /* Make a note so we can always find the primary region easily */
456 am->vlib_primary_rp = am->vlib_rp;
462 send_memclnt_keepalive (vl_api_registration_t * regp, f64 now)
464 vl_api_memclnt_keepalive_t *mp;
466 api_main_t *am = &api_main;
467 svm_region_t *save_vlib_rp = am->vlib_rp;
468 vl_shmem_hdr_t *save_shmem_hdr = am->shmem_hdr;
470 q = regp->vl_input_queue;
473 * If the queue head is moving, assume that the client is processing
474 * messages and skip the ping. This heuristic may fail if the queue
475 * is in the same position as last time, net of wrapping; in which
476 * case, the client will receive a keepalive.
478 if (regp->last_queue_head != q->head)
480 regp->last_heard = now;
481 regp->unanswered_pings = 0;
482 regp->last_queue_head = q->head;
487 * push/pop shared memory segment, so this routine
488 * will work with "normal" as well as "private segment"
492 am->vlib_rp = regp->vlib_rp;
493 am->shmem_hdr = regp->shmem_hdr;
495 mp = vl_msg_api_alloc (sizeof (*mp));
496 memset (mp, 0, sizeof (*mp));
497 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_MEMCLNT_KEEPALIVE);
498 mp->context = mp->client_index =
499 vl_msg_api_handle_from_index_and_epoch
500 (regp->vl_api_registration_pool_index,
501 am->shmem_hdr->application_restarts);
503 regp->unanswered_pings++;
505 /* Failure-to-send due to a stuffed queue is absolutely expected */
506 if (svm_queue_add (q, (u8 *) & mp, 1 /* nowait */ ))
507 vl_msg_api_free (mp);
509 am->vlib_rp = save_vlib_rp;
510 am->shmem_hdr = save_shmem_hdr;
514 vl_mem_send_client_keepalive_w_reg (api_main_t * am, f64 now,
515 vl_api_registration_t ** regpp,
517 u32 ** confused_indices)
519 vl_api_registration_t *regp = *regpp;
522 /* If we haven't heard from this client recently... */
523 if (regp->last_heard < (now - 10.0))
525 if (regp->unanswered_pings == 2)
528 q = regp->vl_input_queue;
529 if (kill (q->consumer_pid, 0) >= 0)
531 clib_warning ("REAPER: lazy binary API client '%s'",
533 regp->unanswered_pings = 0;
534 regp->last_heard = now;
538 clib_warning ("REAPER: binary API client '%s' died",
540 vec_add1 (*dead_indices, regpp - am->vl_clients);
544 send_memclnt_keepalive (regp, now);
547 regp->unanswered_pings = 0;
551 clib_warning ("NULL client registration index %d",
552 regpp - am->vl_clients);
553 vec_add1 (*confused_indices, regpp - am->vl_clients);
558 vl_mem_api_dead_client_scan (api_main_t * am, vl_shmem_hdr_t * shm, f64 now)
560 vl_api_registration_t **regpp;
561 static u32 *dead_indices;
562 static u32 *confused_indices;
564 vec_reset_length (dead_indices);
565 vec_reset_length (confused_indices);
568 pool_foreach (regpp, am->vl_clients, ({
569 vl_mem_send_client_keepalive_w_reg (am, now, regpp, &dead_indices,
574 /* This should "never happen," but if it does, fix it... */
575 if (PREDICT_FALSE (vec_len (confused_indices) > 0))
578 for (i = 0; i < vec_len (confused_indices); i++)
580 pool_put_index (am->vl_clients, confused_indices[i]);
584 if (PREDICT_FALSE (vec_len (dead_indices) > 0))
590 /* Allow the application to clean up its registrations */
591 for (i = 0; i < vec_len (dead_indices); i++)
593 regpp = pool_elt_at_index (am->vl_clients, dead_indices[i]);
598 handle = vl_msg_api_handle_from_index_and_epoch
599 (dead_indices[i], shm->application_restarts);
600 (void) vl_api_call_reaper_functions (handle);
605 pthread_mutex_lock (&svm->mutex);
606 oldheap = svm_push_data_heap (svm);
608 for (i = 0; i < vec_len (dead_indices); i++)
610 regpp = pool_elt_at_index (am->vl_clients, dead_indices[i]);
613 /* Is this a pairwise SVM segment? */
614 if ((*regpp)->vlib_rp != svm)
617 svm_region_t *dead_rp = (*regpp)->vlib_rp;
618 /* Note: account for the memfd header page */
619 u64 virtual_base = dead_rp->virtual_base - MMAP_PAGESIZE;
620 u64 virtual_size = dead_rp->virtual_size + MMAP_PAGESIZE;
622 /* For horizontal scaling, add a hash table... */
623 for (i = 0; i < vec_len (am->vlib_private_rps); i++)
624 if (am->vlib_private_rps[i] == dead_rp)
626 vec_delete (am->vlib_private_rps, 1, i);
629 clib_warning ("private rp %llx AWOL", dead_rp);
632 /* Kill it, accounting for the memfd header page */
633 if (munmap ((void *) virtual_base, virtual_size) < 0)
634 clib_unix_warning ("munmap");
635 /* Reset the queue-length-address cache */
636 vec_reset_length (vl_api_queue_cursizes);
640 /* Poison the old registration */
641 memset (*regpp, 0xF3, sizeof (**regpp));
642 clib_mem_free (*regpp);
644 /* no dangling references, please */
649 svm_pop_heap (oldheap);
650 clib_warning ("Duplicate free, client index %d",
651 regpp - am->vl_clients);
652 oldheap = svm_push_data_heap (svm);
656 svm_client_scan_this_region_nolock (am->vlib_rp);
658 pthread_mutex_unlock (&svm->mutex);
659 svm_pop_heap (oldheap);
660 for (i = 0; i < vec_len (dead_indices); i++)
661 pool_put_index (am->vl_clients, dead_indices[i]);
666 void_mem_api_handle_msg_i (api_main_t * am, vlib_main_t * vm,
667 vlib_node_runtime_t * node, svm_queue_t * q)
670 if (!svm_queue_sub2 (q, (u8 *) & mp))
672 vl_msg_api_handler_with_vm_node (am, (void *) mp, vm, node);
679 vl_mem_api_handle_msg_main (vlib_main_t * vm, vlib_node_runtime_t * node)
681 api_main_t *am = &api_main;
682 return void_mem_api_handle_msg_i (am, vm, node,
683 am->shmem_hdr->vl_input_queue);
687 vl_mem_api_handle_msg_private (vlib_main_t * vm, vlib_node_runtime_t * node,
690 api_main_t *am = &api_main;
691 vl_shmem_hdr_t *save_shmem_hdr = am->shmem_hdr;
692 svm_region_t *vlib_rp, *save_vlib_rp = am->vlib_rp;
696 vlib_rp = am->vlib_rp = am->vlib_private_rps[reg_index];
698 am->shmem_hdr = (void *) vlib_rp->user_ctx;
699 q = am->shmem_hdr->vl_input_queue;
701 rv = void_mem_api_handle_msg_i (am, vm, node, q);
703 am->shmem_hdr = save_shmem_hdr;
704 am->vlib_rp = save_vlib_rp;
709 vl_api_registration_t *
710 vl_mem_api_client_index_to_registration (u32 handle)
712 vl_api_registration_t **regpp;
713 vl_api_registration_t *regp;
714 api_main_t *am = &api_main;
715 vl_shmem_hdr_t *shmem_hdr;
718 index = vl_msg_api_handle_get_index (handle);
719 regpp = am->vl_clients + index;
721 if (pool_is_free (am->vl_clients, regpp))
723 vl_msg_api_increment_missing_client_counter ();
728 shmem_hdr = (vl_shmem_hdr_t *) regp->shmem_hdr;
729 if (!vl_msg_api_handle_is_valid (handle, shmem_hdr->application_restarts))
731 vl_msg_api_increment_missing_client_counter ();
739 vl_api_client_index_to_input_queue (u32 index)
741 vl_api_registration_t *regp;
742 api_main_t *am = &api_main;
744 /* Special case: vlib trying to send itself a message */
745 if (index == (u32) ~ 0)
746 return (am->shmem_hdr->vl_input_queue);
748 regp = vl_mem_api_client_index_to_registration (index);
751 return (regp->vl_input_queue);
754 static clib_error_t *
755 setup_memclnt_exit (vlib_main_t * vm)
757 atexit (vl_unmap_shmem);
761 VLIB_INIT_FUNCTION (setup_memclnt_exit);
764 format_api_message_rings (u8 * s, va_list * args)
766 api_main_t *am = va_arg (*args, api_main_t *);
767 vl_shmem_hdr_t *shmem_hdr = va_arg (*args, vl_shmem_hdr_t *);
768 int main_segment = va_arg (*args, int);
773 return format (s, "%8s %8s %8s %8s %8s\n",
774 "Owner", "Size", "Nitems", "Hits", "Misses");
776 ap = shmem_hdr->vl_rings;
778 for (i = 0; i < vec_len (shmem_hdr->vl_rings); i++)
780 s = format (s, "%8s %8d %8d %8d %8d\n",
781 "vlib", ap->size, ap->nitems, ap->hits, ap->misses);
785 ap = shmem_hdr->client_rings;
787 for (i = 0; i < vec_len (shmem_hdr->client_rings); i++)
789 s = format (s, "%8s %8d %8d %8d %8d\n",
790 "clnt", ap->size, ap->nitems, ap->hits, ap->misses);
796 s = format (s, "%d ring miss fallback allocations\n", am->ring_misses);
799 "%d application restarts, %d reclaimed msgs, %d garbage collects\n",
800 shmem_hdr->application_restarts, shmem_hdr->restart_reclaims,
801 shmem_hdr->garbage_collects);
806 static clib_error_t *
807 vl_api_ring_command (vlib_main_t * vm,
808 unformat_input_t * input, vlib_cli_command_t * cli_cmd)
811 vl_shmem_hdr_t *shmem_hdr;
812 api_main_t *am = &api_main;
814 /* First, dump the primary region rings.. */
816 if (am->vlib_primary_rp == 0 || am->vlib_primary_rp->user_ctx == 0)
818 vlib_cli_output (vm, "Shared memory segment not initialized...\n");
822 shmem_hdr = (void *) am->vlib_primary_rp->user_ctx;
824 vlib_cli_output (vm, "Main API segment rings:");
826 vlib_cli_output (vm, "%U", format_api_message_rings, am,
827 0 /* print header */ , 0 /* notused */ );
829 vlib_cli_output (vm, "%U", format_api_message_rings, am,
830 shmem_hdr, 1 /* main segment */ );
832 for (i = 0; i < vec_len (am->vlib_private_rps); i++)
834 svm_region_t *vlib_rp = am->vlib_private_rps[i];
835 shmem_hdr = (void *) vlib_rp->user_ctx;
836 vl_api_registration_t **regpp;
837 vl_api_registration_t *regp = 0;
839 /* For horizontal scaling, add a hash table... */
841 pool_foreach (regpp, am->vl_clients,
844 if (regp && regp->vlib_rp == vlib_rp)
846 vlib_cli_output (vm, "%s segment rings:", regp->name);
850 vlib_cli_output (vm, "regp %llx not found?", regp);
854 vlib_cli_output (vm, "%U", format_api_message_rings, am,
855 0 /* print header */ , 0 /* notused */ );
856 vlib_cli_output (vm, "%U", format_api_message_rings, am,
857 shmem_hdr, 0 /* main segment */ );
864 * Display binary api message allocation ring statistics
867 VLIB_CLI_COMMAND (cli_show_api_ring_command, static) =
869 .path = "show api ring-stats",
870 .short_help = "Message ring statistics",
871 .function = vl_api_ring_command,
876 vlibmemory_init (vlib_main_t * vm)
878 api_main_t *am = &api_main;
879 svm_map_region_args_t _a, *a = &_a;
882 memset (a, 0, sizeof (*a));
883 a->root_path = am->root_path;
884 a->name = SVM_GLOBAL_REGION_NAME;
885 a->baseva = (am->global_baseva != 0) ?
886 am->global_baseva : +svm_get_global_region_base_va ();
887 a->size = (am->global_size != 0) ? am->global_size : SVM_GLOBAL_REGION_SIZE;
888 a->flags = SVM_FLAGS_NODATA;
889 a->uid = am->api_uid;
890 a->gid = am->api_gid;
892 (am->global_pvt_heap_size !=
893 0) ? am->global_pvt_heap_size : SVM_PVT_MHEAP_SIZE;
895 svm_region_init_args (a);
897 error = vlib_call_init_function (vm, vlibsocket_init);
902 VLIB_INIT_FUNCTION (vlibmemory_init);
905 vl_set_memory_region_name (const char *name)
907 api_main_t *am = &api_main;
908 am->region_name = name;
912 * fd.io coding-style-patch-verification: ON
915 * eval: (c-set-style "gnu")