67 return (seg - sm->segments);
85 memset (fs, 0xfb,
sizeof (*fs));
137 ASSERT (sm->segments_rwlock->n_readers > 0);
157 u32 rnd_margin = 128 << 10, seg_index, page_size;
159 uword baseva = (
u64) ~ 0, alloc_size;
167 if (!props->add_segment && !segment_size)
170 return VNET_API_ERROR_INVALID_VALUE;
185 memset (seg, 0,
sizeof (*seg));
190 segment_size = segment_size ? segment_size : props->add_segment_size;
192 segment_size = (segment_size + page_size - 1) & ~(page_size - 1);
196 alloc_size = (
uword) segment_size + rnd_margin;
205 seg_name =
format (0,
"%s%c",
"process-private-segment", 0);
213 clib_warning (
"svm_master_init ('%v', %u) failed", seg_name,
227 seg_index = seg - sm->segments;
241 memset (sm, 0,
sizeof (*sm));
252 u32 prealloc_fifo_pairs)
254 u32 rx_fifo_size, tx_fifo_size, pair_size;
255 u32 rx_rounded_data_size, tx_rounded_data_size;
256 u64 approx_total_size, max_seg_size = ((
u64) 1 << 32) - (128 << 10);
259 u32 approx_segment_count;
265 if (prealloc_fifo_pairs)
268 rx_rounded_data_size = (1 << (
max_log2 (props->rx_fifo_size)));
269 tx_rounded_data_size = (1 << (
max_log2 (props->tx_fifo_size)));
271 rx_fifo_size =
sizeof (
svm_fifo_t) + rx_rounded_data_size;
272 tx_fifo_size =
sizeof (
svm_fifo_t) + tx_rounded_data_size;
273 pair_size = rx_fifo_size + tx_fifo_size;
275 approx_total_size = (
u64) prealloc_fifo_pairs *pair_size;
276 if (first_seg_size > approx_total_size)
277 max_seg_size = first_seg_size;
278 approx_segment_count = (approx_total_size + (max_seg_size - 1))
282 for (i = 0; i < approx_segment_count + 1; i++)
298 &prealloc_fifo_pairs);
300 if (prealloc_fifo_pairs == 0)
373 fifo->ct_session_index);
378 fifo->master_thread_index);
414 segment_manager_del_segment (sm, fifo_segment);
422 memset (sm, 0xfe,
sizeof (*sm));
441 u32 rx_fifo_size,
u32 tx_fifo_size,
481 u32 * fifo_segment_index)
484 int alloc_fail = 1, rv = 0, new_fs_index;
486 u8 added_a_segment = 0;
514 ASSERT (rx_fifo && tx_fifo);
516 (*tx_fifo)->segment_manager = sm_index;
517 (*rx_fifo)->segment_manager = sm_index;
522 &fifo_segment->
ssvm);
531 if (props->add_segment)
535 clib_warning (
"Added a segment, still can't allocate a fifo");
537 return SESSION_ERROR_NEW_SEG_NO_SPACE;
542 return SESSION_ERROR_SEG_CREATE;
554 clib_warning (
"Can't add new seg and no space to allocate fifos!");
555 return SESSION_ERROR_NO_SPACE;
588 if (segment_index != 0 || !sm->first_is_protected)
605 u32 fifo_evt_size, notif_q_size, q_hdrs;
606 u32 msg_q_sz, fifo_evt_ring_sz, session_ntf_ring_sz;
608 fifo_evt_size = 1 <<
max_log2 (
sizeof (session_event_t));
609 notif_q_size =
clib_max (16, q_len >> 4);
612 fifo_evt_ring_sz = q_len * fifo_evt_size;
613 session_ntf_ring_sz = notif_q_size * 256;
616 return (msg_q_sz + fifo_evt_ring_sz + session_ntf_ring_sz + q_hdrs);
628 u32 fifo_evt_size, session_evt_size = 256, notif_q_size;
633 fifo_evt_size =
sizeof (session_event_t);
634 notif_q_size =
clib_max (16, props->evt_q_size >> 4);
637 {props->evt_q_size, fifo_evt_size, 0},
638 {notif_q_size, session_evt_size, 0}
650 if (props->use_mq_eventfd)
701 u8 show_segments = 0, verbose = 0;
711 else if (
unformat (input,
"verbose"))
726 vlib_cli_output (vm,
"%-10d%=15d%=12d", segment_manager_index (sm),
727 sm->app_wrk_index, pool_elts (sm->segments));
735 "HeapSize (M)",
"ActiveFifos",
"FreeFifos",
"Address");
739 segment_manager_foreach_segment_w_lock (seg, sm, ({
740 svm_fifo_segment_info (seg, &address, &size);
741 active_fifos = svm_fifo_segment_num_fifos (seg);
742 free_fifos = svm_fifo_segment_num_free_fifos (seg, ~0 );
743 vlib_cli_output (vm,
"%-15v%15U%15llu%15u%15u%15llx",
744 ssvm_name (&seg->ssvm), format_svm_fifo_segment_type,
745 seg, size >> 20ULL, active_fifos, free_fifos,
748 vlib_cli_output (vm,
"%U", format_svm_fifo_segment, seg, verbose);
760 .path =
"show segment-manager",
761 .short_help =
"show segment-manager [segments][verbose]",
segment_manager_main_t segment_manager_main
static void clib_rwlock_reader_lock(clib_rwlock_t *p)
app_worker_t * app_worker_get(u32 wrk_index)
int application_local_session_disconnect_w_index(u32 app_wrk_index, u32 ls_index)
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
segment_manager_properties_t * application_get_segment_manager_properties(u32 app_index)
static u32 default_segment_size
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 u32 default_app_evt_queue_size
clib_valloc_main_t va_allocator
Virtual address allocator.
#define FIFO_SEGMENT_F_IS_PREALLOCATED
ssvm_shared_header_t * sh
void segment_manager_dealloc_fifos(u32 segment_index, svm_fifo_t *rx_fifo, svm_fifo_t *tx_fifo)
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)
struct _svm_fifo svm_fifo_t
memset(h->entries, 0, sizeof(h->entries[0])*entries)
#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)
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...)
struct _stream_session_t stream_session_t
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)
void segment_manager_dealloc_queue(segment_manager_t *sm, svm_queue_t *q)
Frees shm queue allocated in the first segment.
#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.
static stream_session_t * session_get(u32 si, u32 thread_index)
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)
static u32 segment_manager_segment_index(segment_manager_t *sm, svm_fifo_segment_private_t *seg)
void stream_session_disconnect(stream_session_t *s)
Initialize session disconnect.
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)
void segment_manager_segment_writer_unlock(segment_manager_t *sm)
void segment_manager_del(segment_manager_t *sm)
Removes segment manager.
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 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.
int app_worker_add_segment_notify(u32 app_wrk_index, ssvm_private_t *fs)
Send an API message to the external app, to map new segment.
static u32 vlib_num_workers()
static clib_error_t * segment_manager_show_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define SVM_FIFO_INVALID_SESSION_INDEX
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.
uword clib_mem_get_page_size(void)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
svm_fifo_t * svm_fifo_segment_alloc_fifo(svm_fifo_segment_private_t *s, u32 data_size_in_bytes, svm_fifo_segment_freelist_t list_index)
Allocate fifo in svm segment.
ssvm_segment_type_t ssvm_type(const ssvm_private_t *ssvm)
static uword pool_elts(void *v)
Number of active elements in a pool.