1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __LINUX_CACHE_H
3 #define __LINUX_CACHE_H
5 #include <uapi/linux/kernel.h>
9 #define L1_CACHE_ALIGN(x) __ALIGN_KERNEL(x, L1_CACHE_BYTES)
12 #ifndef SMP_CACHE_BYTES
13 #define SMP_CACHE_BYTES L1_CACHE_BYTES
17 * __read_mostly is used to keep rarely changing variables out of frequently
18 * updated cachelines. If an architecture doesn't support it, ignore the
26 * __ro_after_init is used to mark things that are read-only after init (i.e.
27 * after mark_rodata_ro() has been called). These are effectively read-only,
28 * but may get written to during init, so can't live in .rodata (via "const").
30 #ifndef __ro_after_init
31 #define __ro_after_init __attribute__((__section__(".data..ro_after_init")))
34 #ifndef ____cacheline_aligned
35 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
38 #ifndef ____cacheline_aligned_in_smp
40 #define ____cacheline_aligned_in_smp ____cacheline_aligned
42 #define ____cacheline_aligned_in_smp
43 #endif /* CONFIG_SMP */
46 #ifndef __cacheline_aligned
47 #define __cacheline_aligned \
48 __attribute__((__aligned__(SMP_CACHE_BYTES), \
49 __section__(".data..cacheline_aligned")))
50 #endif /* __cacheline_aligned */
52 #ifndef __cacheline_aligned_in_smp
54 #define __cacheline_aligned_in_smp __cacheline_aligned
56 #define __cacheline_aligned_in_smp
57 #endif /* CONFIG_SMP */
61 * The maximum alignment needed for some critical structures
62 * These could be inter-node cacheline sizes/L3 cacheline
63 * size etc. Define this in asm/cache.h for your arch
65 #ifndef INTERNODE_CACHE_SHIFT
66 #define INTERNODE_CACHE_SHIFT L1_CACHE_SHIFT
69 #if !defined(____cacheline_internodealigned_in_smp)
70 #if defined(CONFIG_SMP)
71 #define ____cacheline_internodealigned_in_smp \
72 __attribute__((__aligned__(1 << (INTERNODE_CACHE_SHIFT))))
74 #define ____cacheline_internodealigned_in_smp
78 #ifndef CONFIG_ARCH_HAS_CACHE_LINE_SIZE
79 #define cache_line_size() L1_CACHE_BYTES
82 #endif /* __LINUX_CACHE_H */