58 s =
format (s,
"pos %u, len %u, next %d, prev %d",
67 u32 ooo_segment_index = f->ooos_list_head;
74 ooo_segment_index = seg->
next;
83 int verbose = va_arg (*args,
int);
85 s =
format (s,
"cursize %u nitems %u has_event %d\n",
86 f->cursize, f->nitems, f->has_event);
87 s =
format (s,
" head %d tail %d\n", f->head, f->tail);
91 (s,
" server session %d thread %d client session %d thread %d\n",
92 f->master_session_index, f->master_thread_index,
93 f->client_session_index, f->client_thread_index);
97 s =
format (s,
" ooo pool %d active elts\n",
116 memset (f, 0,
sizeof (*f) + data_size_in_bytes);
117 f->nitems = data_size_in_bytes;
154 next->prev = cur->
prev;
164 f->ooos_list_head = cur->
next;
178 u32 new_index, s_end_pos, s_index;
179 u32 normalized_position, normalized_end_position;
181 normalized_position = (f->tail +
offset) % f->nitems;
182 normalized_end_position = (f->tail + offset + length) % f->nitems;
189 f->ooos_list_head = s - f->ooo_segments;
190 f->ooos_newest = f->ooos_list_head;
210 s_index = s - f->ooo_segments;
217 new_index = new_s - f->ooo_segments;
225 prev->
next = new_index;
230 f->ooos_list_head = new_index;
233 new_s->
next = s_index;
235 f->ooos_newest = new_index;
239 else if (
position_gt (f, normalized_position, s_end_pos))
242 new_index = new_s - f->ooo_segments;
249 new_s->
prev = s_index;
251 f->ooos_newest = new_index;
265 s->
start = normalized_position;
269 else if (
position_gt (f, normalized_end_position, s_end_pos))
282 if (
position_gt (f, normalized_end_position, s_end_pos))
288 normalized_end_position))
307 f->ooos_newest = s - f->ooo_segments;
318 u32 index, bytes = 0;
323 diff = (f->tail >= s->
start) ?
324 f->tail - s->
start : f->nitems + f->tail - s->
start;
326 if (diff > n_bytes_enqueued)
330 while (0 <= diff && diff < n_bytes_enqueued)
332 index = s - f->ooo_segments;
339 f->tail %= f->nitems;
348 diff = (f->tail >= s->
start) ?
349 f->tail - s->
start : f->nitems + f->tail - s->
start;
366 u32 total_copy_bytes, first_copy_bytes, second_copy_bytes;
379 total_copy_bytes = (nitems - cursize) < max_bytes ?
380 (nitems - cursize) : max_bytes;
385 first_copy_bytes = ((nitems - f->tail) < total_copy_bytes)
386 ? (nitems - f->tail) : total_copy_bytes;
388 clib_memcpy (&f->data[f->tail], copy_from_here, first_copy_bytes);
389 f->tail += first_copy_bytes;
390 f->tail = (f->tail == nitems) ? 0 : f->tail;
393 second_copy_bytes = total_copy_bytes - first_copy_bytes;
394 if (second_copy_bytes)
396 clib_memcpy (&f->data[f->tail], copy_from_here + first_copy_bytes,
398 f->tail += second_copy_bytes;
399 f->tail = (f->tail == nitems) ? 0 : f->tail;
405 ASSERT (max_bytes <= (nitems - cursize));
406 f->tail += max_bytes;
407 f->tail = f->tail % nitems;
408 total_copy_bytes = max_bytes;
416 __sync_fetch_and_add (&f->cursize, total_copy_bytes);
418 return (total_copy_bytes);
421 #define SVM_ENQUEUE_CLONE_TEMPLATE(arch, fn, tgt) \ 423 __attribute__ ((flatten)) \ 424 __attribute__ ((target (tgt))) \ 426 fn ## _ ## arch ( svm_fifo_t * f, u32 max_bytes, u8 * copy_from_here) \ 427 { return fn (f, max_bytes, copy_from_here);} 449 fp = (
void *) svm_fifo_enqueue_nowait_ma_multiarch_select ();
451 return (*fp) (f, max_bytes, copy_from_here);
468 u32 total_copy_bytes, first_copy_bytes, second_copy_bytes;
469 u32 cursize, nitems, normalized_offset;
470 u32 offset_from_tail;
478 normalized_offset = (f->tail +
offset) % nitems;
481 offset_from_tail = (nitems + normalized_offset - f->tail) % nitems;
482 if ((required_bytes + offset_from_tail) > (nitems - cursize))
488 total_copy_bytes = required_bytes;
491 first_copy_bytes = ((nitems - normalized_offset) < total_copy_bytes)
492 ? (nitems - normalized_offset) : total_copy_bytes;
494 clib_memcpy (&f->data[normalized_offset], copy_from_here, first_copy_bytes);
497 second_copy_bytes = total_copy_bytes - first_copy_bytes;
498 if (second_copy_bytes)
500 normalized_offset += first_copy_bytes;
501 normalized_offset %= nitems;
503 ASSERT (normalized_offset == 0);
506 copy_from_here + first_copy_bytes, second_copy_bytes);
516 u32 required_bytes,
u8 * copy_from_here)
526 u32 total_copy_bytes, first_copy_bytes, second_copy_bytes;
537 total_copy_bytes = (cursize < max_bytes) ? cursize : max_bytes;
542 first_copy_bytes = ((nitems - f->head) < total_copy_bytes)
543 ? (nitems - f->head) : total_copy_bytes;
544 clib_memcpy (copy_here, &f->data[f->head], first_copy_bytes);
545 f->head += first_copy_bytes;
546 f->head = (f->head == nitems) ? 0 : f->head;
549 second_copy_bytes = total_copy_bytes - first_copy_bytes;
550 if (second_copy_bytes)
553 &f->data[f->head], second_copy_bytes);
554 f->head += second_copy_bytes;
555 f->head = (f->head == nitems) ? 0 : f->head;
561 ASSERT (max_bytes <= cursize);
562 f->head += max_bytes;
563 f->head = f->head % nitems;
564 cursize -= max_bytes;
565 total_copy_bytes = max_bytes;
568 __sync_fetch_and_sub (&f->cursize, total_copy_bytes);
570 return (total_copy_bytes);
579 #define SVM_FIFO_DEQUEUE_CLONE_TEMPLATE(arch, fn, tgt) \ 581 __attribute__ ((flatten)) \ 582 __attribute__ ((target (tgt))) \ 584 fn ## _ ## arch ( svm_fifo_t * f, u32 max_bytes, \ 586 { return fn (f, max_bytes, copy_here);} 601 fp = (
void *) svm_fifo_dequeue_nowait_ma_multiarch_select ();
603 return (*fp) (f, max_bytes, copy_here);
611 u32 total_copy_bytes, first_copy_bytes, second_copy_bytes;
612 u32 cursize, nitems, real_head;
620 real_head = f->head + relative_offset;
621 real_head = real_head >= nitems ? real_head - nitems : real_head;
624 total_copy_bytes = (cursize - relative_offset < max_bytes) ?
625 cursize - relative_offset : max_bytes;
631 ((nitems - real_head) < total_copy_bytes) ?
632 (nitems - real_head) : total_copy_bytes;
633 clib_memcpy (copy_here, &f->data[real_head], first_copy_bytes);
636 second_copy_bytes = total_copy_bytes - first_copy_bytes;
637 if (second_copy_bytes)
639 clib_memcpy (copy_here + first_copy_bytes, &f->data[0],
643 return total_copy_bytes;
646 #define SVM_FIFO_PEEK_CLONE_TEMPLATE(arch, fn, tgt) \ 648 __attribute__ ((flatten)) \ 649 __attribute__ ((target (tgt))) \ 651 fn ## _ ## arch ( svm_fifo_t * f, u32 relative_offset, u32 max_bytes, \ 653 { return fn (f, relative_offset, max_bytes, copy_here);} 668 fp = (
void *) svm_fifo_peek_ma_multiarch_select ();
670 return (*fp) (f, relative_offset, max_bytes, copy_here);
677 u32 total_drop_bytes, first_drop_bytes, second_drop_bytes;
688 total_drop_bytes = (cursize < max_bytes) ? cursize : max_bytes;
692 ((nitems - f->head) < total_drop_bytes) ?
693 (nitems - f->head) : total_drop_bytes;
694 f->head += first_drop_bytes;
695 f->head = (f->head == nitems) ? 0 : f->head;
698 second_drop_bytes = total_drop_bytes - first_drop_bytes;
699 if (second_drop_bytes)
701 f->head += second_drop_bytes;
702 f->head = (f->head == nitems) ? 0 : f->head;
705 __sync_fetch_and_sub (&f->cursize, total_drop_bytes);
707 return total_drop_bytes;
728 f->head = f->tail = pointer % f->nitems;
void svm_fifo_init_pointers(svm_fifo_t *f, u32 pointer)
Set fifo pointers to requested offset.
static u32 position_diff(svm_fifo_t *f, u32 posa, u32 posb)
#define SVM_ENQUEUE_CLONE_TEMPLATE(arch, fn, tgt)
static u8 svm_fifo_has_ooo_data(svm_fifo_t *f)
void svm_fifo_free(svm_fifo_t *f)
u32 prev
Previous linked-list element pool index.
static int ooo_segment_try_collect(svm_fifo_t *f, u32 n_bytes_enqueued)
Removes segments that can now be enqueued because the fifo's tail has advanced.
ooo_segment_t * svm_fifo_first_ooo_segment(svm_fifo_t *f)
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
static int svm_fifo_enqueue_internal(svm_fifo_t *f, u32 max_bytes, u8 *copy_from_here)
struct _svm_fifo svm_fifo_t
static void ooo_segment_add(svm_fifo_t *f, u32 offset, u32 length)
Add segment to fifo's out-of-order segment list.
static u32 svm_fifo_max_dequeue(svm_fifo_t *f)
u8 * format_ooo_list(u8 *s, va_list *args)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
static u8 position_gt(svm_fifo_t *f, u32 a, u32 b)
static int svm_fifo_enqueue_nowait_ma(svm_fifo_t *f, u32 max_bytes, u8 *copy_from_here)
u32 svm_fifo_number_ooo_segments(svm_fifo_t *f)
#define pool_put(P, E)
Free an object E in pool P.
#define SVM_FIFO_DEQUEUE_CLONE_TEMPLATE(arch, fn, tgt)
static int svm_fifo_peek_ma(svm_fifo_t *f, u32 relative_offset, u32 max_bytes, u8 *copy_here)
#define pool_free(p)
Free a pool.
static u8 position_leq(svm_fifo_t *f, u32 a, u32 b)
#define clib_memcpy(a, b, c)
static ooo_segment_t * ooo_segment_get_prev(svm_fifo_t *f, ooo_segment_t *s)
int svm_fifo_enqueue_nowait(svm_fifo_t *f, u32 max_bytes, u8 *copy_from_here)
static void ooo_segment_del(svm_fifo_t *f, u32 index)
#define OOO_SEGMENT_INVALID_INDEX
u8 * format_ooo_segment(u8 *s, va_list *args)
static void * clib_mem_alloc_aligned_or_null(uword size, uword align)
u8 * format_svm_fifo(u8 *s, va_list *args)
static u8 position_lt(svm_fifo_t *f, u32 a, u32 b)
static void clib_mem_free(void *p)
static int svm_fifo_dequeue_nowait_ma(svm_fifo_t *f, u32 max_bytes, u8 *copy_here)
int svm_fifo_enqueue_with_offset(svm_fifo_t *f, u32 offset, u32 required_bytes, u8 *copy_from_here)
u32 length
Length of segment.
CLIB_MULTIARCH_SELECT_FN(svm_fifo_enqueue_nowait_ma)
u32 next
Next linked-list element pool index.
template key/value backing page structure
int svm_fifo_dequeue_drop(svm_fifo_t *f, u32 max_bytes)
static u32 ooo_segment_end_pos(svm_fifo_t *f, ooo_segment_t *s)
static ooo_segment_t * ooo_segment_new(svm_fifo_t *f, u32 start, u32 length)
foreach_march_variant(SVM_ENQUEUE_CLONE_TEMPLATE, svm_fifo_enqueue_nowait_ma)
static int svm_fifo_dequeue_internal(svm_fifo_t *f, u32 max_bytes, u8 *copy_here)
static int svm_fifo_enqueue_with_offset_internal(svm_fifo_t *f, u32 offset, u32 required_bytes, u8 *copy_from_here)
Enqueue a future segment.
struct clib_bihash_value offset
template key/value backing page structure
#define CLIB_CACHE_LINE_BYTES
int svm_fifo_peek(svm_fifo_t *f, u32 relative_offset, u32 max_bytes, u8 *copy_here)
#define SVM_FIFO_PEEK_CLONE_TEMPLATE(arch, fn, tgt)
int svm_fifo_dequeue_nowait(svm_fifo_t *f, u32 max_bytes, u8 *copy_here)
u32 start
Start of segment, normalized.
static u32 ooo_segment_distance_to_tail(svm_fifo_t *f, u32 a)
svm_fifo_t * svm_fifo_create(u32 data_size_in_bytes)
create an svm fifo, in the current heap.
static uword pool_elts(void *v)
Number of active elements in a pool.