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!");
104 __attribute__ ((weak));
160 pthread_mutex_lock (&svm->
mutex);
165 memset (regp, 0,
sizeof (*regp));
175 pthread_mutex_unlock (&svm->
mutex);
179 rp->_vl_msg_id = ntohs (VL_API_MEMCLNT_CREATE_REPLY);
211 u32 handle, client_index, epoch;
224 (
"Stale clnt delete index %d old epoch %d cur epoch %d",
240 rp->_vl_msg_id = ntohs (VL_API_MEMCLNT_DELETE_REPLY);
259 pthread_mutex_lock (&svm->
mutex);
262 memset (regp, 0xF1,
sizeof (*regp));
264 pthread_mutex_unlock (&svm->
mutex);
282 u16 first_msg_id = ~0;
292 strncpy ((
char *) name, (
char *) mp->
name,
ARRAY_LEN (name) - 1);
306 rmp->_vl_msg_id = ntohs (VL_API_GET_FIRST_MSG_ID_REPLY);
313 #define foreach_vlib_api_msg \ 314 _(MEMCLNT_CREATE, memclnt_create) \ 315 _(MEMCLNT_DELETE, memclnt_delete) \ 316 _(GET_FIRST_MSG_ID, get_first_msg_id) 331 #define _(N,n) do { \ 332 c->id = VL_API_##N; \ 334 c->handler = vl_api_##n##_t_handler; \ 335 c->cleanup = vl_noop_handler; \ 336 c->endian = vl_api_##n##_t_endian; \ 337 c->print = vl_api_##n##_t_print; \ 338 c->size = sizeof(vl_api_##n##_t); \ 341 vl_msg_api_config(c);} while (0); 349 #define foreach_histogram_bucket \ 357 #define _(n) SLEEP_##n##_US, 377 f64 dead_client_scan_time;
378 f64 sleep_time, start_time;
385 clib_warning (
"memory_api_init returned %d, wait for godot...", rv);
405 uword event_type __attribute__ ((unused));
423 pthread_mutex_lock (&q->mutex);
427 pthread_mutex_unlock (&q->mutex);
434 .format =
"q-underflow: len %d",
449 headp = (
i8 *) (q->data + sizeof (
uword) * q->head);
453 need_broadcast = (q->cursize == q->maxsize / 2);
458 pthread_mutex_unlock (&q->mutex);
460 (void) pthread_cond_broadcast (&q->condvar);
467 int index = SLEEP_400_US;
468 if (vector_rate > 40.0)
470 else if (vector_rate > 20.0)
472 index = SLEEP_200_US;
475 else if (vector_rate >= 1.0)
477 index = SLEEP_100_US;
485 vector_rate_histogram[index] += 1;
499 static u32 *dead_indices;
500 static u32 *confused_indices;
511 q = regp->vl_input_queue;
512 if (kill (q->consumer_pid, 0) < 0)
514 vec_add1(dead_indices, regpp - am->vl_clients);
519 clib_warning (
"NULL client registration index %d",
520 regpp - am->vl_clients);
521 vec_add1 (confused_indices, regpp - am->vl_clients);
529 for (i = 0; i <
vec_len (confused_indices); i++)
542 for (i = 0; i <
vec_len (dead_indices); i++)
556 pthread_mutex_lock (&svm->
mutex);
559 for (i = 0; i <
vec_len (dead_indices); i++)
565 memset (*regpp, 0xF3,
sizeof (**regpp));
581 pthread_mutex_unlock (&svm->
mutex);
583 for (i = 0; i <
vec_len (dead_indices); i++)
594 .format =
"q-awake: len %d",
603 ed->len = q->cursize;
615 u64 total_counts = 0;
623 if (total_counts == 0)
632 percent = ((f64) vector_rate_histogram[SLEEP_##n##_US]) \ 633 / (f64) total_counts; \ 635 vlib_cli_output (vm, "Sleep %3d us: %llu, %.2f%%",n, \ 636 vector_rate_histogram[SLEEP_##n##_US], \ 647 .path =
"show api histogram",
648 .short_help =
"show api histogram",
667 .path =
"clear api histogram",
668 .short_help =
"clear api histogram",
678 .name =
"api-rx-from-ring",
679 .state = VLIB_NODE_STATE_DISABLED,
686 static volatile int *cursizep;
700 cursizep = &q->cursize;
717 ? VLIB_NODE_STATE_POLLING
718 : VLIB_NODE_STATE_DISABLED));
734 while (n_left_from > 0)
751 _vec_len (long_msg) = 0;
752 vec_add (long_msg, msg, msg_len);
758 vec_add (long_msg, msg, msg_len);
776 .name =
"api-rx-from-node",
808 "Owner",
"Size",
"Nitems",
"Hits",
"Misses");
838 __attribute__ ((weak));
853 u32 *confused_indices = 0;
859 "Name",
"PID",
"Queue Length",
"Queue VA",
"Health");
868 q = regp->vl_input_queue;
869 if (kill (q->consumer_pid, 0) < 0)
877 vlib_cli_output (vm,
"%16s %8d %14d 0x%016llx %s\n",
878 regp->name, q->consumer_pid, q->cursize,
883 clib_warning (
"NULL client registration index %d",
884 regpp - am->vl_clients);
885 vec_add1 (confused_indices, regpp - am->vl_clients);
894 for (i = 0; i <
vec_len (confused_indices); i++)
913 .short_help =
"Show API information",
919 .path =
"show api ring-stats",
920 .short_help =
"Message ring statistics",
927 .path =
"show api clients",
928 .short_help =
"Client information",
974 .path =
"show api message-table",
975 .short_help =
"Message Table",
989 static u8 *msg_buf = 0;
990 void (*endian_fp) (
void *);
991 u8 *(*print_fp) (
void *,
void *);
1013 fp = fopen ((
char *) filename,
"r");
1023 if (fread (tp,
sizeof (*tp), 1, fp) != 1)
1036 for (i = 0; i <=
last; i++)
1039 if (fread (&msg_id,
sizeof (
u16), 1, fp) != 1)
1043 msg_id = ntohs (msg_id);
1045 if (fseek (fp, -2, SEEK_CUR) < 0)
1062 if (fread (msg_buf, size, 1, fp) != 1)
1075 (*endian_fp) (msg_buf);
1081 (*print_fp) (msg_buf, vm);
1102 else if (
unformat (input,
"tx nitems %u", &nitems)
1108 else if (
unformat (input,
"on rx"))
1112 else if (
unformat (input,
"on tx"))
1132 else if (
unformat (input,
"print %s from %d to %d", &filename,
1134 ||
unformat (input,
"print %s", &filename))
1138 else if (
unformat (input,
"debug on"))
1142 else if (
unformat (input,
"debug off"))
1169 .path =
"set api-trace",
1170 .short_help =
"API trace",
1181 memset (a, 0,
sizeof (*a));
1211 int len0, len1, clen;
1215 clen = len0 < len1 ? len0 : len1;
1216 return (strncmp ((
char *) a0->
name, (
char *) a1->
name, clen));
1225 s =
format (s,
"%-20s%9s%9s",
"Name",
"First-ID",
"Last-ID");
1255 for (i = 0; i <
vec_len (rp); i++)
1263 .path =
"show api plugin",
1264 .short_help =
"show api plugin",
1302 rmp->_vl_msg_id = ntohs (VL_API_RPC_REPLY);
1328 memset (mp, 0,
sizeof (*mp));
1330 mp->_vl_msg_id = ntohs (VL_API_RPC_CALL);
1338 #define foreach_rpc_api_msg \ 1339 _(RPC_CALL,rpc_call) \ 1340 _(RPC_REPLY,rpc_reply) 1346 vl_msg_api_set_handlers(VL_API_##N, #n, \ 1347 vl_api_##n##_t_handler, \ 1350 vl_api_##n##_t_print, \ 1351 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...
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)
static heap_elt_t * last(heap_header_t *h)
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)
trace_cfg_t * api_trace_cfg
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 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
#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)
#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
static heap_elt_t * first(heap_header_t *h)
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)
void(** msg_print_handlers)(void *, void *)
static vlib_cli_command_t cli_show_api_ring_command
(constructor) VLIB_CLI_COMMAND (cli_show_api_ring_command)
#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)
#define clib_arch_is_big_endian
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)
#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
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)
void vl_msg_api_handler_no_trace_no_free(void *the_msg)
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.
#define VL_API_EPOCH_MASK
clib_error_t * vlibmemory_init(vlib_main_t *vm)
int vl_msg_api_version_check(vl_api_memclnt_create_t *mp)
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)
u32 next_buffer
Next buffer for this linked-list of buffers.
static void clib_mem_free(void *p)
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 void vl_api_rpc_reply_t_handler(vl_api_rpc_reply_t *mp)
#define SVM_GLOBAL_REGION_NAME
VLIB_CLI_COMMAND(set_interface_ip_source_and_port_range_check_command, static)
void vl_api_memclnt_create_t_handler(vl_api_memclnt_create_t *mp)
void(** msg_endian_handlers)(void *)
#define SVM_PVT_MHEAP_SIZE
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#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(** msg_handlers)(void *)
void vlib_worker_thread_barrier_release(vlib_main_t *vm)
#define VLIB_REGISTER_NODE(x,...)
static int memory_api_init(char *region_name)
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)
#define CLIB_CACHE_LINE_BYTES
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
void vl_api_trace_print_file_cmd(vlib_main_t *vm, u32 first, u32 last, u8 *filename)
static uword pool_elts(void *v)
Number of active elements in a pool.