From 038dad7ef29b0b724071edb5f8cc7a9845584454 Mon Sep 17 00:00:00 2001 From: Damjan Marion Date: Fri, 19 Jan 2024 21:19:57 +0100 Subject: buffers: add compile-time option to set buffer alignment Type: improvement Change-Id: I88c4c45bed0bdd8686e17e4f77a7d32a08c995aa Signed-off-by: Damjan Marion --- src/cmake/platform/octeon10.cmake | 1 + src/vlib/CMakeLists.txt | 6 ++++++ src/vlib/buffer.c | 6 +----- src/vlib/buffer.h | 3 +-- src/vlib/config.h.in | 3 ++- 5 files changed, 11 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/cmake/platform/octeon10.cmake b/src/cmake/platform/octeon10.cmake index da7dbabdc7b..cc2b292a419 100644 --- a/src/cmake/platform/octeon10.cmake +++ b/src/cmake/platform/octeon10.cmake @@ -1,3 +1,4 @@ set(VPP_PLATFORM_CACHE_LINE_SIZE 64) set(VPP_PLATFORM_MARCH_FLAGS -march=armv8.3-a+crypto+sve2-bitperm) +set(VPP_PLATFORM_BUFFER_ALIGN 128) diff --git a/src/vlib/CMakeLists.txt b/src/vlib/CMakeLists.txt index 76de4edcde2..9c4121672a5 100644 --- a/src/vlib/CMakeLists.txt +++ b/src/vlib/CMakeLists.txt @@ -22,6 +22,12 @@ else() set(BUFFER_ALLOC_FAULT_INJECTOR 0 CACHE STRING "fault injector off") endif() +if(VPP_PLATFORM_BUFFER_ALIGN) + set(VLIB_BUFFER_ALIGN ${VPP_PLATFORM_BUFFER_ALIGN}) +else() + set(VLIB_BUFFER_ALIGN ${VPP_CACHE_LINE_SIZE}) +endif() + set(PRE_DATA_SIZE 128 CACHE STRING "Buffer headroom size.") if (CMAKE_BUILD_TYPE_UC STREQUAL "DEBUG") diff --git a/src/vlib/buffer.c b/src/vlib/buffer.c index 005326d3906..82fe6412781 100644 --- a/src/vlib/buffer.c +++ b/src/vlib/buffer.c @@ -471,11 +471,7 @@ static uword vlib_buffer_alloc_size (uword ext_hdr_size, uword data_size) { uword alloc_size = ext_hdr_size + sizeof (vlib_buffer_t) + data_size; - alloc_size = CLIB_CACHE_LINE_ROUND (alloc_size); - - /* in case when we have even number of cachelines, we add one more for - * better cache occupancy */ - alloc_size |= CLIB_CACHE_LINE_BYTES; + alloc_size = round_pow2 (alloc_size, VLIB_BUFFER_ALIGN); return alloc_size; } diff --git a/src/vlib/buffer.h b/src/vlib/buffer.h index a747ea9f966..7d45689ed19 100644 --- a/src/vlib/buffer.h +++ b/src/vlib/buffer.h @@ -47,8 +47,7 @@ #include #include /* for vlib_error_t */ -#include /* for __PRE_DATA_SIZE */ -#define VLIB_BUFFER_PRE_DATA_SIZE __PRE_DATA_SIZE +#include /* for VLIB_BUFFER_PRE_DATA_SIZE */ #define VLIB_BUFFER_DEFAULT_DATA_SIZE (2048) diff --git a/src/vlib/config.h.in b/src/vlib/config.h.in index 19ec10cfcca..b233b327d31 100644 --- a/src/vlib/config.h.in +++ b/src/vlib/config.h.in @@ -16,7 +16,8 @@ #ifndef included_vlib_config_h #define included_vlib_config_h -#define __PRE_DATA_SIZE @PRE_DATA_SIZE@ +#define VLIB_BUFFER_PRE_DATA_SIZE @PRE_DATA_SIZE@ +#define VLIB_BUFFER_ALIGN @VLIB_BUFFER_ALIGN@ #define VLIB_BUFFER_ALLOC_FAULT_INJECTOR @BUFFER_ALLOC_FAULT_INJECTOR@ #define VLIB_PROCESS_LOG2_STACK_SIZE @VLIB_PROCESS_LOG2_STACK_SIZE@ -- cgit 1.2.3-korg