57 memset (ca, 0,
sizeof (*ca));
59 if (!sm->properties->use_private_segment)
70 clib_warning (
"svm_fifo_segment_create ('%s', %d) failed",
72 return VNET_API_ERROR_SVM_SEGMENT_CREATE_FAIL;
77 u32 rx_fifo_size, tx_fifo_size, rx_rounded_data_size,
79 u32 approx_segment_count;
80 u64 approx_total_size;
98 rx_fifo_size =
sizeof (
svm_fifo_t) + rx_rounded_data_size;
99 tx_fifo_size =
sizeof (
svm_fifo_t) + tx_rounded_data_size;
102 * (rx_fifo_size + tx_fifo_size);
103 approx_segment_count =
116 (
"Honoring segment count %u, but calculated count was %u",
121 clib_warning (
"Failed to create process private segment");
135 u32 add_segment_size;
138 memset (ca, 0,
sizeof (*ca));
140 add_segment_size = sm->properties->add_segment_size ?
165 memset (sm, 0,
sizeof (*sm));
181 sm->properties = properties;
202 for (i = 0; i <
vec_len (sm->segment_indices); i++)
207 clib_warning (
"segment %d has no fifos!", sm->segment_indices[i]);
224 u32 svm_segment_index;
226 svm_segment_index = sm->segment_indices[segment_index];
236 vec_del1 (sm->segment_indices, segment_index);
253 for (j = 0; j <
vec_len (sm->segment_indices); j++)
265 u32 session_index, thread_index;
268 session_index = fifo->master_session_index;
269 thread_index = fifo->master_thread_index;
309 for (i =
vec_len (sm->segment_indices) - 1; i >= 0; i--)
321 memset (sm, 0xfe,
sizeof (*sm));
341 u32 * fifo_segment_index)
344 u32 fifo_size, sm_index;
345 u8 added_a_segment = 0;
356 for (i = 0; i <
vec_len (sm->segment_indices); i++)
358 *fifo_segment_index = sm->segment_indices[
i];
361 fifo_size = sm->properties->rx_fifo_size;
367 fifo_size = sm->properties->tx_fifo_size;
373 if (*server_rx_fifo == 0)
376 if (*server_tx_fifo != 0)
384 if (*server_tx_fifo == 0)
386 if (*server_rx_fifo != 0)
398 if (*server_rx_fifo == 0)
400 if (sm->properties->add_segment && !sm->properties->use_private_segment)
404 clib_warning (
"added a segment, still can't allocate a fifo");
406 return SESSION_ERROR_NEW_SEG_NO_SPACE;
412 return VNET_API_ERROR_URI_FIFO_CREATE_FAILED;
422 return SESSION_ERROR_NO_SPACE;
428 (*server_tx_fifo)->segment_manager = sm_index;
429 (*server_rx_fifo)->segment_manager = sm_index;
435 *fifo_segment_index);
446 u32 i, segment_index = ~0;
470 is_first = sm->segment_indices[0] == svm_segment_index;
473 if (!is_first || !sm->first_is_protected)
476 for (i = 0; i <
vec_len (sm->segment_indices); i++)
477 if (sm->segment_indices[i] == svm_segment_index)
504 ASSERT (sm->segment_indices != 0);
511 sizeof (session_fifo_event_t),
529 ASSERT (sm->segment_indices != 0);
545 u8 show_segments = 0, verbose = 0, *name;
557 else if (
unformat (input,
"verbose"))
573 sm->app_index,
vec_len (sm->segment_indices));
584 "HeapSize (M)",
"ActiveFifos",
"FreeFifos",
"Address");
590 address = pointer_to_uword (seg->ssvm.sh->heap);
591 if (seg->h->flags & FIFO_SEGMENT_F_IS_MAIN_HEAP)
592 name = format (0,
"main heap");
594 name = format (0,
"private heap");
595 heap_header = mheap_header (seg->ssvm.sh->heap);
596 size = heap_header->max_size;
600 address = seg->ssvm.sh->ssvm_va;
601 size = seg->ssvm.ssvm_size;
602 name = seg->ssvm.sh->name;
607 name, size >> 20ULL, active_fifos, free_fifos,
624 .path =
"show segment-manager",
625 .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)
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)
u32 svm_fifo_segment_num_fifos(svm_fifo_segment_private_t *fifo_segment)
Get number of active fifos.
#define pool_put(P, E)
Free an object E in pool P.
u8 segment_manager_has_fifos(segment_manager_t *sm)
#define vec_del1(v, i)
Delete the element at index I.
svm_fifo_segment_header_t * h
#define FIFO_SEGMENT_F_IS_PRIVATE
#define SEGMENT_MANAGER_INVALID_APP_INDEX
static u8 svm_fifo_segment_has_fifos(svm_fifo_segment_private_t *fifo_segment)
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
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
void segment_manager_del(segment_manager_t *sm)
Removes segment manager.
static u64 stream_session_handle(stream_session_t *s)
int segment_manager_init(segment_manager_t *sm, segment_manager_properties_t *properties, u32 first_seg_size)
Initializes segment manager based on options provided.
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.
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
static stream_session_t * stream_session_get(u32 si, u32 thread_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.