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 vec_free (regp->name);
343 /* Poison the old registration */
344 memset (regp, 0xF1, sizeof (*regp));
345 clib_mem_free (regp);
346 pthread_mutex_unlock (&svm->mutex);
347 svm_pop_heap (oldheap);
349 * These messages must be freed manually, since they're set up
350 * as "bounce" messages. In the private_registration == 1 case,
351 * we kill the shared-memory segment which contains the message
354 vl_msg_api_free (mp);
359 clib_warning ("unknown client ID %d", mp->index);
364 * client answered a ping, stave off the grim reaper...
367 vl_api_memclnt_keepalive_reply_t_handler
368 (vl_api_memclnt_keepalive_reply_t * mp)
370 vl_api_registration_t *regp;
371 vlib_main_t *vm = vlib_get_main ();
373 regp = vl_api_client_index_to_registration (mp->context);
376 regp->last_heard = vlib_time_now (vm);
377 regp->unanswered_pings = 0;
380 clib_warning ("BUG: anonymous memclnt_keepalive_reply");
384 * We can send ourselves these messages if someone uses the
385 * builtin binary api test tool...
388 vl_api_memclnt_keepalive_t_handler (vl_api_memclnt_keepalive_t * mp)
390 vl_api_memclnt_keepalive_reply_t *rmp;
392 vl_shmem_hdr_t *shmem_hdr;
395 shmem_hdr = am->shmem_hdr;
397 rmp = vl_msg_api_alloc_as_if_client (sizeof (*rmp));
398 memset (rmp, 0, sizeof (*rmp));
399 rmp->_vl_msg_id = ntohs (VL_API_MEMCLNT_KEEPALIVE_REPLY);
400 rmp->context = mp->context;
401 vl_msg_api_send_shmem (shmem_hdr->vl_input_queue, (u8 *) & rmp);
404 #define foreach_vlib_api_msg \
405 _(MEMCLNT_CREATE, memclnt_create) \
406 _(MEMCLNT_DELETE, memclnt_delete) \
407 _(MEMCLNT_KEEPALIVE, memclnt_keepalive) \
408 _(MEMCLNT_KEEPALIVE_REPLY, memclnt_keepalive_reply) \
414 vl_mem_api_init (const char *region_name)
417 api_main_t *am = &api_main;
418 vl_msg_api_msg_config_t cfg;
419 vl_msg_api_msg_config_t *c = &cfg;
421 vlib_main_t *vm = vlib_get_main ();
423 memset (c, 0, sizeof (*c));
425 if ((rv = vl_map_shmem (region_name, 1 /* is_vlib */ )) < 0)
428 #define _(N,n) do { \
429 c->id = VL_API_##N; \
431 c->handler = vl_api_##n##_t_handler; \
432 c->cleanup = vl_noop_handler; \
433 c->endian = vl_api_##n##_t_endian; \
434 c->print = vl_api_##n##_t_print; \
435 c->size = sizeof(vl_api_##n##_t); \
436 c->traced = 1; /* trace, so these msgs print */ \
437 c->replay = 0; /* don't replay client create/delete msgs */ \
438 c->message_bounce = 0; /* don't bounce this message */ \
439 vl_msg_api_config(c);} while (0);
441 foreach_vlib_api_msg;
445 * special-case freeing of memclnt_delete messages, so we can
446 * simply munmap pairwise / private API segments...
448 am->message_bounce[VL_API_MEMCLNT_DELETE] = 1;
449 am->is_mp_safe[VL_API_MEMCLNT_KEEPALIVE_REPLY] = 1;
451 vlib_set_queue_signal_callback (vm, memclnt_queue_callback);
454 ASSERT (shm && shm->vl_input_queue);
456 /* Make a note so we can always find the primary region easily */
457 am->vlib_primary_rp = am->vlib_rp;
462 static clib_error_t *
463 map_api_segment_init (vlib_main_t * vm)
465 api_main_t *am = &api_main;
468 if ((rv = vl_mem_api_init (am->region_name)) < 0)
470 return clib_error_return (0, "vl_mem_api_init (%s) failed",
476 VLIB_INIT_FUNCTION (map_api_segment_init);
479 send_memclnt_keepalive (vl_api_registration_t * regp, f64 now)
481 vl_api_memclnt_keepalive_t *mp;
483 api_main_t *am = &api_main;
484 svm_region_t *save_vlib_rp = am->vlib_rp;
485 vl_shmem_hdr_t *save_shmem_hdr = am->shmem_hdr;
487 q = regp->vl_input_queue;
490 * If the queue head is moving, assume that the client is processing
491 * messages and skip the ping. This heuristic may fail if the queue
492 * is in the same position as last time, net of wrapping; in which
493 * case, the client will receive a keepalive.
495 if (regp->last_queue_head != q->head)
497 regp->last_heard = now;
498 regp->unanswered_pings = 0;
499 regp->last_queue_head = q->head;
504 * push/pop shared memory segment, so this routine
505 * will work with "normal" as well as "private segment"
509 am->vlib_rp = regp->vlib_rp;
510 am->shmem_hdr = regp->shmem_hdr;
512 mp = vl_msg_api_alloc (sizeof (*mp));
513 memset (mp, 0, sizeof (*mp));
514 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_MEMCLNT_KEEPALIVE);
515 mp->context = mp->client_index =
516 vl_msg_api_handle_from_index_and_epoch
517 (regp->vl_api_registration_pool_index,
518 am->shmem_hdr->application_restarts);
520 regp->unanswered_pings++;
522 /* Failure-to-send due to a stuffed queue is absolutely expected */
523 if (svm_queue_add (q, (u8 *) & mp, 1 /* nowait */ ))
524 vl_msg_api_free (mp);
526 am->vlib_rp = save_vlib_rp;
527 am->shmem_hdr = save_shmem_hdr;
531 vl_mem_send_client_keepalive_w_reg (api_main_t * am, f64 now,
532 vl_api_registration_t ** regpp,
534 u32 ** confused_indices)
536 vl_api_registration_t *regp = *regpp;
539 /* If we haven't heard from this client recently... */
540 if (regp->last_heard < (now - 10.0))
542 if (regp->unanswered_pings == 2)
545 q = regp->vl_input_queue;
546 if (kill (q->consumer_pid, 0) >= 0)
548 clib_warning ("REAPER: lazy binary API client '%s'",
550 regp->unanswered_pings = 0;
551 regp->last_heard = now;
555 clib_warning ("REAPER: binary API client '%s' died",
557 vec_add1 (*dead_indices, regpp - am->vl_clients);
561 send_memclnt_keepalive (regp, now);
564 regp->unanswered_pings = 0;
568 clib_warning ("NULL client registration index %d",
569 regpp - am->vl_clients);
570 vec_add1 (*confused_indices, regpp - am->vl_clients);
575 vl_mem_api_dead_client_scan (api_main_t * am, vl_shmem_hdr_t * shm, f64 now)
577 vl_api_registration_t **regpp;
578 static u32 *dead_indices;
579 static u32 *confused_indices;
581 vec_reset_length (dead_indices);
582 vec_reset_length (confused_indices);
585 pool_foreach (regpp, am->vl_clients, ({
586 vl_mem_send_client_keepalive_w_reg (am, now, regpp, &dead_indices,
591 /* This should "never happen," but if it does, fix it... */
592 if (PREDICT_FALSE (vec_len (confused_indices) > 0))
595 for (i = 0; i < vec_len (confused_indices); i++)
597 pool_put_index (am->vl_clients, confused_indices[i]);
601 if (PREDICT_FALSE (vec_len (dead_indices) > 0))
607 /* Allow the application to clean up its registrations */
608 for (i = 0; i < vec_len (dead_indices); i++)
610 regpp = pool_elt_at_index (am->vl_clients, dead_indices[i]);
615 handle = vl_msg_api_handle_from_index_and_epoch
616 (dead_indices[i], shm->application_restarts);
617 (void) vl_api_call_reaper_functions (handle);
622 pthread_mutex_lock (&svm->mutex);
623 oldheap = svm_push_data_heap (svm);
625 for (i = 0; i < vec_len (dead_indices); i++)
627 regpp = pool_elt_at_index (am->vl_clients, dead_indices[i]);
630 /* Is this a pairwise SVM segment? */
631 if ((*regpp)->vlib_rp != svm)
634 svm_region_t *dead_rp = (*regpp)->vlib_rp;
635 /* Note: account for the memfd header page */
636 u64 virtual_base = dead_rp->virtual_base - MMAP_PAGESIZE;
637 u64 virtual_size = dead_rp->virtual_size + MMAP_PAGESIZE;
639 /* For horizontal scaling, add a hash table... */
640 for (i = 0; i < vec_len (am->vlib_private_rps); i++)
641 if (am->vlib_private_rps[i] == dead_rp)
643 vec_delete (am->vlib_private_rps, 1, i);
646 clib_warning ("private rp %llx AWOL", dead_rp);
649 /* Kill it, accounting for the memfd header page */
650 if (munmap ((void *) virtual_base, virtual_size) < 0)
651 clib_unix_warning ("munmap");
652 /* Reset the queue-length-address cache */
653 vec_reset_length (vl_api_queue_cursizes);
657 /* Poison the old registration */
658 memset (*regpp, 0xF3, sizeof (**regpp));
659 clib_mem_free (*regpp);
661 /* no dangling references, please */
666 svm_pop_heap (oldheap);
667 clib_warning ("Duplicate free, client index %d",
668 regpp - am->vl_clients);
669 oldheap = svm_push_data_heap (svm);
673 svm_client_scan_this_region_nolock (am->vlib_rp);
675 pthread_mutex_unlock (&svm->mutex);
676 svm_pop_heap (oldheap);
677 for (i = 0; i < vec_len (dead_indices); i++)
678 pool_put_index (am->vl_clients, dead_indices[i]);
683 void_mem_api_handle_msg_i (api_main_t * am, vlib_main_t * vm,
684 vlib_node_runtime_t * node, svm_queue_t * q)
687 if (!svm_queue_sub2 (q, (u8 *) & mp))
689 vl_msg_api_handler_with_vm_node (am, (void *) mp, vm, node);
696 vl_mem_api_handle_msg_main (vlib_main_t * vm, vlib_node_runtime_t * node)
698 api_main_t *am = &api_main;
699 return void_mem_api_handle_msg_i (am, vm, node,
700 am->shmem_hdr->vl_input_queue);
704 vl_mem_api_handle_msg_private (vlib_main_t * vm, vlib_node_runtime_t * node,
707 api_main_t *am = &api_main;
708 vl_shmem_hdr_t *save_shmem_hdr = am->shmem_hdr;
709 svm_region_t *vlib_rp, *save_vlib_rp = am->vlib_rp;
713 vlib_rp = am->vlib_rp = am->vlib_private_rps[reg_index];
715 am->shmem_hdr = (void *) vlib_rp->user_ctx;
716 q = am->shmem_hdr->vl_input_queue;
718 rv = void_mem_api_handle_msg_i (am, vm, node, q);
720 am->shmem_hdr = save_shmem_hdr;
721 am->vlib_rp = save_vlib_rp;
726 vl_api_registration_t *
727 vl_mem_api_client_index_to_registration (u32 handle)
729 vl_api_registration_t **regpp;
730 vl_api_registration_t *regp;
731 api_main_t *am = &api_main;
732 vl_shmem_hdr_t *shmem_hdr;
735 index = vl_msg_api_handle_get_index (handle);
736 regpp = am->vl_clients + index;
738 if (pool_is_free (am->vl_clients, regpp))
740 vl_msg_api_increment_missing_client_counter ();
745 shmem_hdr = (vl_shmem_hdr_t *) regp->shmem_hdr;
746 if (!vl_msg_api_handle_is_valid (handle, shmem_hdr->application_restarts))
748 vl_msg_api_increment_missing_client_counter ();
756 vl_api_client_index_to_input_queue (u32 index)
758 vl_api_registration_t *regp;
759 api_main_t *am = &api_main;
761 /* Special case: vlib trying to send itself a message */
762 if (index == (u32) ~ 0)
763 return (am->shmem_hdr->vl_input_queue);
765 regp = vl_mem_api_client_index_to_registration (index);
768 return (regp->vl_input_queue);
771 static clib_error_t *
772 setup_memclnt_exit (vlib_main_t * vm)
774 atexit (vl_unmap_shmem);
778 VLIB_INIT_FUNCTION (setup_memclnt_exit);
781 format_api_message_rings (u8 * s, va_list * args)
783 api_main_t *am = va_arg (*args, api_main_t *);
784 vl_shmem_hdr_t *shmem_hdr = va_arg (*args, vl_shmem_hdr_t *);
785 int main_segment = va_arg (*args, int);
790 return format (s, "%8s %8s %8s %8s %8s\n",
791 "Owner", "Size", "Nitems", "Hits", "Misses");
793 ap = shmem_hdr->vl_rings;
795 for (i = 0; i < vec_len (shmem_hdr->vl_rings); i++)
797 s = format (s, "%8s %8d %8d %8d %8d\n",
798 "vlib", ap->size, ap->nitems, ap->hits, ap->misses);
802 ap = shmem_hdr->client_rings;
804 for (i = 0; i < vec_len (shmem_hdr->client_rings); i++)
806 s = format (s, "%8s %8d %8d %8d %8d\n",
807 "clnt", ap->size, ap->nitems, ap->hits, ap->misses);
813 s = format (s, "%d ring miss fallback allocations\n", am->ring_misses);
816 "%d application restarts, %d reclaimed msgs, %d garbage collects\n",
817 shmem_hdr->application_restarts, shmem_hdr->restart_reclaims,
818 shmem_hdr->garbage_collects);
823 static clib_error_t *
824 vl_api_ring_command (vlib_main_t * vm,
825 unformat_input_t * input, vlib_cli_command_t * cli_cmd)
828 vl_shmem_hdr_t *shmem_hdr;
829 api_main_t *am = &api_main;
831 /* First, dump the primary region rings.. */
833 if (am->vlib_primary_rp == 0 || am->vlib_primary_rp->user_ctx == 0)
835 vlib_cli_output (vm, "Shared memory segment not initialized...\n");
839 shmem_hdr = (void *) am->vlib_primary_rp->user_ctx;
841 vlib_cli_output (vm, "Main API segment rings:");
843 vlib_cli_output (vm, "%U", format_api_message_rings, am,
844 0 /* print header */ , 0 /* notused */ );
846 vlib_cli_output (vm, "%U", format_api_message_rings, am,
847 shmem_hdr, 1 /* main segment */ );
849 for (i = 0; i < vec_len (am->vlib_private_rps); i++)
851 svm_region_t *vlib_rp = am->vlib_private_rps[i];
852 shmem_hdr = (void *) vlib_rp->user_ctx;
853 vl_api_registration_t **regpp;
854 vl_api_registration_t *regp = 0;
856 /* For horizontal scaling, add a hash table... */
858 pool_foreach (regpp, am->vl_clients,
861 if (regp && regp->vlib_rp == vlib_rp)
863 vlib_cli_output (vm, "%s segment rings:", regp->name);
867 vlib_cli_output (vm, "regp %llx not found?", regp);
871 vlib_cli_output (vm, "%U", format_api_message_rings, am,
872 0 /* print header */ , 0 /* notused */ );
873 vlib_cli_output (vm, "%U", format_api_message_rings, am,
874 shmem_hdr, 0 /* main segment */ );
881 * Display binary api message allocation ring statistics
884 VLIB_CLI_COMMAND (cli_show_api_ring_command, static) =
886 .path = "show api ring-stats",
887 .short_help = "Message ring statistics",
888 .function = vl_api_ring_command,
893 vlibmemory_init (vlib_main_t * vm)
895 api_main_t *am = &api_main;
896 svm_map_region_args_t _a, *a = &_a;
899 memset (a, 0, sizeof (*a));
900 a->root_path = am->root_path;
901 a->name = SVM_GLOBAL_REGION_NAME;
902 a->baseva = (am->global_baseva != 0) ?
903 am->global_baseva : +svm_get_global_region_base_va ();
904 a->size = (am->global_size != 0) ? am->global_size : SVM_GLOBAL_REGION_SIZE;
905 a->flags = SVM_FLAGS_NODATA;
906 a->uid = am->api_uid;
907 a->gid = am->api_gid;
909 (am->global_pvt_heap_size !=
910 0) ? am->global_pvt_heap_size : SVM_PVT_MHEAP_SIZE;
912 svm_region_init_args (a);
914 error = vlib_call_init_function (vm, vlibsocket_init);
919 VLIB_INIT_FUNCTION (vlibmemory_init);
922 vl_set_memory_region_name (const char *name)
924 api_main_t *am = &api_main;
925 am->region_name = name;
929 * fd.io coding-style-patch-verification: ON
932 * eval: (c-set-style "gnu")