58 u32 normalized_start = (seg->
start + f->nitems - f->tail) % f->nitems;
59 s =
format (s,
"[%u, %u], len %u, next %d, prev %d", normalized_start,
60 (normalized_start + seg->
length) % f->nitems, seg->
length,
110 memset (f->data, 0xFF, f->nitems);
113 for (i = 0; i <
vec_len (data); i++)
116 for (i = 0; i < trace_len; i++)
119 if (trace[i].action == 1)
122 s =
format (s,
"adding [%u, %u]:", trace[i].offset,
124 trace[i].len) % dummy_fifo->nitems);
126 trace[i].len, &data[offset]);
128 else if (trace[i].action == 2)
131 s =
format (s,
"adding [%u, %u]:", 0, trace[i].len);
137 s =
format (s,
"read: %u", trace[i].len);
153 u32 ooo_segment_index = f->ooos_list_head;
160 ooo_segment_index = seg->
next;
170 int verbose = va_arg (*args,
int);
175 s =
format (s,
"cursize %u nitems %u has_event %d\n",
176 f->cursize, f->nitems, f->has_event);
177 s =
format (s,
" head %d tail %d segment manager %u\n", f->head, f->tail,
182 (s,
" server session %d thread %d client session %d thread %d\n",
183 f->master_session_index, f->master_thread_index,
184 f->client_session_index, f->client_thread_index);
188 s =
format (s,
" ooo pool %d active elts newest %u\n",
189 pool_elts (f->ooo_segments), f->ooos_newest);
201 u32 rounded_data_size;
204 rounded_data_size = (1 << (
max_log2 (data_size_in_bytes)));
210 memset (f, 0,
sizeof (*f));
211 f->nitems = data_size_in_bytes;
222 if (--f->refcnt == 0)
253 next->prev = cur->
prev;
263 f->ooos_list_head = cur->
next;
277 u32 new_index, s_end_pos, s_index;
278 u32 normalized_position, normalized_end_position;
281 normalized_position = (f->tail +
offset) % f->nitems;
282 normalized_end_position = (f->tail + offset + length) % f->nitems;
289 f->ooos_list_head = s - f->ooo_segments;
290 f->ooos_newest = f->ooos_list_head;
314 s_index = s - f->ooo_segments;
321 new_index = new_s - f->ooo_segments;
329 prev->
next = new_index;
334 f->ooos_list_head = new_index;
337 new_s->
next = s_index;
339 f->ooos_newest = new_index;
343 else if (
position_gt (f, normalized_position, s_end_pos))
346 new_index = new_s - f->ooo_segments;
354 new_s->
prev = s_index;
356 f->ooos_newest = new_index;
368 s->
start = normalized_position;
370 f->ooos_newest = s - f->ooo_segments;
376 if (
position_gt (f, normalized_end_position, s_end_pos))
383 normalized_end_position))
397 f->ooos_newest = s - f->ooo_segments;
409 u32 index, bytes = 0;
415 ASSERT (diff != n_bytes_enqueued);
417 if (diff > n_bytes_enqueued)
421 while (0 <= diff && diff < n_bytes_enqueued)
423 index = s - f->ooo_segments;
430 f->tail %= f->nitems;
450 ASSERT (bytes <= f->nitems);
456 const u8 * copy_from_here)
458 u32 total_copy_bytes, first_copy_bytes, second_copy_bytes;
471 total_copy_bytes = (nitems - cursize) < max_bytes ?
472 (nitems - cursize) : max_bytes;
477 first_copy_bytes = ((nitems - f->tail) < total_copy_bytes)
478 ? (nitems - f->tail) : total_copy_bytes;
480 clib_memcpy (&f->data[f->tail], copy_from_here, first_copy_bytes);
481 f->tail += first_copy_bytes;
482 f->tail = (f->tail == nitems) ? 0 : f->tail;
485 second_copy_bytes = total_copy_bytes - first_copy_bytes;
486 if (second_copy_bytes)
488 clib_memcpy (&f->data[f->tail], copy_from_here + first_copy_bytes,
490 f->tail += second_copy_bytes;
491 f->tail = (f->tail == nitems) ? 0 : f->tail;
499 ASSERT (max_bytes <= (nitems - cursize));
500 f->tail += max_bytes;
501 f->tail = f->tail % nitems;
502 total_copy_bytes = max_bytes;
512 ASSERT (cursize + total_copy_bytes <= nitems);
513 __sync_fetch_and_add (&f->cursize, total_copy_bytes);
515 return (total_copy_bytes);
518 #define SVM_ENQUEUE_CLONE_TEMPLATE(arch, fn, tgt) \ 520 __attribute__ ((flatten)) \ 521 __attribute__ ((target (tgt))) \ 523 fn ## _ ## arch ( svm_fifo_t * f, u32 max_bytes, u8 * copy_from_here) \ 524 { return fn (f, max_bytes, copy_from_here);} 528 const u8 * copy_from_here)
539 const u8 * copy_from_here)
547 fp = (
void *) svm_fifo_enqueue_nowait_ma_multiarch_select ();
549 return (*fp) (f, max_bytes, copy_from_here);
566 u32 total_copy_bytes, first_copy_bytes, second_copy_bytes;
567 u32 cursize, nitems, normalized_offset;
575 ASSERT (required_bytes < nitems);
577 normalized_offset = (f->tail +
offset) % nitems;
580 if ((required_bytes + offset) > (nitems - cursize))
588 total_copy_bytes = required_bytes;
591 first_copy_bytes = ((nitems - normalized_offset) < total_copy_bytes)
592 ? (nitems - normalized_offset) : total_copy_bytes;
594 clib_memcpy (&f->data[normalized_offset], copy_from_here, first_copy_bytes);
597 second_copy_bytes = total_copy_bytes - first_copy_bytes;
598 if (second_copy_bytes)
600 normalized_offset += first_copy_bytes;
601 normalized_offset %= nitems;
603 ASSERT (normalized_offset == 0);
606 copy_from_here + first_copy_bytes, second_copy_bytes);
616 u32 required_bytes,
u8 * copy_from_here)
626 first_chunk = f->nitems - f->head;
627 ASSERT (len <= f->nitems);
628 if (len <= first_chunk)
632 clib_memcpy (&f->data[f->head], data, first_chunk);
633 clib_memcpy (&f->data[0], data + first_chunk, len - first_chunk);
640 u32 total_copy_bytes, first_copy_bytes, second_copy_bytes;
651 total_copy_bytes = (cursize < max_bytes) ? cursize : max_bytes;
656 first_copy_bytes = ((nitems - f->head) < total_copy_bytes)
657 ? (nitems - f->head) : total_copy_bytes;
658 clib_memcpy (copy_here, &f->data[f->head], first_copy_bytes);
659 f->head += first_copy_bytes;
660 f->head = (f->head == nitems) ? 0 : f->head;
663 second_copy_bytes = total_copy_bytes - first_copy_bytes;
664 if (second_copy_bytes)
667 &f->data[f->head], second_copy_bytes);
668 f->head += second_copy_bytes;
669 f->head = (f->head == nitems) ? 0 : f->head;
676 ASSERT (max_bytes <= cursize);
677 f->head += max_bytes;
678 f->head = f->head % nitems;
679 cursize -= max_bytes;
680 total_copy_bytes = max_bytes;
683 ASSERT (f->head <= nitems);
684 ASSERT (cursize >= total_copy_bytes);
685 __sync_fetch_and_sub (&f->cursize, total_copy_bytes);
687 return (total_copy_bytes);
696 #define SVM_FIFO_DEQUEUE_CLONE_TEMPLATE(arch, fn, tgt) \ 698 __attribute__ ((flatten)) \ 699 __attribute__ ((target (tgt))) \ 701 fn ## _ ## arch ( svm_fifo_t * f, u32 max_bytes, \ 703 { return fn (f, max_bytes, copy_here);} 718 fp = (
void *) svm_fifo_dequeue_nowait_ma_multiarch_select ();
720 return (*fp) (f, max_bytes, copy_here);
728 u32 total_copy_bytes, first_copy_bytes, second_copy_bytes;
729 u32 cursize, nitems, real_head;
737 real_head = f->head + relative_offset;
738 real_head = real_head >= nitems ? real_head - nitems : real_head;
741 total_copy_bytes = (cursize - relative_offset < max_bytes) ?
742 cursize - relative_offset : max_bytes;
748 ((nitems - real_head) < total_copy_bytes) ?
749 (nitems - real_head) : total_copy_bytes;
750 clib_memcpy (copy_here, &f->data[real_head], first_copy_bytes);
753 second_copy_bytes = total_copy_bytes - first_copy_bytes;
754 if (second_copy_bytes)
756 clib_memcpy (copy_here + first_copy_bytes, &f->data[0],
760 return total_copy_bytes;
763 #define SVM_FIFO_PEEK_CLONE_TEMPLATE(arch, fn, tgt) \ 765 __attribute__ ((flatten)) \ 766 __attribute__ ((target (tgt))) \ 768 fn ## _ ## arch ( svm_fifo_t * f, u32 relative_offset, u32 max_bytes, \ 770 { return fn (f, relative_offset, max_bytes, copy_here);} 785 fp = (
void *) svm_fifo_peek_ma_multiarch_select ();
787 return (*fp) (f, relative_offset, max_bytes, copy_here);
794 u32 total_drop_bytes, first_drop_bytes, second_drop_bytes;
805 total_drop_bytes = (cursize < max_bytes) ? cursize : max_bytes;
811 ((nitems - f->head) < total_drop_bytes) ?
812 (nitems - f->head) : total_drop_bytes;
813 f->head += first_drop_bytes;
814 f->head = (f->head == nitems) ? 0 : f->head;
817 second_drop_bytes = total_drop_bytes - first_drop_bytes;
818 if (second_drop_bytes)
820 f->head += second_drop_bytes;
821 f->head = (f->head == nitems) ? 0 : f->head;
824 ASSERT (f->head <= nitems);
825 ASSERT (cursize >= total_drop_bytes);
826 __sync_fetch_and_sub (&f->cursize, total_drop_bytes);
828 return total_drop_bytes;
835 __sync_fetch_and_sub (&f->cursize, f->cursize);
856 f->head = f->tail = pointer % f->nitems;
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
static vlib_cli_command_t trace
(constructor) VLIB_CLI_COMMAND (trace)
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 svm_fifo_enqueue_nowait_ma(svm_fifo_t *f, u32 max_bytes, const u8 *copy_from_here)
void svm_fifo_overwrite_head(svm_fifo_t *f, u8 *data, u32 len)
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)
void svm_fifo_dequeue_drop_all(svm_fifo_t *f)
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
static u32 ooo_segment_distance_from_tail(svm_fifo_t *f, u32 pos)
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)
int svm_fifo_enqueue_nowait(svm_fifo_t *f, u32 max_bytes, const u8 *copy_from_here)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
static int svm_fifo_enqueue_internal(svm_fifo_t *f, u32 max_bytes, const u8 *copy_from_here)
static u8 position_gt(svm_fifo_t *f, u32 a, u32 b)
u32 svm_fifo_number_ooo_segments(svm_fifo_t *f)
#define pool_put(P, E)
Free an object E in pool P.
static ooo_segment_t * ooo_segment_next(svm_fifo_t *f, ooo_segment_t *s)
#define svm_fifo_trace_add(_f, _s, _l, _t)
u8 * svm_fifo_replay(u8 *s, svm_fifo_t *f, u8 no_read, u8 verbose)
#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)
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)
u8 * svm_fifo_dump_trace(u8 *s, svm_fifo_t *f)
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)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
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 uword max_log2(uword x)
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 vec_foreach(var, vec)
Vector iterator.
#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 pos)
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.