22 u32 data_size_in_bytes,
int chunk_size)
27 u32 rounded_data_size;
31 rounded_data_size = (1 << (
max_log2 (data_size_in_bytes)));
32 freelist_index =
max_log2 (rounded_data_size)
36 size = (
sizeof (*f) + rounded_data_size) * chunk_size;
49 for (i = 0; i < chunk_size; i++)
51 f->freelist_index = freelist_index;
54 fifo_space +=
sizeof (*f) + rounded_data_size;
69 u32 rx_fifo_size,
u32 tx_fifo_size,
72 u32 rx_rounded_data_size, tx_rounded_data_size, pair_size;
73 u32 rx_fifos_size, tx_fifos_size, pairs_to_allocate;
74 int rx_freelist_index, tx_freelist_index;
77 u8 *rx_fifo_space, *tx_fifo_space;
78 uword space_available;
84 if (rx_fifo_size == 0 || tx_fifo_size == 0 || *n_fifo_pairs == 0)
90 clib_warning (
"rx fifo_size out of range %d", rx_fifo_size);
97 clib_warning (
"tx fifo_size out of range %d", rx_fifo_size);
101 rx_rounded_data_size = (1 << (
max_log2 (rx_fifo_size)));
102 rx_freelist_index =
max_log2 (rx_fifo_size)
104 tx_rounded_data_size = (1 << (
max_log2 (tx_fifo_size)));
105 tx_freelist_index =
max_log2 (tx_fifo_size)
109 pair_size = 2 *
sizeof (*f) + rx_rounded_data_size + tx_rounded_data_size;
111 pairs_to_allocate =
clib_min (space_available / pair_size, *n_fifo_pairs);
112 rx_fifos_size = (
sizeof (*f) + rx_rounded_data_size) * pairs_to_allocate;
113 tx_fifos_size = (
sizeof (*f) + tx_rounded_data_size) * pairs_to_allocate;
116 clib_max (rx_freelist_index, tx_freelist_index),
131 if (rx_fifo_space == 0 || tx_fifo_space == 0)
136 clib_warning (
"rx fifo preallocation failure: size %d npairs %d",
137 rx_fifo_size, *n_fifo_pairs);
142 clib_warning (
"tx fifo preallocation failure: size %d nfifos %d",
143 tx_fifo_size, *n_fifo_pairs);
150 for (i = 0; i < pairs_to_allocate; i++)
152 f->freelist_index = rx_freelist_index;
155 rx_fifo_space +=
sizeof (*f) + rx_rounded_data_size;
160 for (i = 0; i < pairs_to_allocate; i++)
162 f->freelist_index = tx_freelist_index;
165 tx_fifo_space +=
sizeof (*f) + tx_rounded_data_size;
170 *n_fifo_pairs -= pairs_to_allocate;
188 memset (fsh, 0,
sizeof (*fsh));
209 memset (s, 0,
sizeof (*s));
246 memset (s, 0,
sizeof (*s));
248 rnd_size = (a->
segment_size + (pagesize - 1)) & ~pagesize;
270 memset (sh, 0,
sizeof (*sh));
291 memset (s, 0,
sizeof (*s));
304 _vec_len (s) =
vec_len (s) - 1;
321 memset (s, 0xfe,
sizeof (*s));
330 u32 data_size_in_bytes,
346 clib_warning (
"fifo size out of range %d", data_size_in_bytes);
350 freelist_index =
max_log2 (data_size_in_bytes)
379 memset (f, 0,
sizeof (*f));
380 f->nitems = data_size_in_bytes;
383 f->freelist_index = freelist_index;
402 f->freelist_index = freelist_index;
413 fsh->
fifos->prev = f;
414 f->next = fsh->
fifos;
442 freelist_index = f->freelist_index;
454 f->prev->next = f->next;
456 fsh->
fifos = f->next;
458 f->next->prev = f->prev;
476 f->master_session_index = ~0;
477 f->master_thread_index = ~0;
497 return s - svm_fifo_segment_main.
segments;
521 u32 fifo_size_in_bytes)
527 u32 count = 0, rounded_data_size, freelist_index;
529 sh = fifo_segment->
ssvm.
sh;
533 if (fifo_size_in_bytes == ~0)
550 rounded_data_size = (1 << (
max_log2 (fifo_size_in_bytes)));
551 freelist_index =
max_log2 (rounded_data_size)
602 s =
format (s,
"%s",
"private-heap");
604 s =
format (s,
"%s",
"memfd");
606 s =
format (s,
"%s",
"shm");
608 s =
format (s,
"%s",
"unknown");
620 int verbose = va_arg (*args,
int);
629 s =
format (s,
"%U segment has %u active fifos\n",
644 s =
format (s,
"%U%-5u Kb: %u free",
static void * clib_mem_alloc_aligned_at_offset(uword size, uword align, uword align_offset, int os_out_of_memory_on_failure)
void svm_fifo_segment_info(svm_fifo_segment_private_t *seg, uword *address, u64 *size)
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).
#define FIFO_SEGMENT_F_IS_PREALLOCATED
static mheap_t * mheap_header(u8 *v)
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.
u8 * format_mheap(u8 *s, va_list *va)
void ssvm_delete(ssvm_private_t *ssvm)
svm_fifo_segment_main_t svm_fifo_segment_main
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)
int svm_fifo_segment_create_process_private(svm_fifo_segment_create_args_t *a)
Create an svm fifo segment in process-private memory.
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.
svm_fifo_segment_header_t * h
#define FIFO_SEGMENT_ALLOC_CHUNK_SIZE
void svm_fifo_segment_main_init(u64 baseva, u32 timeout_in_seconds)
u32 svm_fifo_segment_index(svm_fifo_segment_private_t *s)
#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
static void clib_mem_free(void *p)
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)
int svm_fifo_segment_create(svm_fifo_segment_create_args_t *a)
Create an svm fifo segment and initialize as master.
uword mheap_bytes(void *v)
svm_fifo_segment_private_t * segments
pool of segments
svm_fifo_segment_private_t * svm_fifo_segment_segments_pool(void)
Retrieve svm segments pool.
#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)
static void ssvm_unlock_non_recursive(ssvm_shared_header_t *h)
#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
uword clib_mem_get_page_size(void)
int svm_fifo_segment_attach(svm_fifo_segment_create_args_t *a)
Attach as slave to an svm fifo segment.
u8 * format_svm_fifo_segment(u8 *s, va_list *args)
Segment format function.
static void ssvm_lock_non_recursive(ssvm_shared_header_t *h, u32 tag)
void svm_fifo_segment_delete(svm_fifo_segment_private_t *s)
mheap_t * svm_fifo_segment_heap(svm_fifo_segment_private_t *seg)
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)
svm_fifo_t * svm_fifo_create(u32 data_size_in_bytes)
create an svm fifo, in the current heap.