67 return (seg - sm->segments);
143 *sm_index = segment_handle >> 32;
144 *segment_index = segment_handle & 0xFFFFFFFF;
150 u32 sm_index, segment_index;
178 ASSERT (sm->segments_rwlock->n_readers > 0);
198 u32 rnd_margin = 128 << 10, seg_index = ~0, page_size;
208 if (!props->add_segment && !segment_size)
211 return VNET_API_ERROR_INVALID_VALUE;
225 segment_size = segment_size ? segment_size : props->add_segment_size;
228 segment_size =
clib_max (segment_size + page_size - 1, segment_size);
229 segment_size = segment_size & ~(page_size - 1);
233 alloc_size = (
uword) segment_size + rnd_margin;
243 seg_name =
format (0,
"%s%c",
"process-private-segment", 0);
251 clib_warning (
"svm_master_init ('%v', %u) failed", seg_name,
265 seg_index = seg - sm->segments;
292 u32 prealloc_fifo_pairs)
294 u32 rx_fifo_size, tx_fifo_size, pair_size;
295 u32 rx_rounded_data_size, tx_rounded_data_size;
296 u64 approx_total_size, max_seg_size = ((
u64) 1 << 32) - (128 << 10);
299 u32 approx_segment_count;
305 if (prealloc_fifo_pairs)
308 rx_rounded_data_size = (1 << (
max_log2 (props->rx_fifo_size)));
309 tx_rounded_data_size = (1 << (
max_log2 (props->tx_fifo_size)));
311 rx_fifo_size =
sizeof (
svm_fifo_t) + rx_rounded_data_size;
312 tx_fifo_size =
sizeof (
svm_fifo_t) + tx_rounded_data_size;
313 pair_size = rx_fifo_size + tx_fifo_size;
315 approx_total_size = (
u64) prealloc_fifo_pairs *pair_size;
316 if (first_seg_size > approx_total_size)
317 max_seg_size = first_seg_size;
318 approx_segment_count = (approx_total_size + (max_seg_size - 1))
322 for (i = 0; i < approx_segment_count + 1; i++)
338 &prealloc_fifo_pairs);
340 if (prealloc_fifo_pairs == 0)
411 fifo->master_thread_index);
451 segment_manager_del_segment (sm, fifo_segment);
478 u32 rx_fifo_size,
u32 tx_fifo_size,
518 u32 * fifo_segment_index)
521 int alloc_fail = 1, rv = 0, new_fs_index;
523 u8 added_a_segment = 0;
552 ASSERT (rx_fifo && tx_fifo);
555 (*tx_fifo)->segment_manager = sm_index;
556 (*rx_fifo)->segment_manager = sm_index;
557 (*tx_fifo)->segment_index = *fifo_segment_index;
558 (*rx_fifo)->segment_index = *fifo_segment_index;
575 if (props->add_segment)
579 clib_warning (
"Added a segment, still can't allocate a fifo");
581 return SESSION_ERROR_NEW_SEG_NO_SPACE;
586 return SESSION_ERROR_SEG_CREATE;
598 clib_warning (
"Can't add new seg and no space to allocate fifos!");
599 return SESSION_ERROR_NO_SPACE;
610 if (!rx_fifo || !tx_fifo)
618 segment_index = rx_fifo->segment_index;
636 if (segment_index != 0 || !sm->first_is_protected)
653 u32 fifo_evt_size, notif_q_size, q_hdrs;
654 u32 msg_q_sz, fifo_evt_ring_sz, session_ntf_ring_sz;
656 fifo_evt_size = 1 <<
max_log2 (
sizeof (session_event_t));
657 notif_q_size =
clib_max (16, q_len >> 4);
660 fifo_evt_ring_sz = q_len * fifo_evt_size;
661 session_ntf_ring_sz = notif_q_size * 256;
664 return (msg_q_sz + fifo_evt_ring_sz + session_ntf_ring_sz + q_hdrs);
676 u32 fifo_evt_size, session_evt_size = 256, notif_q_size;
681 fifo_evt_size =
sizeof (session_event_t);
682 notif_q_size =
clib_max (16, props->evt_q_size >> 4);
685 {props->evt_q_size, fifo_evt_size, 0},
686 {notif_q_size, session_evt_size, 0}
698 if (props->use_mq_eventfd)
749 u8 show_segments = 0, verbose = 0;
759 else if (
unformat (input,
"verbose"))
774 vlib_cli_output (vm,
"%-10d%=15d%=12d", segment_manager_index (sm),
775 sm->app_wrk_index, pool_elts (sm->segments));
783 "HeapSize (M)",
"ActiveFifos",
"FreeFifos",
"Address");
787 segment_manager_foreach_segment_w_lock (seg, sm, ({
788 svm_fifo_segment_info (seg, &address, &size);
789 active_fifos = svm_fifo_segment_num_fifos (seg);
790 free_fifos = svm_fifo_segment_num_free_fifos (seg, ~0 );
791 vlib_cli_output (vm,
"%-15v%15U%15llu%15u%15u%15llx",
792 ssvm_name (&seg->ssvm), format_svm_fifo_segment_type,
793 seg, size >> 20ULL, active_fifos, free_fifos,
796 vlib_cli_output (vm,
"%U", format_svm_fifo_segment, seg, verbose);
808 .path =
"show segment-manager",
809 .short_help =
"show segment-manager [segments][verbose]",
segment_manager_main_t segment_manager_main
static void clib_rwlock_reader_lock(clib_rwlock_t *p)
void segment_manager_segment_reader_unlock(segment_manager_t *sm)
static segment_manager_t * segment_manager_get_if_valid(u32 index)
static void clib_rwlock_writer_lock(clib_rwlock_t *p)
struct _segment_manager_properties segment_manager_properties_t
#define pool_get_zero(P, E)
Allocate an object E from a pool P and zero it.
segment_manager_properties_t * application_get_segment_manager_properties(u32 app_index)
static u32 default_segment_size
svm_fifo_segment_private_t * segment_manager_get_segment_w_handle(u64 segment_handle)
svm_msg_q_t * segment_manager_alloc_queue(svm_fifo_segment_private_t *segment, segment_manager_properties_t *props)
Allocates shm queue in the first segment.
static void clib_rwlock_free(clib_rwlock_t *p)
static session_t * session_get_if_valid(u64 si, u32 thread_index)
static u32 default_app_evt_queue_size
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
clib_valloc_main_t va_allocator
Virtual address allocator.
#define FIFO_SEGMENT_F_IS_PREALLOCATED
clib_memset(h->entries, 0, sizeof(h->entries[0])*entries)
ssvm_shared_header_t * sh
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.
segment_manager_properties_t * segment_manager_properties_init(segment_manager_properties_t *props)
#define segment_manager_foreach_segment_w_lock(VAR, SM, BODY)
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
void svm_fifo_segment_preallocate_fifo_pairs(svm_fifo_segment_private_t *s, u32 rx_fifo_size, u32 tx_fifo_size, u32 *n_fifo_pairs)
Pre-allocates fifo pairs in fifo segment.
segment_manager_t * segment_managers
Pool of segment managers.
u32 segment_manager_evt_q_expected_size(u32 q_len)
int segment_manager_init(segment_manager_t *sm, u32 first_seg_size, u32 prealloc_fifo_pairs)
Initializes segment manager based on options provided.
void ssvm_delete(ssvm_private_t *ssvm)
static session_handle_t session_handle(session_t *s)
struct _svm_fifo svm_fifo_t
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
svm_msg_q_t * svm_msg_q_alloc(svm_msg_q_cfg_t *cfg)
Allocate message queue.
static u8 segment_manager_app_detached(segment_manager_t *sm)
void segment_manager_dealloc_fifos(svm_fifo_t *rx_fifo, svm_fifo_t *tx_fifo)
svm_fifo_segment_private_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.
static void * ssvm_push_heap(ssvm_shared_header_t *sh)
#define clib_error_return(e, args...)
static void segment_manager_lock_and_del_segment(segment_manager_t *sm, u32 fs_index)
Removes segment after acquiring writer lock.
int ssvm_master_init(ssvm_private_t *ssvm, ssvm_segment_type_t type)
static void ssvm_pop_heap(void *oldheap)
segment_manager_t * segment_manager_new()
static heap_elt_t * first(heap_header_t *h)
#define svm_fifo_segment_flags(_seg)
int segment_manager_alloc_session_fifos(segment_manager_t *sm, svm_fifo_t **rx_fifo, svm_fifo_t **tx_fifo, u32 *fifo_segment_index)
static svm_fifo_t * svm_fifo_segment_get_fifo_list(svm_fifo_segment_private_t *fifo_segment)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
static void clib_rwlock_init(clib_rwlock_t *p)
static void clib_rwlock_reader_unlock(clib_rwlock_t *p)
void segment_manager_app_detach(segment_manager_t *sm)
static session_t * session_get_from_handle(session_handle_t handle)
void segment_manager_dealloc_queue(segment_manager_t *sm, svm_queue_t *q)
Frees shm queue allocated in the first segment.
uword clib_mem_get_page_size(void)
#define pool_put(P, E)
Free an object E in pool P.
svm_fifo_segment_private_t * segment_manager_get_segment(segment_manager_t *sm, u32 segment_index)
Reads a segment from the segment manager's pool without lock.
u8 segment_manager_has_fifos(segment_manager_t *sm)
segment_manager_properties_t * segment_manager_properties_get(segment_manager_t *sm)
uword size
size in bytes of this chunk
void segment_manager_del_segment(segment_manager_t *sm, svm_fifo_segment_private_t *fs)
Remove segment without lock.
int segment_manager_add_segment(segment_manager_t *sm, u32 segment_size)
Adds segment to segment manager's pool.
uword baseva
base VA for this chunk
#define SEGMENT_MANAGER_INVALID_APP_INDEX
static u8 svm_fifo_segment_has_fifos(svm_fifo_segment_private_t *fifo_segment)
static void clib_rwlock_writer_unlock(clib_rwlock_t *p)
u32 n_rings
number of msg rings
#define clib_warning(format, args...)
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
int segment_manager_try_alloc_fifos(svm_fifo_segment_private_t *fifo_segment, u32 rx_fifo_size, u32 tx_fifo_size, svm_fifo_t **rx_fifo, svm_fifo_t **tx_fifo)
static u32 segment_manager_index(segment_manager_t *sm)
void svm_queue_free(svm_queue_t *q)
#define VLIB_CLI_COMMAND(x,...)
uword clib_valloc_alloc(clib_valloc_main_t *vam, uword size, int os_out_of_memory_on_failure)
Allocate virtual space.
void segment_manager_init_del(segment_manager_t *sm)
void segment_manager_main_init(segment_manager_main_init_args_t *a)
svm_fifo_t * svm_fifo_segment_alloc_fifo(svm_fifo_segment_private_t *fs, u32 data_size_in_bytes, svm_fifo_segment_freelist_t list_index)
Allocate fifo in svm segment.
static u32 segment_manager_segment_index(segment_manager_t *sm, svm_fifo_segment_private_t *seg)
svm_msg_q_ring_cfg_t * ring_cfgs
array of ring cfgs
void svm_fifo_segment_free_fifo(svm_fifo_segment_private_t *s, svm_fifo_t *f, svm_fifo_segment_freelist_t list_index)
int app_worker_del_segment_notify(app_worker_t *app_wrk, u64 segment_handle)
void segment_manager_segment_writer_unlock(segment_manager_t *sm)
void segment_manager_del(segment_manager_t *sm)
Removes segment manager.
app_worker_t * app_worker_get(u32 wrk_index)
u64 segment_manager_segment_handle(segment_manager_t *sm, svm_fifo_segment_private_t *segment)
u32 q_nitems
msg queue size (not rings)
static uword max_log2(uword x)
static u32 segment_name_counter
Counter used to build segment names.
void session_close(session_t *s)
Initialize session closing procedure.
void segment_manager_del_sessions(segment_manager_t *sm)
Initiate disconnects for all sessions 'owned' by a segment manager.
uword clib_valloc_free(clib_valloc_main_t *vam, uword baseva)
Free virtual space.
struct _segment_manager segment_manager_t
struct _svm_queue svm_queue_t
int svm_fifo_segment_init(svm_fifo_segment_private_t *s)
Initialize svm fifo segment shared header.
u32 app_index
Index of owning app.
void clib_valloc_init(clib_valloc_main_t *vam, clib_valloc_chunk_t *template, int need_lock)
Initialize a virtual memory allocation arena.
static u32 vlib_num_workers()
#define vec_foreach(var, vec)
Vector iterator.
static clib_error_t * segment_manager_show_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
int consumer_pid
pid of msg consumer
static u32 default_fifo_size
Default fifo and segment size.
int svm_msg_q_alloc_producer_eventfd(svm_msg_q_t *mq)
Allocate event fd for queue consumer.
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
static segment_manager_t * segment_manager_get(u32 index)
void segment_manager_parse_segment_handle(u64 segment_handle, u32 *sm_index, u32 *segment_index)
ssvm_segment_type_t ssvm_type(const ssvm_private_t *ssvm)
static uword pool_elts(void *v)
Number of active elements in a pool.