FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
memory_shared.h
Go to the documentation of this file.
1 /*
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:
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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  *------------------------------------------------------------------
16  */
17 
18 #ifndef SRC_VLIBMEMORY_MEMORY_SHARED_H_
19 #define SRC_VLIBMEMORY_MEMORY_SHARED_H_
20 
21 #include <vlibapi/api_common.h>
22 #include <vppinfra/error.h>
23 
24 /* Allocated in shared memory */
25 
26 /*
27  * Ring-allocation scheme for client API messages
28  *
29  * Only one proc/thread has control of a given message buffer.
30  * To free a buffer allocated from one of these rings, we clear
31  * a field in the buffer (header), and leave.
32  *
33  * No locks, no hits, no errors...
34  */
35 typedef struct ring_alloc_
36 {
42 } ring_alloc_t;
43 
44 typedef enum
45 {
50 
52 {
54  u8 _pad;
58 
60  "Size must be exactly 8 bytes");
61 
62 /*
63  * Initializers for the (shared-memory) rings
64  * _(size, n). Note: each msg has space for a header.
65  */
66 #define foreach_vl_aring_size \
67 _(64+sizeof(ring_alloc_t), 1024) \
68 _(256+sizeof(ring_alloc_t), 128) \
69 _(1024+sizeof(ring_alloc_t), 64)
70 
71 #define foreach_clnt_aring_size \
72  _(1024+sizeof(ring_alloc_t), 1024) \
73  _(2048+sizeof(ring_alloc_t), 128) \
74  _(4096+sizeof(ring_alloc_t), 8)
75 
76 typedef struct vl_shmem_hdr_
77 {
78  int version;
79 
80  /* getpid () for the VLIB client process */
81  volatile int vl_pid;
82 
83  /* Client sends VLIB msgs here. */
85 
86  /* Vector of rings; one for each size. */
87 
88  /* VLIB allocates buffers to send msgs to clients here. */
90 
91  /* Clients allocate buffer to send msgs to VLIB here. */
93 
94  /* Number of detected application restarts */
96 
97  /* Number of messages reclaimed during application restart */
99 
100  /* Number of garbage-collected messages */
102 
103  /* Socket file index used to bootstrap shmem region */
106 
107 #define VL_SHM_VERSION 2
108 #define VL_API_EPOCH_MASK 0xFF
109 #define VL_API_EPOCH_SHIFT 8
110 
111 void *vl_msg_api_alloc (int nbytes);
112 void *vl_msg_api_alloc_zero (int nbytes);
113 void *vl_msg_api_alloc_or_null (int nbytes);
114 void *vl_msg_api_alloc_as_if_client (int nbytes);
115 void *vl_msg_api_alloc_zero_as_if_client (int nbytes);
116 void *vl_msg_api_alloc_as_if_client_or_null (int nbytes);
118  int nbytes);
119 void vl_msg_api_free (void *a);
120 void vl_msg_api_free_w_region (svm_region_t * vlib_rp, void *a);
121 int vl_map_shmem (const char *region_name, int is_vlib);
122 void vl_unmap_shmem (void);
123 void vl_unmap_shmem_client (void);
125 void vl_msg_api_send_shmem (svm_queue_t * q, u8 * elem);
127 void vl_set_memory_region_name (const char *name);
128 void vl_set_memory_root_path (const char *root_path);
129 void vl_set_memory_uid (int uid);
130 void vl_set_memory_gid (int gid);
131 void vl_set_global_memory_baseva (u64 baseva);
136 void vl_init_shmem (svm_region_t * vlib_rp, vl_api_shm_elem_config_t * config,
137  int is_vlib, int is_private_region);
138 
139 #endif /* SRC_VLIBMEMORY_MEMORY_SHARED_H_ */
140 
141 /*
142  * fd.io coding-style-patch-verification: ON
143  *
144  * Local Variables:
145  * eval: (c-set-style "gnu")
146  * End:
147  */
ring_alloc_::hits
u32 hits
Definition: memory_shared.h:40
vl_shmem_hdr_::application_restarts
u32 application_restarts
Definition: memory_shared.h:95
VL_API_CLIENT_RING
@ VL_API_CLIENT_RING
Definition: memory_shared.h:47
vl_api_shm_elem_config_::type
u8 type
Definition: memory_shared.h:53
vl_mem_api_can_send
int vl_mem_api_can_send(svm_queue_t *q)
Definition: memory_shared.c:794
name
string name[64]
Definition: fib.api:25
vl_msg_api_alloc_as_if_client_or_null
void * vl_msg_api_alloc_as_if_client_or_null(int nbytes)
Definition: memory_shared.c:254
vl_msg_api_free
void vl_msg_api_free(void *a)
Definition: memory_shared.c:311
vl_set_memory_region_name
void vl_set_memory_region_name(const char *name)
Definition: memory_api.c:986
ring_alloc_t
struct ring_alloc_ ring_alloc_t
vl_msg_api_alloc_or_null
void * vl_msg_api_alloc_or_null(int nbytes)
Definition: memory_shared.c:224
svm_queue_t
struct _svm_queue svm_queue_t
u16
unsigned short u16
Definition: types.h:57
VL_API_VLIB_RING
@ VL_API_VLIB_RING
Definition: memory_shared.h:46
vl_unmap_shmem
void vl_unmap_shmem(void)
Definition: memory_shared.c:741
vl_shmem_hdr_
Definition: memory_shared.h:76
vl_msg_api_alloc_zero_as_if_client
void * vl_msg_api_alloc_zero_as_if_client(int nbytes)
Definition: memory_shared.c:244
vl_api_shm_config_type_t
vl_api_shm_config_type_t
Definition: memory_shared.h:44
vl_set_global_memory_baseva
void vl_set_global_memory_baseva(u64 baseva)
Definition: memory_shared.c:367
vl_register_mapped_shmem_region
void vl_register_mapped_shmem_region(svm_region_t *rp)
Definition: memory_shared.c:706
vl_shmem_hdr_::client_rings
ring_alloc_t * client_rings
Definition: memory_shared.h:92
vl_set_memory_root_path
void vl_set_memory_root_path(const char *root_path)
Definition: memory_shared.c:343
vl_mem_api_alloc_as_if_client_w_reg
void * vl_mem_api_alloc_as_if_client_w_reg(vl_api_registration_t *reg, int nbytes)
Definition: memory_shared.c:262
error.h
vl_msg_api_alloc_as_if_client
void * vl_msg_api_alloc_as_if_client(int nbytes)
Definition: memory_shared.c:236
vl_set_api_pvt_heap_size
void vl_set_api_pvt_heap_size(u64 size)
Definition: memory_shared.c:399
vl_set_memory_uid
void vl_set_memory_uid(int uid)
Definition: memory_shared.c:351
vl_api_shm_elem_config_::count
u16 count
Definition: memory_shared.h:55
vl_api_registration_
An API client registration, only in vpp/vlib.
Definition: api_common.h:47
vl_shmem_hdr_::vl_pid
volatile int vl_pid
Definition: memory_shared.h:81
vl_shmem_hdr_::vl_input_queue
svm_queue_t * vl_input_queue
Definition: memory_shared.h:84
vl_shmem_hdr_::version
int version
Definition: memory_shared.h:78
vl_shmem_hdr_::clib_file_index
u32 clib_file_index
Definition: memory_shared.h:104
vl_set_memory_gid
void vl_set_memory_gid(int gid)
Definition: memory_shared.c:359
vl_api_shm_elem_config_t
struct vl_api_shm_elem_config_ vl_api_shm_elem_config_t
vl_map_shmem
int vl_map_shmem(const char *region_name, int is_vlib)
Definition: memory_shared.c:534
vl_set_api_memory_size
void vl_set_api_memory_size(u64 size)
Definition: memory_shared.c:383
vl_unmap_shmem_client
void vl_unmap_shmem_client(void)
Definition: memory_shared.c:747
vl_set_global_pvt_heap_size
void vl_set_global_pvt_heap_size(u64 size)
Definition: memory_shared.c:391
vl_msg_api_send_shmem
void vl_msg_api_send_shmem(svm_queue_t *q, u8 *elem)
Definition: memory_shared.c:753
size
u32 size
Definition: vhost_user.h:125
u64
unsigned long u64
Definition: types.h:89
u32
unsigned int u32
Definition: types.h:88
vl_shmem_hdr_::restart_reclaims
u32 restart_reclaims
Definition: memory_shared.h:98
ring_alloc_::size
u16 size
Definition: memory_shared.h:38
vl_shmem_hdr_::vl_rings
ring_alloc_t * vl_rings
Definition: memory_shared.h:89
vl_msg_api_alloc
void * vl_msg_api_alloc(int nbytes)
Definition: memory_shared.c:199
vl_shmem_hdr_t
struct vl_shmem_hdr_ vl_shmem_hdr_t
vl_msg_api_alloc_zero
void * vl_msg_api_alloc_zero(int nbytes)
Definition: memory_shared.c:214
vl_shmem_hdr_::garbage_collects
u32 garbage_collects
Definition: memory_shared.h:101
vl_set_global_memory_size
void vl_set_global_memory_size(u64 size)
Definition: memory_shared.c:375
svm_region_
Definition: svm_common.h:35
u8
unsigned char u8
Definition: types.h:56
a
a
Definition: bitmap.h:525
api_common.h
vl_msg_api_free_w_region
void vl_msg_api_free_w_region(svm_region_t *vlib_rp, void *a)
Definition: memory_shared.c:269
VL_API_QUEUE
@ VL_API_QUEUE
Definition: memory_shared.h:48
vl_api_shm_elem_config_::size
u32 size
Definition: memory_shared.h:56
vl_init_shmem
void vl_init_shmem(svm_region_t *vlib_rp, vl_api_shm_elem_config_t *config, int is_vlib, int is_private_region)
Definition: memory_shared.c:492
ring_alloc_::rp
svm_queue_t * rp
Definition: memory_shared.h:37
vl_api_shm_elem_config_
Definition: memory_shared.h:51
ring_alloc_
Definition: memory_shared.h:35
STATIC_ASSERT
STATIC_ASSERT(sizeof(vl_api_shm_elem_config_t)==8, "Size must be exactly 8 bytes")
ring_alloc_::nitems
u16 nitems
Definition: memory_shared.h:39
ring_alloc_::misses
u32 misses
Definition: memory_shared.h:41