FD.io VPP  v17.07.01-10-g3be13f0
Vector Packet Processing
api_common.h
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2009 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 included_vlibmemory_api_common_h
19 #define included_vlibmemory_api_common_h
20 
21 #include <svm/svm_common.h>
22 #include <vlibapi/api_common.h>
24 
25 /* Allocated in shared memory */
26 
27 /*
28  * Ring-allocation scheme for client API messages
29  *
30  * Only one proc/thread has control of a given message buffer.
31  * To free a buffer allocated from one of these rings, we clear
32  * a field in the buffer (header), and leave.
33  *
34  * No locks, no hits, no errors...
35  */
36 typedef struct ring_alloc_
37 {
43 } ring_alloc_t;
44 
45 /*
46  * Initializers for the (shared-memory) rings
47  * _(size, n). Note: each msg has an 8 byte header.
48  * Might want to change that to an index sometime.
49  */
50 #define foreach_vl_aring_size \
51 _(64+8, 1024) \
52 _(256+8, 128) \
53 _(1024+8, 64)
54 
55 #define foreach_clnt_aring_size \
56 _(1024+8, 1024) \
57 _(2048+8, 128) \
58 _(4096+8, 8)
59 
60 typedef struct vl_shmem_hdr_
61 {
62  int version;
63 
64  /* getpid () for the VLIB client process */
65  volatile int vl_pid;
66 
67  /* Client sends VLIB msgs here. */
69 
70  /* Vector of rings; one for each size. */
71 
72  /* VLIB allocates buffers to send msgs to clients here. */
74 
75  /* Clients allocate buffer to send msgs to VLIB here. */
77 
78  /* Number of detected application restarts */
80 
81  /* Number of messages reclaimed during application restart */
83 
84  /* Number of garbage-collected messages */
86 
88 
89 #define VL_SHM_VERSION 2
90 
91 #define VL_API_EPOCH_MASK 0xFF
92 #define VL_API_EPOCH_SHIFT 8
93 
94 void *vl_msg_api_alloc (int nbytes);
95 void *vl_msg_api_alloc_or_null (int nbytes);
96 void *vl_msg_api_alloc_as_if_client (int nbytes);
97 void *vl_msg_api_alloc_as_if_client_or_null (int nbytes);
98 void vl_msg_api_free (void *a);
99 int vl_map_shmem (const char *region_name, int is_vlib);
101 void vl_unmap_shmem (void);
104 void vl_msg_api_send (vl_api_registration_t * rp, u8 * elem);
105 int vl_client_connect (const char *name, int ctx_quota, int input_queue_size);
106 void vl_client_disconnect (void);
109 int vl_client_api_map (const char *region_name);
110 void vl_client_api_unmap (void);
111 void vl_set_memory_region_name (const char *name);
112 void vl_set_memory_root_path (const char *root_path);
113 void vl_set_memory_uid (int uid);
114 void vl_set_memory_gid (int gid);
115 void vl_set_global_memory_baseva (u64 baseva);
121 int vl_client_connect_to_vlib (const char *svm_name, const char *client_name,
122  int rx_queue_size);
123 int vl_client_connect_to_vlib_no_rx_pthread (const char *svm_name,
124  const char *client_name,
125  int rx_queue_size);
126 u16 vl_client_get_first_plugin_msg_id (const char *plugin_name);
127 
128 void vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length);
129 
130 #endif /* included_vlibmemory_api_common_h */
131 
132 /*
133  * fd.io coding-style-patch-verification: ON
134  *
135  * Local Variables:
136  * eval: (c-set-style "gnu")
137  * End:
138  */
void * vl_msg_api_alloc_as_if_client(int nbytes)
void vl_set_api_memory_size(u64 size)
a
Definition: bitmap.h:516
struct ring_alloc_ ring_alloc_t
void vl_client_disconnect(void)
void vl_set_memory_gid(int gid)
u32 application_restarts
Definition: api_common.h:79
unix_shared_memory_queue_t * vl_input_queue
Definition: api_common.h:68
ring_alloc_t * client_rings
Definition: api_common.h:76
void vl_set_memory_uid(int uid)
int vl_client_connect(const char *name, int ctx_quota, int input_queue_size)
void vl_client_api_unmap(void)
int vl_client_connect_to_vlib(const char *svm_name, const char *client_name, int rx_queue_size)
unsigned long u64
Definition: types.h:89
void * vl_msg_api_alloc(int nbytes)
volatile int vl_pid
Definition: api_common.h:65
void vl_msg_api_free(void *)
void vl_set_global_memory_baseva(u64 baseva)
ring_alloc_t * vl_rings
Definition: api_common.h:73
void * vl_msg_api_alloc_as_if_client_or_null(int nbytes)
void vl_unmap_shmem(void)
void vl_set_global_pvt_heap_size(u64 size)
unix_shared_memory_queue_t * vl_api_client_index_to_input_queue(u32 index)
void vl_set_memory_region_name(const char *name)
Definition: memory_vlib.c:1206
void vl_api_rpc_call_main_thread(void *fp, u8 *data, u32 data_length)
Definition: memory_vlib.c:1328
u32 garbage_collects
Definition: api_common.h:85
void vl_msg_api_send_shmem(unix_shared_memory_queue_t *q, u8 *elem)
unsigned int u32
Definition: types.h:88
void vl_register_mapped_shmem_region(svm_region_t *rp)
u32 restart_reclaims
Definition: api_common.h:82
void vl_set_api_pvt_heap_size(u64 size)
unsigned short u16
Definition: types.h:57
void vl_msg_api_send_shmem_nolock(unix_shared_memory_queue_t *q, u8 *elem)
unsigned char u8
Definition: types.h:56
void vl_client_disconnect_from_vlib(void)
unix_shared_memory_queue_t * rp
Definition: api_common.h:38
vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
int vl_client_api_map(const char *region_name)
struct vl_shmem_hdr_ vl_shmem_hdr_t
void vl_set_global_memory_size(u64 size)
void vl_set_memory_root_path(const char *root_path)
int vl_client_connect_to_vlib_no_rx_pthread(const char *svm_name, const char *client_name, int rx_queue_size)
int vl_map_shmem(const char *region_name, int is_vlib)
void vl_msg_api_send(vl_api_registration_t *rp, u8 *elem)
Definition: memory_vlib.c:104
void * vl_msg_api_alloc_or_null(int nbytes)
u16 vl_client_get_first_plugin_msg_id(const char *plugin_name)
struct _unix_shared_memory_queue unix_shared_memory_queue_t