diff options
author | Ian Moffett <ian@osmora.org> | 2024-06-07 21:25:10 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2024-06-07 21:25:10 -0400 |
commit | f8ce8234aa7247c8f3a4317f5671b5fd40ffb8c8 (patch) | |
tree | 4eb0667b44f557ea9c5449d932c19fc1db19889e /sys/include | |
parent | 19e1b54d12edbe80419b7fde9c602833544eb7ab (diff) |
kernel: Add __cacheline_aligned macro
This commit introduces a "__cacheline_aligned" macro which aligns data
by the cache line size (COHERENCY_UNIT bytes). This is useful for
heavily contended locks.
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys/include')
-rw-r--r-- | sys/include/sys/cdefs.h | 17 | ||||
-rw-r--r-- | sys/include/sys/param.h | 5 |
2 files changed, 22 insertions, 0 deletions
diff --git a/sys/include/sys/cdefs.h b/sys/include/sys/cdefs.h index fc21750..655a023 100644 --- a/sys/include/sys/cdefs.h +++ b/sys/include/sys/cdefs.h @@ -30,10 +30,27 @@ #ifndef _SYS_CDEFS_H_ #define _SYS_CDEFS_H_ +#include <sys/param.h> + #define __ASMV __asm__ __volatile__ #define __always_inline __attribute__((__always_inline__)) #define __packed __attribute__((__packed__)) #define __likely(exp) __builtin_expect(((exp) != 0), 1) #define __unlikely(exp) __builtin_expect(((exp) != 0), 0) +#if defined(_KERNEL) +/* + * Align data on a cache line boundary. This is + * mostly useful for certain locks to ensure they + * have their own cache line to reduce contention. + * + */ +#ifndef __cacheline_aligned +#define __cacheline_aligned \ + __attribute__((__aligned__(COHERENCY_UNIT), \ + __section__(".data.cacheline_aligned"))) + +#endif /* __cacheline_aligned */ +#endif /* _KERNEL */ + #endif /* !_SYS_CDEFS_H_ */ diff --git a/sys/include/sys/param.h b/sys/include/sys/param.h index a35a094..483dc15 100644 --- a/sys/include/sys/param.h +++ b/sys/include/sys/param.h @@ -30,6 +30,11 @@ #ifndef _SYS_PARAM_H_ #define _SYS_PARAM_H_ +/* Assumed cache line size */ +#ifndef COHERENCY_UNIT +#define COHERENCY_UNIT 64 +#endif + /* Bit related macros */ #define ISSET(v, f) ((v) & (f)) #define BIT(n) (1 << (n)) |