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;
64 u32 rx_fifo_size, tx_fifo_size, pairs_to_allocate;
65 u32 rx_rounded_data_size, tx_rounded_data_size, pair_size;
67 u8 *rx_fifo_space, *tx_fifo_space;
68 int rx_freelist_index, tx_freelist_index;
101 pair_size = 2 *
sizeof (*f) + rx_rounded_data_size + tx_rounded_data_size;
104 rx_fifo_size = (
sizeof (*f) + rx_rounded_data_size) * pairs_to_allocate;
105 tx_fifo_size = (
sizeof (*f) + tx_rounded_data_size) * pairs_to_allocate;
108 clib_max (rx_freelist_index, tx_freelist_index),
111 clib_warning (
"rx_fifo_size %u (%d mb), tx_fifo_size %u (%d mb)",
112 rx_fifo_size, rx_fifo_size >> 20,
113 tx_fifo_size, tx_fifo_size >> 20);
126 if (rx_fifo_space == 0 || tx_fifo_space == 0)
131 clib_warning (
"rx fifo preallocation failure: size %d npairs %d",
137 clib_warning (
"tx fifo preallocation failure: size %d nfifos %d",
144 for (i = 0; i < pairs_to_allocate; i++)
146 f->freelist_index = rx_freelist_index;
149 rx_fifo_space +=
sizeof (*f) + rx_rounded_data_size;
154 for (i = 0; i < pairs_to_allocate; i++)
156 f->freelist_index = tx_freelist_index;
159 tx_fifo_space +=
sizeof (*f) + tx_rounded_data_size;
180 memset (s, 0,
sizeof (*s));
192 _vec_len (s) =
vec_len (s) - 1;
204 memset (fsh, 0,
sizeof (*fsh));
228 int segment_count = 1;
254 for (i = 0; i < segment_count; i++)
257 memset (s, 0,
sizeof (*s));
269 memset (sh, 0,
sizeof (*sh));
274 memset (fsh, 0,
sizeof (*fsh));
310 memset (s, 0,
sizeof (*s));
321 _vec_len (s) =
vec_len (s) - 1;
356 u32 data_size_in_bytes,
372 clib_warning (
"fifo size out of range %d", data_size_in_bytes);
376 freelist_index =
max_log2 (data_size_in_bytes)
402 memset (f, 0,
sizeof (*f));
403 f->nitems = data_size_in_bytes;
406 f->freelist_index = freelist_index;
426 f->freelist_index = freelist_index;
437 fsh->
fifos->prev = f;
438 f->next = fsh->
fifos;
466 freelist_index = f->freelist_index;
478 f->prev->next = f->next;
480 fsh->
fifos = f->next;
482 f->next->prev = f->prev;
500 f->master_session_index = ~0;
501 f->master_thread_index = ~0;
521 return s - svm_fifo_segment_main.
segments;
545 u32 fifo_size_in_bytes)
551 u32 count = 0, rounded_data_size, freelist_index;
553 sh = fifo_segment->
ssvm.
sh;
557 if (fifo_size_in_bytes == ~0)
574 rounded_data_size = (1 << (
max_log2 (fifo_size_in_bytes)));
575 freelist_index =
max_log2 (rounded_data_size)
601 int verbose = va_arg (*args,
int);
614 s =
format (s,
"%U segment has %u active fifos\n",
629 s =
format (s,
"%U%-5u Kb: %u free",
sll srl srl sll sra u16x4 i
static void * clib_mem_alloc_aligned_at_offset(uword size, uword align, uword align_offset, int os_out_of_memory_on_failure)
int ssvm_master_init(ssvm_private_t *ssvm, u32 master_index)
u32 private_segment_count
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).
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
static void * ssvm_push_heap(ssvm_shared_header_t *sh)
static void ssvm_pop_heap(void *oldheap)
#define FIFO_SEGMENT_MIN_FIFO_SIZE
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.
int ssvm_slave_init(ssvm_private_t *ssvm, int timeout_in_seconds)
void svm_fifo_segment_init(u64 baseva, u32 timeout_in_seconds)
svm_fifo_segment_header_t * h
#define FIFO_SEGMENT_F_IS_PRIVATE
#define FIFO_SEGMENT_ALLOC_CHUNK_SIZE
u32 svm_fifo_segment_index(svm_fifo_segment_private_t *s)
#define vec_free(V)
Free vector's memory (no header).
static void * clib_mem_set_heap(void *heap)
#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)
#define FIFO_SEGMENT_F_IS_MAIN_HEAP
#define OOO_SEGMENT_INVALID_INDEX
static void * clib_mem_get_heap(void)
#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)
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
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 void preallocate_fifo_pairs(svm_fifo_segment_private_t *s, svm_fifo_segment_create_args_t *a)
static uword max_log2(uword x)
#define clib_unix_warning(format, args...)
u32 preallocated_fifo_pairs
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)
(slave) attach 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)
svm_fifo_t * svm_fifo_create(u32 data_size_in_bytes)
create an svm fifo, in the current heap.