util: Move EXCLUSIVE_CACHELINE and CACHE_LINE_SIZE macros into u_memory.h
authorYonggang Luo <luoyonggang@gmail.com>
Fri, 18 Nov 2022 23:34:59 +0000 (07:34 +0800)
committerMarge Bot <emma+marge@anholt.net>
Thu, 24 Nov 2022 06:21:39 +0000 (06:21 +0000)
They are coupled with MALLOC_STRUCT_CL,  so  move them into a single place and accessed consistently

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19918>

src/gallium/include/pipe/p_compiler.h
src/gallium/include/pipe/p_state.h
src/util/macros.h
src/util/u_memory.h

index 070224f..7d1ddd8 100644 (file)
@@ -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
index e2003f3..d739299 100644 (file)
@@ -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"
index cb6b5a7..399675f 100644 (file)
@@ -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__)
index cff7b53..bc28cf4 100644 (file)
@@ -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)