X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvlib%2Fbuffer.h;h=0fd57f5275be6279487da056377325a43d7c4c9b;hb=f2922422d972644e67d1ca989e40cd0100ecb06d;hp=af9df685376c4d16dabb6a37b1d9ae574e032592;hpb=b67196d8233ee89e79e0e6b05c3fa95a5fb6a579;p=vpp.git diff --git a/src/vlib/buffer.h b/src/vlib/buffer.h index af9df685376..0fd57f5275b 100644 --- a/src/vlib/buffer.h +++ b/src/vlib/buffer.h @@ -48,9 +48,10 @@ #include /* for vlib_error_t */ #include /* for __PRE_DATA_SIZE */ -#define VLIB_BUFFER_DATA_SIZE (2048) #define VLIB_BUFFER_PRE_DATA_SIZE __PRE_DATA_SIZE +#define VLIB_BUFFER_DEFAULT_DATA_SIZE (2048) + /* Minimum buffer chain segment size. Does not apply to last buffer in chain. Dataplane code can safely asume that specified amount of data is not split into 2 chained buffers */ @@ -59,8 +60,6 @@ /* Amount of head buffer data copied to each replica head buffer */ #define VLIB_BUFFER_CLONE_HEAD_SIZE (256) -typedef u8 vlib_buffer_free_list_index_t; - /** \file vlib buffer structure definition and a few select access methods. This structure and the buffer allocation @@ -99,82 +98,98 @@ enum #define VLIB_BUFFER_FLAG_USER(n) (1 << LOG2_VLIB_BUFFER_FLAG_USER(n)) #define VLIB_BUFFER_FLAGS_ALL (0x0f) -/* VLIB buffer representation. */ -typedef struct +/** VLIB buffer representation. */ +typedef union { - CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); - /* Offset within data[] that we are currently processing. - If negative current header points into predata area. */ - i16 current_data; /**< signed offset in data[], pre_data[] - that we are currently processing. - If negative current header points into predata area. - */ - u16 current_length; /**< Nbytes between current data and - the end of this buffer. - */ - u32 flags; /**< buffer flags: -
VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, -
VLIB_BUFFER_IS_TRACED: trace this buffer. -
VLIB_BUFFER_NEXT_PRESENT: this is a multi-chunk buffer. -
VLIB_BUFFER_TOTAL_LENGTH_VALID: as it says -
VLIB_BUFFER_EXT_HDR_VALID: buffer contains valid external buffer manager header, - set to avoid adding it to a flow report -
VLIB_BUFFER_FLAG_USER(n): user-defined bit N - */ - - u32 flow_id; /**< Generic flow identifier */ - - - u32 next_buffer; /**< Next buffer for this linked-list of buffers. - Only valid if VLIB_BUFFER_NEXT_PRESENT flag is set. - */ - - u32 current_config_index; /**< Used by feature subgraph arcs to - visit enabled feature nodes - */ - vlib_error_t error; /**< Error code for buffers to be enqueued - to error handler. - */ - u8 n_add_refs; /**< Number of additional references to this buffer. */ - - u8 buffer_pool_index; /**< index of buffer pool this buffer belongs. */ - - u32 opaque[10]; /**< Opaque data used by sub-graphs for their own purposes. - See .../vnet/vnet/buffer.h - */ - - STRUCT_MARK (template_end); /**< part of buffer metadata which is - initialized on alloc ends here. It may be - different than cacheline on systems with - buffer cacheline size */ - - /***** end of first cache line */ - CLIB_CACHE_LINE_ALIGN_MARK (cacheline1); - - u32 trace_index; /**< Specifies index into trace buffer - if VLIB_PACKET_IS_TRACED flag is set. - */ - u32 recycle_count; /**< Used by L2 path recycle code */ - - u32 total_length_not_including_first_buffer; - /**< Only valid for first buffer in chain. Current length plus - total length given here give total number of bytes in buffer chain. - */ - u8 align_pad[4]; /**< available */ - u32 opaque2[12]; /**< More opaque data, see ../vnet/vnet/buffer.h */ - - /***** end of second cache line */ - CLIB_CACHE_LINE_ALIGN_MARK (cacheline2); - u8 pre_data[VLIB_BUFFER_PRE_DATA_SIZE]; /**< Space for inserting data - before buffer start. - Packet rewrite string will be - rewritten backwards and may extend - back before buffer->data[0]. - Must come directly before packet data. - */ - - u8 data[0]; /**< Packet data. Hardware DMA here */ -} vlib_buffer_t; /* Must be a multiple of 64B. */ + struct + { + CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); + + /** signed offset in data[], pre_data[] that we are currently + * processing. If negative current header points into predata area. */ + i16 current_data; + + /** Nbytes between current data and the end of this buffer. */ + u16 current_length; + + /** buffer flags: +
VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, +
VLIB_BUFFER_IS_TRACED: trace this buffer. +
VLIB_BUFFER_NEXT_PRESENT: this is a multi-chunk buffer. +
VLIB_BUFFER_TOTAL_LENGTH_VALID: as it says +
VLIB_BUFFER_EXT_HDR_VALID: buffer contains valid external buffer manager header, + set to avoid adding it to a flow report +
VLIB_BUFFER_FLAG_USER(n): user-defined bit N + */ + u32 flags; + + /** Generic flow identifier */ + u32 flow_id; + + /** Reference count for this buffer. */ + volatile u8 ref_count; + + /** index of buffer pool this buffer belongs. */ + u8 buffer_pool_index; + + /** Error code for buffers to be enqueued to error handler. */ + vlib_error_t error; + + /** Next buffer for this linked-list of buffers. Only valid if + * VLIB_BUFFER_NEXT_PRESENT flag is set. */ + u32 next_buffer; + + /** The following fields can be in a union because once a packet enters + * the punt path, it is no longer on a feature arc */ + union + { + /** Used by feature subgraph arcs to visit enabled feature nodes */ + u32 current_config_index; + /* the reason the packet once punted */ + u32 punt_reason; + }; + + /** Opaque data used by sub-graphs for their own purposes. */ + u32 opaque[10]; + + /** part of buffer metadata which is initialized on alloc ends here. */ + STRUCT_MARK (template_end); + + /** start of 2nd cache line */ + CLIB_CACHE_LINE_ALIGN_MARK (cacheline1); + + /** Specifies index into trace buffer if VLIB_PACKET_IS_TRACED flag is + * set. */ + u32 trace_index; + + /** Only valid for first buffer in chain. Current length plus total length + * given here give total number of bytes in buffer chain. */ + u32 total_length_not_including_first_buffer; + + /**< More opaque data, see ../vnet/vnet/buffer.h */ + u32 opaque2[14]; + + /** start of third cache line */ + CLIB_CACHE_LINE_ALIGN_MARK (cacheline2); + + /** Space for inserting data before buffer start. Packet rewrite string + * will be rewritten backwards and may extend back before + * buffer->data[0]. Must come directly before packet data. */ + u8 pre_data[VLIB_BUFFER_PRE_DATA_SIZE]; + + /** Packet data */ + u8 data[0]; + }; +#ifdef CLIB_HAVE_VEC128 + u8x16 as_u8x16[4]; +#endif +#ifdef CLIB_HAVE_VEC256 + u8x32 as_u8x32[2]; +#endif +#ifdef CLIB_HAVE_VEC512 + u8x64 as_u8x64[1]; +#endif +} vlib_buffer_t; #define VLIB_BUFFER_HDR_SIZE (sizeof(vlib_buffer_t) - VLIB_BUFFER_PRE_DATA_SIZE) @@ -358,71 +373,36 @@ vlib_buffer_pull (vlib_buffer_t * b, u8 size) /* Forward declaration. */ struct vlib_main_t; -typedef struct vlib_buffer_free_list_t -{ - /* Template buffer used to initialize first 16 bytes of buffers - allocated on this free list. */ - vlib_buffer_t buffer_init_template; - - /* Our index into vlib_main_t's buffer_free_list_pool. */ - vlib_buffer_free_list_index_t index; - - /* Number of data bytes for buffers in this free list. */ - u32 n_data_bytes; - - /* Number of buffers to allocate when we need to allocate new buffers */ - u32 min_n_buffers_each_alloc; - - /* Total number of buffers allocated from this free list. */ - u32 n_alloc; - - /* Vector of free buffers. Each element is a byte offset into I/O heap. */ - u32 *buffers; - - /* index of buffer pool used to get / put buffers */ - u8 buffer_pool_index; - - /* Free list name. */ - u8 *name; - - /* Callback functions to initialize newly allocated buffers. - If null buffers are zeroed. */ - void (*buffer_init_function) (struct vlib_main_t * vm, - struct vlib_buffer_free_list_t * fl, - u32 * buffers, u32 n_buffers); - - uword buffer_init_function_opaque; -} __attribute__ ((aligned (16))) vlib_buffer_free_list_t; - -typedef uword (vlib_buffer_fill_free_list_cb_t) (struct vlib_main_t * vm, - vlib_buffer_free_list_t * fl, - uword min_free_buffers); -typedef void (vlib_buffer_free_cb_t) (struct vlib_main_t * vm, u32 * buffers, - u32 n_buffers); -typedef void (vlib_buffer_free_no_next_cb_t) (struct vlib_main_t * vm, - u32 * buffers, u32 n_buffers); - typedef struct { - vlib_buffer_fill_free_list_cb_t *vlib_buffer_fill_free_list_cb; - vlib_buffer_free_cb_t *vlib_buffer_free_cb; - vlib_buffer_free_no_next_cb_t *vlib_buffer_free_no_next_cb; -} vlib_buffer_callbacks_t; - -extern vlib_buffer_callbacks_t *vlib_buffer_callbacks; - + CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); + u32 *cached_buffers; + u32 n_alloc; +} vlib_buffer_pool_thread_t; typedef struct { CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); uword start; uword size; uword log2_page_size; + u8 index; + u32 numa_node; u32 physmem_map_index; - u32 buffer_size; + u32 data_size; + u32 n_buffers; u32 *buffers; + u8 *name; clib_spinlock_t lock; + + /* per-thread data */ + vlib_buffer_pool_thread_t *threads; + + /* buffer metadata template */ + vlib_buffer_t buffer_template; } vlib_buffer_pool_t; +#define VLIB_BUFFER_MAX_NUMA_NODES 32 + typedef struct { CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); @@ -432,37 +412,25 @@ typedef struct uword buffer_mem_size; vlib_buffer_pool_t *buffer_pools; - /* Buffer free callback, for subversive activities */ - u32 (*buffer_free_callback) (struct vlib_main_t * vm, - u32 * buffers, - u32 n_buffers, u32 follow_buffer_next); -#define VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX (0) -#define VLIB_BUFFER_DEFAULT_FREE_LIST_BYTES VLIB_BUFFER_DATA_SIZE - - /* Hash table mapping buffer size (rounded to next unit of - sizeof (vlib_buffer_t)) to free list index. */ - uword *free_list_by_size; - /* Hash table mapping buffer index into number 0 => allocated but free, 1 => allocated and not-free. If buffer index is not in hash table then this buffer has never been allocated. */ uword *buffer_known_hash; clib_spinlock_t buffer_known_hash_lockp; + u8 default_buffer_pool_index_for_numa[VLIB_BUFFER_MAX_NUMA_NODES]; - /* Callbacks */ - vlib_buffer_callbacks_t cb; - int callbacks_registered; -} vlib_buffer_main_t; + /* config */ + u32 buffers_per_numa; + u16 ext_hdr_size; + u32 default_data_size; -u8 vlib_buffer_register_physmem_map (struct vlib_main_t *vm, - u32 physmem_map_index); + /* logging */ + vlib_log_class_t log_default; +} vlib_buffer_main_t; clib_error_t *vlib_buffer_main_init (struct vlib_main_t *vm); - -void *vlib_set_buffer_free_callback (struct vlib_main_t *vm, void *fp); - /* */ @@ -483,23 +451,17 @@ extern void vlib_buffer_trace_trajectory_init (vlib_buffer_t * b); #define VLIB_BUFFER_TRACE_TRAJECTORY_INIT(b) #endif /* VLIB_BUFFER_TRACE_TRAJECTORY */ -#endif /* included_vlib_buffer_h */ +extern u16 __vlib_buffer_external_hdr_size; +#define VLIB_BUFFER_SET_EXT_HDR_SIZE(x) \ +static void __clib_constructor \ +vnet_buffer_set_ext_hdr_size() \ +{ \ + if (__vlib_buffer_external_hdr_size) \ + clib_error ("buffer external header space already set"); \ + __vlib_buffer_external_hdr_size = CLIB_CACHE_LINE_ROUND (x); \ +} -#define VLIB_BUFFER_REGISTER_CALLBACKS(x,...) \ - __VA_ARGS__ vlib_buffer_callbacks_t __##x##_buffer_callbacks; \ -static void __vlib_add_buffer_callbacks_t_##x (void) \ - __attribute__((__constructor__)) ; \ -static void __vlib_add_buffer_callbacks_t_##x (void) \ -{ \ - if (vlib_buffer_callbacks) \ - clib_panic ("vlib buffer callbacks already registered"); \ - vlib_buffer_callbacks = &__##x##_buffer_callbacks; \ -} \ -static void __vlib_rm_buffer_callbacks_t_##x (void) \ - __attribute__((__destructor__)) ; \ -static void __vlib_rm_buffer_callbacks_t_##x (void) \ -{ vlib_buffer_callbacks = 0; } \ -__VA_ARGS__ vlib_buffer_callbacks_t __##x##_buffer_callbacks +#endif /* included_vlib_buffer_h */ /* * fd.io coding-style-patch-verification: ON