fd-io-styleify pass

Change-Id: I72d0dff064162d11321257c858f68da1ba79ea48
Signed-off-by: Dave Barach <dave@barachs.net>
This commit is contained in:
Dave Barach
2016-07-08 09:38:52 -04:00
committed by Damjan Marion
parent 9b8ffd99fb
commit 371e4e19d1
17 changed files with 4012 additions and 3426 deletions

View File

@ -26,7 +26,8 @@
#include <vlibmemory/unix_shared_memory_queue.h> #include <vlibmemory/unix_shared_memory_queue.h>
#include <vlib/unix/unix.h> #include <vlib/unix/unix.h>
typedef enum { typedef enum
{
REGISTRATION_TYPE_FREE = 0, REGISTRATION_TYPE_FREE = 0,
REGISTRATION_TYPE_SHMEM, REGISTRATION_TYPE_SHMEM,
REGISTRATION_TYPE_SOCKET_LISTEN, REGISTRATION_TYPE_SOCKET_LISTEN,
@ -34,7 +35,8 @@ typedef enum {
REGISTRATION_TYPE_SOCKET_CLIENT, REGISTRATION_TYPE_SOCKET_CLIENT,
} vl_registration_type_t; } vl_registration_type_t;
typedef struct vl_api_registration_ { typedef struct vl_api_registration_
{
vl_registration_type_t registration_type; vl_registration_type_t registration_type;
/* Index in VLIB's brain (not shared memory). */ /* Index in VLIB's brain (not shared memory). */
@ -64,7 +66,8 @@ typedef struct vl_api_registration_ {
/* Trace configuration for a single message */ /* Trace configuration for a single message */
typedef struct { typedef struct
{
int size; int size;
int trace_enable; int trace_enable;
int replay_enable; int replay_enable;
@ -73,7 +76,8 @@ typedef struct {
/* /*
* API recording * API recording
*/ */
typedef struct { typedef struct
{
u8 endian; u8 endian;
u8 enabled; u8 enabled;
u8 wrapped; u8 wrapped;
@ -83,13 +87,14 @@ typedef struct {
u8 **traces; u8 **traces;
} vl_api_trace_t; } vl_api_trace_t;
typedef CLIB_PACKED (struct { typedef CLIB_PACKED (struct
u8 endian; {
u8 wrapped; u8 endian; u8 wrapped;
u32 nitems; u32 nitems;
}) vl_api_trace_file_header_t; }) vl_api_trace_file_header_t;
typedef enum { typedef enum
{
VL_API_TRACE_TX, VL_API_TRACE_TX,
VL_API_TRACE_RX, VL_API_TRACE_RX,
} vl_api_trace_which_t; } vl_api_trace_which_t;
@ -97,13 +102,15 @@ typedef enum {
#define VL_API_LITTLE_ENDIAN 0x00 #define VL_API_LITTLE_ENDIAN 0x00
#define VL_API_BIG_ENDIAN 0x01 #define VL_API_BIG_ENDIAN 0x01
typedef struct { typedef struct
{
u8 *name; u8 *name;
u16 first_msg_id; u16 first_msg_id;
u16 last_msg_id; u16 last_msg_id;
} vl_api_msg_range_t; } vl_api_msg_range_t;
typedef struct { typedef struct
{
void (**msg_handlers) (void *); void (**msg_handlers) (void *);
int (**pd_msg_handlers) (void *, int); int (**pd_msg_handlers) (void *, int);
void (**msg_cleanup_handlers) (void *); void (**msg_cleanup_handlers) (void *);
@ -161,7 +168,8 @@ typedef struct {
api_main_t api_main; api_main_t api_main;
typedef struct { typedef struct
{
int id; int id;
char *name; char *name;
void *handler; void *handler;
@ -200,8 +208,7 @@ void vl_msg_api_set_handlers(int msg_id, char *msg_name,
void *handler, void *handler,
void *cleanup, void *cleanup,
void *endian, void *endian,
void *print, void *print, int msg_size, int traced);
int msg_size, int traced);
void vl_msg_api_config (vl_msg_api_msg_config_t *); 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_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 (unix_shared_memory_queue_t * q);
@ -213,7 +220,8 @@ void vl_noop_handler (void *mp);
clib_error_t *vl_api_init (vlib_main_t * vm); clib_error_t *vl_api_init (vlib_main_t * vm);
void vl_msg_api_increment_missing_client_counter (void); void vl_msg_api_increment_missing_client_counter (void);
void vl_msg_api_post_mortem_dump (void); void vl_msg_api_post_mortem_dump (void);
void vl_msg_api_register_pd_handler (void *handler, u16 msg_id_host_byte_order); 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); int vl_msg_api_pd_handler (void *mp, int rv);
void vl_msg_api_set_first_available_msg_id (u16 first_avail); void vl_msg_api_set_first_available_msg_id (u16 first_avail);
@ -228,3 +236,11 @@ vlib_node_t ** vlib_node_unserialize (u8 * vector);
#define VLIB_API_INIT_FUNCTION(x) VLIB_DECLARE_INIT_FUNCTION(x,api_init) #define VLIB_API_INIT_FUNCTION(x) VLIB_DECLARE_INIT_FUNCTION(x,api_init)
#endif /* included_api_h */ #endif /* included_api_h */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

File diff suppressed because it is too large Load Diff

View File

@ -31,14 +31,14 @@ _(STATE_POLLING, "polling") \
_(STATE_INTERRUPT_WAIT, "interrupt wait") \ _(STATE_INTERRUPT_WAIT, "interrupt wait") \
_(STATE_INTERNAL, "internal") _(STATE_INTERNAL, "internal")
typedef enum { typedef enum
{
#define _(a,b) a, #define _(a,b) a,
foreach_state_string_code foreach_state_string_code
#undef _ #undef _
} state_string_enum_t; } state_string_enum_t;
static char *state_strings[] = static char *state_strings[] = {
{
#define _(a,b) b, #define _(a,b) b,
foreach_state_string_code foreach_state_string_code
#undef _ #undef _
@ -51,9 +51,9 @@ static char *state_strings[] =
* Switch heaps before/after to serialize into API client shared memory. * Switch heaps before/after to serialize into API client shared memory.
*/ */
u8 * vlib_node_serialize (vlib_node_main_t *nm, u8 * vector, u8 *
u32 max_threads, int include_nexts, vlib_node_serialize (vlib_node_main_t * nm, u8 * vector,
int include_stats) u32 max_threads, int include_nexts, int include_stats)
{ {
serialize_main_t _sm, *sm = &_sm; serialize_main_t _sm, *sm = &_sm;
vlib_main_t *vm = vlib_get_main (); vlib_main_t *vm = vlib_get_main ();
@ -132,8 +132,7 @@ u8 * vlib_node_serialize (vlib_node_main_t *nm, u8 * vector,
l = n->stats_total.clocks - n->stats_last_clear.clocks; l = n->stats_total.clocks - n->stats_last_clear.clocks;
v = n->stats_total.vectors - n->stats_last_clear.vectors; v = n->stats_total.vectors - n->stats_last_clear.vectors;
c = n->stats_total.calls - n->stats_last_clear.calls; c = n->stats_total.calls - n->stats_last_clear.calls;
d = n->stats_total.suspends d = n->stats_total.suspends - n->stats_last_clear.suspends;
- n->stats_last_clear.suspends;
state_code = STATE_INTERNAL; state_code = STATE_INTERNAL;
@ -158,9 +157,9 @@ u8 * vlib_node_serialize (vlib_node_main_t *nm, u8 * vector,
state_code = STATE_EVENT_WAIT; state_code = STATE_EVENT_WAIT;
break; break;
case (VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT case (VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT | VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK):
| VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK): state_code =
state_code = STATE_ANY_WAIT; STATE_ANY_WAIT;
break; break;
} }
} }
@ -187,7 +186,8 @@ u8 * vlib_node_serialize (vlib_node_main_t *nm, u8 * vector,
serialize_likely_small_unsigned_integer serialize_likely_small_unsigned_integer
(sm, vec_len (n->next_nodes)); (sm, vec_len (n->next_nodes));
for (k = 0; k < vec_len (n->next_nodes); k++) for (k = 0; k < vec_len (n->next_nodes); k++)
serialize_likely_small_unsigned_integer (sm, n->next_nodes[k]); serialize_likely_small_unsigned_integer (sm,
n->next_nodes[k]);
} }
else else
serialize_likely_small_unsigned_integer (sm, 0); serialize_likely_small_unsigned_integer (sm, 0);
@ -213,7 +213,8 @@ u8 * vlib_node_serialize (vlib_node_main_t *nm, u8 * vector,
return (serialize_close_vector (sm)); return (serialize_close_vector (sm));
} }
vlib_node_t *** vlib_node_unserialize (u8 * vector) vlib_node_t ***
vlib_node_unserialize (u8 * vector)
{ {
serialize_main_t _sm, *sm = &_sm; serialize_main_t _sm, *sm = &_sm;
u32 nnodes, nnexts; u32 nnodes, nnexts;
@ -251,8 +252,7 @@ vlib_node_t *** vlib_node_unserialize (u8 * vector)
state_code = unserialize_likely_small_unsigned_integer (sm); state_code = unserialize_likely_small_unsigned_integer (sm);
node->state_string = (u8 *) state_strings[state_code]; node->state_string = (u8 *) state_strings[state_code];
node->type = node->type = unserialize_likely_small_unsigned_integer (sm);
unserialize_likely_small_unsigned_integer (sm);
nnexts = unserialize_likely_small_unsigned_integer (sm); nnexts = unserialize_likely_small_unsigned_integer (sm);
if (nnexts > 0) if (nnexts > 0)
vec_validate (node->next_nodes, nnexts - 1); vec_validate (node->next_nodes, nnexts - 1);
@ -351,8 +351,7 @@ test_node_serialize_command_fn (vlib_main_t * vm,
" %lld vectors %lld", " %lld vectors %lld",
node->stats_total.clocks, node->stats_total.clocks,
node->stats_total.calls, node->stats_total.calls,
node->stats_total.suspends, node->stats_total.suspends, node->stats_total.vectors);
node->stats_total.vectors);
for (k = 0; k < vec_len (node->next_nodes); k++) for (k = 0; k < vec_len (node->next_nodes); k++)
{ {
@ -380,9 +379,19 @@ test_node_serialize_command_fn (vlib_main_t * vm,
return 0; return 0;
} }
/* *INDENT-OFF* */
VLIB_CLI_COMMAND (test_node_serialize_node, static) = { VLIB_CLI_COMMAND (test_node_serialize_node, static) = {
.path = "test node serialize", .path = "test node serialize",
.short_help = "test node serialize [max-threads NN] nexts stats", .short_help = "test node serialize [max-threads NN] nexts stats",
.function = test_node_serialize_command_fn, .function = test_node_serialize_command_fn,
}; };
/* *INDENT-ON* */
#endif #endif
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -38,7 +38,8 @@
* *
* No locks, no hits, no errors... * No locks, no hits, no errors...
*/ */
typedef struct ring_alloc_ { typedef struct ring_alloc_
{
unix_shared_memory_queue_t *rp; unix_shared_memory_queue_t *rp;
u16 size; u16 size;
u16 nitems; u16 nitems;
@ -61,7 +62,8 @@ _(1024+8, 1024) \
_(2048+8, 128) \ _(2048+8, 128) \
_(4096+8, 8) _(4096+8, 8)
typedef struct vl_shmem_hdr_ { typedef struct vl_shmem_hdr_
{
int version; int version;
/* getpid () for the VLIB client process */ /* getpid () for the VLIB client process */
@ -87,7 +89,8 @@ typedef struct vl_shmem_hdr_ {
} vl_shmem_hdr_t; } vl_shmem_hdr_t;
/* Note that the size of the structure is 16 bytes, with 4 bytes of padding after data[0]. */ /* Note that the size of the structure is 16 bytes, with 4 bytes of padding after data[0]. */
typedef struct msgbuf_ { typedef struct msgbuf_
{
unix_shared_memory_queue_t *q; unix_shared_memory_queue_t *q;
u32 data_len; u32 data_len;
u8 data[0]; u8 data[0];
@ -98,16 +101,20 @@ typedef struct msgbuf_ {
#define VL_API_EPOCH_MASK 0xFF #define VL_API_EPOCH_MASK 0xFF
#define VL_API_EPOCH_SHIFT 8 #define VL_API_EPOCH_SHIFT 8
static inline u32 vl_msg_api_handle_get_epoch (u32 index) static inline u32
vl_msg_api_handle_get_epoch (u32 index)
{ {
return (index & VL_API_EPOCH_MASK); return (index & VL_API_EPOCH_MASK);
} }
static inline u32 vl_msg_api_handle_get_index (u32 index)
static inline u32
vl_msg_api_handle_get_index (u32 index)
{ {
return (index >> VL_API_EPOCH_SHIFT); return (index >> VL_API_EPOCH_SHIFT);
} }
static inline u32 vl_msg_api_handle_from_index_and_epoch (u32 index, u32 epoch) static inline u32
vl_msg_api_handle_from_index_and_epoch (u32 index, u32 epoch)
{ {
u32 handle; u32 handle;
ASSERT (index < 0x00FFFFFF); ASSERT (index < 0x00FFFFFF);
@ -139,10 +146,19 @@ void vl_enable_disable_memory_api (vlib_main_t *vm, int yesno);
void vl_client_disconnect_from_vlib (void); void vl_client_disconnect_from_vlib (void);
int vl_client_connect_to_vlib (char *svm_name, char *client_name, int vl_client_connect_to_vlib (char *svm_name, char *client_name,
int rx_queue_size); 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_no_rx_pthread (char *svm_name,
char *client_name,
int rx_queue_size); int rx_queue_size);
u16 vl_client_get_first_plugin_msg_id (char *plugin_name); 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); void vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length);
#endif /* included_vlibmemory_api_h */ #endif /* included_vlibmemory_api_h */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -61,7 +61,8 @@
#include <vlibmemory/vl_memory_api_h.h> #include <vlibmemory/vl_memory_api_h.h>
#undef vl_printfun #undef vl_printfun
typedef struct { typedef struct
{
u8 rx_thread_jmpbuf_valid; u8 rx_thread_jmpbuf_valid;
u8 connected_to_vlib; u8 connected_to_vlib;
jmp_buf rx_thread_jmpbuf; jmp_buf rx_thread_jmpbuf;
@ -73,7 +74,8 @@ typedef struct {
memory_client_main_t memory_client_main; memory_client_main_t memory_client_main;
static void *rx_thread_fn(void *arg) static void *
rx_thread_fn (void *arg)
{ {
unix_shared_memory_queue_t *q; unix_shared_memory_queue_t *q;
memory_client_main_t *mm = &memory_client_main; memory_client_main_t *mm = &memory_client_main;
@ -82,37 +84,42 @@ static void *rx_thread_fn(void *arg)
q = am->vl_input_queue; q = am->vl_input_queue;
/* So we can make the rx thread terminate cleanly */ /* So we can make the rx thread terminate cleanly */
if (setjmp(mm->rx_thread_jmpbuf) == 0) { if (setjmp (mm->rx_thread_jmpbuf) == 0)
{
mm->rx_thread_jmpbuf_valid = 1; mm->rx_thread_jmpbuf_valid = 1;
while (1) { while (1)
{
vl_msg_api_queue_handler (q); vl_msg_api_queue_handler (q);
} }
} }
pthread_exit (0); pthread_exit (0);
} }
static void vl_api_rx_thread_exit_t_handler ( static void
vl_api_rx_thread_exit_t *mp) vl_api_rx_thread_exit_t_handler (vl_api_rx_thread_exit_t * mp)
{ {
memory_client_main_t *mm = &memory_client_main; memory_client_main_t *mm = &memory_client_main;
vl_msg_api_free (mp); vl_msg_api_free (mp);
longjmp (mm->rx_thread_jmpbuf, 1); longjmp (mm->rx_thread_jmpbuf, 1);
} }
static void noop_handler (void *notused) static void
noop_handler (void *notused)
{ {
} }
#define foreach_api_msg \ #define foreach_api_msg \
_(RX_THREAD_EXIT, rx_thread_exit) _(RX_THREAD_EXIT, rx_thread_exit)
static int connect_to_vlib_internal (char *svm_name, char *client_name, static int
connect_to_vlib_internal (char *svm_name, char *client_name,
int rx_queue_size, int want_pthread) int rx_queue_size, int want_pthread)
{ {
int rv = 0; int rv = 0;
memory_client_main_t *mm = &memory_client_main; memory_client_main_t *mm = &memory_client_main;
if ((rv = vl_client_api_map(svm_name))) { if ((rv = vl_client_api_map (svm_name)))
{
clib_warning ("vl_client_api map rv %d", rv); clib_warning ("vl_client_api map rv %d", rv);
return rv; return rv;
} }
@ -128,14 +135,16 @@ static int connect_to_vlib_internal (char *svm_name, char *client_name,
#undef _ #undef _
if (vl_client_connect (client_name, 0 /* punt quota */ , if (vl_client_connect (client_name, 0 /* punt quota */ ,
rx_queue_size /* input queue */) < 0) { rx_queue_size /* input queue */ ) < 0)
{
vl_client_api_unmap (); vl_client_api_unmap ();
return -1; return -1;
} }
/* Start the rx queue thread */ /* Start the rx queue thread */
if (want_pthread) { if (want_pthread)
{
rv = pthread_create (&mm->rx_thread_handle, rv = pthread_create (&mm->rx_thread_handle,
NULL /*attr */ , rx_thread_fn, 0); NULL /*attr */ , rx_thread_fn, 0);
if (rv) if (rv)
@ -146,34 +155,39 @@ static int connect_to_vlib_internal (char *svm_name, char *client_name,
return 0; return 0;
} }
int vl_client_connect_to_vlib(char *svm_name, char *client_name, int
vl_client_connect_to_vlib (char *svm_name, char *client_name,
int rx_queue_size) int rx_queue_size)
{ {
return connect_to_vlib_internal (svm_name, client_name, rx_queue_size, return connect_to_vlib_internal (svm_name, client_name, rx_queue_size,
1 /* want pthread */ ); 1 /* want pthread */ );
} }
int vl_client_connect_to_vlib_no_rx_pthread (char *svm_name, char *client_name, int
vl_client_connect_to_vlib_no_rx_pthread (char *svm_name, char *client_name,
int rx_queue_size) int rx_queue_size)
{ {
return connect_to_vlib_internal (svm_name, client_name, rx_queue_size, return connect_to_vlib_internal (svm_name, client_name, rx_queue_size,
0 /* want pthread */ ); 0 /* want pthread */ );
} }
void vl_client_disconnect_from_vlib (void) void
vl_client_disconnect_from_vlib (void)
{ {
memory_client_main_t *mm = &memory_client_main; memory_client_main_t *mm = &memory_client_main;
api_main_t *am = &api_main; api_main_t *am = &api_main;
uword junk; uword junk;
if (mm->rx_thread_jmpbuf_valid) { if (mm->rx_thread_jmpbuf_valid)
{
vl_api_rx_thread_exit_t *ep; vl_api_rx_thread_exit_t *ep;
ep = vl_msg_api_alloc (sizeof (*ep)); ep = vl_msg_api_alloc (sizeof (*ep));
ep->_vl_msg_id = ntohs (VL_API_RX_THREAD_EXIT); ep->_vl_msg_id = ntohs (VL_API_RX_THREAD_EXIT);
vl_msg_api_send_shmem (am->vl_input_queue, (u8 *) & ep); vl_msg_api_send_shmem (am->vl_input_queue, (u8 *) & ep);
pthread_join (mm->rx_thread_handle, (void **) &junk); pthread_join (mm->rx_thread_handle, (void **) &junk);
} }
if (mm->connected_to_vlib) { if (mm->connected_to_vlib)
{
vl_client_disconnect (); vl_client_disconnect ();
vl_client_api_unmap (); vl_client_api_unmap ();
} }
@ -190,7 +204,8 @@ static void vl_api_get_first_msg_id_reply_t_handler
mm->first_msg_id_reply_ready = 1; mm->first_msg_id_reply_ready = 1;
} }
u16 vl_client_get_first_plugin_msg_id (char * plugin_name) u16
vl_client_get_first_plugin_msg_id (char *plugin_name)
{ {
vl_api_get_first_msg_id_t *mp; vl_api_get_first_msg_id_t *mp;
api_main_t *am = &api_main; api_main_t *am = &api_main;
@ -223,11 +238,14 @@ u16 vl_client_get_first_plugin_msg_id (char * plugin_name)
vl_msg_api_send_shmem (am->shmem_hdr->vl_input_queue, (u8 *) & mp); vl_msg_api_send_shmem (am->shmem_hdr->vl_input_queue, (u8 *) & mp);
/* Synchronously wait for the answer */ /* Synchronously wait for the answer */
do { do
{
timeout = clib_time_now (&clib_time) + 1.0; timeout = clib_time_now (&clib_time) + 1.0;
while (clib_time_now (&clib_time) < timeout) { while (clib_time_now (&clib_time) < timeout)
if (mm->first_msg_id_reply_ready == 1) { {
if (mm->first_msg_id_reply_ready == 1)
{
rv = mm->first_msg_id_reply; rv = mm->first_msg_id_reply;
goto result; goto result;
} }
@ -236,7 +254,8 @@ u16 vl_client_get_first_plugin_msg_id (char * plugin_name)
am->msg_handlers[VL_API_GET_FIRST_MSG_ID_REPLY] = old_handler; am->msg_handlers[VL_API_GET_FIRST_MSG_ID_REPLY] = old_handler;
return rv; return rv;
} while(0); }
while (0);
result: result:
@ -249,5 +268,16 @@ result:
return rv; return rv;
} }
void vlib_node_sync_stats (vlib_main_t * vm, vlib_node_t * n) void
{ clib_warning ("STUB called..."); } vlib_node_sync_stats (vlib_main_t * vm, vlib_node_t * n)
{
clib_warning ("STUB called...");
}
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -96,24 +96,28 @@ unix_shared_memory_queue_init(int nels,
/* /*
* unix_shared_memory_queue_free * unix_shared_memory_queue_free
*/ */
void unix_shared_memory_queue_free(unix_shared_memory_queue_t *q) void
unix_shared_memory_queue_free (unix_shared_memory_queue_t * q)
{ {
(void) pthread_mutex_destroy (&q->mutex); (void) pthread_mutex_destroy (&q->mutex);
(void) pthread_cond_destroy (&q->condvar); (void) pthread_cond_destroy (&q->condvar);
clib_mem_free (q); clib_mem_free (q);
} }
void unix_shared_memory_queue_lock (unix_shared_memory_queue_t *q) void
unix_shared_memory_queue_lock (unix_shared_memory_queue_t * q)
{ {
pthread_mutex_lock (&q->mutex); pthread_mutex_lock (&q->mutex);
} }
void unix_shared_memory_queue_unlock (unix_shared_memory_queue_t *q) void
unix_shared_memory_queue_unlock (unix_shared_memory_queue_t * q)
{ {
pthread_mutex_unlock (&q->mutex); pthread_mutex_unlock (&q->mutex);
} }
int unix_shared_memory_queue_is_full (unix_shared_memory_queue_t *q) int
unix_shared_memory_queue_is_full (unix_shared_memory_queue_t * q)
{ {
return q->cursize == q->maxsize; return q->cursize == q->maxsize;
} }
@ -121,14 +125,17 @@ int unix_shared_memory_queue_is_full (unix_shared_memory_queue_t *q)
/* /*
* unix_shared_memory_queue_add_nolock * unix_shared_memory_queue_add_nolock
*/ */
int unix_shared_memory_queue_add_nolock (unix_shared_memory_queue_t *q, int
unix_shared_memory_queue_add_nolock (unix_shared_memory_queue_t * q,
u8 * elem) u8 * elem)
{ {
i8 *tailp; i8 *tailp;
int need_broadcast = 0; int need_broadcast = 0;
if (PREDICT_FALSE(q->cursize == q->maxsize)) { if (PREDICT_FALSE (q->cursize == q->maxsize))
while(q->cursize == q->maxsize) { {
while (q->cursize == q->maxsize)
{
(void) pthread_cond_wait (&q->condvar, &q->mutex); (void) pthread_cond_wait (&q->condvar, &q->mutex);
} }
} }
@ -144,7 +151,8 @@ int unix_shared_memory_queue_add_nolock (unix_shared_memory_queue_t *q,
if (q->tail == q->maxsize) if (q->tail == q->maxsize)
q->tail = 0; q->tail = 0;
if (need_broadcast) { if (need_broadcast)
{
(void) pthread_cond_broadcast (&q->condvar); (void) pthread_cond_broadcast (&q->condvar);
if (q->signal_when_queue_non_empty) if (q->signal_when_queue_non_empty)
kill (q->consumer_pid, q->signal_when_queue_non_empty); kill (q->consumer_pid, q->signal_when_queue_non_empty);
@ -152,12 +160,13 @@ int unix_shared_memory_queue_add_nolock (unix_shared_memory_queue_t *q,
return 0; return 0;
} }
int unix_shared_memory_queue_add_raw (unix_shared_memory_queue_t *q, int
u8 *elem) unix_shared_memory_queue_add_raw (unix_shared_memory_queue_t * q, u8 * elem)
{ {
i8 *tailp; i8 *tailp;
if (PREDICT_FALSE(q->cursize == q->maxsize)) { if (PREDICT_FALSE (q->cursize == q->maxsize))
{
while (q->cursize == q->maxsize) while (q->cursize == q->maxsize)
; ;
} }
@ -177,26 +186,33 @@ int unix_shared_memory_queue_add_raw (unix_shared_memory_queue_t *q,
/* /*
* unix_shared_memory_queue_add * unix_shared_memory_queue_add
*/ */
int unix_shared_memory_queue_add (unix_shared_memory_queue_t *q, int
unix_shared_memory_queue_add (unix_shared_memory_queue_t * q,
u8 * elem, int nowait) u8 * elem, int nowait)
{ {
i8 *tailp; i8 *tailp;
int need_broadcast = 0; int need_broadcast = 0;
if (nowait) { if (nowait)
{
/* zero on success */ /* zero on success */
if (pthread_mutex_trylock (&q->mutex)) { if (pthread_mutex_trylock (&q->mutex))
{
return (-1); return (-1);
} }
} else }
else
pthread_mutex_lock (&q->mutex); pthread_mutex_lock (&q->mutex);
if (PREDICT_FALSE(q->cursize == q->maxsize)) { if (PREDICT_FALSE (q->cursize == q->maxsize))
if (nowait) { {
if (nowait)
{
pthread_mutex_unlock (&q->mutex); pthread_mutex_unlock (&q->mutex);
return (-2); return (-2);
} }
while(q->cursize == q->maxsize) { while (q->cursize == q->maxsize)
{
(void) pthread_cond_wait (&q->condvar, &q->mutex); (void) pthread_cond_wait (&q->condvar, &q->mutex);
} }
} }
@ -212,7 +228,8 @@ int unix_shared_memory_queue_add (unix_shared_memory_queue_t *q,
if (q->tail == q->maxsize) if (q->tail == q->maxsize)
q->tail = 0; q->tail = 0;
if (need_broadcast) { if (need_broadcast)
{
(void) pthread_cond_broadcast (&q->condvar); (void) pthread_cond_broadcast (&q->condvar);
if (q->signal_when_queue_non_empty) if (q->signal_when_queue_non_empty)
kill (q->consumer_pid, q->signal_when_queue_non_empty); kill (q->consumer_pid, q->signal_when_queue_non_empty);
@ -225,26 +242,33 @@ int unix_shared_memory_queue_add (unix_shared_memory_queue_t *q,
/* /*
* unix_shared_memory_queue_sub * unix_shared_memory_queue_sub
*/ */
int unix_shared_memory_queue_sub(unix_shared_memory_queue_t *q, int
unix_shared_memory_queue_sub (unix_shared_memory_queue_t * q,
u8 * elem, int nowait) u8 * elem, int nowait)
{ {
i8 *headp; i8 *headp;
int need_broadcast = 0; int need_broadcast = 0;
if (nowait) { if (nowait)
{
/* zero on success */ /* zero on success */
if (pthread_mutex_trylock (&q->mutex)) { if (pthread_mutex_trylock (&q->mutex))
{
return (-1); return (-1);
} }
} else }
else
pthread_mutex_lock (&q->mutex); pthread_mutex_lock (&q->mutex);
if (PREDICT_FALSE(q->cursize == 0)) { if (PREDICT_FALSE (q->cursize == 0))
if (nowait) { {
if (nowait)
{
pthread_mutex_unlock (&q->mutex); pthread_mutex_unlock (&q->mutex);
return (-2); return (-2);
} }
while (q->cursize == 0) { while (q->cursize == 0)
{
(void) pthread_cond_wait (&q->condvar, &q->mutex); (void) pthread_cond_wait (&q->condvar, &q->mutex);
} }
} }
@ -269,12 +293,13 @@ int unix_shared_memory_queue_sub(unix_shared_memory_queue_t *q,
return 0; return 0;
} }
int unix_shared_memory_queue_sub_raw (unix_shared_memory_queue_t *q, int
u8 *elem) unix_shared_memory_queue_sub_raw (unix_shared_memory_queue_t * q, u8 * elem)
{ {
i8 *headp; i8 *headp;
if (PREDICT_FALSE(q->cursize == 0)) { if (PREDICT_FALSE (q->cursize == 0))
{
while (q->cursize == 0) while (q->cursize == 0)
; ;
} }
@ -289,3 +314,11 @@ int unix_shared_memory_queue_sub_raw (unix_shared_memory_queue_t *q,
q->head = 0; q->head = 0;
return 0; return 0;
} }
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -23,7 +23,8 @@
#include <pthread.h> #include <pthread.h>
#include <vppinfra/mem.h> #include <vppinfra/mem.h>
typedef struct _unix_shared_memory_queue { typedef struct _unix_shared_memory_queue
{
pthread_mutex_t mutex; /* 8 bytes */ pthread_mutex_t mutex; /* 8 bytes */
pthread_cond_t condvar; /* 8 bytes */ pthread_cond_t condvar; /* 8 bytes */
int head; int head;
@ -36,11 +37,11 @@ typedef struct _unix_shared_memory_queue {
char data[0]; char data[0];
} unix_shared_memory_queue_t; } unix_shared_memory_queue_t;
unix_shared_memory_queue_t * unix_shared_memory_queue_t *unix_shared_memory_queue_init (int nels,
unix_shared_memory_queue_init(int nels,
int elsize, int elsize,
int consumer_pid, int consumer_pid,
int signal_when_queue_non_empty); int
signal_when_queue_non_empty);
void unix_shared_memory_queue_free (unix_shared_memory_queue_t * q); void unix_shared_memory_queue_free (unix_shared_memory_queue_t * q);
int unix_shared_memory_queue_add (unix_shared_memory_queue_t * q, int unix_shared_memory_queue_add (unix_shared_memory_queue_t * q,
u8 * elem, int nowait); u8 * elem, int nowait);
@ -58,3 +59,11 @@ int unix_shared_memory_queue_add_raw (unix_shared_memory_queue_t *q,
u8 * elem); u8 * elem);
#endif /* included_unix_shared_memory_queue_h */ #endif /* included_unix_shared_memory_queue_h */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -23,3 +23,11 @@
*/ */
#include <vlibmemory/memclnt.api.h> #include <vlibmemory/memclnt.api.h>
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -24,10 +24,19 @@
#include <vppinfra/byte_order.h> #include <vppinfra/byte_order.h>
#define vl_msg_id(n,h) n, #define vl_msg_id(n,h) n,
typedef enum { typedef enum
{
VL_ILLEGAL_MESSAGE_ID = 0, VL_ILLEGAL_MESSAGE_ID = 0,
#include <vlibmemory/vl_memory_api_h.h> #include <vlibmemory/vl_memory_api_h.h>
} vl_msg_id_t; } vl_msg_id_t;
#undef vl_msg_id #undef vl_msg_id
#endif /* __VL_MSG_ENUM_H__ */ #endif /* __VL_MSG_ENUM_H__ */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -22,7 +22,8 @@
#include <vlibapi/api.h> #include <vlibapi/api.h>
typedef struct { typedef struct
{
/* Server port number */ /* Server port number */
int portno; int portno;
@ -59,8 +60,7 @@ void vl_socket_process_msg (struct unix_file *uf,
clib_error_t *vl_socket_read_ready (struct unix_file *uf); clib_error_t *vl_socket_read_ready (struct unix_file *uf);
void vl_socket_add_pending_output (struct unix_file *uf, void vl_socket_add_pending_output (struct unix_file *uf,
struct vl_api_registration_ *rp, struct vl_api_registration_ *rp,
u8 * buffer, u8 * buffer, uword buffer_bytes);
uword buffer_bytes);
clib_error_t *vl_socket_write_ready (struct unix_file *uf); clib_error_t *vl_socket_write_ready (struct unix_file *uf);
void vl_socket_api_send (vl_api_registration_t * rp, u8 * elem); void vl_socket_api_send (vl_api_registration_t * rp, u8 * elem);
void vl_socket_api_send_with_data (vl_api_registration_t * rp, void vl_socket_api_send_with_data (vl_api_registration_t * rp,
@ -77,3 +77,11 @@ void socksvr_set_port (u16 port);
void socksvr_set_bind_address (u32 bind_address); void socksvr_set_bind_address (u32 bind_address);
#endif /* included_vlibsocket_api_h */ #endif /* included_vlibsocket_api_h */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -36,39 +36,38 @@ typedef unsigned long uword;
#define VL_API_PACKED(x) x __attribute__ ((packed)) #define VL_API_PACKED(x) x __attribute__ ((packed))
typedef VL_API_PACKED(struct _vl_api_sockclnt_create { typedef VL_API_PACKED (struct _vl_api_sockclnt_create
u16 _vl_msg_id; {
u8 name[64]; u16 _vl_msg_id; u8 name[64];
u32 context; u32 context;
}) vl_api_sockclnt_create_t; }) vl_api_sockclnt_create_t;
typedef VL_API_PACKED(struct _vl_api_sockclnt_create_reply { typedef VL_API_PACKED (struct _vl_api_sockclnt_create_reply
{
u16 _vl_msg_id; u16 _vl_msg_id;
i32 response; i32 response; u64 handle; u32 index; u32 context;
u64 handle;
u32 index;
u32 context;
}) vl_api_sockclnt_create_reply_t; }) vl_api_sockclnt_create_reply_t;
typedef VL_API_PACKED(struct _vl_api_sockclnt_delete { typedef VL_API_PACKED (struct _vl_api_sockclnt_delete
u16 _vl_msg_id; {
u32 index; u16 _vl_msg_id; u32 index;
u64 handle; u64 handle;
}) vl_api_sockclnt_delete_t; }) vl_api_sockclnt_delete_t;
typedef VL_API_PACKED(struct _vl_api_sockclnt_delete_reply { typedef VL_API_PACKED (struct _vl_api_sockclnt_delete_reply
u16 _vl_msg_id; {
i32 response; u16 _vl_msg_id; i32 response; u64 handle;
u64 handle;
}) vl_api_sockclnt_delete_reply_t; }) vl_api_sockclnt_delete_reply_t;
void error(char *msg) void
error (char *msg)
{ {
perror (msg); perror (msg);
exit (0); exit (0);
} }
int main(int argc, char *argv[]) int
main (int argc, char *argv[])
{ {
int sockfd, portno, n; int sockfd, portno, n;
struct sockaddr_in serv_addr; struct sockaddr_in serv_addr;
@ -81,21 +80,22 @@ int main(int argc, char *argv[])
char *rdptr; char *rdptr;
int total_bytes; int total_bytes;
for (i = 0; i < 1; i++) { for (i = 0; i < 1; i++)
{
portno = SOCKCLNT_SERVER_PORT; portno = SOCKCLNT_SERVER_PORT;
sockfd = socket (AF_INET, SOCK_STREAM, 0); sockfd = socket (AF_INET, SOCK_STREAM, 0);
if (sockfd < 0) if (sockfd < 0)
error ("ERROR opening socket"); error ("ERROR opening socket");
server = gethostbyname ("localhost"); server = gethostbyname ("localhost");
if (server == NULL) { if (server == NULL)
{
fprintf (stderr, "ERROR, no such host\n"); fprintf (stderr, "ERROR, no such host\n");
exit (0); exit (0);
} }
bzero ((char *) &serv_addr, sizeof (serv_addr)); bzero ((char *) &serv_addr, sizeof (serv_addr));
serv_addr.sin_family = AF_INET; serv_addr.sin_family = AF_INET;
bcopy ((char *) server->h_addr, bcopy ((char *) server->h_addr,
(char *)&serv_addr.sin_addr.s_addr, (char *) &serv_addr.sin_addr.s_addr, server->h_length);
server->h_length);
serv_addr.sin_port = htons (portno); serv_addr.sin_port = htons (portno);
if (connect (sockfd, (const void *) &serv_addr, sizeof (serv_addr)) < 0) if (connect (sockfd, (const void *) &serv_addr, sizeof (serv_addr)) < 0)
error ("ERROR connecting"); error ("ERROR connecting");
@ -121,18 +121,21 @@ int main(int argc, char *argv[])
total_bytes = 0; total_bytes = 0;
rdptr = buffer; rdptr = buffer;
do { do
{
n = read (sockfd, rdptr, sizeof (buffer) - (rdptr - buffer)); n = read (sockfd, rdptr, sizeof (buffer) - (rdptr - buffer));
if (n < 0) if (n < 0)
error ("ERROR reading from socket"); error ("ERROR reading from socket");
printf ("read %d bytes\n", n); printf ("read %d bytes\n", n);
total_bytes += n; total_bytes += n;
rdptr += n; rdptr += n;
} while (total_bytes < sizeof (vl_api_sockclnt_create_reply_t) + 4); }
while (total_bytes < sizeof (vl_api_sockclnt_create_reply_t) + 4);
rp = (vl_api_sockclnt_create_reply_t *) (buffer + 4); rp = (vl_api_sockclnt_create_reply_t *) (buffer + 4);
/* VL_API_SOCKCLNT_CREATE_REPLY */ /* VL_API_SOCKCLNT_CREATE_REPLY */
if (ntohs(rp->_vl_msg_id) != 9) { if (ntohs (rp->_vl_msg_id) != 9)
{
printf ("WARNING: msg id %d\n", ntohs (rp->_vl_msg_id)); printf ("WARNING: msg id %d\n", ntohs (rp->_vl_msg_id));
} }
@ -142,3 +145,11 @@ int main(int argc, char *argv[])
} }
return 0; return 0;
} }
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -48,8 +48,8 @@
#include <vlibsocket/vl_socket_api_h.h> #include <vlibsocket/vl_socket_api_h.h>
#undef vl_endianfun #undef vl_endianfun
static void vl_api_sockclnt_create_reply_t_handler ( static void
vl_api_sockclnt_create_reply_t *mp) vl_api_sockclnt_create_reply_t_handler (vl_api_sockclnt_create_reply_t * mp)
{ {
vl_api_registration_t *rp = socket_main.current_rp; vl_api_registration_t *rp = socket_main.current_rp;
@ -57,8 +57,8 @@ static void vl_api_sockclnt_create_reply_t_handler (
rp->server_index = mp->index; rp->server_index = mp->index;
} }
static void vl_api_sockclnt_delete_reply_t_handler ( static void
vl_api_sockclnt_delete_reply_t *mp) vl_api_sockclnt_delete_reply_t_handler (vl_api_sockclnt_delete_reply_t * mp)
{ {
unix_main_t *um = &unix_main; unix_main_t *um = &unix_main;
unix_file_t *uf = socket_main.current_uf; unix_file_t *uf = socket_main.current_uf;
@ -68,7 +68,8 @@ static void vl_api_sockclnt_delete_reply_t_handler (
vl_free_socket_registration_index (rp->vl_api_registration_pool_index); vl_free_socket_registration_index (rp->vl_api_registration_pool_index);
} }
u32 sockclnt_open_index (char *client_name, char *hostname, int port) u32
sockclnt_open_index (char *client_name, char *hostname, int port)
{ {
vl_api_registration_t *rp; vl_api_registration_t *rp;
unix_main_t *um = &unix_main; unix_main_t *um = &unix_main;
@ -82,7 +83,8 @@ u32 sockclnt_open_index (char *client_name, char *hostname, int port)
char my_hostname[64]; char my_hostname[64];
server = gethostbyname (hostname); server = gethostbyname (hostname);
if (server == NULL) { if (server == NULL)
{
clib_warning ("Couldn't translate server name %s", hostname); clib_warning ("Couldn't translate server name %s", hostname);
return ~0; return ~0;
} }
@ -90,7 +92,8 @@ u32 sockclnt_open_index (char *client_name, char *hostname, int port)
/* Set up non-blocking server socket on CLIENT_API_SERVER_PORT */ /* Set up non-blocking server socket on CLIENT_API_SERVER_PORT */
sockfd = socket (AF_INET, SOCK_STREAM, 0); sockfd = socket (AF_INET, SOCK_STREAM, 0);
if (sockfd < 0) { if (sockfd < 0)
{
clib_unix_warning ("socket"); clib_unix_warning ("socket");
return ~0; return ~0;
} }
@ -98,18 +101,18 @@ u32 sockclnt_open_index (char *client_name, char *hostname, int port)
bzero ((char *) &serv_addr, sizeof (serv_addr)); bzero ((char *) &serv_addr, sizeof (serv_addr));
serv_addr.sin_family = AF_INET; serv_addr.sin_family = AF_INET;
bcopy ((char *) server->h_addr, bcopy ((char *) server->h_addr,
(char *)&serv_addr.sin_addr.s_addr, (char *) &serv_addr.sin_addr.s_addr, server->h_length);
server->h_length);
serv_addr.sin_port = htons (port); serv_addr.sin_port = htons (port);
if (connect(sockfd,(const void *)&serv_addr,sizeof(serv_addr)) < 0) { if (connect (sockfd, (const void *) &serv_addr, sizeof (serv_addr)) < 0)
clib_unix_warning("Connect failure to (%s, %d)", {
hostname, port); clib_unix_warning ("Connect failure to (%s, %d)", hostname, port);
return ~0; return ~0;
} }
rv = ioctl (sockfd, FIONBIO, &one); rv = ioctl (sockfd, FIONBIO, &one);
if (rv < 0) { if (rv < 0)
{
clib_unix_warning ("FIONBIO"); clib_unix_warning ("FIONBIO");
return ~0; return ~0;
} }
@ -131,7 +134,8 @@ u32 sockclnt_open_index (char *client_name, char *hostname, int port)
mp->_vl_msg_id = ntohs (VL_API_SOCKCLNT_CREATE); mp->_vl_msg_id = ntohs (VL_API_SOCKCLNT_CREATE);
mp->context = rp - socket_main.registration_pool; mp->context = rp - socket_main.registration_pool;
if (gethostname(my_hostname, sizeof (my_hostname)) < 0) { if (gethostname (my_hostname, sizeof (my_hostname)) < 0)
{
clib_unix_warning ("gethostname"); clib_unix_warning ("gethostname");
strncpy (my_hostname, "unknown!", sizeof (my_hostname) - 1); strncpy (my_hostname, "unknown!", sizeof (my_hostname) - 1);
} }
@ -141,13 +145,15 @@ u32 sockclnt_open_index (char *client_name, char *hostname, int port)
return rp - socket_main.registration_pool; return rp - socket_main.registration_pool;
} }
void sockclnt_close_index (u32 index) void
sockclnt_close_index (u32 index)
{ {
vl_api_sockclnt_delete_t *mp; vl_api_sockclnt_delete_t *mp;
vl_api_registration_t *rp; vl_api_registration_t *rp;
/* Don't crash / assert if fed garbage */ /* Don't crash / assert if fed garbage */
if (pool_is_free_index (socket_main.registration_pool, index)) { if (pool_is_free_index (socket_main.registration_pool, index))
{
clib_warning ("registration_pool index %d already free", index); clib_warning ("registration_pool index %d already free", index);
return; return;
} }
@ -160,7 +166,8 @@ void sockclnt_close_index (u32 index)
vl_msg_api_send (rp, (u8 *) mp); vl_msg_api_send (rp, (u8 *) mp);
} }
vl_api_registration_t *sockclnt_get_registration (u32 index) vl_api_registration_t *
sockclnt_get_registration (u32 index)
{ {
return pool_elt_at_index (socket_main.registration_pool, index); return pool_elt_at_index (socket_main.registration_pool, index);
} }
@ -190,3 +197,11 @@ sockclnt_vlib_api_init (vlib_main_t *vm)
} }
VLIB_API_INIT_FUNCTION (sockclnt_vlib_api_init); VLIB_API_INIT_FUNCTION (sockclnt_vlib_api_init);
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

File diff suppressed because it is too large Load Diff

View File

@ -23,3 +23,11 @@
*/ */
#include <vlibmemory/vl_memory_api_h.h> #include <vlibmemory/vl_memory_api_h.h>
#include <vlibsocket/sockclnt.api.h> #include <vlibsocket/sockclnt.api.h>
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -24,10 +24,19 @@
#include <vppinfra/byte_order.h> #include <vppinfra/byte_order.h>
#define vl_msg_id(n,h) n, #define vl_msg_id(n,h) n,
typedef enum { typedef enum
{
VL_ILLEGAL_MESSAGE_ID = 0, VL_ILLEGAL_MESSAGE_ID = 0,
#include <vlibsocket/vl_socket_api_h.h> #include <vlibsocket/vl_socket_api_h.h>
} vl_msg_id_t; } vl_msg_id_t;
#undef vl_msg_id #undef vl_msg_id
#endif /* __VL_MSG_ENUM_H__ */ #endif /* __VL_MSG_ENUM_H__ */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/