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
This commit is contained in:
Mateusz Guzik 2017-01-27 14:53:09 +00:00
parent a8fefd0ed5
commit 21b737495b
4 changed files with 17 additions and 2 deletions

View File

@ -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

View File

@ -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.*)

View File

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

View File

@ -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