1CACHEFLUSH(2)              Linux Programmer's Manual             CACHEFLUSH(2)
2
3
4

NAME

6       cacheflush - flush contents of instruction and/or data cache
7

SYNOPSIS

9       #include <sys/cachectl.h>
10
11       int cacheflush(void *addr, int nbytes, int cache);
12
13       Note:  On some architectures, there is no glibc wrapper for this system
14       call; see NOTES.
15

DESCRIPTION

17       cacheflush() flushes the contents of the  indicated  cache(s)  for  the
18       user  addresses in the range addr to (addr+nbytes-1).  cache may be one
19       of:
20
21       ICACHE Flush the instruction cache.
22
23       DCACHE Write back to memory and invalidate  the  affected  valid  cache
24              lines.
25
26       BCACHE Same as (ICACHE|DCACHE).
27

RETURN VALUE

29       cacheflush()  returns  0  on success.  On error, it returns -1 and sets
30       errno to indicate the error.
31

ERRORS

33       EFAULT Some or all of the address range addr to (addr+nbytes-1) is  not
34              accessible.
35
36       EINVAL cache is not one of ICACHE, DCACHE, or BCACHE (but see BUGS).
37

CONFORMING TO

39       Historically,  this system call was available on all MIPS UNIX variants
40       including RISC/os, IRIX, Ultrix, NetBSD, OpenBSD, and FreeBSD (and also
41       on some non-UNIX MIPS operating systems), so that the existence of this
42       call in MIPS operating systems is a de-facto standard.
43
44   Caveat
45       cacheflush() should not be used in programs intended  to  be  portable.
46       On  Linux, this call first appeared on the MIPS architecture, but nowa‐
47       days, Linux provides a cacheflush() system call on some other architec‐
48       tures, but with different arguments.
49

NOTES

51   Architecture-specific variants
52       Glibc provides a wrapper for this system call, with the prototype shown
53       in SYNOPSIS, for the following  architectures:  ARC,  CSKY,  MIPS,  and
54       NIOS2.
55
56       On some other architectures, Linux provides this system call, with dif‐
57       ferent arguments:
58
59       M68K:
60              int cacheflush(unsigned long addr, int scope, int cache,
61                             unsigned long len);
62
63       SH:
64              int cacheflush(unsigned long addr, unsigned long len, int op);
65
66       NDS32:
67              int cacheflush(unsigned int start, unsigned int end, int cache);
68
69       On the above architectures, glibc does not provide a wrapper  for  this
70       system call; call it using syscall(2).
71
72   GCC alternative
73       Unless  you  need  the finer grained control that this system call pro‐
74       vides,  you  probably  want  to   use   the   GCC   built-in   function
75       __builtin___clear_cache(),  which  provides a portable interface across
76       platforms supported by GCC and compatible compilers:
77
78           void __builtin___clear_cache(void *begin, void *end);
79
80       On  platforms   that   don't   require   instruction   cache   flushes,
81       __builtin___clear_cache() has no effect.
82
83       Note: On some GCC-compatible compilers, the prototype for this built-in
84       function uses char * instead of void * for the parameters.
85

BUGS

87       Linux kernels older than version 2.6.11 ignore the addr and nbytes  ar‐
88       guments,  making  this function fairly expensive.  Therefore, the whole
89       cache is always flushed.
90
91       This function always behaves as if BCACHE has been passed for the cache
92       argument and does not do any error checking on the cache argument.
93

COLOPHON

95       This  page  is  part of release 5.13 of the Linux man-pages project.  A
96       description of the project, information about reporting bugs,  and  the
97       latest     version     of     this    page,    can    be    found    at
98       https://www.kernel.org/doc/man-pages/.
99
100
101
102Linux                             2021-03-22                     CACHEFLUSH(2)
Impressum