From 7cd468a3d7dee7d6c92f69a0bb7061ae208ec727 Mon Sep 17 00:00:00 2001 From: Damjan Marion Date: Mon, 19 Dec 2016 23:05:39 +0100 Subject: Reorganize source tree to use single autotools instance Change-Id: I7b51f88292e057c6443b12224486f2d0c9f8ae23 Signed-off-by: Damjan Marion --- src/vlibmemory/api.h | 163 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 src/vlibmemory/api.h (limited to 'src/vlibmemory/api.h') diff --git a/src/vlibmemory/api.h b/src/vlibmemory/api.h new file mode 100644 index 00000000..54a0a001 --- /dev/null +++ b/src/vlibmemory/api.h @@ -0,0 +1,163 @@ +/* + *------------------------------------------------------------------ + * api.h + * + * Copyright (c) 2009 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------ + */ + +#ifndef included_vlibmemory_api_h +#define included_vlibmemory_api_h + +#include +#include +#include +#include +#include +#include + +/* Allocated in shared memory */ + +/* + * Ring-allocation scheme for client API messages + * + * Only one proc/thread has control of a given message buffer. + * To free a buffer allocated from one of these rings, we clear + * a field in the buffer (header), and leave. + * + * No locks, no hits, no errors... + */ +typedef struct ring_alloc_ +{ + unix_shared_memory_queue_t *rp; + u16 size; + u16 nitems; + u32 hits; + u32 misses; +} ring_alloc_t; + +/* + * Initializers for the (shared-memory) rings + * _(size, n). Note: each msg has an 8 byte header. + * Might want to change that to an index sometime. + */ +#define foreach_vl_aring_size \ +_(64+8, 1024) \ +_(256+8, 128) \ +_(1024+8, 64) + +#define foreach_clnt_aring_size \ +_(1024+8, 1024) \ +_(2048+8, 128) \ +_(4096+8, 8) + +typedef struct vl_shmem_hdr_ +{ + int version; + + /* getpid () for the VLIB client process */ + volatile int vl_pid; + + /* Client sends VLIB msgs here. */ + unix_shared_memory_queue_t *vl_input_queue; + + /* Vector of rings; one for each size. */ + + /* VLIB allocates buffers to send msgs to clients here. */ + ring_alloc_t *vl_rings; + + /* Clients allocate buffer to send msgs to VLIB here. */ + ring_alloc_t *client_rings; + + /* Number of detected application restarts */ + u32 application_restarts; + + /* Number of messages reclaimed during application restart */ + u32 restart_reclaims; + +} vl_shmem_hdr_t; + +#define VL_SHM_VERSION 2 + +#define VL_API_EPOCH_MASK 0xFF +#define VL_API_EPOCH_SHIFT 8 + +static inline u32 +vl_msg_api_handle_get_epoch (u32 index) +{ + return (index & VL_API_EPOCH_MASK); +} + +static inline u32 +vl_msg_api_handle_get_index (u32 index) +{ + return (index >> VL_API_EPOCH_SHIFT); +} + +static inline u32 +vl_msg_api_handle_from_index_and_epoch (u32 index, u32 epoch) +{ + u32 handle; + ASSERT (index < 0x00FFFFFF); + + handle = (index << VL_API_EPOCH_SHIFT) | (epoch & VL_API_EPOCH_MASK); + return handle; +} + +void *vl_msg_api_alloc (int nbytes); +void *vl_msg_api_alloc_or_null (int nbytes); +void *vl_msg_api_alloc_as_if_client (int nbytes); +void *vl_msg_api_alloc_as_if_client_or_null (int nbytes); +void vl_msg_api_free (void *a); +int vl_map_shmem (char *region_name, int is_vlib); +void vl_register_mapped_shmem_region (svm_region_t * rp); +void vl_unmap_shmem (void); +void vl_msg_api_send_shmem (unix_shared_memory_queue_t * q, u8 * elem); +void vl_msg_api_send_shmem_nolock (unix_shared_memory_queue_t * q, u8 * elem); +void vl_msg_api_send (vl_api_registration_t * rp, u8 * elem); +int vl_client_connect (char *name, int ctx_quota, int input_queue_size); +void vl_client_disconnect (void); +unix_shared_memory_queue_t *vl_api_client_index_to_input_queue (u32 index); +vl_api_registration_t *vl_api_client_index_to_registration (u32 index); +int vl_client_api_map (char *region_name); +void vl_client_api_unmap (void); +void vl_set_memory_region_name (char *name); +void vl_set_memory_root_path (char *root_path); +void vl_set_memory_uid (int uid); +void vl_set_memory_gid (int gid); +void vl_set_global_memory_baseva (u64 baseva); +void vl_set_global_memory_size (u64 size); +void vl_set_api_memory_size (u64 size); +void vl_set_global_pvt_heap_size (u64 size); +void vl_set_api_pvt_heap_size (u64 size); +void vl_enable_disable_memory_api (vlib_main_t * vm, int yesno); +void vl_client_disconnect_from_vlib (void); +int vl_client_connect_to_vlib (char *svm_name, char *client_name, + int rx_queue_size); +int vl_client_connect_to_vlib_no_rx_pthread (char *svm_name, + char *client_name, + int rx_queue_size); +u16 vl_client_get_first_plugin_msg_id (char *plugin_name); + +void vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length); + +#endif /* included_vlibmemory_api_h */ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ -- cgit 1.2.3-korg From 842b9c59cc21b3e2917aaa25069fb15addf976f1 Mon Sep 17 00:00:00 2001 From: Dave Barach Date: Mon, 9 Jan 2017 15:54:00 -0500 Subject: Self-service garbage collection for the API message allocator Change-Id: Iadc08eede15fa5978e4010bbece0232aab8b0fee Signed-off-by: Dave Barach --- src/vlibapi/api.h | 3 ++- src/vlibmemory/api.h | 3 +++ src/vlibmemory/memory_shared.c | 21 +++++++++++++++++++++ src/vlibmemory/memory_vlib.c | 7 ++++--- 4 files changed, 30 insertions(+), 4 deletions(-) (limited to 'src/vlibmemory/api.h') diff --git a/src/vlibapi/api.h b/src/vlibapi/api.h index 970a0ee0..fcb101d7 100644 --- a/src/vlibapi/api.h +++ b/src/vlibapi/api.h @@ -124,6 +124,7 @@ typedef struct u8 *is_mp_safe; struct ring_alloc_ *arings; u32 ring_misses; + u32 garbage_collects; u32 missing_clients; vl_api_trace_t *rx_trace; vl_api_trace_t *tx_trace; @@ -212,7 +213,7 @@ typedef struct msgbuf_ { unix_shared_memory_queue_t *q; u32 data_len; - u32 pad; + u32 gc_mark_timestamp; u8 data[0]; } msgbuf_t; diff --git a/src/vlibmemory/api.h b/src/vlibmemory/api.h index 54a0a001..8e44c20d 100644 --- a/src/vlibmemory/api.h +++ b/src/vlibmemory/api.h @@ -86,6 +86,9 @@ typedef struct vl_shmem_hdr_ /* Number of messages reclaimed during application restart */ u32 restart_reclaims; + /* Number of garbage-collected messages */ + u32 garbage_collects; + } vl_shmem_hdr_t; #define VL_SHM_VERSION 2 diff --git a/src/vlibmemory/memory_shared.c b/src/vlibmemory/memory_shared.c index d8d32004..c41f32f7 100644 --- a/src/vlibmemory/memory_shared.c +++ b/src/vlibmemory/memory_shared.c @@ -95,12 +95,31 @@ vl_msg_api_alloc_internal (int nbytes, int pool, int may_return_null) */ if (rv->q) { + u32 now = (u32) time (0); + + if (PREDICT_TRUE (rv->gc_mark_timestamp == 0)) + rv->gc_mark_timestamp = now; + else + { + if (now - rv->gc_mark_timestamp > 10) + { + if (CLIB_DEBUG > 0) + clib_warning ("garbage collect pool %d ring %d index %d", + pool, i, q->head); + shmem_hdr->garbage_collects++; + goto collected; + } + } + + /* yes, loser; try next larger pool */ ap[i].misses++; if (pool == 0) pthread_mutex_unlock (&q->mutex); continue; } + collected: + /* OK, we have a winner */ ap[i].hits++; /* @@ -108,6 +127,7 @@ vl_msg_api_alloc_internal (int nbytes, int pool, int may_return_null) * don't need to know the queue to free the item. */ rv->q = q; + rv->gc_mark_timestamp = 0; q->head++; if (q->head == q->maxsize) q->head = 0; @@ -201,6 +221,7 @@ vl_msg_api_free (void *a) if (rv->q) { rv->q = 0; + rv->gc_mark_timestamp = 0; return; } diff --git a/src/vlibmemory/memory_vlib.c b/src/vlibmemory/memory_vlib.c index 69f35d72..7d21c9dd 100644 --- a/src/vlibmemory/memory_vlib.c +++ b/src/vlibmemory/memory_vlib.c @@ -853,9 +853,10 @@ vl_api_ring_command (vlib_main_t * vm, vlib_cli_output (vm, "%d ring miss fallback allocations\n", am->ring_misses); - vlib_cli_output (vm, "%d application restarts, %d reclaimed msgs\n", - shmem_hdr->application_restarts, - shmem_hdr->restart_reclaims); + vlib_cli_output + (vm, "%d application restarts, %d reclaimed msgs, %d garbage collects\n", + shmem_hdr->application_restarts, + shmem_hdr->restart_reclaims, shmem_hdr->garbage_collects); return 0; } -- cgit 1.2.3-korg From e72be39cd0f498178fd62dfc0a0b0daa2b633f62 Mon Sep 17 00:00:00 2001 From: Neale Ranns Date: Wed, 26 Apr 2017 13:59:20 -0700 Subject: A sprinkling of const in vlibmemory/api.h and friends Change-Id: I953ebb37eeec7de0c4a6b00258c3c67a83cbc020 Signed-off-by: Neale Ranns --- src/svm/svm.c | 6 +++--- src/svm/svm.h | 10 +++++----- src/svm/svmdb.h | 2 +- src/vlibapi/api.h | 11 ++++++----- src/vlibapi/api_shared.c | 4 ++-- src/vlibmemory/api.h | 20 ++++++++++---------- src/vlibmemory/memory_client.c | 16 +++++++++------- src/vlibmemory/memory_shared.c | 4 ++-- src/vlibmemory/memory_vlib.c | 4 ++-- src/vpp/api/api_main.c | 2 +- 10 files changed, 41 insertions(+), 38 deletions(-) (limited to 'src/vlibmemory/api.h') diff --git a/src/svm/svm.c b/src/svm/svm.c index e4ca98e1..97add5a7 100644 --- a/src/svm/svm.c +++ b/src/svm/svm.c @@ -796,7 +796,7 @@ svm_region_init (void) } void -svm_region_init_chroot (char *root_path) +svm_region_init_chroot (const char *root_path) { svm_map_region_args_t _a, *a = &_a; @@ -813,7 +813,7 @@ svm_region_init_chroot (char *root_path) } void -svm_region_init_chroot_uid_gid (char *root_path, int uid, int gid) +svm_region_init_chroot_uid_gid (const char *root_path, int uid, int gid) { svm_map_region_args_t _a, *a = &_a; @@ -1151,7 +1151,7 @@ svm_client_scan_this_region_nolock (svm_region_t * rp) * Scan svm regions for dead clients */ void -svm_client_scan (char *root_path) +svm_client_scan (const char *root_path) { int i, j; svm_main_region_t *mp; diff --git a/src/svm/svm.h b/src/svm/svm.h index 0b87dbcb..06797fa1 100644 --- a/src/svm/svm.h +++ b/src/svm/svm.h @@ -69,8 +69,8 @@ typedef struct svm_region_ typedef struct svm_map_region_args_ { - char *root_path; /* NULL means use the truly global arena */ - char *name; + const char *root_path; /* NULL means use the truly global arena */ + const char *name; u64 baseva; u64 size; u64 pvt_heap_size; @@ -115,12 +115,12 @@ typedef struct void *svm_region_find_or_create (svm_map_region_args_t * a); void svm_region_init (void); -void svm_region_init_chroot (char *root_path); -void svm_region_init_chroot_uid_gid (char *root_path, int uid, int gid); +void svm_region_init_chroot (const char *root_path); +void svm_region_init_chroot_uid_gid (const char *root_path, int uid, int gid); void svm_region_init_args (svm_map_region_args_t * a); void svm_region_exit (void); void svm_region_unmap (void *rp_arg); -void svm_client_scan (char *root_path); +void svm_client_scan (const char *root_path); void svm_client_scan_this_region_nolock (svm_region_t * rp); u8 *shm_name_from_svm_map_region_args (svm_map_region_args_t * a); diff --git a/src/svm/svmdb.h b/src/svm/svmdb.h index e02628a0..e35be8aa 100644 --- a/src/svm/svmdb.h +++ b/src/svm/svmdb.h @@ -83,7 +83,7 @@ typedef struct typedef struct { - char *root_path; + const char *root_path; uword size; u32 uid; u32 gid; diff --git a/src/vlibapi/api.h b/src/vlibapi/api.h index a62fa644..7538050e 100644 --- a/src/vlibapi/api.h +++ b/src/vlibapi/api.h @@ -127,7 +127,7 @@ typedef struct void (**msg_cleanup_handlers) (void *); void (**msg_endian_handlers) (void *); void (**msg_print_handlers) (void *, void *); - char **msg_names; + const char **msg_names; u8 *message_bounce; u8 *is_mp_safe; struct ring_alloc_ *arings; @@ -195,8 +195,8 @@ typedef struct /* client side message index hash table */ uword *msg_index_by_name_and_crc; - char *region_name; - char *root_path; + const char *region_name; + const char *root_path; /* Replay in progress? */ int replay_in_progress; @@ -276,8 +276,9 @@ void vl_msg_api_register_pd_handler (void *handler, int vl_msg_api_pd_handler (void *mp, int rv); void vl_msg_api_set_first_available_msg_id (u16 first_avail); -u16 vl_msg_api_get_msg_ids (char *name, int n); -void vl_msg_api_add_msg_name_crc (api_main_t * am, char *string, u32 id); +u16 vl_msg_api_get_msg_ids (const char *name, int n); +void vl_msg_api_add_msg_name_crc (api_main_t * am, const char *string, + u32 id); u32 vl_api_get_msg_index (u8 * name_and_crc); /* node_serialize.c prototypes */ diff --git a/src/vlibapi/api_shared.c b/src/vlibapi/api_shared.c index 6774e3dd..0817f38e 100644 --- a/src/vlibapi/api_shared.c +++ b/src/vlibapi/api_shared.c @@ -828,7 +828,7 @@ vl_msg_api_set_first_available_msg_id (u16 first_avail) } u16 -vl_msg_api_get_msg_ids (char *name, int n) +vl_msg_api_get_msg_ids (const char *name, int n) { api_main_t *am = &api_main; u8 *name_copy; @@ -872,7 +872,7 @@ vl_msg_api_get_msg_ids (char *name, int n) } void -vl_msg_api_add_msg_name_crc (api_main_t * am, char *string, u32 id) +vl_msg_api_add_msg_name_crc (api_main_t * am, const char *string, u32 id) { uword *p; diff --git a/src/vlibmemory/api.h b/src/vlibmemory/api.h index 8e44c20d..c195e181 100644 --- a/src/vlibmemory/api.h +++ b/src/vlibmemory/api.h @@ -123,20 +123,20 @@ void *vl_msg_api_alloc_or_null (int nbytes); void *vl_msg_api_alloc_as_if_client (int nbytes); void *vl_msg_api_alloc_as_if_client_or_null (int nbytes); void vl_msg_api_free (void *a); -int vl_map_shmem (char *region_name, int is_vlib); +int vl_map_shmem (const char *region_name, int is_vlib); void vl_register_mapped_shmem_region (svm_region_t * rp); void vl_unmap_shmem (void); void vl_msg_api_send_shmem (unix_shared_memory_queue_t * q, u8 * elem); void vl_msg_api_send_shmem_nolock (unix_shared_memory_queue_t * q, u8 * elem); void vl_msg_api_send (vl_api_registration_t * rp, u8 * elem); -int vl_client_connect (char *name, int ctx_quota, int input_queue_size); +int vl_client_connect (const char *name, int ctx_quota, int input_queue_size); void vl_client_disconnect (void); unix_shared_memory_queue_t *vl_api_client_index_to_input_queue (u32 index); vl_api_registration_t *vl_api_client_index_to_registration (u32 index); -int vl_client_api_map (char *region_name); +int vl_client_api_map (const char *region_name); void vl_client_api_unmap (void); -void vl_set_memory_region_name (char *name); -void vl_set_memory_root_path (char *root_path); +void vl_set_memory_region_name (const char *name); +void vl_set_memory_root_path (const char *root_path); void vl_set_memory_uid (int uid); void vl_set_memory_gid (int gid); void vl_set_global_memory_baseva (u64 baseva); @@ -146,12 +146,12 @@ void vl_set_global_pvt_heap_size (u64 size); void vl_set_api_pvt_heap_size (u64 size); void vl_enable_disable_memory_api (vlib_main_t * vm, int yesno); void vl_client_disconnect_from_vlib (void); -int vl_client_connect_to_vlib (char *svm_name, char *client_name, - int rx_queue_size); -int vl_client_connect_to_vlib_no_rx_pthread (char *svm_name, - char *client_name, +int vl_client_connect_to_vlib (const char *svm_name, + const char *client_name, int rx_queue_size); +int vl_client_connect_to_vlib_no_rx_pthread (const char *svm_name, + const char *client_name, int rx_queue_size); -u16 vl_client_get_first_plugin_msg_id (char *plugin_name); +u16 vl_client_get_first_plugin_msg_id (const char *plugin_name); void vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length); diff --git a/src/vlibmemory/memory_client.c b/src/vlibmemory/memory_client.c index 25b06f65..d48a4fa1 100644 --- a/src/vlibmemory/memory_client.c +++ b/src/vlibmemory/memory_client.c @@ -155,7 +155,7 @@ noop_handler (void *notused) } int -vl_client_connect (char *name, int ctx_quota, int input_queue_size) +vl_client_connect (const char *name, int ctx_quota, int input_queue_size) { svm_region_t *svm; vl_api_memclnt_create_t *mp; @@ -326,7 +326,7 @@ _(MEMCLNT_DELETE_REPLY, memclnt_delete_reply) int -vl_client_api_map (char *region_name) +vl_client_api_map (const char *region_name) { int rv; @@ -354,7 +354,8 @@ vl_client_api_unmap (void) } static int -connect_to_vlib_internal (char *svm_name, char *client_name, +connect_to_vlib_internal (const char *svm_name, + const char *client_name, int rx_queue_size, int want_pthread) { int rv = 0; @@ -388,15 +389,16 @@ connect_to_vlib_internal (char *svm_name, char *client_name, } int -vl_client_connect_to_vlib (char *svm_name, char *client_name, - int rx_queue_size) +vl_client_connect_to_vlib (const char *svm_name, + const char *client_name, int rx_queue_size) { return connect_to_vlib_internal (svm_name, client_name, rx_queue_size, 1 /* want pthread */ ); } int -vl_client_connect_to_vlib_no_rx_pthread (char *svm_name, char *client_name, +vl_client_connect_to_vlib_no_rx_pthread (const char *svm_name, + const char *client_name, int rx_queue_size) { return connect_to_vlib_internal (svm_name, client_name, rx_queue_size, @@ -437,7 +439,7 @@ static void vl_api_get_first_msg_id_reply_t_handler } u16 -vl_client_get_first_plugin_msg_id (char *plugin_name) +vl_client_get_first_plugin_msg_id (const char *plugin_name) { vl_api_get_first_msg_id_t *mp; api_main_t *am = &api_main; diff --git a/src/vlibmemory/memory_shared.c b/src/vlibmemory/memory_shared.c index 6cea5df9..aea90330 100644 --- a/src/vlibmemory/memory_shared.c +++ b/src/vlibmemory/memory_shared.c @@ -257,7 +257,7 @@ vl_msg_api_free_nolock (void *a) } void -vl_set_memory_root_path (char *name) +vl_set_memory_root_path (const char *name) { api_main_t *am = &api_main; @@ -321,7 +321,7 @@ vl_set_api_pvt_heap_size (u64 size) } int -vl_map_shmem (char *region_name, int is_vlib) +vl_map_shmem (const char *region_name, int is_vlib) { svm_map_region_args_t _a, *a = &_a; svm_region_t *vlib_rp, *root_rp; diff --git a/src/vlibmemory/memory_vlib.c b/src/vlibmemory/memory_vlib.c index 43574dea..29a5c2c2 100644 --- a/src/vlibmemory/memory_vlib.c +++ b/src/vlibmemory/memory_vlib.c @@ -361,7 +361,7 @@ _(GET_FIRST_MSG_ID, get_first_msg_id) * vl_api_init */ static int -memory_api_init (char *region_name) +memory_api_init (const char *region_name) { int rv; vl_msg_api_msg_config_t cfg; @@ -1202,7 +1202,7 @@ vlibmemory_init (vlib_main_t * vm) VLIB_INIT_FUNCTION (vlibmemory_init); void -vl_set_memory_region_name (char *name) +vl_set_memory_region_name (const char *name) { api_main_t *am = &api_main; diff --git a/src/vpp/api/api_main.c b/src/vpp/api/api_main.c index d48e4eff..ac09cd15 100644 --- a/src/vpp/api/api_main.c +++ b/src/vpp/api/api_main.c @@ -211,7 +211,7 @@ api_cli_output (void *notused, const char *fmt, ...) } u16 -vl_client_get_first_plugin_msg_id (char *plugin_name) +vl_client_get_first_plugin_msg_id (const char *plugin_name) { api_main_t *am = &api_main; vl_api_msg_range_t *rp; -- cgit 1.2.3-korg From 58eb866b15a45514dc356170f28640d6c9db8034 Mon Sep 17 00:00:00 2001 From: Klement Sekera Date: Fri, 9 Jun 2017 06:06:49 +0200 Subject: Refactor API message handling code This is preparation for new C API. Moving common stuff to separate headers reduces dependency issues. Change-Id: Ie7adb23398de72448e5eba6c1c1da4e1bc678725 Signed-off-by: Klement Sekera --- src/svm.am | 2 +- src/svm/svm.h | 102 +--------------- src/svm/svm_common.h | 133 +++++++++++++++++++++ src/vlib-api.am | 6 +- src/vlibapi/api.h | 280 ++++---------------------------------------- src/vlibapi/api_common.h | 268 ++++++++++++++++++++++++++++++++++++++++++ src/vlibmemory/api.h | 107 +---------------- src/vlibmemory/api_common.h | 138 ++++++++++++++++++++++ src/vppinfra.am | 1 + src/vppinfra/clib_error.h | 35 ++++++ src/vppinfra/error.h | 14 +-- 11 files changed, 609 insertions(+), 477 deletions(-) create mode 100644 src/svm/svm_common.h create mode 100644 src/vlibapi/api_common.h create mode 100644 src/vlibmemory/api_common.h create mode 100644 src/vppinfra/clib_error.h (limited to 'src/vlibmemory/api.h') diff --git a/src/svm.am b/src/svm.am index 442eba8e..7116eb37 100644 --- a/src/svm.am +++ b/src/svm.am @@ -13,7 +13,7 @@ bin_PROGRAMS += svmtool svmdbtool -nobase_include_HEADERS += svm/svm.h svm/ssvm.h svm/svmdb.h \ +nobase_include_HEADERS += svm/svm.h svm/svm_common.h svm/ssvm.h svm/svmdb.h \ svm/svm_fifo.h svm/svm_fifo_segment.h lib_LTLIBRARIES += libsvm.la libsvmdb.la diff --git a/src/svm/svm.h b/src/svm/svm.h index 06797fa1..894c3d95 100644 --- a/src/svm/svm.h +++ b/src/svm/svm.h @@ -24,106 +24,10 @@ #include #include #include +#include #define MMAP_PAGESIZE (clib_mem_get_page_size()) -#define SVM_VERSION ((1<<16) | 1) /* set to declare region ready. */ - -#define SVM_FLAGS_MHEAP (1<<0) /* region contains an mheap */ -#define SVM_FLAGS_FILE (1<<1) /* region backed by one or more files */ -#define SVM_FLAGS_NODATA (1<<2) /* region will be further subdivided */ -#define SVM_FLAGS_NEED_DATA_INIT (1<<3) - -#define SVM_PVT_MHEAP_SIZE (128<<10) /* region's private mheap (128k) */ - -typedef struct svm_region_ -{ - volatile uword version; - pthread_mutex_t mutex; - pthread_cond_t condvar; - int mutex_owner_pid; /* in case of trouble */ - int mutex_owner_tag; - uword flags; - uword virtual_base; /* base of the region object */ - uword virtual_size; - void *region_heap; - void *data_base; /* data portion base address */ - void *data_heap; /* data heap, if any */ - volatile void *user_ctx; /* user context pointer */ - /* stuff allocated in the region's heap */ - uword bitmap_size; /* nbits in virtual alloc bitmap */ - uword *bitmap; /* the bitmap */ - char *region_name; - char *backing_file; - char **filenames; - uword *client_pids; - /* pad */ - - /* next page: - * (64K) clib heap for the region itself - * - * data_base -> whatever is in this region - */ - -} svm_region_t; - -typedef struct svm_map_region_args_ -{ - const char *root_path; /* NULL means use the truly global arena */ - const char *name; - u64 baseva; - u64 size; - u64 pvt_heap_size; - uword flags; - char *backing_file; - uword backing_mmap_size; - /* uid, gid to own the svm region(s) */ - int uid; - int gid; -} svm_map_region_args_t; - - -/* - * Memory shared across all router instances. Packet buffers, etc - * Base should be "out of the way," and size should be big enough to - * cover everything we plan to put here. - */ -#define SVM_GLOBAL_REGION_BASEVA 0x30000000 -#define SVM_GLOBAL_REGION_SIZE (64<<20) -#define SVM_GLOBAL_REGION_NAME "/global_vm" - -/* - * Memory shared across individual router instances. - */ -#define SVM_OVERLAY_REGION_BASEVA \ - (SVM_GLOBAL_REGION_BASEVA + SVM_GLOBAL_REGION_SIZE) -#define SVM_OVERLAY_REGION_SIZE (1<<20) -#define SVM_OVERLAY_REGION_BASENAME "/overlay_vm" - -typedef struct -{ - u8 *subregion_name; -} svm_subregion_t; - -typedef struct -{ - svm_subregion_t *subregions; /* subregion pool */ - uword *name_hash; - u8 *root_path; -} svm_main_region_t; - - -void *svm_region_find_or_create (svm_map_region_args_t * a); -void svm_region_init (void); -void svm_region_init_chroot (const char *root_path); -void svm_region_init_chroot_uid_gid (const char *root_path, int uid, int gid); -void svm_region_init_args (svm_map_region_args_t * a); -void svm_region_exit (void); -void svm_region_unmap (void *rp_arg); -void svm_client_scan (const char *root_path); -void svm_client_scan_this_region_nolock (svm_region_t * rp); -u8 *shm_name_from_svm_map_region_args (svm_map_region_args_t * a); - static inline void * svm_mem_alloc (svm_region_t * rp, uword size) { @@ -192,10 +96,6 @@ svm_pop_heap (void *oldheap) clib_mem_set_heap (oldheap); } -u8 *format_svm_region (u8 * s, va_list * args); - -svm_region_t *svm_get_root_rp (void); - #endif /* __included_svm_h__ */ /* diff --git a/src/svm/svm_common.h b/src/svm/svm_common.h new file mode 100644 index 00000000..1f184432 --- /dev/null +++ b/src/svm/svm_common.h @@ -0,0 +1,133 @@ +/* + *------------------------------------------------------------------ + * Copyright (c) 2009 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------ + */ + +#ifndef __included_svm_common_h__ +#define __included_svm_common_h__ + +#include +#include +#include + +#define SVM_VERSION ((1<<16) | 1) /* set to declare region ready. */ + +#define SVM_FLAGS_MHEAP (1<<0) /* region contains an mheap */ +#define SVM_FLAGS_FILE (1<<1) /* region backed by one or more files */ +#define SVM_FLAGS_NODATA (1<<2) /* region will be further subdivided */ +#define SVM_FLAGS_NEED_DATA_INIT (1<<3) + +#define SVM_PVT_MHEAP_SIZE (128<<10) /* region's private mheap (128k) */ + +typedef struct svm_region_ +{ + volatile uword version; + pthread_mutex_t mutex; + pthread_cond_t condvar; + int mutex_owner_pid; /* in case of trouble */ + int mutex_owner_tag; + uword flags; + uword virtual_base; /* base of the region object */ + uword virtual_size; + void *region_heap; + void *data_base; /* data portion base address */ + void *data_heap; /* data heap, if any */ + volatile void *user_ctx; /* user context pointer */ + /* stuff allocated in the region's heap */ + uword bitmap_size; /* nbits in virtual alloc bitmap */ + uword *bitmap; /* the bitmap */ + char *region_name; + char *backing_file; + char **filenames; + uword *client_pids; + /* pad */ + + /* next page: + * (64K) clib heap for the region itself + * + * data_base -> whatever is in this region + */ + +} svm_region_t; + +typedef struct svm_map_region_args_ +{ + const char *root_path; /* NULL means use the truly global arena */ + const char *name; + u64 baseva; + u64 size; + u64 pvt_heap_size; + uword flags; + char *backing_file; + uword backing_mmap_size; + /* uid, gid to own the svm region(s) */ + int uid; + int gid; +} svm_map_region_args_t; + + +/* + * Memory shared across all router instances. Packet buffers, etc + * Base should be "out of the way," and size should be big enough to + * cover everything we plan to put here. + */ +#define SVM_GLOBAL_REGION_BASEVA 0x30000000 +#define SVM_GLOBAL_REGION_SIZE (64<<20) +#define SVM_GLOBAL_REGION_NAME "/global_vm" + +/* + * Memory shared across individual router instances. + */ +#define SVM_OVERLAY_REGION_BASEVA \ + (SVM_GLOBAL_REGION_BASEVA + SVM_GLOBAL_REGION_SIZE) +#define SVM_OVERLAY_REGION_SIZE (1<<20) +#define SVM_OVERLAY_REGION_BASENAME "/overlay_vm" + +typedef struct +{ + u8 *subregion_name; +} svm_subregion_t; + +typedef struct +{ + svm_subregion_t *subregions; /* subregion pool */ + uword *name_hash; + u8 *root_path; +} svm_main_region_t; + + +void *svm_region_find_or_create (svm_map_region_args_t * a); +void svm_region_init (void); +void svm_region_init_chroot (const char *root_path); +void svm_region_init_chroot_uid_gid (const char *root_path, int uid, int gid); +void svm_region_init_args (svm_map_region_args_t * a); +void svm_region_exit (void); +void svm_region_unmap (void *rp_arg); +void svm_client_scan (const char *root_path); +void svm_client_scan_this_region_nolock (svm_region_t * rp); +u8 *shm_name_from_svm_map_region_args (svm_map_region_args_t * a); +u8 *format_svm_region (u8 * s, va_list * args); + +svm_region_t *svm_get_root_rp (void); + +#endif /* __included_svm_common_h__ */ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/vlib-api.am b/src/vlib-api.am index eea52420..677811bc 100644 --- a/src/vlib-api.am +++ b/src/vlib-api.am @@ -30,7 +30,10 @@ libvlibmemory_la_SOURCES = \ vlibmemory/vl_memory_api_h.h \ vlibmemory/vl_memory_msg_enum.h -nobase_include_HEADERS += vlibapi/api.h vlibapi/api_helper_macros.h vlibapi/vat_helper_macros.h +nobase_include_HEADERS += vlibapi/api.h \ + vlibapi/api_common.h \ + vlibapi/api_helper_macros.h \ + vlibapi/vat_helper_macros.h libvlibmemoryclient_la_DEPENDENCIES = libvppinfra.la libsvm.la libvlibmemoryclient_la_LIBADD = $(libvlibmemoryclient_la_DEPENDENCIES) -lpthread @@ -49,6 +52,7 @@ libvlibmemoryclient_la_SOURCES = \ nobase_include_HEADERS += \ vlibmemory/api.h \ + vlibmemory/api_common.h \ vlibmemory/vl_memory_api_h.h \ vlibmemory/vl_memory_msg_enum.h \ vlibmemory/unix_shared_memory_queue.h \ diff --git a/src/vlibapi/api.h b/src/vlibapi/api.h index 0e2c2101..49f5d5fb 100644 --- a/src/vlibapi/api.h +++ b/src/vlibapi/api.h @@ -20,73 +20,13 @@ #ifndef included_api_h #define included_api_h +#include #include #include #include #include #include -#include - -typedef enum -{ - REGISTRATION_TYPE_FREE = 0, - REGISTRATION_TYPE_SHMEM, - REGISTRATION_TYPE_SOCKET_LISTEN, - REGISTRATION_TYPE_SOCKET_SERVER, - REGISTRATION_TYPE_SOCKET_CLIENT, -} vl_registration_type_t; - -typedef struct vl_api_registration_ -{ - vl_registration_type_t registration_type; - - /* Index in VLIB's brain (not shared memory). */ - u32 vl_api_registration_pool_index; - - u8 *name; - - /* - * The following groups of data could be unioned, but my fingers are - * going to be sore enough. - */ - - /* shared memory only */ - unix_shared_memory_queue_t *vl_input_queue; - - /* socket server and client */ - u32 unix_file_index; - i8 *unprocessed_input; - u32 unprocessed_msg_length; - u8 *output_vector; - - /* socket client only */ - u32 server_handle; - u32 server_index; - -} vl_api_registration_t; - - -/* Trace configuration for a single message */ -typedef struct -{ - int size; - int trace_enable; - int replay_enable; -} trace_cfg_t; - -/* - * API recording - */ -typedef struct -{ - u8 endian; - u8 enabled; - u8 wrapped; - u8 pad; - u32 nitems; - u32 curindex; - u8 **traces; -} vl_api_trace_t; +#include /* *INDENT-OFF* */ typedef CLIB_PACKED @@ -97,200 +37,8 @@ typedef CLIB_PACKED }) vl_api_trace_file_header_t; /* *INDENT-ON* */ -typedef enum -{ - VL_API_TRACE_TX, - VL_API_TRACE_RX, -} vl_api_trace_which_t; - -#define VL_API_LITTLE_ENDIAN 0x00 -#define VL_API_BIG_ENDIAN 0x01 - -typedef struct -{ - u8 *name; - u16 first_msg_id; - u16 last_msg_id; -} vl_api_msg_range_t; - -typedef clib_error_t *(vl_msg_api_init_function_t) (u32 client_index); - -typedef struct _vl_msg_api_init_function_list_elt -{ - struct _vl_msg_api_init_function_list_elt *next_init_function; - vl_msg_api_init_function_t *f; -} _vl_msg_api_function_list_elt_t; - -typedef struct -{ - void (**msg_handlers) (void *); - int (**pd_msg_handlers) (void *, int); - void (**msg_cleanup_handlers) (void *); - void (**msg_endian_handlers) (void *); - void (**msg_print_handlers) (void *, void *); - const char **msg_names; - u8 *message_bounce; - u8 *is_mp_safe; - struct ring_alloc_ *arings; - u32 ring_misses; - u32 garbage_collects; - u32 missing_clients; - vl_api_trace_t *rx_trace; - vl_api_trace_t *tx_trace; - int msg_print_flag; - trace_cfg_t *api_trace_cfg; - int our_pid; - svm_region_t *vlib_rp; - svm_region_t **mapped_shmem_regions; - struct vl_shmem_hdr_ *shmem_hdr; - vl_api_registration_t **vl_clients; - - u8 *serialized_message_table_in_shmem; - - /* For plugin msg allocator */ - u16 first_available_msg_id; - - /* message range by name hash */ - uword *msg_range_by_name; - - /* vector of message ranges */ - vl_api_msg_range_t *msg_ranges; - - /* uid for the api shared memory region */ - int api_uid; - /* gid for the api shared memory region */ - int api_gid; - - /* base virtual address for global VM region */ - u64 global_baseva; - - /* size of the global VM region */ - u64 global_size; - - /* size of the API region */ - u64 api_size; - - /* size of the global VM private mheap */ - u64 global_pvt_heap_size; - - /* size of the api private mheap */ - u64 api_pvt_heap_size; - - /* Client-only data structures */ - unix_shared_memory_queue_t *vl_input_queue; - - /* - * All VLIB-side message handlers use my_client_index to identify - * the queue / client. This works in sim replay. - */ - int my_client_index; - /* - * This is the (shared VM) address of the registration, - * don't use it to id the connection since it can't possibly - * work in simulator replay. - */ - vl_api_registration_t *my_registration; - - i32 vlib_signal; - - /* vlib input queue length */ - u32 vlib_input_queue_length; - - /* client side message index hash table */ - uword *msg_index_by_name_and_crc; - - const char *region_name; - const char *root_path; - - /* Replay in progress? */ - int replay_in_progress; - - /* List of API client reaper functions */ - _vl_msg_api_function_list_elt_t *reaper_function_registrations; - -} api_main_t; - -extern api_main_t api_main; - -typedef struct -{ - int id; - char *name; - u32 crc; - void *handler; - void *cleanup; - void *endian; - void *print; - int size; - int traced; - int replay; - int message_bounce; - int is_mp_safe; -} vl_msg_api_msg_config_t; - -typedef struct msgbuf_ -{ - unix_shared_memory_queue_t *q; - u32 data_len; - u32 gc_mark_timestamp; - u8 data[0]; -} msgbuf_t; - -/* api_shared.c prototypes */ -int vl_msg_api_rx_trace_enabled (api_main_t * am); -int vl_msg_api_tx_trace_enabled (api_main_t * am); -void vl_msg_api_trace (api_main_t * am, vl_api_trace_t * tp, void *msg); -int vl_msg_api_trace_onoff (api_main_t * am, vl_api_trace_which_t which, - int onoff); -int vl_msg_api_trace_free (api_main_t * am, vl_api_trace_which_t which); int vl_msg_api_trace_save (api_main_t * am, vl_api_trace_which_t which, FILE * fp); -int vl_msg_api_trace_configure (api_main_t * am, vl_api_trace_which_t which, - u32 nitems); -void vl_msg_api_handler_with_vm_node (api_main_t * am, - void *the_msg, vlib_main_t * vm, - vlib_node_runtime_t * node); -void vl_msg_api_handler (void *the_msg); -void vl_msg_api_handler_no_free (void *the_msg); -void vl_msg_api_handler_no_trace_no_free (void *the_msg); -void vl_msg_api_trace_only (void *the_msg); -void vl_msg_api_cleanup_handler (void *the_msg); -void vl_msg_api_replay_handler (void *the_msg); -void vl_msg_api_socket_handler (void *the_msg); -void vl_msg_api_set_handlers (int msg_id, char *msg_name, - void *handler, - void *cleanup, - void *endian, - void *print, int msg_size, int traced); -void vl_msg_api_config (vl_msg_api_msg_config_t *); -void vl_msg_api_set_cleanup_handler (int msg_id, void *fp); -void vl_msg_api_queue_handler (unix_shared_memory_queue_t * q); -vl_api_trace_t *vl_msg_api_trace_get (api_main_t * am, - vl_api_trace_which_t which); - -void vl_msg_api_barrier_sync (void) __attribute__ ((weak)); -void vl_msg_api_barrier_release (void) __attribute__ ((weak)); -void vl_msg_api_free (void *); -void vl_noop_handler (void *mp); -void vl_msg_api_increment_missing_client_counter (void); -void vl_msg_api_post_mortem_dump (void); -void vl_msg_api_post_mortem_dump_enable_disable (int enable); -void vl_msg_api_register_pd_handler (void *handler, - u16 msg_id_host_byte_order); -int vl_msg_api_pd_handler (void *mp, int rv); - -void vl_msg_api_set_first_available_msg_id (u16 first_avail); -u16 vl_msg_api_get_msg_ids (const char *name, int n); -void vl_msg_api_add_msg_name_crc (api_main_t * am, const char *string, - u32 id); -u32 vl_api_get_msg_index (u8 * name_and_crc); -u32 vl_msg_api_get_msg_length (void *msg_arg); - -/* node_serialize.c prototypes */ -u8 *vlib_node_serialize (vlib_node_main_t * nm, u8 * vector, - u32 max_threads, int include_nexts, - int include_stats); -vlib_node_t **vlib_node_unserialize (u8 * vector); #define VLIB_API_INIT_FUNCTION(x) VLIB_DECLARE_INIT_FUNCTION(x,api_init) @@ -350,8 +98,30 @@ vl_msg_api_get_msg_length_inline (void *msg_arg) return clib_net_to_host_u32 (header->data_len); } -#endif /* included_api_h */ +int vl_msg_api_rx_trace_enabled (api_main_t * am); +int vl_msg_api_tx_trace_enabled (api_main_t * am); +void vl_msg_api_trace (api_main_t * am, vl_api_trace_t * tp, void *msg); +int vl_msg_api_trace_onoff (api_main_t * am, vl_api_trace_which_t which, + int onoff); +int vl_msg_api_trace_free (api_main_t * am, vl_api_trace_which_t which); +int vl_msg_api_trace_configure (api_main_t * am, vl_api_trace_which_t which, + u32 nitems); +void vl_msg_api_handler_with_vm_node (api_main_t * am, + void *the_msg, vlib_main_t * vm, + vlib_node_runtime_t * node); +vl_api_trace_t *vl_msg_api_trace_get (api_main_t * am, + vl_api_trace_which_t which); +void vl_msg_api_add_msg_name_crc (api_main_t * am, const char *string, + u32 id); +/* node_serialize.c prototypes */ +u8 *vlib_node_serialize (vlib_node_main_t * nm, u8 * vector, + u32 max_threads, int include_nexts, + int include_stats); +vlib_node_t **vlib_node_unserialize (u8 * vector); +u32 vl_msg_api_get_msg_length (void *msg_arg); + +#endif /* included_api_h */ /* * fd.io coding-style-patch-verification: ON * diff --git a/src/vlibapi/api_common.h b/src/vlibapi/api_common.h new file mode 100644 index 00000000..b84d269e --- /dev/null +++ b/src/vlibapi/api_common.h @@ -0,0 +1,268 @@ +/* + *------------------------------------------------------------------ + * api_common.h + * + * Copyright (c) 2009-2015 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------ + */ + +#ifndef included_api_common_h +#define included_api_common_h + +#include +#include +#include + +typedef enum +{ + REGISTRATION_TYPE_FREE = 0, + REGISTRATION_TYPE_SHMEM, + REGISTRATION_TYPE_SOCKET_LISTEN, + REGISTRATION_TYPE_SOCKET_SERVER, + REGISTRATION_TYPE_SOCKET_CLIENT, +} vl_registration_type_t; + +typedef struct vl_api_registration_ +{ + vl_registration_type_t registration_type; + + /* Index in VLIB's brain (not shared memory). */ + u32 vl_api_registration_pool_index; + + u8 *name; + + /* + * The following groups of data could be unioned, but my fingers are + * going to be sore enough. + */ + + /* shared memory only */ + unix_shared_memory_queue_t *vl_input_queue; + + /* socket server and client */ + u32 unix_file_index; + i8 *unprocessed_input; + u32 unprocessed_msg_length; + u8 *output_vector; + + /* socket client only */ + u32 server_handle; + u32 server_index; + +} vl_api_registration_t; + + +/* Trace configuration for a single message */ +typedef struct +{ + int size; + int trace_enable; + int replay_enable; +} trace_cfg_t; + +/* + * API recording + */ +typedef struct +{ + u8 endian; + u8 enabled; + u8 wrapped; + u8 pad; + u32 nitems; + u32 curindex; + u8 **traces; +} vl_api_trace_t; + +typedef enum +{ + VL_API_TRACE_TX, + VL_API_TRACE_RX, +} vl_api_trace_which_t; + +#define VL_API_LITTLE_ENDIAN 0x00 +#define VL_API_BIG_ENDIAN 0x01 + +typedef struct +{ + u8 *name; + u16 first_msg_id; + u16 last_msg_id; +} vl_api_msg_range_t; + +typedef struct +{ + int id; + char *name; + u32 crc; + void *handler; + void *cleanup; + void *endian; + void *print; + int size; + int traced; + int replay; + int message_bounce; + int is_mp_safe; +} vl_msg_api_msg_config_t; + +typedef struct msgbuf_ +{ + unix_shared_memory_queue_t *q; + u32 data_len; + u32 gc_mark_timestamp; + u8 data[0]; +} msgbuf_t; + +/* api_shared.c prototypes */ +void vl_msg_api_handler (void *the_msg); +void vl_msg_api_handler_no_free (void *the_msg); +void vl_msg_api_handler_no_trace_no_free (void *the_msg); +void vl_msg_api_trace_only (void *the_msg); +void vl_msg_api_cleanup_handler (void *the_msg); +void vl_msg_api_replay_handler (void *the_msg); +void vl_msg_api_socket_handler (void *the_msg); +void vl_msg_api_set_handlers (int msg_id, char *msg_name, + void *handler, + void *cleanup, + void *endian, + void *print, int msg_size, int traced); +void vl_msg_api_config (vl_msg_api_msg_config_t *); +void vl_msg_api_set_cleanup_handler (int msg_id, void *fp); +void vl_msg_api_queue_handler (unix_shared_memory_queue_t * q); + +void vl_msg_api_barrier_sync (void) __attribute__ ((weak)); +void vl_msg_api_barrier_release (void) __attribute__ ((weak)); +void vl_msg_api_free (void *); +void vl_noop_handler (void *mp); +void vl_msg_api_increment_missing_client_counter (void); +void vl_msg_api_post_mortem_dump (void); +void vl_msg_api_post_mortem_dump_enable_disable (int enable); +void vl_msg_api_register_pd_handler (void *handler, + u16 msg_id_host_byte_order); +int vl_msg_api_pd_handler (void *mp, int rv); + +void vl_msg_api_set_first_available_msg_id (u16 first_avail); +u16 vl_msg_api_get_msg_ids (const char *name, int n); +u32 vl_api_get_msg_index (u8 * name_and_crc); + +typedef clib_error_t *(vl_msg_api_init_function_t) (u32 client_index); + +typedef struct _vl_msg_api_init_function_list_elt +{ + struct _vl_msg_api_init_function_list_elt *next_init_function; + vl_msg_api_init_function_t *f; +} _vl_msg_api_function_list_elt_t; + +typedef struct +{ + void (**msg_handlers) (void *); + int (**pd_msg_handlers) (void *, int); + void (**msg_cleanup_handlers) (void *); + void (**msg_endian_handlers) (void *); + void (**msg_print_handlers) (void *, void *); + const char **msg_names; + u8 *message_bounce; + u8 *is_mp_safe; + struct ring_alloc_ *arings; + u32 ring_misses; + u32 garbage_collects; + u32 missing_clients; + vl_api_trace_t *rx_trace; + vl_api_trace_t *tx_trace; + int msg_print_flag; + trace_cfg_t *api_trace_cfg; + int our_pid; + svm_region_t *vlib_rp; + svm_region_t **mapped_shmem_regions; + struct vl_shmem_hdr_ *shmem_hdr; + vl_api_registration_t **vl_clients; + + u8 *serialized_message_table_in_shmem; + + /* For plugin msg allocator */ + u16 first_available_msg_id; + + /* message range by name hash */ + uword *msg_range_by_name; + + /* vector of message ranges */ + vl_api_msg_range_t *msg_ranges; + + /* uid for the api shared memory region */ + int api_uid; + /* gid for the api shared memory region */ + int api_gid; + + /* base virtual address for global VM region */ + u64 global_baseva; + + /* size of the global VM region */ + u64 global_size; + + /* size of the API region */ + u64 api_size; + + /* size of the global VM private mheap */ + u64 global_pvt_heap_size; + + /* size of the api private mheap */ + u64 api_pvt_heap_size; + + /* Client-only data structures */ + unix_shared_memory_queue_t *vl_input_queue; + + /* + * All VLIB-side message handlers use my_client_index to identify + * the queue / client. This works in sim replay. + */ + int my_client_index; + /* + * This is the (shared VM) address of the registration, + * don't use it to id the connection since it can't possibly + * work in simulator replay. + */ + vl_api_registration_t *my_registration; + + i32 vlib_signal; + + /* vlib input queue length */ + u32 vlib_input_queue_length; + + /* client side message index hash table */ + uword *msg_index_by_name_and_crc; + + const char *region_name; + const char *root_path; + + /* Replay in progress? */ + int replay_in_progress; + + /* List of API client reaper functions */ + _vl_msg_api_function_list_elt_t *reaper_function_registrations; + +} api_main_t; + +extern api_main_t api_main; + + +#endif /* included_api_common_h */ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/vlibmemory/api.h b/src/vlibmemory/api.h index c195e181..2a1438fd 100644 --- a/src/vlibmemory/api.h +++ b/src/vlibmemory/api.h @@ -20,81 +20,12 @@ #ifndef included_vlibmemory_api_h #define included_vlibmemory_api_h -#include #include #include #include #include #include - -/* Allocated in shared memory */ - -/* - * Ring-allocation scheme for client API messages - * - * Only one proc/thread has control of a given message buffer. - * To free a buffer allocated from one of these rings, we clear - * a field in the buffer (header), and leave. - * - * No locks, no hits, no errors... - */ -typedef struct ring_alloc_ -{ - unix_shared_memory_queue_t *rp; - u16 size; - u16 nitems; - u32 hits; - u32 misses; -} ring_alloc_t; - -/* - * Initializers for the (shared-memory) rings - * _(size, n). Note: each msg has an 8 byte header. - * Might want to change that to an index sometime. - */ -#define foreach_vl_aring_size \ -_(64+8, 1024) \ -_(256+8, 128) \ -_(1024+8, 64) - -#define foreach_clnt_aring_size \ -_(1024+8, 1024) \ -_(2048+8, 128) \ -_(4096+8, 8) - -typedef struct vl_shmem_hdr_ -{ - int version; - - /* getpid () for the VLIB client process */ - volatile int vl_pid; - - /* Client sends VLIB msgs here. */ - unix_shared_memory_queue_t *vl_input_queue; - - /* Vector of rings; one for each size. */ - - /* VLIB allocates buffers to send msgs to clients here. */ - ring_alloc_t *vl_rings; - - /* Clients allocate buffer to send msgs to VLIB here. */ - ring_alloc_t *client_rings; - - /* Number of detected application restarts */ - u32 application_restarts; - - /* Number of messages reclaimed during application restart */ - u32 restart_reclaims; - - /* Number of garbage-collected messages */ - u32 garbage_collects; - -} vl_shmem_hdr_t; - -#define VL_SHM_VERSION 2 - -#define VL_API_EPOCH_MASK 0xFF -#define VL_API_EPOCH_SHIFT 8 +#include static inline u32 vl_msg_api_handle_get_epoch (u32 index) @@ -118,43 +49,7 @@ vl_msg_api_handle_from_index_and_epoch (u32 index, u32 epoch) return handle; } -void *vl_msg_api_alloc (int nbytes); -void *vl_msg_api_alloc_or_null (int nbytes); -void *vl_msg_api_alloc_as_if_client (int nbytes); -void *vl_msg_api_alloc_as_if_client_or_null (int nbytes); -void vl_msg_api_free (void *a); -int vl_map_shmem (const char *region_name, int is_vlib); -void vl_register_mapped_shmem_region (svm_region_t * rp); -void vl_unmap_shmem (void); -void vl_msg_api_send_shmem (unix_shared_memory_queue_t * q, u8 * elem); -void vl_msg_api_send_shmem_nolock (unix_shared_memory_queue_t * q, u8 * elem); -void vl_msg_api_send (vl_api_registration_t * rp, u8 * elem); -int vl_client_connect (const char *name, int ctx_quota, int input_queue_size); -void vl_client_disconnect (void); -unix_shared_memory_queue_t *vl_api_client_index_to_input_queue (u32 index); -vl_api_registration_t *vl_api_client_index_to_registration (u32 index); -int vl_client_api_map (const char *region_name); -void vl_client_api_unmap (void); -void vl_set_memory_region_name (const char *name); -void vl_set_memory_root_path (const char *root_path); -void vl_set_memory_uid (int uid); -void vl_set_memory_gid (int gid); -void vl_set_global_memory_baseva (u64 baseva); -void vl_set_global_memory_size (u64 size); -void vl_set_api_memory_size (u64 size); -void vl_set_global_pvt_heap_size (u64 size); -void vl_set_api_pvt_heap_size (u64 size); void vl_enable_disable_memory_api (vlib_main_t * vm, int yesno); -void vl_client_disconnect_from_vlib (void); -int vl_client_connect_to_vlib (const char *svm_name, - const char *client_name, int rx_queue_size); -int vl_client_connect_to_vlib_no_rx_pthread (const char *svm_name, - const char *client_name, - int rx_queue_size); -u16 vl_client_get_first_plugin_msg_id (const char *plugin_name); - -void vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length); - #endif /* included_vlibmemory_api_h */ /* diff --git a/src/vlibmemory/api_common.h b/src/vlibmemory/api_common.h new file mode 100644 index 00000000..53909cc4 --- /dev/null +++ b/src/vlibmemory/api_common.h @@ -0,0 +1,138 @@ +/* + *------------------------------------------------------------------ + * Copyright (c) 2009 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------ + */ + +#ifndef included_vlibmemory_api_common_h +#define included_vlibmemory_api_common_h + +#include +#include +#include + +/* Allocated in shared memory */ + +/* + * Ring-allocation scheme for client API messages + * + * Only one proc/thread has control of a given message buffer. + * To free a buffer allocated from one of these rings, we clear + * a field in the buffer (header), and leave. + * + * No locks, no hits, no errors... + */ +typedef struct ring_alloc_ +{ + unix_shared_memory_queue_t *rp; + u16 size; + u16 nitems; + u32 hits; + u32 misses; +} ring_alloc_t; + +/* + * Initializers for the (shared-memory) rings + * _(size, n). Note: each msg has an 8 byte header. + * Might want to change that to an index sometime. + */ +#define foreach_vl_aring_size \ +_(64+8, 1024) \ +_(256+8, 128) \ +_(1024+8, 64) + +#define foreach_clnt_aring_size \ +_(1024+8, 1024) \ +_(2048+8, 128) \ +_(4096+8, 8) + +typedef struct vl_shmem_hdr_ +{ + int version; + + /* getpid () for the VLIB client process */ + volatile int vl_pid; + + /* Client sends VLIB msgs here. */ + unix_shared_memory_queue_t *vl_input_queue; + + /* Vector of rings; one for each size. */ + + /* VLIB allocates buffers to send msgs to clients here. */ + ring_alloc_t *vl_rings; + + /* Clients allocate buffer to send msgs to VLIB here. */ + ring_alloc_t *client_rings; + + /* Number of detected application restarts */ + u32 application_restarts; + + /* Number of messages reclaimed during application restart */ + u32 restart_reclaims; + + /* Number of garbage-collected messages */ + u32 garbage_collects; + +} vl_shmem_hdr_t; + +#define VL_SHM_VERSION 2 + +#define VL_API_EPOCH_MASK 0xFF +#define VL_API_EPOCH_SHIFT 8 + +void *vl_msg_api_alloc (int nbytes); +void *vl_msg_api_alloc_or_null (int nbytes); +void *vl_msg_api_alloc_as_if_client (int nbytes); +void *vl_msg_api_alloc_as_if_client_or_null (int nbytes); +void vl_msg_api_free (void *a); +int vl_map_shmem (const char *region_name, int is_vlib); +void vl_register_mapped_shmem_region (svm_region_t * rp); +void vl_unmap_shmem (void); +void vl_msg_api_send_shmem (unix_shared_memory_queue_t * q, u8 * elem); +void vl_msg_api_send_shmem_nolock (unix_shared_memory_queue_t * q, u8 * elem); +void vl_msg_api_send (vl_api_registration_t * rp, u8 * elem); +int vl_client_connect (const char *name, int ctx_quota, int input_queue_size); +void vl_client_disconnect (void); +unix_shared_memory_queue_t *vl_api_client_index_to_input_queue (u32 index); +vl_api_registration_t *vl_api_client_index_to_registration (u32 index); +int vl_client_api_map (const char *region_name); +void vl_client_api_unmap (void); +void vl_set_memory_region_name (const char *name); +void vl_set_memory_root_path (const char *root_path); +void vl_set_memory_uid (int uid); +void vl_set_memory_gid (int gid); +void vl_set_global_memory_baseva (u64 baseva); +void vl_set_global_memory_size (u64 size); +void vl_set_api_memory_size (u64 size); +void vl_set_global_pvt_heap_size (u64 size); +void vl_set_api_pvt_heap_size (u64 size); +void vl_client_disconnect_from_vlib (void); +int vl_client_connect_to_vlib (const char *svm_name, const char *client_name, + int rx_queue_size); +int vl_client_connect_to_vlib_no_rx_pthread (const char *svm_name, + const char *client_name, + int rx_queue_size); +u16 vl_client_get_first_plugin_msg_id (const char *plugin_name); + +void vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length); + +#endif /* included_vlibmemory_api_common_h */ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/src/vppinfra.am b/src/vppinfra.am index ff2b8ea4..785445a6 100644 --- a/src/vppinfra.am +++ b/src/vppinfra.am @@ -167,6 +167,7 @@ nobase_include_HEADERS = \ vppinfra/byte_order.h \ vppinfra/cache.h \ vppinfra/clib.h \ + vppinfra/clib_error.h \ vppinfra/cpu.h \ vppinfra/crc32.h \ vppinfra/dlist.h \ diff --git a/src/vppinfra/clib_error.h b/src/vppinfra/clib_error.h new file mode 100644 index 00000000..45f18eb1 --- /dev/null +++ b/src/vppinfra/clib_error.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2015 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef included_clib_error_h +#define included_clib_error_h + +#include + +typedef struct +{ + /* Error message. */ + u8 *what; + + /* Where error occurred (e.g. __FUNCTION__ __LINE__) */ + const u8 *where; + + uword flags; + + /* Error code (e.g. errno for Unix errors). */ + any code; +} clib_error_t; + +#endif diff --git a/src/vppinfra/error.h b/src/vppinfra/error.h index e51f938e..e0e2d472 100644 --- a/src/vppinfra/error.h +++ b/src/vppinfra/error.h @@ -72,19 +72,7 @@ void clib_error_register_handler (clib_error_handler_func_t func, void *arg); #define clib_panic(format,args...) \ _clib_error (CLIB_ERROR_ABORT, (char *) clib_error_function, __LINE__, format, ## args) -typedef struct -{ - /* Error message. */ - u8 *what; - - /* Where error occurred (e.g. __FUNCTION__ __LINE__) */ - const u8 *where; - - uword flags; - - /* Error code (e.g. errno for Unix errors). */ - any code; -} clib_error_t; +#include #define clib_error_get_code(err) ((err) ? (err)->code : 0) #define clib_error_set_code(err, c) \ -- cgit 1.2.3-korg