40 #ifndef included_vlib_buffer_funcs_h 41 #define included_vlib_buffer_funcs_h 104 #if defined(CLIB_HAVE_VEC512) 105 while (n_indices >= 16)
107 u32x16_store_unaligned (u32x16_load_unaligned (src), dst);
114 #if defined(CLIB_HAVE_VEC256) 115 while (n_indices >= 8)
117 u32x8_store_unaligned (u32x8_load_unaligned (src), dst);
124 #if defined(CLIB_HAVE_VEC128) 125 while (n_indices >= 4)
127 u32x4_store_unaligned (u32x4_load_unaligned (src), dst);
147 #if defined CLIB_HAVE_VEC512 148 b->as_u8x64[0] = bt->as_u8x64[0];
149 #elif defined (CLIB_HAVE_VEC256) 150 b->as_u8x32[0] = bt->as_u8x32[0];
151 b->as_u8x32[1] = bt->as_u8x32[1];
152 #elif defined (CLIB_HAVE_VEC128) 153 b->as_u8x16[0] = bt->as_u8x16[0];
154 b->as_u8x16[1] = bt->as_u8x16[1];
155 b->as_u8x16[2] = bt->as_u8x16[2];
156 b->as_u8x16[3] = bt->as_u8x16[3];
182 #ifdef CLIB_HAVE_VEC256 183 u64x4 off = u64x4_splat (buffer_mem_start + offset);
188 u64x4 b0 = u32x4_extend_to_u64x4 (u32x4_load_unaligned (bi));
189 u64x4 b1 = u32x4_extend_to_u64x4 (u32x4_load_unaligned (bi + 4));
200 #ifdef CLIB_HAVE_VEC256 201 u64x4 b0 = u32x4_extend_to_u64x4 (u32x4_load_unaligned (bi));
204 #elif defined (CLIB_HAVE_VEC128) 205 u64x2 off = u64x2_splat (buffer_mem_start + offset);
206 u32x4 bi4 = u32x4_load_unaligned (bi);
208 #if defined (__aarch64__) 279 #ifdef CLIB_HAVE_VEC256 280 u32x8 mask = { 0, 2, 4, 6, 1, 3, 5, 7 };
286 u64x4 v0 = u64x4_load_unaligned (b);
287 u64x4 v1 = u64x4_load_unaligned (b + 4);
302 u32x4_store_unaligned (u32x8_extract_lo (v2), bi);
303 u32x4_store_unaligned (u32x8_extract_lo (v3), bi + 4);
352 return (b->
flags & VLIB_BUFFER_NEXT_PRESENT
402 uword content_len = 0;
412 if (!(b->
flags & VLIB_BUFFER_NEXT_PRESENT))
440 #define vlib_prefetch_buffer_with_index(vm,bi,type) \ 442 vlib_buffer_t * _b = vlib_get_buffer (vm, bi); \ 443 vlib_prefetch_buffer_header (_b, type); \ 479 uword next_buffer_stride,
482 uword follow_buffer_next);
531 u8 buffer_pool_index)
546 if (len >= n_buffers)
647 u32 ring_size,
u32 n_buffers)
651 ASSERT (n_buffers <= ring_size);
676 u32 ring_size,
u32 n_buffers,
677 u8 buffer_pool_index)
681 ASSERT (n_buffers <= ring_size);
699 u32 * buffers,
u32 n_buffers)
704 u32 n_cached, n_empty;
712 if (n_buffers <= n_empty)
716 bpt->
n_cached = n_cached + n_buffers;
721 buffers + n_buffers - n_empty, n_empty);
726 n_buffers - n_empty);
727 bp->
n_avail += n_buffers - n_empty;
735 const int queue_size = 128;
737 u8 buffer_pool_index = ~0;
738 u32 n_queue = 0, queue[queue_size + 4];
740 #if defined(CLIB_HAVE_VEC128) 744 .
flags = VLIB_BUFFER_NEXT_PRESENT,
765 #if defined(CLIB_HAVE_VEC128) 766 u8x16 p0, p1, p2, p3, r;
767 p0 = u8x16_load_unaligned (b[0]);
768 p1 = u8x16_load_unaligned (b[1]);
769 p2 = u8x16_load_unaligned (b[2]);
770 p3 = u8x16_load_unaligned (b[3]);
772 r = p0 ^ bpi_vec.as_u8x16[0];
773 r |= p1 ^ bpi_vec.as_u8x16[0];
774 r |= p2 ^ bpi_vec.as_u8x16[0];
775 r |= p3 ^ bpi_vec.as_u8x16[0];
776 r &= bpi_mask.as_u8x16[0];
777 r |= (p0 | p1 | p2 | p3) & flags_refs_mask.as_u8x16[0];
779 sum = !u8x16_is_all_zero (r);
785 sum &= VLIB_BUFFER_NEXT_PRESENT;
816 if (n_queue >= queue_size)
833 if (
PREDICT_FALSE (buffer_pool_index != b[0]->buffer_pool_index))
843 #if defined(CLIB_HAVE_VEC128) 857 queue[n_queue++] = bi;
860 if (n_queue == queue_size)
866 if (maybe_next && (
flags & VLIB_BUFFER_NEXT_PRESENT))
938 u32 ring_size,
u32 n_buffers)
940 ASSERT (n_buffers <= ring_size);
963 u32 ring_size,
u32 n_buffers)
965 ASSERT (n_buffers <= ring_size);
983 #define VLIB_BUFFER_COPY_CLONE_FLAGS_MASK \ 984 (VLIB_BUFFER_NEXT_PRESENT | VLIB_BUFFER_TOTAL_LENGTH_VALID | \ 985 VLIB_BUFFER_IS_TRACED | ~VLIB_BUFFER_FLAGS_ALL) 992 uword n_alloc, n_buffers = 1;
997 while (s->
flags & VLIB_BUFFER_NEXT_PRESENT)
1002 u32 new_buffers[n_buffers];
1029 for (i = 1; i < n_buffers; i++)
1076 ASSERT ((b->
flags & VLIB_BUFFER_NEXT_PRESENT) == 0);
1086 if (source + length <= destination)
1089 memmove (destination, source, length);
1115 ASSERT (n_buffers <= 256);
1117 ASSERT ((offset + head_end_offset) <
1122 buffers[0] = src_buffer;
1126 for (i = 1; i < n_buffers; i++)
1140 buffers[0] = src_buffer;
1147 for (i = 0; i < n_buffers; i++)
1166 VLIB_BUFFER_NEXT_PRESENT;
1176 while (s->
flags & VLIB_BUFFER_NEXT_PRESENT)
1206 while (n_buffers > 256)
1212 (buffers + n_cloned),
1213 256, head_end_offset, offset);
1218 n_buffers, head_end_offset, offset);
1237 u16 n_buffers,
u16 head_end_offset)
1240 head_end_offset, 0);
1254 ASSERT ((head->
flags & VLIB_BUFFER_NEXT_PRESENT) == 0);
1257 head->
flags |= VLIB_BUFFER_NEXT_PRESENT;
1258 head->
flags &= ~VLIB_BUFFER_TOTAL_LENGTH_VALID;
1259 head->
flags &= ~VLIB_BUFFER_EXT_HDR_VALID;
1260 head->
flags |= (tail->
flags & VLIB_BUFFER_TOTAL_LENGTH_VALID);
1268 if (tail->
flags & VLIB_BUFFER_NEXT_PRESENT)
1281 first->
flags &= ~VLIB_BUFFER_NEXT_PRESENT;
1282 first->
flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
1291 last->
flags |= VLIB_BUFFER_NEXT_PRESENT;
1293 next_buffer->
flags &= ~VLIB_BUFFER_NEXT_PRESENT;
1358 uword n_packet_data_bytes,
1359 uword min_n_buffers_each_alloc,
1384 u32 bytes_left = 0, data_size;
1385 u16 src_left, dst_left, n_buffers = 1;
1396 while (b->
flags & VLIB_BUFFER_NEXT_PRESENT)
1407 if (is_cloned && bytes_left >= dst_left)
1410 u32 space_needed = bytes_left - dst_left;
1420 while (len < space_needed)
1428 b->
flags = VLIB_BUFFER_NEXT_PRESENT;
1435 to_free = first->next_buffer;
1436 first->next_buffer = tail;
1441 src_left = sb->current_length;
1454 dst_left = data_size;
1466 while (src_left == 0)
1468 ASSERT (sb->flags & VLIB_BUFFER_NEXT_PRESENT);
1470 src_left = sb->current_length;
1474 bytes_to_copy =
clib_min (dst_left, src_left);
1479 bytes_to_copy =
clib_min (bytes_to_copy, sp - dp);
1484 src_left -= bytes_to_copy;
1485 dst_left -= bytes_to_copy;
1486 dp += bytes_to_copy;
1487 sp += bytes_to_copy;
1488 bytes_left -= bytes_to_copy;
1494 if (is_cloned && to_free)
1498 if (db->
flags & VLIB_BUFFER_NEXT_PRESENT)
1500 db->
flags &= ~VLIB_BUFFER_NEXT_PRESENT;
1503 while (b->
flags & VLIB_BUFFER_NEXT_PRESENT)
1510 first->flags &= ~VLIB_BUFFER_TOTAL_LENGTH_VALID;
#define VLIB_BUFFER_COPY_CLONE_FLAGS_MASK
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
static uword vlib_buffer_get_current_pa(vlib_main_t *vm, vlib_buffer_t *b)
static u8 * vlib_buffer_get_tail(vlib_buffer_t *b)
Get pointer to the end of buffer's data.
static_always_inline void clib_spinlock_unlock(clib_spinlock_t *p)
static_always_inline void clib_spinlock_lock(clib_spinlock_t *p)
uword vlib_buffer_length_in_chain_slow_path(vlib_main_t *vm, vlib_buffer_t *b_first)
static void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
#define clib_atomic_add_fetch(a, b)
format_function_t format_vlib_buffer_contents
static uword vlib_buffer_get_pa(vlib_main_t *vm, vlib_buffer_t *b)
static_always_inline u64x2 u32x4_extend_to_u64x2_high(u32x4 v)
format_function_t format_vlib_buffer
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
static_always_inline vlib_buffer_pool_t * vlib_get_buffer_pool(vlib_main_t *vm, u8 buffer_pool_index)
#define clib_memcpy_fast(a, b, c)
u16 vlib_buffer_chain_append_data_with_alloc(vlib_main_t *vm, vlib_buffer_t *first, vlib_buffer_t **last, void *data, u16 data_len)
static void vlib_buffer_attach_clone(vlib_main_t *vm, vlib_buffer_t *head, vlib_buffer_t *tail)
Attach cloned tail to the buffer.
static void vlib_buffer_chain_increase_length(vlib_buffer_t *first, vlib_buffer_t *last, i32 len)
static void vlib_buffer_move(vlib_main_t *vm, vlib_buffer_t *b, i16 offset)
#define VLIB_BUFFER_PRE_DATA_SIZE
int vlib_buffer_add_data(vlib_main_t *vm, u32 *buffer_index, void *data, u32 n_data_bytes)
u16 current_length
Nbytes between current data and the end of this buffer.
#define CLIB_LOG2_CACHE_LINE_BYTES
vlib_buffer_main_t * buffer_main
foreach_avx2_vec256i static foreach_avx2_vec256u u32x8 u32x8_permute(u32x8 v, u32x8 idx)
static_always_inline void vlib_get_buffers_with_offset(vlib_main_t *vm, u32 *bi, void **b, int count, i32 offset)
Translate array of buffer indices into buffer pointers with offset.
static vlib_buffer_known_state_t vlib_buffer_is_known(vlib_main_t *vm, u32 buffer_index)
static u32 vlib_buffer_alloc_to_ring_from_pool(vlib_main_t *vm, u32 *ring, u32 start, u32 ring_size, u32 n_buffers, u8 buffer_pool_index)
Allocate buffers into ring from specific buffer pool.
static uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
static u32 vlib_buffer_alloc_on_numa(vlib_main_t *vm, u32 *buffers, u32 n_buffers, u32 numa_node)
Allocate buffers from specific numa node into supplied array.
static vlib_buffer_t * vlib_buffer_copy(vlib_main_t *vm, vlib_buffer_t *b)
u8 default_buffer_pool_index_for_numa[VLIB_BUFFER_MAX_NUMA_NODES]
STATIC_ASSERT_OFFSET_OF(vlib_buffer_t, template_end, 64)
u8 buffer_pool_index
index of buffer pool this buffer belongs.
static_always_inline void vlib_get_buffer_indices(vlib_main_t *vm, vlib_buffer_t **b, u32 *bi, uword count)
Translate array of buffer pointers into buffer indices.
format_function_t format_vlib_buffer_no_chain
vlib_buffer_pool_thread_t * threads
#define static_always_inline
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
static u32 vlib_get_buffer_index(vlib_main_t *vm, void *p)
Translate buffer pointer into buffer index.
static u16 vlib_buffer_chain_append_data(vlib_main_t *vm, vlib_buffer_t *first, vlib_buffer_t *last, void *data, u16 data_len)
epu8_epi32 epu16_epi32 u64x2
static void vlib_buffer_free_from_ring(vlib_main_t *vm, u32 *ring, u32 start, u32 ring_size, u32 n_buffers)
Free buffers from ring.
static heap_elt_t * first(heap_header_t *h)
static u32 vlib_buffer_chain_linearize(vlib_main_t *vm, vlib_buffer_t *b)
static vlib_buffer_t * vlib_buffer_copy_no_chain(vlib_main_t *vm, vlib_buffer_t *b, u32 *di)
u32 min_n_buffers_each_alloc
u8 * vlib_validate_buffer(vlib_main_t *vm, u32 buffer_index, uword follow_chain)
static_always_inline void vlib_buffer_copy_template(vlib_buffer_t *b, vlib_buffer_t *bt)
format_function_t format_vlib_buffer_and_data
static void vlib_buffer_validate(vlib_main_t *vm, vlib_buffer_t *b)
vlib_buffer_t buffer_template
u8 * vlib_validate_buffers(vlib_main_t *vm, u32 *buffers, uword next_buffer_stride, uword n_buffers, vlib_buffer_known_state_t known_state, uword follow_buffer_next)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
static_always_inline uword vlib_buffer_pool_get(vlib_main_t *vm, u8 buffer_pool_index, u32 *buffers, u32 n_buffers)
static_always_inline u32x4 u32x4_shuffle(u32x4 v, const int a, const int b, const int c, const int d)
vlib_buffer_pool_t * buffer_pools
u32 trace_handle
Specifies trace buffer handle if VLIB_PACKET_IS_TRACED flag is set.
static_always_inline void vlib_get_buffer_indices_with_offset(vlib_main_t *vm, void **b, u32 *bi, uword count, i32 offset)
Translate array of buffer pointers into buffer indices with offset.
static uword vlib_buffer_contents(vlib_main_t *vm, u32 buffer_index, u8 *contents)
Copy buffer contents to memory.
static void vlib_buffer_chain_init(vlib_buffer_t *first)
#define clib_atomic_sub_fetch(a, b)
static_always_inline u32 vlib_buffer_get_default_data_size(vlib_main_t *vm)
clib_spinlock_t buffer_known_hash_lockp
static void vlib_buffer_free_no_next(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers, does not free the buffer chain for each buffer.
static u16 vlib_buffer_clone(vlib_main_t *vm, u32 src_buffer, u32 *buffers, u16 n_buffers, u16 head_end_offset)
Create multiple clones of buffer and store them in the supplied array.
static_always_inline void vlib_buffer_pool_put(vlib_main_t *vm, u8 buffer_pool_index, u32 *buffers, u32 n_buffers)
void vlib_buffer_chain_validate(vlib_main_t *vm, vlib_buffer_t *first)
#define vec_free(V)
Free vector's memory (no header).
#define VLIB_BUFFER_MAX_NUMA_NODES
static vlib_buffer_t * vlib_get_next_buffer(vlib_main_t *vm, vlib_buffer_t *b)
Get next buffer in buffer linklist, or zero for end of list.
void vlib_buffer_validate_alloc_free(vlib_main_t *vm, u32 *buffers, uword n_buffers, vlib_buffer_known_state_t expected_state)
static u32 vlib_buffer_space_left_at_end(vlib_main_t *vm, vlib_buffer_t *b)
static uword round_pow2(uword x, uword pow2)
vlib_buffer_known_state_t
static_always_inline u64x2 u32x4_extend_to_u64x2(u32x4 v)
static u32 vlib_buffer_alloc_from_pool(vlib_main_t *vm, u32 *buffers, u32 n_buffers, u8 buffer_pool_index)
Allocate buffers from specific pool into supplied array.
#define uword_to_pointer(u, type)
vlib buffer structure definition and a few select access methods.
static u16 vlib_buffer_clone_at_offset(vlib_main_t *vm, u32 src_buffer, u32 *buffers, u16 n_buffers, u16 head_end_offset, i16 offset)
Create multiple clones of buffer and store them in the supplied array.
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
static uword vlib_buffer_index_length_in_chain(vlib_main_t *vm, u32 bi)
Get length in bytes of the buffer index buffer chain.
static void * vlib_buffer_ptr_from_index(uword buffer_mem_start, u32 buffer_index, uword offset)
static_always_inline void vlib_buffer_free_inline(vlib_main_t *vm, u32 *buffers, u32 n_buffers, int maybe_next)
static uword pointer_to_uword(const void *p)
template key/value backing page structure
static u64 vlib_physmem_get_pa(vlib_main_t *vm, void *mem)
static u32 vlib_buffer_alloc_to_ring(vlib_main_t *vm, u32 *ring, u32 start, u32 ring_size, u32 n_buffers)
Allocate buffers into ring.
static_always_inline void vlib_buffer_copy_indices(u32 *dst, u32 *src, u32 n_indices)
static vlib_buffer_t * vlib_buffer_chain_buffer(vlib_main_t *vm, vlib_buffer_t *last, u32 next_bi)
#define VLIB_BUFFER_POOL_PER_THREAD_CACHE_SZ
u32 next_buffer
Next buffer for this linked-list of buffers.
u32 cached_buffers[VLIB_BUFFER_POOL_PER_THREAD_CACHE_SZ]
#define VLIB_BUFFER_TRACE_TRAJECTORY_INIT(b)
VLIB buffer representation.
uword * buffer_known_hash
struct clib_bihash_value offset
template key/value backing page structure
void * vlib_packet_template_get_packet(vlib_main_t *vm, vlib_packet_template_t *t, u32 *bi_result)
static u16 vlib_buffer_clone_256(vlib_main_t *vm, u32 src_buffer, u32 *buffers, u16 n_buffers, u16 head_end_offset, i16 offset)
Create a maximum of 256 clones of buffer and store them in the supplied array.
static void vlib_packet_template_free(vlib_main_t *vm, vlib_packet_template_t *t)
static void vlib_buffer_free_one(vlib_main_t *vm, u32 buffer_index)
Free one buffer Shorthand to free a single buffer chain.
static_always_inline void vlib_get_buffers(vlib_main_t *vm, u32 *bi, vlib_buffer_t **b, int count)
Translate array of buffer indices into buffer pointers.
#define CLIB_CACHE_LINE_BYTES
u32 total_length_not_including_first_buffer
Only valid for first buffer in chain.
void vlib_packet_template_init(vlib_main_t *vm, vlib_packet_template_t *t, void *packet_data, uword n_packet_data_bytes, uword min_n_buffers_each_alloc, char *fmt,...)
static u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
static u8 vlib_buffer_pool_get_default_for_numa(vlib_main_t *vm, u32 numa_node)
static void vlib_buffer_free_from_ring_no_next(vlib_main_t *vm, u32 *ring, u32 start, u32 ring_size, u32 n_buffers)
Free buffers from ring without freeing tail buffers.
volatile u8 ref_count
Reference count for this buffer.
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
u32 opaque[10]
Opaque data used by sub-graphs for their own purposes.