From eb987d3a09f669787014b1553f032219522149e1 Mon Sep 17 00:00:00 2001 From: Dave Barach Date: Thu, 3 May 2018 08:26:39 -0400 Subject: Harmonize vec/pool_get_aligned object sizes and alignment requests Object sizes must evenly divide alignment requests, or vice versa. Otherwise, only the first object will be aligned as requested. Three choices: add CLIB_CACHE_LINE_ALIGN_MARK(align_me) at the end of structures, manually pad to an even divisor or multiple of the alignment request, or use plain vectors/pools. static assert for enforcement. Change-Id: I41aa6ff1a58267301d32aaf4b9cd24678ac1c147 Signed-off-by: Dave Barach --- src/vppinfra/pool.h | 2 ++ src/vppinfra/vec.h | 2 ++ 2 files changed, 4 insertions(+) (limited to 'src/vppinfra') diff --git a/src/vppinfra/pool.h b/src/vppinfra/pool.h index 14c6a75c13b..8b39a914eb5 100644 --- a/src/vppinfra/pool.h +++ b/src/vppinfra/pool.h @@ -190,6 +190,8 @@ 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); \ diff --git a/src/vppinfra/vec.h b/src/vppinfra/vec.h index e2cb24c5ce7..a029630559c 100644 --- a/src/vppinfra/vec.h +++ b/src/vppinfra/vec.h @@ -411,6 +411,8 @@ do { \ #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)) \ -- cgit 1.2.3-korg