|
FD.io VPP
v21.10.1-2-g0a485f517
Vector Packet Processing
|
Go to the documentation of this file.
38 #define segment_manager_foreach_segment_w_lock(VAR, SM, BODY) \
40 clib_rwlock_reader_lock (&(SM)->segments_rwlock); \
41 pool_foreach((VAR), ((SM)->segments)) (BODY); \
42 clib_rwlock_reader_unlock (&(SM)->segments_rwlock); \
81 return (seg - sm->segments);
104 if (!props->add_segment && !segment_size)
107 return VNET_API_ERROR_INVALID_VALUE;
121 segment_size = segment_size ? segment_size : props->add_segment_size;
132 seg_name =
format (0,
"%v segment%c", app->
name, 0);
141 clib_warning (
"svm_master_init ('%v', %u) failed", seg_name,
156 fs_index = fs - sm->segments;
292 u32 sm_index, segment_index;
353 sm->max_fifo_size = props->max_fifo_size ?
355 sm->max_fifo_size =
clib_max (sm->max_fifo_size, 4096);
358 props->high_watermark,
359 props->low_watermark);
371 uword first_seg_size;
377 first_seg_size =
clib_max (props->segment_size,
380 if (props->prealloc_fifos)
382 u64 approx_total_size, max_seg_size = ((
u64) 1 << 32) - (128 << 10);
383 u32 rx_rounded_data_size, tx_rounded_data_size;
384 u32 prealloc_fifo_pairs = props->prealloc_fifos;
385 u32 rx_fifo_size, tx_fifo_size, pair_size;
386 u32 approx_segment_count;
389 rx_rounded_data_size = (1 << (
max_log2 (props->rx_fifo_size)));
390 tx_rounded_data_size = (1 << (
max_log2 (props->tx_fifo_size)));
392 rx_fifo_size =
sizeof (
svm_fifo_t) + rx_rounded_data_size;
393 tx_fifo_size =
sizeof (
svm_fifo_t) + tx_rounded_data_size;
394 pair_size = rx_fifo_size + tx_fifo_size;
396 approx_total_size = (
u64) prealloc_fifo_pairs *pair_size;
397 if (first_seg_size > approx_total_size)
398 max_seg_size = first_seg_size;
399 approx_segment_count = (approx_total_size + (max_seg_size - 1))
403 for (
i = 0;
i < approx_segment_count + 1;
i++)
419 &prealloc_fifo_pairs);
421 if (prealloc_fifo_pairs == 0)
437 if (props->prealloc_fifo_hdrs)
443 hdrs_per_slice = props->prealloc_fifo_hdrs / (fs->
n_slices -
i);
448 return VNET_API_ERROR_SVM_SEGMENT_CREATE_FAIL;
507 u32 sm_index = *(
u32 *) arg;
609 for (slice_index = 0; slice_index < fs->
n_slices; slice_index++)
621 f->master_thread_index);
663 for (slice_index = 0; slice_index < fs->
n_slices; slice_index++)
669 f->master_thread_index);
700 u32 rx_fifo_size,
u32 tx_fifo_size,
742 int alloc_fail = 1,
rv = 0, new_fs_index;
743 uword free_bytes, max_free_bytes = 0;
746 u32 sm_index, fs_index;
760 if (free_bytes > max_free_bytes)
762 max_free_bytes = free_bytes;
783 if (props->add_segment)
788 return SESSION_E_SEG_CREATE;
797 clib_warning (
"Added a segment, still can't allocate a fifo");
799 return SESSION_E_SEG_NO_SPACE2;
804 SESSION_DBG (
"Can't add new seg and no space to allocate fifos!");
805 return SESSION_E_SEG_NO_SPACE;
809 ASSERT (rx_fifo && tx_fifo);
813 (*tx_fifo)->segment_manager = sm_index;
814 (*rx_fifo)->segment_manager = sm_index;
815 (*tx_fifo)->segment_index = fs_index;
816 (*rx_fifo)->segment_index = fs_index;
831 if (!rx_fifo || !tx_fifo)
839 segment_index = rx_fifo->segment_index;
855 if (segment_index != 0 || !sm->first_is_protected)
894 u32 fifo_evt_size, notif_q_size, q_hdrs;
895 u32 msg_q_sz, fifo_evt_ring_sz, session_ntf_ring_sz;
897 fifo_evt_size = 1 <<
max_log2 (
sizeof (session_event_t));
898 notif_q_size =
clib_max (16, q_len >> 4);
901 fifo_evt_ring_sz = q_len * fifo_evt_size;
902 session_ntf_ring_sz = notif_q_size * 256;
905 return (msg_q_sz + fifo_evt_ring_sz + session_ntf_ring_sz + q_hdrs);
917 u32 fifo_evt_size, session_evt_size = 256, notif_q_size;
921 fifo_evt_size =
sizeof (session_event_t);
922 notif_q_size =
clib_max (16, props->evt_q_size >> 4);
925 {props->evt_q_size, fifo_evt_size, 0},
926 {notif_q_size, session_evt_size, 0}
936 if (props->use_mq_eventfd)
947 return sm->event_queue;
992 u8 show_segments = 0, verbose = 0;
1004 else if (
unformat (input,
"verbose"))
1015 "Index",
"AppIndex",
"Segments",
"MaxFifoSize",
1016 "HighWater",
"LowWater",
"FifoTuning");
1023 max_fifo_size = sm->max_fifo_size;
1027 sm->app_wrk_index,
pool_elts (sm->segments),
1029 sm->high_watermark, sm->low_watermark,
1030 custom_logic ?
"custom" :
"none");
1055 .path =
"show segment-manager",
1056 .short_help =
"show segment-manager [segments][verbose]",
1076 "Connection",
"App",
"API Client",
"SegManager");
1090 for (slice_index = 0; slice_index < fs->
n_slices; slice_index++)
1098 session_index =
f->shr->master_session_index;
1127 u8 high_watermark,
u8 low_watermark)
1129 ASSERT (high_watermark <= 100 && low_watermark <= 100 &&
1130 low_watermark <= high_watermark);
1132 sm->high_watermark = high_watermark;
1133 sm->low_watermark = low_watermark;
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
struct segment_manager_main_ segment_manager_main_t
fifo_segment_t * segment_manager_get_segment_w_lock(segment_manager_t *sm, u32 segment_index)
Reads a segment from the segment manager's pool and acquires reader lock.
u32 n_rings
number of msg rings
static segment_manager_props_t * segment_manager_properties_get(segment_manager_t *sm)
static u32 vlib_num_workers()
static u32 segment_manager_segment_index(segment_manager_t *sm, fifo_segment_t *seg)
void segment_manager_segment_reader_lock(segment_manager_t *sm)
segment_manager_t * segment_manager_get(u32 index)
int segment_manager_init_first(segment_manager_t *sm)
Initializes segment manager based on options provided.
void segment_manager_segment_writer_unlock(segment_manager_t *sm)
static clib_error_t * segment_manager_show_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
u32 session_index
Index in thread pool where session was allocated.
svm_fifo_t * fifo_segment_alloc_fifo_w_slice(fifo_segment_t *fs, u32 slice_index, u32 data_bytes, fifo_segment_ftype_t ftype)
Allocate fifo in fifo segment.
segment_manager_t * segment_managers
Pool of segment managers.
#define SESSION_CLI_ID_LEN
void session_close(session_t *s)
Initialize session closing procedure.
void fifo_segment_attach_fifo(fifo_segment_t *fs, svm_fifo_t **f, u32 slice_index)
static void sm_lock_and_del_segment_inline(segment_manager_t *sm, u32 fs_index)
Removes segment after acquiring writer lock.
int segment_manager_init(segment_manager_t *sm)
static void ssvm_pop_heap(void *oldheap)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
u8 high_watermark
memory pressure watermark high
u8 default_low_watermark
default low watermark %
segment_manager_props_t * segment_manager_props_init(segment_manager_props_t *props)
void fifo_segment_detach_fifo(fifo_segment_t *fs, svm_fifo_t **f)
struct _segment_manager segment_manager_t
#define clib_error_return(e, args...)
struct _svm_queue svm_queue_t
static void * ssvm_push_heap(ssvm_shared_header_t *sh)
u32 q_nitems
msg queue size (not rings)
static heap_elt_t * first(heap_header_t *h)
#define APP_INVALID_INDEX
u8 thread_index
Index of the thread that allocated the session.
#define pool_put(P, E)
Free an object E in pool P.
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
#define fifo_segment_flags(_fs)
vl_api_dhcp_client_state_t state
int svm_msg_q_alloc_eventfd(svm_msg_q_t *mq)
Allocate event fd for queue.
ssvm_shared_header_t * sh
int app_worker_del_segment_notify(app_worker_t *app_wrk, u64 segment_handle)
static void clib_rwlock_reader_lock(clib_rwlock_t *p)
static void segment_manager_parse_segment_handle(u64 segment_handle, u32 *sm_index, u32 *segment_index)
static void clib_rwlock_reader_unlock(clib_rwlock_t *p)
segment_manager_t * segment_manager_alloc(void)
static void clib_rwlock_writer_unlock(clib_rwlock_t *p)
u8 segment_manager_app_detached(segment_manager_t *sm)
struct _svm_fifo svm_fifo_t
static uword max_log2(uword x)
fifo_segment_t * segment_manager_get_segment_w_handle(u64 segment_handle)
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
u32 default_app_mq_size
default app msg q size
static uword round_pow2(uword x, uword pow2)
application_t * application_get(u32 app_index)
u32 app_wrk_index
Index of the app worker that owns the session.
int segment_manager_alloc_session_fifos(segment_manager_t *sm, u32 thread_index, svm_fifo_t **rx_fifo, svm_fifo_t **tx_fifo)
#define pool_foreach(VAR, POOL)
Iterate through pool.
void segment_manager_app_detach(segment_manager_t *sm)
void fifo_segment_cleanup(fifo_segment_t *fs)
void svm_queue_free(svm_queue_t *q)
svm_msg_q_t * segment_manager_event_queue(segment_manager_t *sm)
@ SEG_MANAGER_F_DETACHED_LISTENER
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
void segment_manager_dealloc_fifos(svm_fifo_t *rx_fifo, svm_fifo_t *tx_fifo)
segment_manager_props_t * application_get_segment_manager_properties(u32 app_index)
void segment_manager_del_sessions(segment_manager_t *sm)
Initiate disconnects for all sessions 'owned' by a segment manager.
void segment_manager_free(segment_manager_t *sm)
Cleanup segment manager.
void ssvm_delete(ssvm_private_t *ssvm)
svm_msg_q_t * fifo_segment_msg_q_alloc(fifo_segment_t *fs, u32 mq_index, svm_msg_q_cfg_t *cfg)
Allocate message queue on segment.
struct _segment_manager_props segment_manager_props_t
static_always_inline uword vlib_get_thread_index(void)
app_worker_t * app_worker_get_if_valid(u32 wrk_index)
static fifo_segment_t * segment_manager_get_segment_if_valid(segment_manager_t *sm, u32 segment_index)
void segment_manager_format_sessions(segment_manager_t *sm, int verbose)
void fifo_segment_preallocate_fifo_pairs(fifo_segment_t *fs, u32 rx_fifo_size, u32 tx_fifo_size, u32 *n_fifo_pairs)
Pre-allocates fifo pairs in fifo segment.
@ FIFO_SEGMENT_F_MEM_LIMIT
static void clib_rwlock_writer_lock(clib_rwlock_t *p)
void segment_manager_segment_reader_unlock(segment_manager_t *sm)
static u8 vlib_thread_is_main_w_barrier(void)
u8 flags
private fifo segment flags
fifo_segment_t * segment_manager_get_segment(segment_manager_t *sm, u32 segment_index)
Reads a segment from the segment manager's pool without lock.
int segment_manager_add_segment(segment_manager_t *sm, uword segment_size, u8 notify_app)
static vlib_cli_command_t segment_manager_show_command
(constructor) VLIB_CLI_COMMAND (segment_manager_show_command)
static session_handle_t session_handle(session_t *s)
svm_msg_q_ring_cfg_t * ring_cfgs
array of ring cfgs
u64 segment_manager_segment_handle(segment_manager_t *sm, fifo_segment_t *segment)
static session_t * session_get_from_handle(session_handle_t handle)
void segment_manager_lock_and_del_segment(segment_manager_t *sm, u32 fs_index)
static int segment_manager_add_segment_inline(segment_manager_t *sm, uword segment_size, u8 notify_app, u8 flags)
Adds segment to segment manager's pool.
#define VLIB_CLI_COMMAND(x,...)
u32 segment_manager_evt_q_expected_size(u32 q_len)
u32 segment_manager_index(segment_manager_t *sm)
static session_t * session_get(u32 si, u32 thread_index)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
u32 default_fifo_size
default rx/tx fifo size
static void clib_rwlock_init(clib_rwlock_t *p)
u8 * format_session(u8 *s, va_list *args)
Format stream session as per the following format.
u8 n_slices
number of fifo segment slices
u32 default_segment_size
default fifo segment size
static void sm_free_w_index_helper(void *arg)
ssvm_private_t ssvm
ssvm segment data
svm_msg_q_t * segment_manager_alloc_queue(fifo_segment_t *segment, segment_manager_props_t *props)
Allocates shm queue in the first segment.
#define vec_free(V)
Free vector's memory (no header).
void fifo_segment_free_fifo(fifo_segment_t *fs, svm_fifo_t *f)
Free fifo allocated in fifo segment.
void segment_manager_init_free(segment_manager_t *sm)
Initiate segment manager cleanup.
u32 connects_seg_manager
Segment manager used for outgoing connects issued by the app.
segment_manager_t * segment_manager_get_if_valid(u32 index)
description fragment has unexpected format
u8 default_high_watermark
default high watermark %
int ssvm_server_init(ssvm_private_t *ssvm, ssvm_segment_type_t type)
#define SESSION_DBG(_fmt, _args...)
static session_t * session_get_if_valid(u64 si, u32 thread_index)
int app_worker_add_segment_notify(app_worker_t *app_wrk, u64 segment_handle)
Send an API message to the external app, to map new segment.
ssvm_segment_type_t ssvm_type(const ssvm_private_t *ssvm)
u8 low_watermark
memory pressure watermark low
app_worker_t * app_worker_get(u32 wrk_index)
void segment_manager_del_sessions_filter(segment_manager_t *sm, session_state_t *states)
Initiate disconnects for sessions in specified state 'owned' by a segment manager.
#define vec_foreach(var, vec)
Vector iterator.
static_always_inline uword clib_mem_get_page_size(void)
void segment_manager_dealloc_queue(segment_manager_t *sm, svm_queue_t *q)
Frees shm queue allocated in the first segment.
static uword pool_elts(void *v)
Number of active elements in a pool.
void vlib_rpc_call_main_thread(void *callback, u8 *args, u32 arg_size)
const u8 * application_name_from_index(u32 app_index)
Returns app name for app-index.
void segment_manager_main_init(void)
uword fifo_segment_available_bytes(fifo_segment_t *fs)
u8 segment_manager_has_fifos(segment_manager_t *sm)
int fifo_segment_init(fifo_segment_t *fs)
Initialize fifo segment shared header.
int consumer_pid
pid of msg consumer
void segment_manager_cleanup_detached_listener(segment_manager_t *sm)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
@ FIFO_SEGMENT_F_CUSTOM_USE
static vlib_main_t * vlib_get_main(void)
#define pool_get_zero(P, E)
Allocate an object E from a pool P and zero it.
void segment_manager_del_segment(segment_manager_t *sm, fifo_segment_t *fs)
Remove segment without lock.
#define pool_free(p)
Free a pool.
#define clib_warning(format, args...)
static void clib_rwlock_free(clib_rwlock_t *p)
u32 default_max_fifo_size
default max fifo size
int(* fifo_tuning_callback)(session_t *s, svm_fifo_t *f, session_ft_action_t act, u32 bytes)
Delegate fifo-tuning-logic to application.
void segment_manager_free_safe(segment_manager_t *sm)
session_cb_vft_t cb_fns
Callbacks: shoulder-taps for the server/client.
u8 * name
Name registered by builtin apps.
int segment_manager_add_segment2(segment_manager_t *sm, uword segment_size, u8 flags)
static segment_manager_main_t sm_main
u32 seg_name_counter
Counter for segment names.
u32 app_index
Index of owning app.
void segment_manager_set_watermarks(segment_manager_t *sm, u8 high_watermark, u8 low_watermark)
int fifo_segment_prealloc_fifo_hdrs(fifo_segment_t *fs, u32 slice_index, u32 batch_size)
Try to preallocate fifo headers.
fifo_segment_header_t * h
fifo segment data
u32 api_client_index
API index for the worker.
u8 fifo_segment_has_fifos(fifo_segment_t *fs)
#define segment_manager_foreach_segment_w_lock(VAR, SM, BODY)
svm_fifo_t * fifo_segment_get_slice_fifo_list(fifo_segment_t *fs, u32 slice_index)
volatile u8 session_state
State in session layer state machine.
void segment_manager_detach_fifo(segment_manager_t *sm, svm_fifo_t **f)
@ FIFO_SEGMENT_F_IS_PREALLOCATED
int segment_manager_try_alloc_fifos(fifo_segment_t *fifo_segment, u32 thread_index, u32 rx_fifo_size, u32 tx_fifo_size, svm_fifo_t **rx_fifo, svm_fifo_t **tx_fifo)
void segment_manager_attach_fifo(segment_manager_t *sm, svm_fifo_t **f, session_t *s)
format_function_t format_fifo_segment
u64 segment_manager_make_segment_handle(u32 segment_manager_index, u32 segment_index)
void app_worker_del_detached_sm(app_worker_t *app_wrk, u32 sm_index)
vl_api_wireguard_peer_flags_t flags