aboutsummaryrefslogtreecommitdiffstats
path: root/src/vlibapi
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2018-01-05 03:20:25 -0800
committerDave Barach <openvpp@barachs.net>2018-01-09 18:33:08 +0000
commite86a8edd3c14fb41ace2a12efd17bc7772bf623f (patch)
tree480219864cadd743fdb95c21379aeaf88a985e23 /src/vlibapi
parent4363ad6c96b5641fca1b16c5a6ec22e2364adcfd (diff)
api: refactor vlibmemory
- separate client/server code for both memory and socket apis - separate memory api code from generic vlib api code - move unix_shared_memory_fifo to svm and rename to svm_fifo_t - overall declutter Change-Id: I90cdd98ff74d0787d58825b914b0f1eafcfa4dc2 Signed-off-by: Florin Coras <fcoras@cisco.com>
Diffstat (limited to 'src/vlibapi')
-rw-r--r--src/vlibapi/api.h16
-rw-r--r--src/vlibapi/api_common.h12
-rw-r--r--src/vlibapi/api_helper_macros.h8
-rw-r--r--src/vlibapi/api_shared.c19
-rw-r--r--src/vlibapi/node_serialize.c59
-rw-r--r--src/vlibapi/node_unserialize.c227
6 files changed, 38 insertions, 303 deletions
diff --git a/src/vlibapi/api.h b/src/vlibapi/api.h
index 6820a541cba..48c3813452e 100644
--- a/src/vlibapi/api.h
+++ b/src/vlibapi/api.h
@@ -23,16 +23,15 @@
#include <stddef.h>
#include <vppinfra/error.h>
#include <svm/svm.h>
+#include <svm/queue.h>
#include <vlib/vlib.h>
-#include <vlibmemory/unix_shared_memory_queue.h>
#include <vlib/unix/unix.h>
#include <vlibapi/api_common.h>
/* *INDENT-OFF* */
-typedef CLIB_PACKED
-(struct
- {
- u8 endian; u8 wrapped;
+typedef CLIB_PACKED ( struct {
+ u8 endian;
+ u8 wrapped;
u32 nitems;
}) vl_api_trace_file_header_t;
/* *INDENT-ON* */
@@ -56,7 +55,6 @@ int vl_msg_api_trace_save (api_main_t * am,
_error; \
})
-
#define _VL_MSG_API_FUNCTION_SYMBOL(x, type) \
_vl_msg_api_##type##_function_##x
@@ -117,10 +115,10 @@ void vl_msg_api_add_msg_name_crc (api_main_t * am, const char *string,
void vl_msg_api_add_version (api_main_t * am, const char *string,
u32 major, u32 minor, u32 patch);
/* node_serialize.c prototypes */
-u8 *vlib_node_serialize (vlib_node_main_t * nm, u8 * vector,
- u32 max_threads, int include_nexts,
- int include_stats);
+u8 *vlib_node_serialize (vlib_main_t * vm, vlib_node_t *** node_dups,
+ u8 * vector, 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 */
diff --git a/src/vlibapi/api_common.h b/src/vlibapi/api_common.h
index 56b036d7f07..055164812de 100644
--- a/src/vlibapi/api_common.h
+++ b/src/vlibapi/api_common.h
@@ -26,7 +26,7 @@
#include <vppinfra/clib_error.h>
#include <svm/svm_common.h>
-#include <vlibmemory/unix_shared_memory_queue.h>
+#include <svm/queue.h>
/** API registration types
*/
@@ -56,7 +56,7 @@ typedef struct vl_api_registration_
int unanswered_pings;
/** shared memory only: pointer to client input queue */
- unix_shared_memory_queue_t *vl_input_queue;
+ svm_queue_t *vl_input_queue;
svm_region_t *vlib_rp;
void *shmem_hdr;
@@ -133,7 +133,7 @@ typedef struct
/** Message header structure */
typedef struct msgbuf_
{
- unix_shared_memory_queue_t *q; /**< message allocated in this shmem ring */
+ svm_queue_t *q; /**< message allocated in this shmem ring */
u32 data_len; /**< message length not including header */
u32 gc_mark_timestamp; /**< message garbage collector mark TS */
u8 data[0]; /**< actual message begins here */
@@ -155,7 +155,7 @@ void vl_msg_api_set_handlers (int msg_id, char *msg_name,
void vl_msg_api_clean_handlers (int msg_id);
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_queue_handler (svm_queue_t * q);
void vl_msg_api_barrier_sync (void) __attribute__ ((weak));
void vl_msg_api_barrier_release (void) __attribute__ ((weak));
@@ -176,7 +176,7 @@ 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);
+u32 vl_msg_api_get_msg_index (u8 * name_and_crc);
typedef clib_error_t *(vl_msg_api_init_function_t) (u32 client_index);
@@ -297,7 +297,7 @@ typedef struct
u64 api_pvt_heap_size;
/** Peer input queue pointer */
- unix_shared_memory_queue_t *vl_input_queue;
+ svm_queue_t *vl_input_queue;
/**
* All VLIB-side message handlers use my_client_index to identify
diff --git a/src/vlibapi/api_helper_macros.h b/src/vlibapi/api_helper_macros.h
index fc9374f8a26..23340425978 100644
--- a/src/vlibapi/api_helper_macros.h
+++ b/src/vlibapi/api_helper_macros.h
@@ -40,7 +40,7 @@ do { \
rmp->context = mp->context; \
rmp->retval = ntohl(rv); \
\
- vl_msg_api_send (rp, (u8 *)rmp); \
+ vl_api_send_msg (rp, (u8 *)rmp); \
} while(0);
#define REPLY_MACRO2(t, body) \
@@ -56,7 +56,7 @@ do { \
rmp->context = mp->context; \
rmp->retval = ntohl(rv); \
do {body;} while (0); \
- vl_msg_api_send (rp, (u8 *)rmp); \
+ vl_api_send_msg (rp, (u8 *)rmp); \
} while(0);
#define REPLY_MACRO3(t, n, body) \
@@ -72,7 +72,7 @@ do { \
rmp->context = mp->context; \
rmp->retval = ntohl(rv); \
do {body;} while (0); \
- vl_msg_api_send (rp, (u8 *)rmp); \
+ vl_api_send_msg (rp, (u8 *)rmp); \
} while(0);
#define REPLY_MACRO4(t, n, body) \
@@ -103,7 +103,7 @@ do { \
rmp->retval = ntohl(rv); \
if (!is_error) \
do {body;} while (0); \
- vl_msg_api_send (rp, (u8 *)rmp); \
+ vl_api_send_msg (rp, (u8 *)rmp); \
} while(0);
/* "trust, but verify" */
diff --git a/src/vlibapi/api_shared.c b/src/vlibapi/api_shared.c
index 4d11b519cf2..d4196264064 100644
--- a/src/vlibapi/api_shared.c
+++ b/src/vlibapi/api_shared.c
@@ -754,11 +754,11 @@ vl_msg_api_set_cleanup_handler (int msg_id, void *fp)
}
void
-vl_msg_api_queue_handler (unix_shared_memory_queue_t * q)
+vl_msg_api_queue_handler (svm_queue_t * q)
{
uword msg;
- while (!unix_shared_memory_queue_sub (q, (u8 *) & msg, 0))
+ while (!svm_queue_sub (q, (u8 *) & msg, 0))
vl_msg_api_handler ((void *) msg);
}
@@ -940,6 +940,21 @@ vl_msg_api_add_version (api_main_t * am, const char *string,
vec_add1 (am->api_version_list, version);
}
+u32
+vl_msg_api_get_msg_index (u8 * name_and_crc)
+{
+ api_main_t *am = &api_main;
+ uword *p;
+
+ if (am->msg_index_by_name_and_crc)
+ {
+ p = hash_get_mem (am->msg_index_by_name_and_crc, name_and_crc);
+ if (p)
+ return p[0];
+ }
+ return ~0;
+}
+
/*
* fd.io coding-style-patch-verification: ON
*
diff --git a/src/vlibapi/node_serialize.c b/src/vlibapi/node_serialize.c
index 50e5c41c219..575de11b8cc 100644
--- a/src/vlibapi/node_serialize.c
+++ b/src/vlibapi/node_serialize.c
@@ -16,9 +16,6 @@
#include <vppinfra/serialize.h>
-extern void vl_msg_api_barrier_sync (void);
-extern void vl_msg_api_barrier_release (void);
-
/* serialized representation of state strings */
#define foreach_state_string_code \
@@ -50,72 +47,24 @@ static char *state_strings[] = {
* to recycle a vector / avoid memory allocation, etc.
* Switch heaps before/after to serialize into API client shared memory.
*/
-
u8 *
-vlib_node_serialize (vlib_node_main_t * nm, u8 * vector,
- u32 max_threads, int include_nexts, int include_stats)
+vlib_node_serialize (vlib_main_t * vm, vlib_node_t *** node_dups, u8 * vector,
+ int include_nexts, int include_stats)
{
serialize_main_t _sm, *sm = &_sm;
- vlib_main_t *vm = vlib_get_main ();
vlib_node_t *n;
- static vlib_node_t ***node_dups;
vlib_node_t **nodes;
- static vlib_main_t **stat_vms;
- vlib_main_t *stat_vm;
u8 *namep;
u32 name_bytes;
uword i, j, k;
u64 l, v, c, d;
state_string_enum_t state_code;
- u32 threads_to_serialize;
-
- vec_reset_length (node_dups);
-
- if (vec_len (stat_vms) == 0)
- {
- for (i = 0; i < vec_len (vlib_mains); i++)
- {
- stat_vm = vlib_mains[i];
- if (stat_vm)
- vec_add1 (stat_vms, stat_vm);
- }
- }
-
- threads_to_serialize = clib_min (max_threads, vec_len (stat_vms));
-
- /*
- * Barrier sync across stats scraping.
- * Otherwise, the counts will be grossly inaccurate.
- */
- vl_msg_api_barrier_sync ();
-
- for (j = 0; j < threads_to_serialize; j++)
- {
- stat_vm = stat_vms[j];
- nm = &stat_vm->node_main;
-
- if (include_stats)
- {
- for (i = 0; i < vec_len (nm->nodes); i++)
- {
- n = nm->nodes[i];
- vlib_node_sync_stats (stat_vm, n);
- }
- }
-
- nodes = vec_dup (nm->nodes);
-
- vec_add1 (node_dups, nodes);
- }
- vl_msg_api_barrier_release ();
serialize_open_vector (sm, vector);
+ serialize_likely_small_unsigned_integer (sm, vec_len (node_dups));
- serialize_likely_small_unsigned_integer (sm, vec_len (stat_vms));
-
- for (j = 0; j < vec_len (stat_vms); j++)
+ for (j = 0; j < vec_len (node_dups); j++)
{
- stat_vm = stat_vms[j];
nodes = node_dups[j];
serialize_likely_small_unsigned_integer (sm, vec_len (nodes));
diff --git a/src/vlibapi/node_unserialize.c b/src/vlibapi/node_unserialize.c
deleted file mode 100644
index bb0edfedda1..00000000000
--- a/src/vlibapi/node_unserialize.c
+++ /dev/null
@@ -1,227 +0,0 @@
-/*
- * Copyright (c) 2016 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.
- */
-#include <vlib/vlib.h>
-
-#include <vppinfra/serialize.h>
-
-/* serialized representation of state strings */
-
-#define foreach_state_string_code \
-_(STATE_DONE, "done") \
-_(STATE_DISABLED, "disabled") \
-_(STATE_TIME_WAIT, "time wait") \
-_(STATE_EVENT_WAIT, "event wait") \
-_(STATE_ANY_WAIT, "any wait") \
-_(STATE_POLLING, "polling") \
-_(STATE_INTERRUPT_WAIT, "interrupt wait") \
-_(STATE_INTERNAL, "internal")
-
-typedef enum
-{
-#define _(a,b) a,
- foreach_state_string_code
-#undef _
-} state_string_enum_t;
-
-static char *state_strings[] = {
-#define _(a,b) b,
- foreach_state_string_code
-#undef _
-};
-
-vlib_node_t ***
-vlib_node_unserialize (u8 * vector)
-{
- serialize_main_t _sm, *sm = &_sm;
- u32 nnodes, nnexts;
- u32 nstat_vms;
- vlib_node_t *node;
- vlib_node_t **nodes;
- vlib_node_t ***nodes_by_thread = 0;
- int i, j, k;
- u64 l, v, c, d;
- state_string_enum_t state_code;
- int stats_present;
-
- serialize_open_vector (sm, vector);
-
- nstat_vms = unserialize_likely_small_unsigned_integer (sm);
-
- vec_validate (nodes_by_thread, nstat_vms - 1);
- _vec_len (nodes_by_thread) = 0;
-
- for (i = 0; i < nstat_vms; i++)
- {
- nnodes = unserialize_likely_small_unsigned_integer (sm);
-
- nodes = 0;
- vec_validate (nodes, nnodes - 1);
- vec_add1 (nodes_by_thread, nodes);
-
- for (j = 0; j < nnodes; j++)
- {
- node = 0;
- vec_validate (node, 0);
- nodes[j] = node;
-
- unserialize_cstring (sm, (char **) &(node->name));
- state_code = unserialize_likely_small_unsigned_integer (sm);
- node->state_string = (u8 *) state_strings[state_code];
-
- node->type = unserialize_likely_small_unsigned_integer (sm);
- nnexts = unserialize_likely_small_unsigned_integer (sm);
- if (nnexts > 0)
- vec_validate (node->next_nodes, nnexts - 1);
- for (k = 0; k < nnexts; k++)
- node->next_nodes[k] =
- unserialize_likely_small_unsigned_integer (sm);
-
- stats_present = unserialize_likely_small_unsigned_integer (sm);
-
- if (stats_present)
- {
- /* total clocks */
- unserialize_integer (sm, &l, 8);
- node->stats_total.clocks = l;
- node->stats_last_clear.clocks = 0;
-
- /* Total calls */
- unserialize_integer (sm, &c, 8);
- node->stats_total.calls = c;
-
- /* Total vectors */
- unserialize_integer (sm, &v, 8);
- node->stats_total.vectors = v;
-
- /* Total suspends */
- unserialize_integer (sm, &d, 8);
- node->stats_total.suspends = d;
- }
- }
- }
- return nodes_by_thread;
-}
-
-#if TEST_CODE
-
-static clib_error_t *
-test_node_serialize_command_fn (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
-{
- vlib_node_main_t *nm = &vm->node_main;
- u8 *vector = 0;
- vlib_node_t ***nodes_by_thread;
- vlib_node_t **nodes;
- vlib_node_t *node;
- vlib_node_t *next_node;
- int i, j, k;
- u32 max_threads = (u32) ~ 0;
- int include_nexts = 0;
- int include_stats = 0;
-
- while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (input, "max-threads %d", &max_threads))
- ;
- else if (unformat (input, "stats"))
- include_stats = 1;
- else if (unformat (input, "nexts"))
- include_nexts = 1;
- else
- break;
- }
-
- /*
- * Keep the number of memcpy ops to a minimum (e.g. 1).
- * The current size of the serialized vector is
- * slightly under 4K.
- */
- vec_validate (vector, 16383);
- vec_reset_length (vector);
-
- vector = vlib_node_serialize (nm, vector, max_threads,
- include_nexts, include_stats);
-
- vlib_cli_output (vm, "result vector %d bytes", vec_len (vector));
-
- nodes_by_thread = vlib_node_unserialize (vector);
-
- vec_free (vector);
-
- for (i = 0; i < vec_len (nodes_by_thread); i++)
- {
- nodes = nodes_by_thread[i];
-
- vlib_cli_output (vm, "thread %d", i);
-
- for (j = 0; j < vec_len (nodes); j++)
- {
- node = nodes[j];
-
- vlib_cli_output (vm, "[%d] %s state %s", j, node->name,
- node->state_string);
-
- vlib_cli_output
- (vm, " clocks %lld calls %lld suspends"
- " %lld vectors %lld",
- node->stats_total.clocks,
- node->stats_total.calls,
- node->stats_total.suspends, node->stats_total.vectors);
-
- for (k = 0; k < vec_len (node->next_nodes); k++)
- {
- if (node->next_nodes[k] != ~0)
- {
- next_node = nodes[node->next_nodes[k]];
- vlib_cli_output (vm, " [%d] %s", k, next_node->name);
- }
- }
- }
- }
-
- for (j = 0; j < vec_len (nodes_by_thread); j++)
- {
- nodes = nodes_by_thread[j];
-
- for (i = 0; i < vec_len (nodes); i++)
- {
- vec_free (nodes[i]->name);
- vec_free (nodes[i]->next_nodes);
- vec_free (nodes[i]);
- }
- vec_free (nodes);
- }
- vec_free (nodes_by_thread);
-
- return 0;
-}
-
-/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (test_node_serialize_node, static) = {
- .path = "test node serialize",
- .short_help = "test node serialize [max-threads NN] nexts stats",
- .function = test_node_serialize_command_fn,
-};
-/* *INDENT-ON* */
-#endif
-
-/*
- * fd.io coding-style-patch-verification: ON
- *
- * Local Variables:
- * eval: (c-set-style "gnu")
- * End:
- */