lib: use C99 syntax for zero-size arrays
[dpdk.git] / lib / librte_sched / rte_bitmap.h
index 89ed7fb..1b5df02 100644 (file)
@@ -45,11 +45,11 @@ extern "C" {
  * The bitmap component provides a mechanism to manage large arrays of bits
  * through bit get/set/clear and bit array scan operations.
  *
- * The bitmap scan operation is optimized for 64-bit CPUs using 64-byte cache
+ * The bitmap scan operation is optimized for 64-bit CPUs using 64/128 byte cache
  * lines. The bitmap is hierarchically organized using two arrays (array1 and
  * array2), with each bit in array1 being associated with a full cache line
- * (512 bits) of bitmap bits, which are stored in array2: the bit in array1 is
- * set only when there is at least one bit set within its associated array2
+ * (512/1024 bits) of bitmap bits, which are stored in array2: the bit in array1
+ * is set only when there is at least one bit set within its associated array2
  * bits, otherwise the bit in array1 is cleared. The read and write operations
  * for array1 and array2 are always done in slabs of 64 bits.
  *
@@ -73,9 +73,6 @@ extern "C" {
 #ifndef RTE_BITMAP_OPTIMIZATIONS
 #define RTE_BITMAP_OPTIMIZATIONS                        1
 #endif
-#if RTE_BITMAP_OPTIMIZATIONS
-#include <tmmintrin.h>
-#endif
 
 /* Slab */
 #define RTE_BITMAP_SLAB_BIT_SIZE                 64
@@ -83,12 +80,12 @@ extern "C" {
 #define RTE_BITMAP_SLAB_BIT_MASK                 (RTE_BITMAP_SLAB_BIT_SIZE - 1)
 
 /* Cache line (CL) */
-#define RTE_BITMAP_CL_BIT_SIZE                   (CACHE_LINE_SIZE * 8)
-#define RTE_BITMAP_CL_BIT_SIZE_LOG2              9
+#define RTE_BITMAP_CL_BIT_SIZE                   (RTE_CACHE_LINE_SIZE * 8)
+#define RTE_BITMAP_CL_BIT_SIZE_LOG2              (RTE_CACHE_LINE_SIZE_LOG2 + 3)
 #define RTE_BITMAP_CL_BIT_MASK                   (RTE_BITMAP_CL_BIT_SIZE - 1)
 
 #define RTE_BITMAP_CL_SLAB_SIZE                  (RTE_BITMAP_CL_BIT_SIZE / RTE_BITMAP_SLAB_BIT_SIZE)
-#define RTE_BITMAP_CL_SLAB_SIZE_LOG2             3
+#define RTE_BITMAP_CL_SLAB_SIZE_LOG2             (RTE_BITMAP_CL_BIT_SIZE_LOG2 - RTE_BITMAP_SLAB_BIT_SIZE_LOG2)
 #define RTE_BITMAP_CL_SLAB_MASK                  (RTE_BITMAP_CL_SLAB_SIZE - 1)
 
 /** Bitmap data structure */
@@ -106,7 +103,7 @@ struct rte_bitmap {
        uint32_t go2;     /**< Bitmap scan: Go/stop condition for current array2 cache line */
 
        /* Storage space for array1 and array2 */
-       uint8_t memory[0];
+       uint8_t memory[];
 };
 
 static inline void
@@ -118,7 +115,7 @@ __rte_bitmap_index1_inc(struct rte_bitmap *bmp)
 static inline uint64_t
 __rte_bitmap_mask1_get(struct rte_bitmap *bmp)
 {
-       return ((~1lu) << bmp->offset1);
+       return (~1lu) << bmp->offset1;
 }
 
 static inline void
@@ -178,7 +175,7 @@ __rte_bitmap_get_memory_footprint(uint32_t n_bits,
        n_slabs_array1 = rte_align32pow2(n_slabs_array1);
        n_slabs_context = (sizeof(struct rte_bitmap) + (RTE_BITMAP_SLAB_BIT_SIZE / 8) - 1) / (RTE_BITMAP_SLAB_BIT_SIZE / 8);
        n_cache_lines_context_and_array1 = (n_slabs_context + n_slabs_array1 + RTE_BITMAP_CL_SLAB_SIZE - 1) / RTE_BITMAP_CL_SLAB_SIZE;
-       n_bytes_total = (n_cache_lines_context_and_array1 + n_cache_lines_array2) * CACHE_LINE_SIZE;
+       n_bytes_total = (n_cache_lines_context_and_array1 + n_cache_lines_array2) * RTE_CACHE_LINE_SIZE;
 
        if (array1_byte_offset) {
                *array1_byte_offset = n_slabs_context * (RTE_BITMAP_SLAB_BIT_SIZE / 8);
@@ -187,7 +184,7 @@ __rte_bitmap_get_memory_footprint(uint32_t n_bits,
                *array1_slabs = n_slabs_array1;
        }
        if (array2_byte_offset) {
-               *array2_byte_offset = n_cache_lines_context_and_array1 * CACHE_LINE_SIZE;
+               *array2_byte_offset = n_cache_lines_context_and_array1 * RTE_CACHE_LINE_SIZE;
        }
        if (array2_slabs) {
                *array2_slabs = n_cache_lines_array2 * RTE_BITMAP_CL_SLAB_SIZE;
@@ -228,14 +225,14 @@ rte_bitmap_get_memory_footprint(uint32_t n_bits) {
 /**
  * Bitmap initialization
  *
- * @param bmp
- *   Handle to bitmap instance
- * @param array2
- *   Base address of pre-allocated array2
+ * @param mem_size
+ *   Minimum expected size of bitmap.
+ * @param mem
+ *   Base address of array1 and array2.
  * @param n_bits
  *   Number of pre-allocated bits in array2. Must be non-zero and multiple of 512.
  * @return
- *   0 upon success, error code otherwise
+ *   Handle to bitmap instance.
  */
 static inline struct rte_bitmap *
 rte_bitmap_init(uint32_t n_bits, uint8_t *mem, uint32_t mem_size)
@@ -249,7 +246,7 @@ rte_bitmap_init(uint32_t n_bits, uint8_t *mem, uint32_t mem_size)
                return NULL;
        }
 
-       if ((mem == NULL) || (((uintptr_t) mem) & CACHE_LINE_MASK)) {
+       if ((mem == NULL) || (((uintptr_t) mem) & RTE_CACHE_LINE_MASK)) {
                return NULL;
        }
 
@@ -347,7 +344,7 @@ rte_bitmap_get(struct rte_bitmap *bmp, uint32_t pos)
        index2 = pos >> RTE_BITMAP_SLAB_BIT_SIZE_LOG2;
        offset2 = pos & RTE_BITMAP_SLAB_BIT_MASK;
        slab2 = bmp->array2 + index2;
-       return ((*slab2) & (1lu << offset2));
+       return (*slab2) & (1lu << offset2);
 }
 
 /**
@@ -415,7 +412,7 @@ __rte_bitmap_line_not_empty(uint64_t *slab2)
        v1 |= v2;
        v3 |= v4;
 
-       return (v1 | v3);
+       return v1 | v3;
 }
 
 /**