From 21b737495b4acba14849ea33e7ac97803e021a35 Mon Sep 17 00:00:00 2001 From: Mateusz Guzik Date: Fri, 27 Jan 2017 14:53:09 +0000 Subject: [PATCH] Introduce __read_mostly and __exclusive_cache_line macros. The intended use is to annotate frequently used globals which either rarely change (and thus can be grouped in the same cacheline) or are an atomic counter (which means it may benefit from being the only variable in the cacheline). Linker script support is provided only for amd64. Architectures without it risk having other variables put in, i.e. as if they were not annotated. This is harmless from correctness point of view. Reviewed by: bde (previous version) MFC after: 1 month --- sys/compat/linuxkpi/common/include/linux/compiler.h | 1 - sys/conf/ldscript.amd64 | 11 +++++++++++ sys/dev/drm2/drm_os_freebsd.h | 1 - sys/sys/systm.h | 6 ++++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/linux/compiler.h b/sys/compat/linuxkpi/common/include/linux/compiler.h index c780abc8d0b0..c32f1fa002c0 100644 --- a/sys/compat/linuxkpi/common/include/linux/compiler.h +++ b/sys/compat/linuxkpi/common/include/linux/compiler.h @@ -67,7 +67,6 @@ #define typeof(x) __typeof(x) #define uninitialized_var(x) x = x -#define __read_mostly __attribute__((__section__(".data.read_mostly"))) #define __always_unused __unused #define __must_check __result_use_check diff --git a/sys/conf/ldscript.amd64 b/sys/conf/ldscript.amd64 index 5d86b0352e1b..e64a957c8c09 100644 --- a/sys/conf/ldscript.amd64 +++ b/sys/conf/ldscript.amd64 @@ -145,6 +145,17 @@ SECTIONS .got : { *(.got) } . = DATA_SEGMENT_RELRO_END (24, .); .got.plt : { *(.got.plt) } + . = ALIGN(64); + .data.read_mostly : + { + *(.data.read_mostly) + } + . = ALIGN(64); + .data.exclusive_cache_line : + { + *(.data.exclusive_cache_line) + } + . = ALIGN(64); .data : { *(.data .data.* .gnu.linkonce.d.*) diff --git a/sys/dev/drm2/drm_os_freebsd.h b/sys/dev/drm2/drm_os_freebsd.h index dc01c6a64595..11c9feb9b4aa 100644 --- a/sys/dev/drm2/drm_os_freebsd.h +++ b/sys/dev/drm2/drm_os_freebsd.h @@ -80,7 +80,6 @@ typedef void irqreturn_t; #define __init #define __exit -#define __read_mostly #define BUILD_BUG_ON(x) CTASSERT(!(x)) #define BUILD_BUG_ON_NOT_POWER_OF_2(x) diff --git a/sys/sys/systm.h b/sys/sys/systm.h index a1ce9b4a2246..6537b7bbbdc1 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -128,6 +128,12 @@ void kassert_panic(const char *fmt, ...) __printflike(1, 2); */ #define SCHEDULER_STOPPED() __predict_false(curthread->td_stopsched) +/* + * Align variables. + */ +#define __read_mostly __section(".data.read_mostly") +#define __exclusive_cache_line __aligned(CACHE_LINE_SIZE) \ + __section(".data.exclusive_cache_line") /* * XXX the hints declarations are even more misplaced than most declarations * in this file, since they are needed in one file (per arch) and only used