diff options
author | kleines Filmröllchen <filmroellchen@serenityos.org> | 2022-03-04 14:57:38 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-04-21 13:55:00 +0200 |
commit | 65b338ad04e2c1943d039ed6e31f43f0aaa5db4c (patch) | |
tree | 19d8cf42e994ba048244cb39584b32a2a5a4491f /AK | |
parent | d463f6e00a29e552f26de923a5f762d37a47b66f (diff) | |
download | serenity-65b338ad04e2c1943d039ed6e31f43f0aaa5db4c.zip |
AK: Allow alignment to cache line size with CACHE_ALIGNED
This is particularly important to avoid false sharing, which thrashes
performance when two process-shared atomics are on the same cache line.
Diffstat (limited to 'AK')
-rw-r--r-- | AK/Platform.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/AK/Platform.h b/AK/Platform.h index d69ceba3af..b1534436d5 100644 --- a/AK/Platform.h +++ b/AK/Platform.h @@ -110,3 +110,16 @@ extern "C" { # define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC # define CLOCK_REALTIME_COARSE CLOCK_REALTIME #endif + +#ifndef SYSTEM_CACHE_ALIGNMENT_SIZE +# if ARCH(AARCH64) || ARCH(x86_64) +# define SYSTEM_CACHE_ALIGNMENT_SIZE 64 +# else +# define SYSTEM_CACHE_ALIGNMENT_SIZE 128 +# endif +#endif /* SYSTEM_CACHE_ALIGNMENT_SIZE */ + +#ifdef CACHE_ALIGNED +# undef CACHE_ALIGNED +#endif +#define CACHE_ALIGNED alignas(SYSTEM_CACHE_ALIGNMENT_SIZE) |