From b0203b5d47bb7910fb855099d53f96a59d3942e6 Mon Sep 17 00:00:00 2001 From: Yonggang Luo Date: Sat, 19 Nov 2022 07:34:59 +0800 Subject: [PATCH] util: Move EXCLUSIVE_CACHELINE and CACHE_LINE_SIZE macros into u_memory.h They are coupled with MALLOC_STRUCT_CL, so move them into a single place and accessed consistently Signed-off-by: Yonggang Luo Reviewed-by: Erik Faye-Lund Part-of: --- src/gallium/include/pipe/p_compiler.h | 18 ------------------ src/gallium/include/pipe/p_state.h | 2 ++ src/util/macros.h | 3 --- src/util/u_memory.h | 20 ++++++++++++++++++++ 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/gallium/include/pipe/p_compiler.h b/src/gallium/include/pipe/p_compiler.h index 070224fb4bd..7d1ddd84f86 100644 --- a/src/gallium/include/pipe/p_compiler.h +++ b/src/gallium/include/pipe/p_compiler.h @@ -86,24 +86,6 @@ typedef unsigned char boolean; #define PIPE_CDECL #endif -/** - * Declare a variable on its own cache line. - * - * This helps eliminate "False sharing" to make atomic operations - * on pipe_reference::count faster and/or access to adjacent fields faster. - * - * https://en.wikipedia.org/wiki/False_sharing - * - * CALLOC_STRUCT_CL or MALLOC_STRUCT_CL and FREE_CL should be used to allocate - * structures that contain this. - * - * NOTE: Don't use c11 alignas because it causes the whole structure to be - * aligned, but we only want to align the field. - */ -#define EXCLUSIVE_CACHELINE(decl) \ - union { char __cl_space[CACHE_LINE_SIZE]; \ - decl; } - #if defined(__cplusplus) } #endif diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h index e2003f3369f..d73929905c9 100644 --- a/src/gallium/include/pipe/p_state.h +++ b/src/gallium/include/pipe/p_state.h @@ -44,6 +44,8 @@ #ifndef PIPE_STATE_H #define PIPE_STATE_H +#include "util/u_memory.h" + #include "p_compiler.h" #include "p_defines.h" #include "util/format/u_formats.h" diff --git a/src/util/macros.h b/src/util/macros.h index cb6b5a753a2..399675f9538 100644 --- a/src/util/macros.h +++ b/src/util/macros.h @@ -452,9 +452,6 @@ typedef int lock_cap_t; #endif -/* TODO: this could be different on non-x86 architectures. */ -#define CACHE_LINE_SIZE 64 - #define DO_PRAGMA(X) _Pragma (#X) #if defined(__clang__) diff --git a/src/util/u_memory.h b/src/util/u_memory.h index cff7b53ac57..bc28cf44026 100644 --- a/src/util/u_memory.h +++ b/src/util/u_memory.h @@ -89,6 +89,26 @@ mem_dup(const void *src, size_t size) */ #define Offset(TYPE, MEMBER) ((uintptr_t)&(((TYPE *)NULL)->MEMBER)) +/* TODO: this could be different on non-x86 architectures. */ +#define CACHE_LINE_SIZE 64 + +/** + * Declare a variable on its own cache line. + * + * This helps eliminate "False sharing" to make atomic operations + * on pipe_reference::count faster and/or access to adjacent fields faster. + * + * https://en.wikipedia.org/wiki/False_sharing + * + * CALLOC_STRUCT_CL or MALLOC_STRUCT_CL and FREE_CL should be used to allocate + * structures that contain this. + * + * NOTE: Don't use c11 alignas because it causes the whole structure to be + * aligned, but we only want to align the field. + */ +#define EXCLUSIVE_CACHELINE(decl) \ + union { char __cl_space[CACHE_LINE_SIZE]; \ + decl; } /* Allocate a structure aligned to a cache line. (used to make atomic ops faster) */ #define MALLOC_STRUCT_CL(T) (struct T *)align_malloc(sizeof(struct T), CACHE_LINE_SIZE)