瀏覽代碼

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.
kleines Filmröllchen 3 年之前
父節點
當前提交
65b338ad04
共有 1 個文件被更改,包括 13 次插入0 次删除
  1. 13 0
      AK/Platform.h

+ 13 - 0
AK/Platform.h

@@ -110,3 +110,16 @@ extern "C" {
 #    define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC
 #    define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC
 #    define CLOCK_REALTIME_COARSE CLOCK_REALTIME
 #    define CLOCK_REALTIME_COARSE CLOCK_REALTIME
 #endif
 #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)