20 u32 data_size_in_bytes,
int chunk_size)
25 u32 rounded_data_size;
29 rounded_data_size = (1 << (
max_log2 (data_size_in_bytes)));
30 freelist_index =
max_log2 (rounded_data_size)
34 size = (
sizeof (*f) + rounded_data_size) * chunk_size;
47 for (i = 0; i < chunk_size; i++)
49 f->freelist_index = freelist_index;
52 fifo_space +=
sizeof (*f) + rounded_data_size;
67 u32 rx_fifo_size,
u32 tx_fifo_size,
70 u32 rx_rounded_data_size, tx_rounded_data_size, pair_size;
71 u32 rx_fifos_size, tx_fifos_size, pairs_to_allocate;
72 int rx_freelist_index, tx_freelist_index;
75 u8 *rx_fifo_space, *tx_fifo_space;
76 uword space_available;
82 if (rx_fifo_size == 0 || tx_fifo_size == 0 || *n_fifo_pairs == 0)
88 clib_warning (
"rx fifo_size out of range %d", rx_fifo_size);
95 clib_warning (
"tx fifo_size out of range %d", rx_fifo_size);
99 rx_rounded_data_size = (1 << (
max_log2 (rx_fifo_size)));
100 rx_freelist_index =
max_log2 (rx_fifo_size)
102 tx_rounded_data_size = (1 << (
max_log2 (tx_fifo_size)));
103 tx_freelist_index =
max_log2 (tx_fifo_size)
107 pair_size = 2 *
sizeof (*f) + rx_rounded_data_size + tx_rounded_data_size;
108 #if USE_DLMALLOC == 0 114 pairs_to_allocate =
clib_min (space_available / pair_size, *n_fifo_pairs);
115 rx_fifos_size = (
sizeof (*f) + rx_rounded_data_size) * pairs_to_allocate;
116 tx_fifos_size = (
sizeof (*f) + tx_rounded_data_size) * pairs_to_allocate;
119 clib_max (rx_freelist_index, tx_freelist_index),
134 if (rx_fifo_space == 0 || tx_fifo_space == 0)
139 clib_warning (
"rx fifo preallocation failure: size %d npairs %d",
140 rx_fifo_size, *n_fifo_pairs);
145 clib_warning (
"tx fifo preallocation failure: size %d nfifos %d",
146 tx_fifo_size, *n_fifo_pairs);
153 for (i = 0; i < pairs_to_allocate; i++)
155 f->freelist_index = rx_freelist_index;
158 rx_fifo_space +=
sizeof (*f) + rx_rounded_data_size;
163 for (i = 0; i < pairs_to_allocate; i++)
165 f->freelist_index = tx_freelist_index;
168 tx_fifo_space +=
sizeof (*f) + tx_rounded_data_size;
173 *n_fifo_pairs -= pairs_to_allocate;
250 rnd_size = (a->
segment_size + (pagesize - 1)) & ~pagesize;
252 #if USE_DLMALLOC == 0 313 _vec_len (s) =
vec_len (s) - 1;
338 u32 data_size_in_bytes,
354 clib_warning (
"fifo size out of range %d", data_size_in_bytes);
358 freelist_index =
max_log2 (data_size_in_bytes)
384 f->nitems = data_size_in_bytes;
388 f->freelist_index = freelist_index;
407 f->freelist_index = freelist_index;
418 fsh->
fifos->prev = f;
419 f->next = fsh->
fifos;
446 freelist_index = f->freelist_index;
457 f->prev->next = f->next;
459 fsh->
fifos = f->next;
461 f->next->prev = f->prev;
479 f->master_session_index = ~0;
480 f->master_thread_index = ~0;
489 u32 timeout_in_seconds)
522 u32 fifo_size_in_bytes)
528 u32 count = 0, rounded_data_size, freelist_index;
530 sh = fifo_segment->
ssvm.
sh;
534 if (fifo_size_in_bytes == ~0)
551 rounded_data_size = (1 << (
max_log2 (fifo_size_in_bytes)));
552 freelist_index =
max_log2 (rounded_data_size)
576 #if USE_DLMALLOC == 0 607 s =
format (s,
"%s",
"private-heap");
609 s =
format (s,
"%s",
"memfd");
611 s =
format (s,
"%s",
"shm");
613 s =
format (s,
"%s",
"unknown");
625 int verbose __attribute__ ((unused)) = va_arg (*args,
int);
632 #if USE_DLMALLOC == 0 635 s =
format (s,
"%U segment has %u active fifos\n",
651 s =
format (s,
"%U%-5u Kb: %u free",
void svm_fifo_segment_info(svm_fifo_segment_private_t *seg, char **address, size_t *size)
static void * clib_mem_alloc_aligned_at_offset(uword size, uword align, uword align_offset, int os_out_of_memory_on_failure)
void * mheap_alloc(void *memory, uword size)
svm_fifo_segment_freelist_t
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
static mheap_t * mheap_header(u8 *v)
clib_memset(h->entries, 0, sizeof(h->entries[0])*entries)
ssvm_shared_header_t * sh
#define MHEAP_FLAG_THREAD_SAFE
#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.
void ssvm_delete(ssvm_private_t *ssvm)
struct _svm_fifo svm_fifo_t
enum ssvm_segment_type_ ssvm_segment_type_t
static void * ssvm_push_heap(ssvm_shared_header_t *sh)
int attach_timeout
shm segments attach timeout (sec)
int ssvm_master_init(ssvm_private_t *ssvm, ssvm_segment_type_t type)
static void ssvm_pop_heap(void *oldheap)
#define FIFO_SEGMENT_MIN_FIFO_SIZE
ssvm_segment_type_t segment_type
u8 * format_svm_fifo_segment_type(u8 *s, va_list *args)
u8 * format_mheap(u8 *s, va_list *va)
u32 svm_fifo_segment_num_fifos(svm_fifo_segment_private_t *fifo_segment)
Get number of active fifos.
uword clib_mem_get_page_size(void)
#define pool_put(P, E)
Free an object E in pool P.
svm_fifo_segment_header_t * h
#define FIFO_SEGMENT_ALLOC_CHUNK_SIZE
int svm_fifo_segment_attach(svm_fifo_segment_main_t *sm, svm_fifo_segment_create_args_t *a)
Attach as slave to an svm fifo segment.
void svm_fifo_segment_delete(svm_fifo_segment_main_t *sm, svm_fifo_segment_private_t *s)
DLMALLOC_EXPORT mspace create_mspace(size_t capacity, int locked)
DLMALLOC_EXPORT void mspace_get_address_and_size(mspace msp, char **addrp, size_t *sizep)
int svm_fifo_segment_create_process_private(svm_fifo_segment_main_t *sm, svm_fifo_segment_create_args_t *a)
Create an svm fifo segment in process-private memory.
#define clib_warning(format, args...)
u32 * new_segment_indices
static void allocate_new_fifo_chunk(svm_fifo_segment_header_t *fsh, u32 data_size_in_bytes, int chunk_size)
int ssvm_slave_init(ssvm_private_t *ssvm, ssvm_segment_type_t type)
#define OOO_SEGMENT_INVALID_INDEX
#define FIFO_SEGMENT_MAX_FIFO_SIZE
int svm_fifo_segment_create(svm_fifo_segment_main_t *sm, svm_fifo_segment_create_args_t *a)
Create an svm fifo segment and initialize as master.
void * svm_fifo_segment_heap(svm_fifo_segment_private_t *seg)
u32 svm_fifo_segment_index(svm_fifo_segment_main_t *sm, svm_fifo_segment_private_t *s)
static void clib_mem_free(void *p)
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 heap_header_t * heap_header(void *v)
static void * clib_mem_alloc(uword size)
static uword pointer_to_uword(const void *p)
void svm_fifo_segment_free_fifo(svm_fifo_segment_private_t *s, svm_fifo_t *f, svm_fifo_segment_freelist_t list_index)
uword mheap_bytes(void *v)
DLMALLOC_EXPORT size_t mspace_usable_size(const void *mem)
svm_fifo_segment_private_t * segments
pool of segments
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static uword max_log2(uword x)
#define clib_unix_warning(format, args...)
int svm_fifo_segment_init(svm_fifo_segment_private_t *s)
Initialize svm fifo segment shared header.
static void * clib_mem_alloc_aligned(uword size, uword align)
u32 svm_fifo_segment_num_free_fifos(svm_fifo_segment_private_t *fifo_segment, u32 fifo_size_in_bytes)
#define SVM_FIFO_INVALID_SESSION_INDEX
static void ssvm_unlock_non_recursive(ssvm_shared_header_t *h)
void svm_fifo_segment_main_init(svm_fifo_segment_main_t *sm, u64 baseva, u32 timeout_in_seconds)
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header, unspecified alignment)
#define CLIB_CACHE_LINE_BYTES
u8 * format_svm_fifo_segment(u8 *s, va_list *args)
Segment format function.
svm_fifo_segment_private_t * svm_fifo_segment_segments_pool(svm_fifo_segment_main_t *sm)
Retrieve svm segments pool.
static void ssvm_lock_non_recursive(ssvm_shared_header_t *h, u32 tag)
ssvm_segment_type_t ssvm_type(const ssvm_private_t *ssvm)
svm_fifo_t * svm_fifo_create(u32 data_size_in_bytes)
create an svm fifo, in the current heap.