|
FD.io VPP
v21.10.1-2-g0a485f517
Vector Packet Processing
|
Go to the documentation of this file.
114 ASSERT (e >=
h->elts && e <= l);
124 h->head = n -
h->elts;
129 h->tail = p -
h->elts;
142 _vec_len (
h->elts)--;
159 h->head =
new -
h->elts;
184 h->tail =
new -
h->elts;
200 if ((l =
vec_len (
h->free_elts)) > 0)
202 e =
elt_at (
h,
h->free_elts[l - 1]);
203 _vec_len (
h->free_elts) -= 1;
225 if (
h->elt_bytes >= sizeof (
u32))
233 uword elt_index = e -
h->elts;
235 h->small_free_elt_free_index[elt_index] = fi;
248 if (
h->elt_bytes >= sizeof (
u32))
254 uword elt_index = e -
h->elts;
255 fi =
vec_elt (
h->small_free_elt_free_index, elt_index);
275 uword t =
h->free_lists[
b][l - 1];
276 h->free_lists[
b][
i] = t;
279 _vec_len (
h->free_lists[
b]) = l - 1;
287 uword b, fb, f_size, f_index;
295 if ((l =
vec_len (
h->free_lists[
b])) > 0)
304 f_index =
h->free_lists[
b][l];
307 if ((s = f_size -
size) >= 0)
386 _heap_alloc (
void *v,
407 align_size =
size + align - 1;
420 if (max_len &&
offset + align_size > max_len)
427 (
offset + align_size) * elt_bytes,
430 _vec_len (v) += align_size;
435 h->elt_bytes = elt_bytes;
452 uword new_offset, old_offset;
455 new_offset = (old_offset + align - 1) & ~(align - 1);
457 e_index = e -
h->elts;
460 if (new_offset > old_offset)
463 before_e->
offset = old_offset;
468 if (new_offset +
size < old_offset + align_size)
476 e =
h->elts + e_index;
485 uword handle = e -
h->elts;
487 h->used_elt_bitmap = clib_bitmap_ori (
h->used_elt_bitmap, handle);
490 *offset_return = e->
offset;
491 *handle_return = e -
h->elts;
495 *offset_return = *handle_return = ~0;
512 h->used_elt_bitmap = clib_bitmap_andnoti (
h->used_elt_bitmap, handle);
517 e =
h->elts + handle;
529 uword total_size,
i,
b, tb,
ti, i_last, g_offset;
550 f[
i].index =
h->free_lists[tb][
ti];
566 g.index = g.bin_index = 0;
567 for (
i = 0;
i <= i_last;
i++)
579 g.bin_index =
vec_len (
h->free_lists[
b]);
587 for (
i = 0;
i <= i_last;
i++)
588 if (g.index !=
f[
i].index)
640 bytes =
sizeof (
h[0]);
641 bytes +=
vec_len (v) *
sizeof (
h->elt_bytes);
667 for (j = 0; j < n / 2; j++)
672 e1 =
h->elts +
h->tail;
676 for (j = 0; j < n / 2; j++)
684 s =
format (s,
"index %4d, free\n", e -
h->elts);
685 else if (
h->format_elt)
688 s =
format (s,
"index %4d, used\n", e -
h->elts);
700 void *v = va_arg (*va,
void *);
714 s =
format (s,
"heap %p, %6d objects, size %.1fk + overhead %.1fk\n",
715 v,
h->used_count, elt_bytes / 1024,
716 (overhead_bytes - elt_bytes) / 1024);
733 uword used_count, total_size;
734 uword free_count, free_size;
742 free_size = free_count = 0;
745 free_count +=
vec_len (
h->free_lists[
i]);
746 for (o = 0; o <
vec_len (
h->free_lists[
i]); o++)
748 e =
h->elts +
h->free_lists[
i][o];
757 uword elt_free_size, elt_free_count;
759 used_count = total_size = elt_free_size = elt_free_count = 0;
760 for (e =
first (
h); 1; e = n)
784 ASSERT (free_count == elt_free_count);
785 ASSERT (free_size == elt_free_size);
786 ASSERT (used_count ==
h->used_count + free_count);
793 for (
i = o = 0; 1;
i++)
806 ASSERT (
h->free_lists[fb][fi] == e -
h->elts);
static void combine_free_blocks(void *v, heap_elt_t *e0, heap_elt_t *e1)
__clib_export void heap_validate(void *v)
#define vec_new(T, N)
Create new vector of given type and length (unspecified alignment, no header).
static void set_free_elt(void *v, heap_elt_t *e, uword fi)
static void elt_delete(heap_header_t *h, heap_elt_t *e)
static void elt_insert_before(heap_header_t *h, heap_elt_t *e, heap_elt_t *new)
#define HEAP_ELT_FREE_BIT
#define vec_end(v)
End (last data address) of vector.
static u32 * elt_data(void *v, heap_elt_t *e)
#define vec_capacity(v, b)
Total number of bytes that can fit in vector with current allocation.
static heap_elt_t * first(heap_header_t *h)
static uword heap_offset(heap_elt_t *e)
static heap_elt_t * elt_at(heap_header_t *h, uword i)
static uword max_log2(uword x)
#define vec_elt(v, i)
Get vector value at index i.
static heap_header_t * heap_header(void *v)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static uword clib_bitmap_get(uword *ai, uword i)
Gets the ith bit value from a bitmap.
static uword heap_elt_size(void *v, heap_elt_t *e)
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
struct clib_bihash_value offset
template key/value backing page structure
static uword clib_bitmap_count_set_bits(uword *ai)
Return the number of set bits in a bitmap.
static uword heap_get_max_len(void *v)
#define clib_bitmap_free(v)
Free a bitmap.
static heap_elt_t * last(heap_header_t *h)
static u8 * debug_elt(u8 *s, void *v, word i, word n)
static heap_elt_t * heap_prev(heap_elt_t *e)
#define HEAP_LOG2_SMALL_BINS
static heap_elt_t * elt_new(heap_header_t *h)
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
__clib_export void heap_dealloc(void *v, uword handle)
#define vec_free(V)
Free vector's memory (no header).
template key/value backing page structure
__clib_export u8 * format_heap(u8 *s, va_list *va)
static void dealloc_elt(void *v, heap_elt_t *e)
description fragment has unexpected format
static heap_elt_t * heap_next(heap_elt_t *e)
static uword get_free_elt(void *v, heap_elt_t *e, uword *bin_result)
static void elt_insert_after(heap_header_t *h, heap_elt_t *e, heap_elt_t *new)
static heap_elt_t * search_free_list(void *v, uword size)
__clib_export uword heap_len(void *v, word handle)
static uword size_to_bin(uword size)
uword heap_bytes(void *v)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static uword bin_to_size(uword bin)
#define vec_free_h(V, H)
Free vector's memory (general version)
static void remove_free_block(void *v, uword b, uword i)
static uword heap_is_free(heap_elt_t *e)
static uword max_pow2(uword x)
#define vec_bytes(v)
Number of data bytes in vector.