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 <luoyonggang@gmail.com>
Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19918>
This commit is contained in:
Yonggang Luo 2022-11-19 07:34:59 +08:00 committed by Marge Bot
parent 50ab93afde
commit b0203b5d47
4 changed files with 22 additions and 21 deletions

View 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

View 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"

View 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__)

View 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)