vlib: vlib_buffer_t should be always 128 bytes, not 2 cachelines
[vpp.git] / src / vlib / buffer.h
index c8761af..d1a00bb 100644 (file)
@@ -72,7 +72,7 @@
  */
 #define foreach_vlib_buffer_flag \
   _( 0, IS_TRACED, 0)                                  \
-  _( 1, NEXT_PRESENT, 0)                               \
+  _( 1, NEXT_PRESENT, "next-present")                  \
   _( 2, TOTAL_LENGTH_VALID, 0)                         \
   _( 3, EXT_HDR_VALID, "ext-hdr-valid")
 
@@ -155,8 +155,8 @@ typedef union
     /** 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);
+    /** start of 2nd half (2nd cacheline on systems where cacheline size is 64) */
+      CLIB_ALIGN_MARK (second_half, 64);
 
     /** Specifies trace buffer handle if VLIB_PACKET_IS_TRACED flag is
       * set. */
@@ -169,8 +169,8 @@ typedef union
     /**< More opaque data, see ../vnet/vnet/buffer.h */
     u32 opaque2[14];
 
-    /** start of third cache line */
-      CLIB_CACHE_LINE_ALIGN_MARK (cacheline2);
+    /** start of buffer headroom */
+      CLIB_ALIGN_MARK (headroom, 64);
 
     /** Space for inserting data before buffer start.  Packet rewrite string
       * will be rewritten backwards and may extend back before
@@ -178,7 +178,7 @@ typedef union
     u8 pre_data[VLIB_BUFFER_PRE_DATA_SIZE];
 
     /** Packet data */
-    u8 data[0];
+    u8 data[];
   };
 #ifdef CLIB_HAVE_VEC128
   u8x16 as_u8x16[4];
@@ -191,6 +191,10 @@ typedef union
 #endif
 } vlib_buffer_t;
 
+STATIC_ASSERT_SIZEOF (vlib_buffer_t, 128 + VLIB_BUFFER_PRE_DATA_SIZE);
+STATIC_ASSERT (VLIB_BUFFER_PRE_DATA_SIZE % CLIB_CACHE_LINE_BYTES == 0,
+              "VLIB_BUFFER_PRE_DATA_SIZE must be divisible by cache line size");
+
 #define VLIB_BUFFER_HDR_SIZE  (sizeof(vlib_buffer_t) - VLIB_BUFFER_PRE_DATA_SIZE)
 
 /** \brief Prefetch buffer metadata.
@@ -349,7 +353,6 @@ vlib_buffer_push_uninit (vlib_buffer_t * b, u8 size)
 always_inline void *
 vlib_buffer_make_headroom (vlib_buffer_t * b, u8 size)
 {
-  ASSERT (b->current_data + VLIB_BUFFER_PRE_DATA_SIZE >= size);
   b->current_data += size;
   return vlib_buffer_get_current (b);
 }
@@ -411,12 +414,15 @@ vlib_buffer_pull (vlib_buffer_t * b, u8 size)
 /* Forward declaration. */
 struct vlib_main_t;
 
+#define VLIB_BUFFER_POOL_PER_THREAD_CACHE_SZ 512
+
 typedef struct
 {
   CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
-  u32 *cached_buffers;
-  u32 n_alloc;
+  u32 cached_buffers[VLIB_BUFFER_POOL_PER_THREAD_CACHE_SZ];
+  u32 n_cached;
 } vlib_buffer_pool_thread_t;
+
 typedef struct
 {
   CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
@@ -428,6 +434,7 @@ typedef struct
   u32 physmem_map_index;
   u32 data_size;
   u32 n_buffers;
+  u32 n_avail;
   u32 *buffers;
   u8 *name;
   clib_spinlock_t lock;