|
FD.io VPP
v21.06-3-gbb25fbf28
Vector Packet Processing
|
Go to the documentation of this file.
44 #define DEBUG_MESSAGE_BUFFER_OVERRUN 0
58 shmem_hdr = (
void *) vlib_rp->
user_ctx;
93 if (nbytes > ap[
i].
size)
101 pthread_mutex_lock (&q->mutex);
103 rv = (
msgbuf_t *) (&q->data[0] + q->head * q->elsize);
112 rv->gc_mark_timestamp =
now;
115 if (
now -
rv->gc_mark_timestamp > 10)
119 u16 *msg_idp, msg_id;
121 (
"garbage collect pool %d ring %d index %d", pool,
i,
123 msg_idp = (
u16 *) (
rv->data);
124 msg_id = clib_net_to_host_u16 (*msg_idp);
138 pthread_mutex_unlock (&q->mutex);
150 rv->gc_mark_timestamp = 0;
152 if (q->head == q->maxsize)
156 pthread_mutex_unlock (&q->mutex);
180 rv->gc_mark_timestamp = 0;
184 #if DEBUG_MESSAGE_BUFFER_OVERRUN > 0
189 *overrun = 0x1badbabe;
192 rv->data_len = htonl (nbytes -
sizeof (
msgbuf_t));
208 pool = (
am->our_pid == shmem_hdr->
vl_pid);
230 pool = (
am->our_pid == shmem_hdr->
vl_pid);
284 rv->gc_mark_timestamp = 0;
285 #if DEBUG_MESSAGE_BUFFER_OVERRUN > 0
288 overrun = (
u32 *) (
rv->data + ntohl (
rv->data_len));
289 ASSERT (*overrun == 0x1badbabe);
298 #if DEBUG_MESSAGE_BUFFER_OVERRUN > 0
301 overrun = (
u32 *) (
rv->data + ntohl (
rv->data_len));
302 ASSERT (*overrun == 0x1badbabe);
371 am->global_baseva = baseva;
395 am->global_pvt_heap_size =
size;
403 am->api_pvt_heap_size =
size;
410 u32 vlib_input_queue_length;
413 vlib_input_queue_length = 1024;
414 if (
am->vlib_input_queue_length)
415 vlib_input_queue_length =
am->vlib_input_queue_length;
424 _rp.rp = svm_queue_alloc_and_init ((n), (sz), 0); \
429 vec_add1(shmem_hdr->vl_rings, _rp); \
438 _rp.rp = svm_queue_alloc_and_init ((n), (sz), 0); \
443 vec_add1(shmem_hdr->client_rings, _rp); \
493 int is_vlib,
int is_private_region)
511 if (is_private_region == 0)
513 am->shmem_hdr = shmem_hdr;
514 am->vlib_rp = vlib_rp;
515 am->our_pid = getpid ();
517 am->shmem_hdr->vl_pid =
am->our_pid;
530 pthread_mutex_unlock (&vlib_rp->
mutex);
540 struct timespec ts, tsrem;
541 char *vpe_api_region_suffix =
"-vpe-api";
545 if (strstr (region_name, vpe_api_region_suffix))
547 u8 *root_path =
format (0,
"%s", region_name);
548 _vec_len (root_path) = (
vec_len (root_path) -
549 strlen (vpe_api_region_suffix));
551 a->root_path = (
const char *) root_path;
552 am->root_path = (
const char *) root_path;
563 api_name =
format (0,
"/dev/shm/%s-%s%c",
am->root_path,
566 api_name =
format (0,
"/dev/shm%s%c", region_name, 0);
569 for (
i = 0;
i < 10000;
i++)
572 ts.tv_nsec = 10000 * 1000;
573 while (nanosleep (&ts, &tsrem) < 0)
575 tfd = open ((
char *) api_name, O_RDWR);
589 if (
a->root_path != NULL)
591 a->name =
"/vpe-api";
594 a->name = region_name;
595 a->size =
am->api_size ?
am->api_size : (16 << 20);
597 a->uid =
am->api_uid;
598 a->gid =
am->api_gid;
599 a->pvt_heap_size =
am->api_pvt_heap_size;
606 pthread_mutex_lock (&vlib_rp->
mutex);
611 am->our_pid = getpid ();
624 am->shmem_hdr->application_restarts++;
625 q =
am->shmem_hdr->vl_input_queue;
626 am->shmem_hdr->vl_pid = getpid ();
627 q->consumer_pid =
am->shmem_hdr->vl_pid;
629 for (
i = 0;
i < 10;
i++)
631 if (pthread_mutex_trylock (&q->mutex) == 0)
633 pthread_mutex_unlock (&q->mutex);
637 ts.tv_nsec = 10000 * 1000;
638 while (nanosleep (&ts, &tsrem) < 0)
643 clib_warning (
"forcibly release main input queue mutex");
646 am->vlib_rp = vlib_rp;
651 am->shmem_hdr->restart_reclaims++;
653 pthread_mutex_unlock (&vlib_rp->
mutex);
663 pthread_mutex_unlock (&vlib_rp->
mutex);
665 am->vlib_rp = vlib_rp;
672 pthread_mutex_unlock (&vlib_rp->
mutex);
675 for (
i = 0;
i < 10000;
i++)
678 ts.tv_nsec = 10000 * 1000;
679 while (nanosleep (&ts, &tsrem) < 0)
691 am->our_pid = getpid ();
692 am->vlib_rp = vlib_rp;
723 for (
i = 0;
i <
vec_len (
am->mapped_shmem_regions);
i++)
725 rp =
am->mapped_shmem_regions[
i];
756 void *msg = (
void *) *(
uword *) elem;
758 if (
am->tx_trace &&
am->tx_trace->enabled)
767 (
am->vl_clients && (q->cursize == q->maxsize)))
774 .format =
"api-client-queue-stuffed: %x%x",
775 .format_args =
"i4i4",
783 ed->hi = (
uword) q >> 32;
784 ed->low = (
uword) q & 0xFFFFFFFF;
785 clib_warning (
"WARNING: client input queue at %llx is stuffed...",
796 return (q->cursize < q->maxsize);
803 void *msg = (
void *) *(
uword *) elem;
805 if (
am->tx_trace &&
am->tx_trace->enabled)
struct msgbuf_ msgbuf_t
Message header structure.
void * vl_msg_api_alloc_or_null(int nbytes)
void svm_region_exit(void)
void * vl_mem_api_alloc_as_if_client_w_reg(vl_api_registration_t *reg, int nbytes)
svm_region_t * svm_get_root_rp(void)
int vl_map_shmem(const char *region_name, int is_vlib)
void svm_region_unmap_client(void *rp_arg)
void svm_region_exit_client(void)
#define DEBUG_MESSAGE_BUFFER_OVERRUN
static void clib_mem_free(void *p)
void svm_region_unmap(void *rp_arg)
struct ring_alloc_ ring_alloc_t
struct _svm_queue svm_queue_t
#define foreach_vl_aring_size
static void vl_api_default_mem_config(vl_shmem_hdr_t *shmem_hdr)
@ SVM_Q_NOWAIT
non-blocking call - works with both condvar and eventfd signaling
void vl_set_memory_uid(int uid)
static void vl_unmap_shmem_internal(u8 is_client)
void * vl_msg_api_alloc_zero(int nbytes)
void svm_region_init_chroot_uid_gid(const char *root_path, int uid, int gid)
void vl_api_mem_config(vl_shmem_hdr_t *hdr, vl_api_shm_elem_config_t *config)
int svm_queue_add_nolock(svm_queue_t *q, u8 *elem)
void * vl_msg_api_alloc_as_if_client(int nbytes)
void vl_set_global_pvt_heap_size(u64 size)
void vl_set_api_pvt_heap_size(u64 size)
void vl_msg_pop_heap_w_region(svm_region_t *vlib_rp, void *oldheap)
static void * clib_mem_alloc_or_null(uword size)
static CLIB_NOSANITIZE_ADDR void VL_MSG_API_UNPOISON(const void *a)
void vl_msg_api_free(void *a)
ring_alloc_t * client_rings
void * vl_msg_api_alloc_as_if_client_or_null(int nbytes)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define ELOG_TYPE_DECLARE(f)
void * svm_region_find_or_create(svm_map_region_args_t *a)
void vl_msg_api_send_shmem_nolock(svm_queue_t *q, u8 *elem)
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
#define CLIB_NOSANITIZE_ADDR
static_always_inline uword vlib_get_thread_index(void)
An API client registration, only in vpp/vlib.
svm_queue_t * vl_input_queue
if(node->flags &VLIB_NODE_FLAG_TRACE) vnet_interface_output_trace(vm
static void svm_pop_heap(void *oldheap)
void vl_set_memory_root_path(const char *name)
static api_main_t * vlibapi_get_main(void)
void * vl_msg_api_alloc_zero_as_if_client(int nbytes)
sll srl srl sll sra u16x4 i
static void VL_MSG_API_POISON(const void *a)
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
void vl_init_shmem(svm_region_t *vlib_rp, vl_api_shm_elem_config_t *config, int is_vlib, int is_private_region)
void vl_unmap_shmem(void)
#define VL_API_INVALID_FI
API main structure, used by both vpp and binary API clients.
#define vec_free(V)
Free vector's memory (no header).
void vl_msg_api_free_w_region(svm_region_t *vlib_rp, void *a)
static svm_region_t * root_rp
int svm_queue_add(svm_queue_t *q, u8 *elem, int nowait)
void vl_set_api_memory_size(u64 size)
description fragment has unexpected format
void svm_client_scan_this_region_nolock(svm_region_t *rp)
void vl_set_global_memory_size(u64 size)
void vl_register_mapped_shmem_region(svm_region_t *rp)
#define vec_foreach(var, vec)
Vector iterator.
void * vl_msg_push_heap_w_region(svm_region_t *vlib_rp)
static void vl_msg_api_free_nolock(void *a)
Message header structure.
static CLIB_NOSANITIZE_ADDR void * vl_msg_api_alloc_internal(svm_region_t *vlib_rp, int nbytes, int pool, int may_return_null)
void vl_msg_api_send_shmem(svm_queue_t *q, u8 *elem)
void vl_unmap_shmem_client(void)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
void vl_set_global_memory_baseva(u64 baseva)
#define vec_terminate_c_string(V)
(If necessary) NULL terminate a vector containing a c-string.
#define clib_warning(format, args...)
void vl_msg_api_trace(api_main_t *am, vl_api_trace_t *tp, void *msg)
int svm_queue_sub(svm_queue_t *q, u8 *elem, svm_q_conditional_wait_t cond, u32 time)
int vl_mem_api_can_send(svm_queue_t *q)
svm_queue_t * svm_queue_alloc_and_init(int nels, int elsize, int consumer_pid)
Allocate and initialize svm queue.
static void * svm_push_data_heap(svm_region_t *rp)
static void * clib_mem_alloc(uword size)
#define foreach_clnt_aring_size
void vl_set_memory_gid(int gid)
void * vl_msg_api_alloc(int nbytes)