51 memset (props, 0,
sizeof (*props));
59 memset (props, 0xFB,
sizeof (*props));
93 memset (ca, 0,
sizeof (*ca));
95 if (!props->use_private_segment)
106 clib_warning (
"svm_fifo_segment_create ('%s', %d) failed",
108 return VNET_API_ERROR_SVM_SEGMENT_CREATE_FAIL;
113 u32 rx_fifo_size, tx_fifo_size, rx_rounded_data_size,
114 tx_rounded_data_size;
115 u32 approx_segment_count;
116 u64 approx_total_size;
129 rx_fifo_size =
sizeof (
svm_fifo_t) + rx_rounded_data_size;
130 tx_fifo_size =
sizeof (
svm_fifo_t) + tx_rounded_data_size;
133 * (rx_fifo_size + tx_fifo_size);
134 approx_segment_count = (approx_total_size + (ca->
segment_size - 1))
145 clib_warning (
"Honoring segment count %u, calculated count was %u",
150 clib_warning (
"Failed to create process private segment");
164 u32 add_segment_size;
168 memset (ca, 0,
sizeof (*ca));
171 add_segment_size = props->add_segment_size ?
196 memset (sm, 0,
sizeof (*sm));
211 sm->properties_index = props_index;
230 for (i = 0; i <
vec_len (sm->segment_indices); i++)
235 clib_warning (
"segment %d has no fifos!", sm->segment_indices[i]);
258 u32 svm_segment_index;
260 svm_segment_index = sm->segment_indices[segment_index];
270 vec_del1 (sm->segment_indices, segment_index);
287 for (j = 0; j <
vec_len (sm->segment_indices); j++)
299 u32 session_index, thread_index;
302 session_index = fifo->master_session_index;
303 thread_index = fifo->master_thread_index;
304 session =
session_get (session_index, thread_index);
343 for (i =
vec_len (sm->segment_indices) - 1; i >= 0; i--)
355 memset (sm, 0xfe,
sizeof (*sm));
376 u32 * fifo_segment_index)
380 u32 fifo_size, sm_index;
381 u8 added_a_segment = 0;
393 for (i = 0; i <
vec_len (sm->segment_indices); i++)
395 *fifo_segment_index = sm->segment_indices[
i];
398 fifo_size = props->rx_fifo_size;
404 fifo_size = props->tx_fifo_size;
410 if (*server_rx_fifo == 0)
413 if (*server_tx_fifo != 0)
421 if (*server_tx_fifo == 0)
423 if (*server_rx_fifo != 0)
435 if (*server_rx_fifo == 0)
437 if (props->add_segment && !props->use_private_segment)
441 clib_warning (
"added a segment, still can't allocate a fifo");
443 return SESSION_ERROR_NEW_SEG_NO_SPACE;
449 return VNET_API_ERROR_URI_FIFO_CREATE_FAILED;
459 return SESSION_ERROR_NO_SPACE;
465 (*server_tx_fifo)->segment_manager = sm_index;
466 (*server_rx_fifo)->segment_manager = sm_index;
472 *fifo_segment_index);
483 u32 i, segment_index = ~0;
507 is_first = sm->segment_indices[0] == svm_segment_index;
510 if (!is_first || !sm->first_is_protected)
513 for (i = 0; i <
vec_len (sm->segment_indices); i++)
514 if (sm->segment_indices[i] == svm_segment_index)
541 ASSERT (sm->segment_indices != 0);
548 sizeof (session_fifo_event_t),
566 ASSERT (sm->segment_indices != 0);
582 u8 show_segments = 0, verbose = 0, *name;
594 else if (
unformat (input,
"verbose"))
610 sm->app_index,
vec_len (sm->segment_indices));
621 "HeapSize (M)",
"ActiveFifos",
"FreeFifos",
"Address");
627 address = pointer_to_uword (seg->ssvm.sh->heap);
628 if (seg->h->flags & FIFO_SEGMENT_F_IS_MAIN_HEAP)
629 name = format (0,
"main heap");
631 name = format (0,
"private heap");
632 heap_header = mheap_header (seg->ssvm.sh->heap);
633 size = heap_header->max_size;
637 address = seg->ssvm.sh->ssvm_va;
638 size = seg->ssvm.ssvm_size;
639 name = seg->ssvm.sh->name;
644 name, size >> 20ULL, active_fifos, free_fifos,
661 .path =
"show segment-manager",
662 .short_help =
"show segment-manager [segments][verbose]",
sll srl srl sll sra u16x4 i
int application_add_segment_notify(u32 app_index, u32 fifo_segment_index)
static_always_inline void clib_spinlock_unlock(clib_spinlock_t *p)
static_always_inline void clib_spinlock_lock(clib_spinlock_t *p)
int segment_manager_alloc_session_fifos(segment_manager_t *sm, svm_fifo_t **server_rx_fifo, svm_fifo_t **server_tx_fifo, u32 *fifo_segment_index)
u32 segment_manager_properties_index(segment_manager_properties_t *p)
static segment_manager_t * segment_manager_get_if_valid(u32 index)
struct _segment_manager_properties segment_manager_properties_t
u32 private_segment_count
void unix_shared_memory_queue_free(unix_shared_memory_queue_t *q)
int session_manager_add_first_segment(segment_manager_t *sm, u32 segment_size)
segment_manager_t * segment_managers
Pool of segment managers.
#define FIFO_SEGMENT_F_IS_PREALLOCATED
static void segment_manager_del_segment(segment_manager_t *sm, u32 segment_index)
ssvm_shared_header_t * sh
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
static void clib_spinlock_free(clib_spinlock_t *p)
struct _svm_fifo svm_fifo_t
static int session_manager_add_segment_i(segment_manager_t *sm, u32 segment_size, u8 *segment_name)
void segment_manager_get_segment_info(u32 index, u8 **name, u32 *size)
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
static u8 segment_manager_app_detached(segment_manager_t *sm)
static void * ssvm_push_heap(ssvm_shared_header_t *sh)
#define clib_error_return(e, args...)
unix_shared_memory_queue_t * segment_manager_alloc_queue(segment_manager_t *sm, u32 queue_size)
Allocates shm queue in the first segment.
format_function_t format_svm_fifo_segment
struct _stream_session_t stream_session_t
u32 * private_segment_indices
Process private segment index.
static void ssvm_pop_heap(void *oldheap)
void session_send_session_evt_to_thread(u64 session_handle, fifo_event_type_t evt_type, u32 thread_index)
segment_manager_t * segment_manager_new()
static void clib_spinlock_init(clib_spinlock_t *p)
int svm_fifo_segment_create_process_private(svm_fifo_segment_create_args_t *a)
Create an svm fifo segment in process-private memory.
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.
u32 svm_fifo_segment_num_fifos(svm_fifo_segment_private_t *fifo_segment)
Get number of active fifos.
void segment_manager_app_detach(segment_manager_t *sm)
#define pool_put(P, E)
Free an object E in pool P.
u8 segment_manager_has_fifos(segment_manager_t *sm)
void segment_manager_properties_free(segment_manager_properties_t *props)
#define vec_del1(v, i)
Delete the element at index I.
svm_fifo_segment_header_t * h
#define FIFO_SEGMENT_F_IS_PRIVATE
static stream_session_t * session_get(u32 si, u32 thread_index)
#define SEGMENT_MANAGER_INVALID_APP_INDEX
static u8 svm_fifo_segment_has_fifos(svm_fifo_segment_private_t *fifo_segment)
segment_manager_properties_t * segment_manager_properties_alloc(void)
void segment_manager_dealloc_queue(segment_manager_t *sm, unix_shared_memory_queue_t *q)
Frees shm queue allocated in the first segment.
#define vec_free(V)
Free vector's memory (no header).
#define clib_warning(format, args...)
u32 * new_segment_indices
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
static svm_fifo_segment_private_t * svm_fifo_segment_get_segment(u32 segment_index)
static u32 segment_manager_index(segment_manager_t *sm)
#define VLIB_CLI_COMMAND(x,...)
void segment_manager_init_del(segment_manager_t *sm)
unix_shared_memory_queue_t * unix_shared_memory_queue_init(int nels, int elsize, int consumer_pid, int signal_when_queue_non_empty)
#define vec_append(v1, v2)
Append v2 after v1.
static heap_header_t * heap_header(void *v)
void svm_fifo_segment_free_fifo(svm_fifo_segment_private_t *s, svm_fifo_t *f, svm_fifo_segment_freelist_t list_index)
int svm_fifo_segment_create(svm_fifo_segment_create_args_t *a)
(master) create an svm fifo segment
static segment_manager_properties_t * segment_manager_properties_pool
void segment_manager_del(segment_manager_t *sm)
Removes segment manager.
static u64 session_handle(stream_session_t *s)
svm_fifo_segment_private_t * svm_fifo_segment_segments_pool(void)
Retrieve svm segments pool.
void segment_manager_dealloc_fifos(u32 svm_segment_index, svm_fifo_t *rx_fifo, svm_fifo_t *tx_fifo)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static uword max_log2(uword x)
u32 segment_name_counter
Counter used to build segment names.
int segment_manager_init(segment_manager_t *sm, u32 props_index, u32 first_seg_size)
Initializes segment manager based on options provided.
void segment_manager_del_sessions(segment_manager_t *sm)
Initiate disconnects for all sessions 'owned' by a segment manager.
struct _segment_manager segment_manager_t
u32 preallocated_fifo_pairs
u32 svm_fifo_segment_num_free_fifos(svm_fifo_segment_private_t *fifo_segment, u32 fifo_size_in_bytes)
static clib_error_t * segment_manager_show_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
int session_manager_add_segment(segment_manager_t *sm)
u32 default_fifo_size
Default fifo and segment size.
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
void svm_fifo_segment_delete(svm_fifo_segment_private_t *s)
struct _unix_shared_memory_queue unix_shared_memory_queue_t
segment_manager_properties_t * segment_manager_properties_get(u32 smp_index)
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)
static uword pool_elts(void *v)
Number of active elements in a pool.