24 #include <sys/types.h> 39 #define TRACE_VLIB_MEMORY_QUEUE 0 48 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) 56 vl_print (handle,
"vl_api_memclnt_create_t:\n");
67 vl_print (handle,
"vl_api_memclnt_delete_t:\n");
79 __attribute__ ((weak));
87 clib_warning (
"need to link against -lvlibsocket, msg not sent!");
117 serialize_likely_small_unsigned_integer
141 u8 *serialized_message_table = 0;
176 pthread_mutex_lock (&svm->
mutex);
181 memset (regp, 0,
sizeof (*regp));
190 if (serialized_message_table)
192 vec_dup (serialized_message_table);
194 pthread_mutex_unlock (&svm->
mutex);
197 vec_free (serialized_message_table);
200 rp->_vl_msg_id = ntohs (VL_API_MEMCLNT_CREATE_REPLY);
233 u32 handle, client_index, epoch;
246 (
"Stale clnt delete index %d old epoch %d cur epoch %d",
262 rp->_vl_msg_id = ntohs (VL_API_MEMCLNT_DELETE_REPLY);
281 pthread_mutex_lock (&svm->
mutex);
284 memset (regp, 0xF1,
sizeof (*regp));
286 pthread_mutex_unlock (&svm->
mutex);
304 u16 first_msg_id = ~0;
314 strncpy ((
char *) name, (
char *) mp->
name,
ARRAY_LEN (name) - 1);
328 rmp->_vl_msg_id = ntohs (VL_API_GET_FIRST_MSG_ID_REPLY);
335 #define foreach_vlib_api_msg \ 336 _(MEMCLNT_CREATE, memclnt_create) \ 337 _(MEMCLNT_DELETE, memclnt_delete) \ 338 _(GET_FIRST_MSG_ID, get_first_msg_id) 350 memset (c, 0,
sizeof (*c));
355 #define _(N,n) do { \ 356 c->id = VL_API_##N; \ 358 c->handler = vl_api_##n##_t_handler; \ 359 c->cleanup = vl_noop_handler; \ 360 c->endian = vl_api_##n##_t_endian; \ 361 c->print = vl_api_##n##_t_print; \ 362 c->size = sizeof(vl_api_##n##_t); \ 365 c->message_bounce = 0; \ 366 vl_msg_api_config(c);} while (0); 374 #define foreach_histogram_bucket \ 382 #define _(n) SLEEP_##n##_US, 402 f64 dead_client_scan_time;
403 f64 sleep_time, start_time;
410 clib_warning (
"memory_api_init returned %d, wait for godot...", rv);
430 uword event_type __attribute__ ((unused));
448 pthread_mutex_lock (&q->mutex);
452 pthread_mutex_unlock (&q->mutex);
459 .format =
"q-underflow: len %d",
474 headp = (
i8 *) (q->data + sizeof (
uword) * q->head);
478 need_broadcast = (q->cursize == q->maxsize / 2);
483 pthread_mutex_unlock (&q->mutex);
485 (void) pthread_cond_broadcast (&q->condvar);
492 int index = SLEEP_400_US;
493 if (vector_rate > 40.0)
495 else if (vector_rate > 20.0)
497 index = SLEEP_200_US;
500 else if (vector_rate >= 1.0)
502 index = SLEEP_100_US;
510 vector_rate_histogram[index] += 1;
524 static u32 *dead_indices;
525 static u32 *confused_indices;
536 q = regp->vl_input_queue;
537 if (kill (q->consumer_pid, 0) < 0)
539 vec_add1(dead_indices, regpp - am->vl_clients);
544 clib_warning (
"NULL client registration index %d",
545 regpp - am->vl_clients);
546 vec_add1 (confused_indices, regpp - am->vl_clients);
554 for (i = 0; i <
vec_len (confused_indices); i++)
567 for (i = 0; i <
vec_len (dead_indices); i++)
581 pthread_mutex_lock (&svm->
mutex);
584 for (i = 0; i <
vec_len (dead_indices); i++)
590 memset (*regpp, 0xF3,
sizeof (**regpp));
606 pthread_mutex_unlock (&svm->
mutex);
608 for (i = 0; i <
vec_len (dead_indices); i++)
619 .format =
"q-awake: len %d",
628 ed->len = q->cursize;
640 u64 total_counts = 0;
648 if (total_counts == 0)
657 percent = ((f64) vector_rate_histogram[SLEEP_##n##_US]) \ 658 / (f64) total_counts; \ 660 vlib_cli_output (vm, "Sleep %3d us: %llu, %.2f%%",n, \ 661 vector_rate_histogram[SLEEP_##n##_US], \ 672 .path =
"show api histogram",
673 .short_help =
"show api histogram",
692 .path =
"clear api histogram",
693 .short_help =
"clear api histogram",
703 .name =
"api-rx-from-ring",
704 .state = VLIB_NODE_STATE_DISABLED,
711 static volatile int *cursizep;
725 cursizep = &q->cursize;
742 ? VLIB_NODE_STATE_POLLING
743 : VLIB_NODE_STATE_DISABLED));
759 while (n_left_from > 0)
776 _vec_len (long_msg) = 0;
777 vec_add (long_msg, msg, msg_len);
783 vec_add (long_msg, msg, msg_len);
801 .name =
"api-rx-from-node",
833 "Owner",
"Size",
"Nitems",
"Hits",
"Misses");
863 __attribute__ ((weak));
878 u32 *confused_indices = 0;
884 "Name",
"PID",
"Queue Length",
"Queue VA",
"Health");
893 q = regp->vl_input_queue;
894 if (kill (q->consumer_pid, 0) < 0)
902 vlib_cli_output (vm,
"%16s %8d %14d 0x%016llx %s\n",
903 regp->name, q->consumer_pid, q->cursize,
908 clib_warning (
"NULL client registration index %d",
909 regpp - am->vl_clients);
910 vec_add1 (confused_indices, regpp - am->vl_clients);
919 for (i = 0; i <
vec_len (confused_indices); i++)
973 .short_help =
"Show API information",
979 .path =
"show api ring-stats",
980 .short_help =
"Message ring statistics",
987 .path =
"show api clients",
988 .short_help =
"Client information",
995 .path =
"show api status",
996 .short_help =
"Show API trace status",
1042 .path =
"show api message-table",
1043 .short_help =
"Message Table",
1060 else if (
unformat (input,
"tx nitems %u", &nitems)
1066 else if (
unformat (input,
"on rx"))
1070 else if (
unformat (input,
"on tx"))
1090 else if (
unformat (input,
"debug on"))
1094 else if (
unformat (input,
"debug off"))
1116 .path =
"set api-trace",
1117 .short_help =
"API trace",
1128 memset (a, 0,
sizeof (*a));
1158 int len0, len1, clen;
1162 clen = len0 < len1 ? len0 : len1;
1163 return (strncmp ((
char *) a0->
name, (
char *) a1->
name, clen));
1172 s =
format (s,
"%-20s%9s%9s",
"Name",
"First-ID",
"Last-ID");
1202 for (i = 0; i <
vec_len (rp); i++)
1210 .path =
"show api plugin",
1211 .short_help =
"show api plugin",
1249 rmp->_vl_msg_id = ntohs (VL_API_RPC_REPLY);
1279 void (*call_fp) (
void *);
1293 memset (mp, 0,
sizeof (*mp));
1295 mp->_vl_msg_id = ntohs (VL_API_RPC_CALL);
1306 while (pthread_mutex_trylock (&q->mutex))
1311 pthread_mutex_unlock (&q->mutex);
1313 while (pthread_mutex_trylock (&q->mutex))
1319 pthread_mutex_unlock (&q->mutex);
1322 #define foreach_rpc_api_msg \ 1323 _(RPC_CALL,rpc_call) \ 1324 _(RPC_REPLY,rpc_reply) 1330 vl_msg_api_set_handlers(VL_API_##N, #n, \ 1331 vl_api_##n##_t_handler, \ 1334 vl_api_##n##_t_print, \ 1335 sizeof(vl_api_##n##_t), 0 );
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
#define TRACE_VLIB_MEMORY_QUEUE
#define vl_print(handle,...)
sll srl srl sll sra u16x4 i
void vl_api_memclnt_delete_t_handler(vl_api_memclnt_delete_t *mp)
static void svm_pop_heap(void *oldheap)
static f64 vlib_process_wait_for_event_or_clock(vlib_main_t *vm, f64 dt)
Suspend a cooperative multi-tasking thread Waits for an event, or for the indicated number of seconds...
int unix_shared_memory_queue_is_full(unix_shared_memory_queue_t *q)
static vlib_cli_command_t trace
(constructor) VLIB_CLI_COMMAND (trace)
void vl_msg_api_send_shmem(unix_shared_memory_queue_t *q, u8 *elem)
static vlib_main_t * vlib_get_main(void)
static clib_error_t * setup_memclnt_exit(vlib_main_t *vm)
Fixed length block allocator.
unix_shared_memory_queue_t * vl_input_queue
static vlib_node_registration_t api_rx_from_node_node
(constructor) VLIB_REGISTER_NODE (api_rx_from_node_node)
static f64 vlib_time_now(vlib_main_t *vm)
static clib_error_t * vl_api_client_command(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cli_cmd)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
static clib_error_t * vl_api_message_table_command(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cli_cmd)
static clib_error_t * vl_api_show_plugin_command(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cli_cmd)
unix_shared_memory_queue_t * vl_api_client_index_to_input_queue(u32 index)
ring_alloc_t * client_rings
static clib_error_t * vl_api_clear_histogram_command(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cli_cmd)
void vl_msg_api_send(vl_api_registration_t *rp, u8 *elem)
#define pool_is_free(P, E)
Use free bitmap to query whether given element is free.
#define clib_error_report(e)
void vl_api_get_first_msg_id_t_handler(vl_api_get_first_msg_id_t *mp)
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
int vl_api_memclnt_delete_callback(u32 client_index)
void vl_enable_disable_memory_api(vlib_main_t *vm, int enable)
static vlib_cli_command_t cli_show_api_clients_command
(constructor) VLIB_CLI_COMMAND (cli_show_api_clients_command)
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
#define vec_add(V, E, N)
Add N elements to end of vector V (no header, unspecified alignment)
static f64 vlib_last_vector_length_per_node(vlib_main_t *vm)
static void vlib_worker_thread_barrier_check(void)
static uword vlib_process_suspend(vlib_main_t *vm, f64 dt)
Suspend a vlib cooperative multi-tasking thread for a period of time.
void vl_set_memory_region_name(char *name)
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
_vlib_init_function_list_elt_t * api_init_function_registrations
static vlib_cli_command_t cli_show_api_status_command
(constructor) VLIB_CLI_COMMAND (cli_show_api_status_command)
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
static int range_compare(vl_api_msg_range_t *a0, vl_api_msg_range_t *a1)
vl_api_trace_t * rx_trace
#define VLIB_INIT_FUNCTION(x)
static uword vlib_process_get_events(vlib_main_t *vm, uword **data_vector)
Return the first event type which has occurred and a vector of per-event data of that type...
void vl_unmap_shmem(void)
static void * svm_push_data_heap(svm_region_t *rp)
void vl_msg_api_free(void *)
vl_api_registration_t ** vl_clients
static vlib_cli_command_t cli_show_api_message_table_command
(constructor) VLIB_CLI_COMMAND (cli_show_api_message_table_command)
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
#define clib_warning(format, args...)
struct vl_shmem_hdr_ * shmem_hdr
static void * vl_api_memclnt_create_t_print(vl_api_memclnt_create_t *a, void *handle)
void vl_socket_api_send(vl_api_registration_t *rp, u8 *elem)
#define SVM_GLOBAL_REGION_BASEVA
static uword pointer_to_uword(const void *p)
static void memclnt_queue_callback(vlib_main_t *vm)
static void vlib_set_queue_signal_callback(vlib_main_t *vm, void(*fp)(vlib_main_t *))
#define VLIB_BUFFER_NEXT_PRESENT
vl_shmem_hdr_t * shmem_hdr
int vl_msg_api_trace_free(api_main_t *am, vl_api_trace_which_t which)
vl_registration_type_t registration_type
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
#define foreach_rpc_api_msg
static vlib_node_registration_t memclnt_node
(constructor) VLIB_REGISTER_NODE (memclnt_node)
static clib_error_t * vl_api_ring_command(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cli_cmd)
u16 current_length
Nbytes between current data and the end of this buffer.
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
static vlib_cli_command_t cli_show_api_ring_command
(constructor) VLIB_CLI_COMMAND (cli_show_api_ring_command)
uword os_get_cpu_number(void)
#define vec_dup(V)
Return copy of vector (no header, no alignment)
void svm_region_init_args(svm_map_region_args_t *a)
static void vl_api_rpc_call_t_handler(vl_api_rpc_call_t *mp)
static u32 vl_msg_api_handle_get_index(u32 index)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
#define foreach_vlib_api_msg
void vl_msg_api_handler_with_vm_node(api_main_t *am, void *the_msg, vlib_main_t *vm, vlib_node_runtime_t *node)
volatile u32 queue_signal_pending
#define uword_to_pointer(u, type)
int vl_msg_api_trace_onoff(api_main_t *am, vl_api_trace_which_t which, int onoff)
void * vl_msg_api_alloc(int nbytes)
void vl_api_rpc_call_main_thread(void *fp, u8 *data, u32 data_length)
void serialize_open_vector(serialize_main_t *m, u8 *vector)
#define vec_free(V)
Free vector's memory (no header).
unix_shared_memory_queue_t * vl_input_queue
vl_api_msg_range_t * msg_ranges
#define clib_memcpy(a, b, c)
#define foreach_histogram_bucket
static void serialize_integer(serialize_main_t *m, u64 x, u32 n_bytes)
void vlib_worker_thread_barrier_sync(vlib_main_t *vm)
#define ELOG_TYPE_DECLARE(f)
static vlib_cli_command_t cli_show_api_command
(constructor) VLIB_CLI_COMMAND (cli_show_api_command)
static clib_error_t * vl_api_trace_command(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cli_cmd)
#define VLIB_CLI_COMMAND(x,...)
void vl_msg_api_handler_no_trace_no_free(void *the_msg)
vl_api_trace_t * tx_trace
static uword api_rx_from_node(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
static vlib_cli_command_t cli_show_api_plugin_command
(constructor) VLIB_CLI_COMMAND (cli_show_api_plugin_command)
#define pool_put_index(p, i)
Free pool element with given index.
static uword hash_elts(void *v)
#define VL_API_EPOCH_MASK
clib_error_t * vlibmemory_init(vlib_main_t *vm)
static u64 vector_rate_histogram[SLEEP_N_BUCKETS]
void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
static uword memclnt_process(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *f)
clib_error_t * vlib_call_init_exit_functions(vlib_main_t *vm, _vlib_init_function_list_elt_t *head, int call_once)
VLIB_API_INIT_FUNCTION(rpc_api_hookup)
u8 * vl_api_serialize_message_table(api_main_t *am, u8 *vector)
u32 next_buffer
Next buffer for this linked-list of buffers.
static void clib_mem_free(void *p)
u8 * serialized_message_table_in_shmem
static void * vlib_frame_args(vlib_frame_t *f)
Get pointer to frame scalar data.
void dump_socket_clients(vlib_main_t *vm, api_main_t *am)
static void vlib_node_set_state(vlib_main_t *vm, u32 node_index, vlib_node_state_t new_state)
Set node dispatch state.
#define SVM_GLOBAL_REGION_SIZE
static void * clib_mem_alloc(uword size)
static u8 * format_api_msg_range(u8 *s, va_list *args)
static clib_error_t * rpc_api_hookup(vlib_main_t *vm)
static clib_error_t * vl_api_status_command(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cli_cmd)
static void vl_api_rpc_reply_t_handler(vl_api_rpc_reply_t *mp)
#define SVM_GLOBAL_REGION_NAME
void vl_api_memclnt_create_t_handler(vl_api_memclnt_create_t *mp)
#define SVM_PVT_MHEAP_SIZE
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define hash_foreach_pair(p, v, body)
Iterate over hash pairs.
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
int vl_map_shmem(char *region_name, int is_vlib)
u32 vl_api_registration_pool_index
void svm_client_scan_this_region_nolock(svm_region_t *rp)
static clib_error_t * vl_api_show_histogram_command(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cli_cmd)
volatile u32 api_queue_nonempty
#define hash_get_mem(h, key)
void vlib_worker_thread_barrier_release(vlib_main_t *vm)
#define VLIB_REGISTER_NODE(x,...)
void vl_msg_api_send_shmem_nolock(unix_shared_memory_queue_t *q, u8 *elem)
static int memory_api_init(char *region_name)
void * serialize_close_vector(serialize_main_t *m)
static void * vl_api_memclnt_delete_t_print(vl_api_memclnt_delete_t *a, void *handle)
void * vl_msg_api_alloc_as_if_client(int nbytes)
#define clib_error_return(e, args...)
static u32 vl_msg_api_handle_get_epoch(u32 index)
uword * msg_index_by_name_and_crc
int vl_msg_api_trace_configure(api_main_t *am, vl_api_trace_which_t which, u32 nitems)
u32 flags
buffer flags: VLIB_BUFFER_IS_TRACED: trace this buffer.
uword * msg_range_by_name
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
static u32 vl_msg_api_handle_from_index_and_epoch(u32 index, u32 epoch)
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".
struct _unix_shared_memory_queue unix_shared_memory_queue_t
static uword pool_elts(void *v)
Number of active elements in a pool.