diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/vppinfra/pool.c | 6 | ||||
-rw-r--r-- | src/vppinfra/pool.h | 98 | ||||
-rw-r--r-- | src/vppinfra/vec.c | 23 | ||||
-rw-r--r-- | src/vppinfra/vec.h | 164 | ||||
-rw-r--r-- | src/vppinfra/vec_bootstrap.h | 30 |
5 files changed, 101 insertions, 220 deletions
diff --git a/src/vppinfra/pool.c b/src/vppinfra/pool.c index 0cd14d4bb97..ff7278b1dcd 100644 --- a/src/vppinfra/pool.c +++ b/src/vppinfra/pool.c @@ -48,9 +48,9 @@ _pool_init_fixed (void **pool_ptr, u32 elt_size, u32 max_elts) ASSERT (elt_size); ASSERT (max_elts); - v = vec_resize_allocate_memory (0, max_elts, elt_size * max_elts, - sizeof (pool_header_t), - CLIB_CACHE_LINE_BYTES, VEC_NUMA_UNSPECIFIED); + v = + vec_resize_allocate_memory (0, max_elts, elt_size * max_elts, + sizeof (pool_header_t), CLIB_CACHE_LINE_BYTES); ph = pool_header (v); ph->max_elts = max_elts; diff --git a/src/vppinfra/pool.h b/src/vppinfra/pool.h index 7a679cee5cb..45265b31cbc 100644 --- a/src/vppinfra/pool.h +++ b/src/vppinfra/pool.h @@ -180,62 +180,48 @@ pool_header_bytes (void *v) First search free list. If nothing is free extend vector of objects. */ -#define _pool_get_aligned_internal_numa(P,E,A,Z,N) \ -do { \ - pool_header_t * _pool_var (p) = pool_header (P); \ - uword _pool_var (l); \ - \ - STATIC_ASSERT(A==0 || ((A % sizeof(P[0]))==0) \ - || ((sizeof(P[0]) % A) == 0), \ - "Pool aligned alloc of incorrectly sized object"); \ - _pool_var (l) = 0; \ - if (P) \ - _pool_var (l) = vec_len (_pool_var (p)->free_indices); \ - \ - if (_pool_var (l) > 0) \ - { \ - /* Return free element from free list. */ \ - uword _pool_var (i) = \ - _pool_var (p)->free_indices[_pool_var (l) - 1]; \ - (E) = (P) + _pool_var (i); \ - _pool_var (p)->free_bitmap = \ - clib_bitmap_andnoti_notrim (_pool_var (p)->free_bitmap, \ - _pool_var (i)); \ - _vec_len (_pool_var (p)->free_indices) = _pool_var (l) - 1; \ - CLIB_MEM_UNPOISON((E), sizeof((E)[0])); \ - } \ - else \ - { \ - /* fixed-size, preallocated pools cannot expand */ \ - if ((P) && _pool_var(p)->max_elts) \ - { \ - clib_warning ("can't expand fixed-size pool"); \ - os_out_of_memory(); \ - } \ - /* Nothing on free list, make a new element and return it. */ \ - P = _vec_resize_numa (P, \ - /* length_increment */ 1, \ - /* new size */ (vec_len (P) + 1) * sizeof (P[0]), \ - pool_aligned_header_bytes, \ - /* align */ (A), \ - /* numa */ (N)); \ - E = vec_end (P) - 1; \ - } \ - if (Z) \ - memset(E, 0, sizeof(*E)); \ -} while (0) - -#define pool_get_aligned_zero_numa(P,E,A,Z,S) \ - _pool_get_aligned_internal_numa(P,E,A,Z,S) - -#define pool_get_aligned_numa(P,E,A,S) \ - _pool_get_aligned_internal_numa(P,E,A,0/*zero*/,S) - -#define pool_get_numa(P,E,S) \ - _pool_get_aligned_internal_numa(P,E,0/*align*/,0/*zero*/,S) - -#define _pool_get_aligned_internal(P,E,A,Z) \ - _pool_get_aligned_internal_numa(P,E,A,Z,VEC_NUMA_UNSPECIFIED) +#define _pool_get_aligned_internal(P, E, A, Z) \ + do \ + { \ + pool_header_t *_pool_var (p) = pool_header (P); \ + uword _pool_var (l); \ + \ + STATIC_ASSERT (A == 0 || ((A % sizeof (P[0])) == 0) || \ + ((sizeof (P[0]) % A) == 0), \ + "Pool aligned alloc of incorrectly sized object"); \ + _pool_var (l) = 0; \ + if (P) \ + _pool_var (l) = vec_len (_pool_var (p)->free_indices); \ + \ + if (_pool_var (l) > 0) \ + { \ + /* Return free element from free list. */ \ + uword _pool_var (i) = \ + _pool_var (p)->free_indices[_pool_var (l) - 1]; \ + (E) = (P) + _pool_var (i); \ + _pool_var (p)->free_bitmap = clib_bitmap_andnoti_notrim ( \ + _pool_var (p)->free_bitmap, _pool_var (i)); \ + _vec_len (_pool_var (p)->free_indices) = _pool_var (l) - 1; \ + CLIB_MEM_UNPOISON ((E), sizeof ((E)[0])); \ + } \ + else \ + { \ + /* fixed-size, preallocated pools cannot expand */ \ + if ((P) && _pool_var (p)->max_elts) \ + { \ + clib_warning ("can't expand fixed-size pool"); \ + os_out_of_memory (); \ + } \ + /* Nothing on free list, make a new element and return it. */ \ + P = _vec_resize (P, /* length_increment */ 1, \ + /* new size */ (vec_len (P) + 1) * sizeof (P[0]), \ + pool_aligned_header_bytes, /* align */ (A)); \ + E = vec_end (P) - 1; \ + } \ + if (Z) \ + memset (E, 0, sizeof (*E)); \ + } \ + while (0) /** Allocate an object E from a pool P with alignment A */ #define pool_get_aligned(P,E,A) _pool_get_aligned_internal(P,E,A,0) diff --git a/src/vppinfra/vec.c b/src/vppinfra/vec.c index ba842e64d25..300ef8520ed 100644 --- a/src/vppinfra/vec.c +++ b/src/vppinfra/vec.c @@ -45,28 +45,18 @@ /* Vector resize operator. Called as needed by various macros such as vec_add1() when we need to allocate memory. */ __clib_export void * -vec_resize_allocate_memory (void *v, - word length_increment, - uword data_bytes, - uword header_bytes, uword data_align, - uword numa_id) +vec_resize_allocate_memory (void *v, word length_increment, uword data_bytes, + uword header_bytes, uword data_align) { vec_header_t *vh = _vec_find (v); uword old_alloc_bytes, new_alloc_bytes; void *old, *new; - void *oldheap; header_bytes = vec_header_bytes (header_bytes); data_align = data_align == 0 ? 1 : data_align; data_bytes += header_bytes; - if (PREDICT_FALSE (numa_id != VEC_NUMA_UNSPECIFIED)) - { - oldheap = clib_mem_get_per_cpu_heap (); - clib_mem_set_per_cpu_heap (clib_mem_get_per_numa_heap (numa_id)); - } - /* alignment must be power of 2 */ ASSERT (count_set_bits (data_align) == 1); @@ -80,12 +70,9 @@ vec_resize_allocate_memory (void *v, CLIB_MEM_POISON (new + data_bytes, new_alloc_bytes - data_bytes); v = new + header_bytes; _vec_len (v) = length_increment; - _vec_numa (v) = numa_id; ASSERT (header_bytes / VEC_HEADER_ROUND <= 255); _vec_find (v)->hdr_size = header_bytes / VEC_HEADER_ROUND; _vec_find (v)->log2_align = min_log2 (data_align); - if (PREDICT_FALSE (numa_id != VEC_NUMA_UNSPECIFIED)) - clib_mem_set_per_cpu_heap (oldheap); return v; } @@ -107,8 +94,6 @@ vec_resize_allocate_memory (void *v, if (data_bytes <= old_alloc_bytes) { CLIB_MEM_UNPOISON (v, data_bytes); - if (PREDICT_FALSE (numa_id != VEC_NUMA_UNSPECIFIED)) - clib_mem_set_per_cpu_heap (oldheap); return v; } @@ -144,10 +129,6 @@ vec_resize_allocate_memory (void *v, memset (v + old_alloc_bytes, 0, new_alloc_bytes - old_alloc_bytes); CLIB_MEM_POISON (new + data_bytes, new_alloc_bytes - data_bytes); - _vec_numa ((v + header_bytes)) = numa_id; - if (PREDICT_FALSE (numa_id != VEC_NUMA_UNSPECIFIED)) - clib_mem_set_per_cpu_heap (oldheap); - return v + header_bytes; } diff --git a/src/vppinfra/vec.h b/src/vppinfra/vec.h index 7e4cc0f8959..1e2f614d910 100644 --- a/src/vppinfra/vec.h +++ b/src/vppinfra/vec.h @@ -96,14 +96,11 @@ @param data_bytes requested size in bytes @param header_bytes header size in bytes (may be zero) @param data_align alignment (may be zero) - @param numa_id numa id (may be zero) @return v_prime pointer to resized vector, may or may not equal v */ -void *vec_resize_allocate_memory (void *v, - word length_increment, - uword data_bytes, - uword header_bytes, uword data_align, - uword numa_id); +void *vec_resize_allocate_memory (void *v, word length_increment, + uword data_bytes, uword header_bytes, + uword data_align); /** \brief Low-level vector resize function, usually not called directly @@ -112,29 +109,23 @@ void *vec_resize_allocate_memory (void *v, @param data_bytes requested size in bytes @param header_bytes header size in bytes (may be zero) @param data_align alignment (may be zero) - @param numa_id (may be ~0) @return v_prime pointer to resized vector, may or may not equal v */ -#define _vec_resize_numa(V,L,DB,HB,A,S) \ -({ \ - __typeof__ ((V)) _V; \ - _V = _vec_resize_inline((void *)V,L,DB,HB,clib_max((__alignof__((V)[0])),(A)),(S)); \ - _V; \ -}) - -#define _vec_resize(V,L,DB,HB,A) \ - _vec_resize_numa(V,L,DB,HB,A,VEC_NUMA_UNSPECIFIED) +#define _vec_resize(V, L, DB, HB, A) \ + ({ \ + __typeof__ ((V)) _V; \ + _V = _vec_resize_inline ((void *) V, L, DB, HB, \ + clib_max ((__alignof__((V)[0])), (A))); \ + _V; \ + }) always_inline void * -_vec_resize_inline (void *v, - word length_increment, - uword data_bytes, uword header_bytes, uword data_align, - uword numa_id) +_vec_resize_inline (void *v, word length_increment, uword data_bytes, + uword header_bytes, uword data_align) { vec_header_t *vh = _vec_find (v); uword new_data_bytes, aligned_header_bytes; - void *oldheap; aligned_header_bytes = vec_header_bytes (header_bytes); @@ -144,12 +135,6 @@ _vec_resize_inline (void *v, { void *p = v - aligned_header_bytes; - if (PREDICT_FALSE (numa_id != VEC_NUMA_UNSPECIFIED)) - { - oldheap = clib_mem_get_per_cpu_heap (); - clib_mem_set_per_cpu_heap (clib_mem_get_per_numa_heap (numa_id)); - } - /* Vector header must start heap object. */ ASSERT (clib_mem_is_heap_object (p)); @@ -158,19 +143,14 @@ _vec_resize_inline (void *v, { CLIB_MEM_UNPOISON (v, data_bytes); vh->len += length_increment; - if (PREDICT_FALSE (numa_id != VEC_NUMA_UNSPECIFIED)) - clib_mem_set_per_cpu_heap (oldheap); return v; } - if (PREDICT_FALSE (numa_id != VEC_NUMA_UNSPECIFIED)) - clib_mem_set_per_cpu_heap (oldheap); } /* Slow path: call helper function. */ - return vec_resize_allocate_memory (v, length_increment, data_bytes, - header_bytes, - clib_max (sizeof (vec_header_t), - data_align), numa_id); + return vec_resize_allocate_memory ( + v, length_increment, data_bytes, header_bytes, + clib_max (sizeof (vec_header_t), data_align)); } /** \brief Determine if vector will resize with next allocation @@ -231,31 +211,18 @@ clib_mem_is_vec (void *v) @param N number of elements to add @param H header size in bytes (may be zero) @param A alignment (may be zero) - @param S numa_id (may be zero) @return V (value-result macro parameter) */ -#define vec_resize_has(V,N,H,A,S) \ -do { \ - word _v(n) = (N); \ - word _v(l) = vec_len (V); \ - V = _vec_resize_numa ((V), _v(n), \ - (_v(l) + _v(n)) * sizeof ((V)[0]), \ - (H), (A),(S)); \ -} while (0) - -/** \brief Resize a vector (less general version). - Add N elements to end of given vector V, return pointer to start of vector. - Vector will have room for H header bytes and will have user's data aligned - at alignment A (rounded to next power of 2). - - @param V pointer to a vector - @param N number of elements to add - @param H header size in bytes (may be zero) - @param A alignment (may be zero) - @return V (value-result macro parameter) -*/ -#define vec_resize_ha(V,N,H,A) vec_resize_has(V,N,H,A,VEC_NUMA_UNSPECIFIED) +#define vec_resize_ha(V, N, H, A) \ + do \ + { \ + word _v (n) = (N); \ + word _v (l) = vec_len (V); \ + V = _vec_resize ((V), _v (n), (_v (l) + _v (n)) * sizeof ((V)[0]), (H), \ + (A)); \ + } \ + while (0) /** \brief Resize a vector (no header, unspecified alignment) Add N elements to end of given vector V, return pointer to start of vector. @@ -374,34 +341,21 @@ void vec_free_not_inline (void *v); @param V pointer to a vector @param H size of header in bytes @param A alignment (may be zero) - @param S numa (may be VEC_NUMA_UNSPECIFIED) @return Vdup copy of vector */ -#define vec_dup_ha_numa(V,H,A,S) \ -({ \ - __typeof__ ((V)[0]) * _v(v) = 0; \ - uword _v(l) = vec_len (V); \ - if (_v(l) > 0) \ - { \ - vec_resize_has (_v(v), _v(l), (H), (A), (S)); \ - clib_memcpy_fast (_v(v), (V), _v(l) * sizeof ((V)[0]));\ - } \ - _v(v); \ -}) - -/** \brief Return copy of vector (VEC_NUMA_UNSPECIFIED). - - @param V pointer to a vector - @param H size of header in bytes - @param A alignment (may be zero) - - @return Vdup copy of vector -*/ -#define vec_dup_ha(V,H,A) \ - vec_dup_ha_numa(V,H,A,VEC_NUMA_UNSPECIFIED) - +#define vec_dup_ha(V, H, A) \ + ({ \ + __typeof__ ((V)[0]) *_v (v) = 0; \ + uword _v (l) = vec_len (V); \ + if (_v (l) > 0) \ + { \ + vec_resize_ha (_v (v), _v (l), (H), (A)); \ + clib_memcpy_fast (_v (v), (V), _v (l) * sizeof ((V)[0])); \ + } \ + _v (v); \ + }) /** \brief Return copy of vector (no header, no alignment) @@ -447,39 +401,27 @@ do { \ @param I vector index which will be valid upon return @param H header size in bytes (may be zero) @param A alignment (may be zero) - @param N numa_id (may be zero) @return V (value-result macro parameter) */ -#define vec_validate_han(V,I,H,A,N) \ -do { \ - void *oldheap; \ - STATIC_ASSERT(A==0 || ((A % sizeof(V[0]))==0) \ - || ((sizeof(V[0]) % A) == 0), \ - "vector validate aligned on incorrectly sized object"); \ - word _v(i) = (I); \ - word _v(l) = vec_len (V); \ - if (_v(i) >= _v(l)) \ - { \ - /* switch to the per-numa heap if directed */ \ - if (PREDICT_FALSE(N != VEC_NUMA_UNSPECIFIED)) \ - { \ - oldheap = clib_mem_get_per_cpu_heap(); \ - clib_mem_set_per_cpu_heap (clib_mem_get_per_numa_heap(N)); \ - } \ - \ - vec_resize_ha ((V), 1 + (_v(i) - _v(l)), (H), (A)); \ - /* Must zero new space since user may have previously \ - used e.g. _vec_len (v) -= 10 */ \ - clib_memset ((V) + _v(l), 0, \ - (1 + (_v(i) - _v(l))) * sizeof ((V)[0])); \ - /* Switch back to the global heap */ \ - if (PREDICT_FALSE (N != VEC_NUMA_UNSPECIFIED)) \ - clib_mem_set_per_cpu_heap (oldheap); \ - } \ -} while (0) - -#define vec_validate_ha(V,I,H,A) vec_validate_han(V,I,H,A,VEC_NUMA_UNSPECIFIED) +#define vec_validate_ha(V, I, H, A) \ + do \ + { \ + STATIC_ASSERT (A == 0 || ((A % sizeof (V[0])) == 0) || \ + ((sizeof (V[0]) % A) == 0), \ + "vector validate aligned on incorrectly sized object"); \ + word _v (i) = (I); \ + word _v (l) = vec_len (V); \ + if (_v (i) >= _v (l)) \ + { \ + vec_resize_ha ((V), 1 + (_v (i) - _v (l)), (H), (A)); \ + /* Must zero new space since user may have previously \ + used e.g. _vec_len (v) -= 10 */ \ + clib_memset ((V) + _v (l), 0, \ + (1 + (_v (i) - _v (l))) * sizeof ((V)[0])); \ + } \ + } \ + while (0) /** \brief Make sure vector is long enough for given index (no header, unspecified alignment) diff --git a/src/vppinfra/vec_bootstrap.h b/src/vppinfra/vec_bootstrap.h index 5dc1b6af540..bb6ac84e734 100644 --- a/src/vppinfra/vec_bootstrap.h +++ b/src/vppinfra/vec_bootstrap.h @@ -55,15 +55,12 @@ typedef struct { u32 len; /**< Number of elements in vector (NOT its allocated length). */ - u8 numa_id; /**< NUMA id */ u8 hdr_size; /**< header size divided by VEC_HEADER_ROUND */ u8 log2_align; /**< data alignment */ - u8 vpad[1]; /**< pad to 8 bytes */ + u8 vpad[2]; /**< pad to 8 bytes */ u8 vector_data[0]; /**< Vector data . */ } vec_header_t; -#define VEC_NUMA_UNSPECIFIED (0xFF) - #define VEC_HEADER_ROUND 8 /** \brief Find the vector header @@ -133,20 +130,6 @@ vec_header_end (void *v) #define vec_len(v) ((v) ? _vec_len(v) : 0) u32 vec_len_not_inline (void *v); -/** \brief Vector's NUMA id (lvalue-capable) - - _vec_numa(v) does not check for null, but can be used as an lvalue - (e.g. _vec_numa(v) = 1). -*/ - -#define _vec_numa(v) (_vec_find(v)->numa_id) - -/** \brief Return vector's NUMA ID (rvalue-only, NULL tolerant) - vec_numa(v) checks for NULL, but cannot be used as an lvalue. -*/ -#define vec_numa(v) ((v) ? _vec_numa(v) : 0) - - /** \brief Number of data bytes in vector. */ #define vec_bytes(v) (vec_len (v) * sizeof (v[0])) @@ -229,17 +212,6 @@ _vec_set_len (void *v, uword len, uword elt_size) if (v) \ for ((var) = vec_len ((v)) - 1; (var) >= 0; (var)--) -/** \brief return the NUMA index for a vector */ -always_inline uword -vec_get_numa (void *v) -{ - vec_header_t *vh; - if (v == 0) - return 0; - vh = _vec_find (v); - return vh->numa_id; -} - #endif /* included_clib_vec_bootstrap_h */ /* |