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;
110 #if USE_DLMALLOC == 0 116 pairs_to_allocate =
clib_min (space_available / pair_size, *n_fifo_pairs);
117 rx_fifos_size = (
sizeof (*f) + rx_rounded_data_size) * pairs_to_allocate;
118 tx_fifos_size = (
sizeof (*f) + tx_rounded_data_size) * pairs_to_allocate;
121 clib_max (rx_freelist_index, tx_freelist_index),
136 if (rx_fifo_space == 0 || tx_fifo_space == 0)
141 clib_warning (
"rx fifo preallocation failure: size %d npairs %d",
142 rx_fifo_size, *n_fifo_pairs);
147 clib_warning (
"tx fifo preallocation failure: size %d nfifos %d",
148 tx_fifo_size, *n_fifo_pairs);
155 for (i = 0; i < pairs_to_allocate; i++)
157 f->freelist_index = rx_freelist_index;
160 rx_fifo_space +=
sizeof (*f) + rx_rounded_data_size;
165 for (i = 0; i < pairs_to_allocate; i++)
167 f->freelist_index = tx_freelist_index;
170 tx_fifo_space +=
sizeof (*f) + tx_rounded_data_size;
175 *n_fifo_pairs -= pairs_to_allocate;
193 memset (fsh, 0,
sizeof (*fsh));
214 memset (s, 0,
sizeof (*s));
250 memset (s, 0,
sizeof (*s));
252 rnd_size = (a->
segment_size + (pagesize - 1)) & ~pagesize;
254 #if USE_DLMALLOC == 0 281 memset (sh, 0,
sizeof (*sh));
302 memset (s, 0,
sizeof (*s));
315 _vec_len (s) =
vec_len (s) - 1;
332 memset (s, 0xfe,
sizeof (*s));
341 u32 data_size_in_bytes,
357 clib_warning (
"fifo size out of range %d", data_size_in_bytes);
361 freelist_index =
max_log2 (data_size_in_bytes)
390 memset (f, 0,
sizeof (*f));
391 f->nitems = data_size_in_bytes;
395 f->freelist_index = freelist_index;
414 f->freelist_index = freelist_index;
425 fsh->
fifos->prev = f;
426 f->next = fsh->
fifos;
454 freelist_index = f->freelist_index;
466 f->prev->next = f->next;
468 fsh->
fifos = f->next;
470 f->next->prev = f->prev;
488 f->master_session_index = ~0;
489 f->master_thread_index = ~0;
509 return s - svm_fifo_segment_main.
segments;
533 u32 fifo_size_in_bytes)
539 u32 count = 0, rounded_data_size, freelist_index;
541 sh = fifo_segment->
ssvm.
sh;
545 if (fifo_size_in_bytes == ~0)
562 rounded_data_size = (1 << (
max_log2 (fifo_size_in_bytes)));
563 freelist_index =
max_log2 (rounded_data_size)
587 #if USE_DLMALLOC == 0 595 (
unsigned long long *) address,
596 (
unsigned long long *) size);
620 s =
format (s,
"%s",
"private-heap");
622 s =
format (s,
"%s",
"memfd");
624 s =
format (s,
"%s",
"shm");
626 s =
format (s,
"%s",
"unknown");
638 int verbose __attribute__ ((unused)) = va_arg (*args,
int);
645 #if USE_DLMALLOC == 0 648 s =
format (s,
"%U segment has %u active fifos\n",
664 s =
format (s,
"%U%-5u Kb: %u free",
DLMALLOC_EXPORT void mspace_get_address_and_size(mspace msp, unsigned long long *addrp, unsigned long long *sizep)
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.
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
memset(h->entries, 0, sizeof(h->entries[0])*entries)
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)
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)
DLMALLOC_EXPORT mspace create_mspace(size_t capacity, int locked)
#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
void * svm_fifo_segment_heap(svm_fifo_segment_private_t *seg)
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)
DLMALLOC_EXPORT size_t mspace_usable_size(const void *mem)
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)
#define SVM_FIFO_INVALID_SESSION_INDEX
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)
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.