1cacheflush(2) System Calls Manual cacheflush(2)
2
3
4
6 cacheflush - flush contents of instruction and/or data cache
7
9 Standard C library (libc, -lc)
10
12 #include <sys/cachectl.h>
13
14 int cacheflush(void addr[.nbytes], int nbytes, int cache);
15
16 Note: On some architectures, there is no glibc wrapper for this system
17 call; see NOTES.
18
20 cacheflush() flushes the contents of the indicated cache(s) for the
21 user addresses in the range addr to (addr+nbytes-1). cache may be one
22 of:
23
24 ICACHE Flush the instruction cache.
25
26 DCACHE Write back to memory and invalidate the affected valid cache
27 lines.
28
29 BCACHE Same as (ICACHE|DCACHE).
30
32 cacheflush() returns 0 on success. On error, it returns -1 and sets
33 errno to indicate the error.
34
36 EFAULT Some or all of the address range addr to (addr+nbytes-1) is not
37 accessible.
38
39 EINVAL cache is not one of ICACHE, DCACHE, or BCACHE (but see BUGS).
40
42 cacheflush() should not be used in programs intended to be portable.
43 On Linux, this call first appeared on the MIPS architecture, but nowa‐
44 days, Linux provides a cacheflush() system call on some other architec‐
45 tures, but with different arguments.
46
47 Architecture-specific variants
48 glibc provides a wrapper for this system call, with the prototype shown
49 in SYNOPSIS, for the following architectures: ARC, CSKY, MIPS, and
50 NIOS2.
51
52 On some other architectures, Linux provides this system call, with dif‐
53 ferent arguments:
54
55 M68K:
56 int cacheflush(unsigned long addr, int scope, int cache,
57 unsigned long len);
58
59 SH:
60 int cacheflush(unsigned long addr, unsigned long len, int op);
61
62 NDS32:
63 int cacheflush(unsigned int start, unsigned int end, int cache);
64
65 On the above architectures, glibc does not provide a wrapper for this
66 system call; call it using syscall(2).
67
68 GCC alternative
69 Unless you need the finer grained control that this system call pro‐
70 vides, you probably want to use the GCC built-in function
71 __builtin___clear_cache(), which provides a portable interface across
72 platforms supported by GCC and compatible compilers:
73
74 void __builtin___clear_cache(void *begin, void *end);
75
76 On platforms that don't require instruction cache flushes,
77 __builtin___clear_cache() has no effect.
78
79 Note: On some GCC-compatible compilers, the prototype for this built-in
80 function uses char * instead of void * for the parameters.
81
83 Historically, this system call was available on all MIPS UNIX variants
84 including RISC/os, IRIX, Ultrix, NetBSD, OpenBSD, and FreeBSD (and also
85 on some non-UNIX MIPS operating systems), so that the existence of this
86 call in MIPS operating systems is a de-facto standard.
87
89 Linux kernels older than Linux 2.6.11 ignore the addr and nbytes argu‐
90 ments, making this function fairly expensive. Therefore, the whole
91 cache is always flushed.
92
93 This function always behaves as if BCACHE has been passed for the cache
94 argument and does not do any error checking on the cache argument.
95
96
97
98Linux man-pages 6.04 2023-03-30 cacheflush(2)