FD.io VPP  v16.06
Vector Packet Processing
api.h
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * api.h
4  *
5  * Copyright (c) 2009 Cisco and/or its affiliates.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *------------------------------------------------------------------
18  */
19 
20 #ifndef included_vlibmemory_api_h
21 #define included_vlibmemory_api_h
22 
23 #include <vppinfra/error.h>
24 #include <svm.h>
25 #include <vlib/vlib.h>
27 #include <vlib/unix/unix.h>
28 #include <vlibapi/api.h>
29 
30 /* Allocated in shared memory */
31 
32 /*
33  * Ring-allocation scheme for client API messages
34  *
35  * Only one proc/thread has control of a given message buffer.
36  * To free a buffer allocated from one of these rings, we clear
37  * a field in the buffer (header), and leave.
38  *
39  * No locks, no hits, no errors...
40  */
41 typedef struct ring_alloc_ {
47 } ring_alloc_t;
48 
49 /*
50  * Initializers for the (shared-memory) rings
51  * _(size, n). Note: each msg has an 8 byte header.
52  * Might want to change that to an index sometime.
53  */
54 #define foreach_vl_aring_size \
55 _(64+8, 1024) \
56 _(256+8, 128) \
57 _(1024+8, 64)
58 
59 #define foreach_clnt_aring_size \
60 _(1024+8, 1024) \
61 _(2048+8, 128) \
62 _(4096+8, 8)
63 
64 typedef struct vl_shmem_hdr_ {
65  int version;
66 
67  /* getpid () for the VLIB client process */
68  volatile int vl_pid;
69 
70  /* Client sends VLIB msgs here. */
72 
73  /* Vector of rings; one for each size. */
74 
75  /* VLIB allocates buffers to send msgs to clients here. */
77 
78  /* Clients allocate buffer to send msgs to VLIB here. */
80 
81  /* Number of detected application restarts */
83 
84  /* Number of messages reclaimed during application restart */
86 
88 
89 /* Note that the size of the structure is 16 bytes, with 4 bytes of padding after data[0]. */
90 typedef struct msgbuf_ {
93  u8 data[0];
94 } msgbuf_t;
95 
96 #define VL_SHM_VERSION 2
97 
98 #define VL_API_EPOCH_MASK 0xFF
99 #define VL_API_EPOCH_SHIFT 8
100 
101 static inline u32 vl_msg_api_handle_get_epoch (u32 index)
102 {
103  return (index & VL_API_EPOCH_MASK);
104 }
105 static inline u32 vl_msg_api_handle_get_index (u32 index)
106 {
107  return (index >> VL_API_EPOCH_SHIFT);
108 }
109 
110 static inline u32 vl_msg_api_handle_from_index_and_epoch (u32 index, u32 epoch)
111 {
112  u32 handle;
113  ASSERT (index < 0x00FFFFFF);
114 
115  handle = (index<<VL_API_EPOCH_SHIFT) | (epoch & VL_API_EPOCH_MASK);
116  return handle;
117 }
118 
119 void *vl_msg_api_alloc(int nbytes);
120 void *vl_msg_api_alloc_as_if_client (int nbytes);
121 void vl_msg_api_free(void *a);
122 int vl_map_shmem (char *region_name, int is_vlib);
124 void vl_unmap_shmem (void);
127 void vl_msg_api_send (vl_api_registration_t *rp, u8 *elem);
128 int vl_client_connect (char *name, int ctx_quota, int input_queue_size);
129 void vl_client_disconnect (void);
132 int vl_client_api_map (char *region_name);
133 void vl_client_api_unmap (void);
134 void vl_set_memory_region_name (char *name);
135 void vl_set_memory_root_path (char *root_path);
136 void vl_set_memory_uid (int uid);
137 void vl_set_memory_gid (int gid);
138 void vl_enable_disable_memory_api (vlib_main_t *vm, int yesno);
140 int vl_client_connect_to_vlib(char *svm_name, char *client_name,
141  int rx_queue_size);
142 int vl_client_connect_to_vlib_no_rx_pthread (char *svm_name, char *client_name,
143  int rx_queue_size);
144 u16 vl_client_get_first_plugin_msg_id (char * plugin_name);
145 
146 void vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length);
147 
148 #endif /* included_vlibmemory_api_h */
int vl_client_connect_to_vlib(char *svm_name, char *client_name, int rx_queue_size)
void vl_enable_disable_memory_api(vlib_main_t *vm, int yesno)
Definition: memory_vlib.c:651
a
Definition: bitmap.h:393
void vl_set_memory_gid(int gid)
void vl_msg_api_send_shmem(unix_shared_memory_queue_t *q, u8 *elem)
u32 application_restarts
Definition: api.h:82
void vl_client_disconnect_from_vlib(void)
unix_shared_memory_queue_t * vl_input_queue
Definition: api.h:71
u16 nitems
Definition: api.h:44
unix_shared_memory_queue_t * vl_api_client_index_to_input_queue(u32 index)
ring_alloc_t * client_rings
Definition: api.h:79
void vl_unmap_shmem(void)
void vl_set_memory_uid(int uid)
void vl_msg_api_free(void *)
void vl_api_rpc_call_main_thread(void *fp, u8 *data, u32 data_length)
Definition: memory_vlib.c:1173
vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
int vl_client_api_map(char *region_name)
void vl_set_memory_root_path(char *root_path)
volatile int vl_pid
Definition: api.h:68
static u32 vl_msg_api_handle_get_index(u32 index)
Definition: api.h:105
u16 vl_client_get_first_plugin_msg_id(char *plugin_name)
void * vl_msg_api_alloc(int nbytes)
ring_alloc_t * vl_rings
Definition: api.h:76
int vl_client_connect_to_vlib_no_rx_pthread(char *svm_name, char *client_name, int rx_queue_size)
unix_shared_memory_queue_t * q
Definition: api.h:91
struct vl_shmem_hdr_ vl_shmem_hdr_t
int vl_client_connect(char *name, int ctx_quota, int input_queue_size)
struct msgbuf_ msgbuf_t
int version
Definition: api.h:65
#define ASSERT(truth)
#define VL_API_EPOCH_MASK
Definition: api.h:98
unsigned int u32
Definition: types.h:88
u16 size
Definition: api.h:43
u32 data_len
Definition: api.h:92
Definition: api.h:90
u32 misses
Definition: api.h:46
u32 restart_reclaims
Definition: api.h:85
void vl_msg_api_send(vl_api_registration_t *rp, u8 *elem)
Definition: memory_vlib.c:90
#define VL_API_EPOCH_SHIFT
Definition: api.h:99
void vl_register_mapped_shmem_region(svm_region_t *rp)
void vl_client_disconnect(void)
void vl_client_api_unmap(void)
void vl_set_memory_region_name(char *name)
Definition: memory_vlib.c:1063
unsigned short u16
Definition: types.h:57
unsigned char u8
Definition: types.h:56
int vl_map_shmem(char *region_name, int is_vlib)
struct ring_alloc_ ring_alloc_t
unix_shared_memory_queue_t * rp
Definition: api.h:42
void vl_msg_api_send_shmem_nolock(unix_shared_memory_queue_t *q, u8 *elem)
void * vl_msg_api_alloc_as_if_client(int nbytes)
static u32 vl_msg_api_handle_get_epoch(u32 index)
Definition: api.h:101
u32 hits
Definition: api.h:45
static u32 vl_msg_api_handle_from_index_and_epoch(u32 index, u32 epoch)
Definition: api.h:110
struct _unix_shared_memory_queue unix_shared_memory_queue_t