XenevaOS
Loading...
Searching...
No Matches
cache.h
Go to the documentation of this file.
1#ifndef __LINUX_CACHE_H
2#define __LINUX_CACHE_H
3
4/*
5 * DCL <linux/cache.h> -- cache-line alignment types and the cacheline-group
6 * markers.
7 *
8 * mainline's version also carries ____cacheline_aligned_in_smp,
9 * ____cacheline_internodealigned_in_smp, INTERNODE_CACHE_* and the arch hooks
10 * for cache_line_size(). None of those have a caller in this tree, so they are
11 * not here: an uncompiled definition reads as supported and is worse than an
12 * absent one.
13 */
14
15#include <linux/kernel.h> /* __u8, size_t */
16#include <asm/cache.h> /* L1_CACHE_SHIFT / L1_CACHE_BYTES */
17
18/*
19 * SMP_CACHE_BYTES -- the coherency-line size, i.e. the unit ____cacheline_aligned
20 * aligns to. On aarch64 it is the L1 line. Provided because dma-mapping.h's
21 * group markers and virtio-rng.c's buffer sizing both key off it.
22 */
23#ifndef SMP_CACHE_SHIFT
24#define SMP_CACHE_SHIFT L1_CACHE_SHIFT
25#endif
26
27#ifndef SMP_CACHE_BYTES
28#define SMP_CACHE_BYTES L1_CACHE_BYTES
29#endif
30
31#ifndef SMP_CACHE_ALIGN
32#define SMP_CACHE_ALIGN(x) (((x) + (SMP_CACHE_BYTES - 1)) & ~(SMP_CACHE_BYTES - 1))
33#endif
34
35#ifndef ____cacheline_aligned
36#define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
37#endif
38
39/*
40 * __cacheline_group_begin/__end -- mainline's spelling, byte for byte:
41 *
42 * #define __cacheline_group_begin(GROUP) \
43 * __u8 __cacheline_group_begin__##GROUP[0]
44 *
45 * It is a zero-length array member, which is a GNU extension and a legal
46 * member declaration here, used to fence a run of fields inside a struct so a
47 * checker can assert they sit in their own cacheline. No section is emitted
48 * (mainline's alternative definition, used when the toolchain supports it,
49 * puts them in .data.cacheline_group.<GROUP>; DCL has no such checker).
50 *
51 * Two things a caller gets wrong on the first try, so they are written down:
52 *
53 * - the macros take NO trailing semicolon. The source writes
54 * `__dma_from_device_group_begin();` and that `;` is the member's.
55 * Emitting one inside the macro would leave a stray declaration.
56 * - GROUP may be empty. virtio-rng.c's struct virtrng_info calls both with
57 * `()`, so GROUP pastes to nothing and the member is plain
58 * `__cacheline_group_begin__[0]`. That is why this cannot be a variadic
59 * or no-argument macro: it has to accept exactly one, possibly-empty token.
60 */
61#ifndef __cacheline_group_begin
62#define __cacheline_group_begin(GROUP) __u8 __cacheline_group_begin__##GROUP[0]
63#endif
64
65#ifndef __cacheline_group_end
66#define __cacheline_group_end(GROUP) __u8 __cacheline_group_end__##GROUP[0]
67#endif
68
69#endif /* __LINUX_CACHE_H */