]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/cacheflush.2
d3694f0ebb29733d1393b50867749717053e5552
[thirdparty/man-pages.git] / man2 / cacheflush.2
1 .\" Written by Ralf Baechle (ralf@waldorf-gmbh.de),
2 .\" Copyright (c) 1994, 1995 Waldorf GMBH
3 .\"
4 .\" SPDX-License-Identifier: GPL-2.0-or-later
5 .\"
6 .TH CACHEFLUSH 2 2021-03-22 "Linux man-pages (unreleased)" "Linux Programmer's Manual"
7 .SH NAME
8 cacheflush \- flush contents of instruction and/or data cache
9 .SH LIBRARY
10 Standard C library
11 .RI ( libc ", " \-lc )
12 .SH SYNOPSIS
13 .nf
14 .B #include <sys/cachectl.h>
15 .PP
16 .BI "int cacheflush(void *" addr ", int "nbytes ", int "cache );
17 .fi
18 .PP
19 .IR Note :
20 On some architectures,
21 there is no glibc wrapper for this system call; see NOTES.
22 .SH DESCRIPTION
23 .BR cacheflush ()
24 flushes the contents of the indicated cache(s) for the
25 user addresses in the range
26 .I addr
27 to
28 .IR (addr+nbytes\-1) .
29 .I cache
30 may be one of:
31 .TP
32 .B ICACHE
33 Flush the instruction cache.
34 .TP
35 .B DCACHE
36 Write back to memory and invalidate the affected valid cache lines.
37 .TP
38 .B BCACHE
39 Same as
40 .BR (ICACHE|DCACHE) .
41 .SH RETURN VALUE
42 .BR cacheflush ()
43 returns 0 on success.
44 On error, it returns \-1 and sets
45 .I errno
46 to indicate the error.
47 .SH ERRORS
48 .TP
49 .B EFAULT
50 Some or all of the address range
51 .I addr
52 to
53 .I (addr+nbytes\-1)
54 is not accessible.
55 .TP
56 .B EINVAL
57 .I cache
58 is not one of
59 .BR ICACHE ,
60 .BR DCACHE ,
61 or
62 .B BCACHE
63 (but see BUGS).
64 .SH STANDARDS
65 Historically, this system call was available on all MIPS UNIX variants
66 including RISC/os, IRIX, Ultrix, NetBSD, OpenBSD, and FreeBSD
67 (and also on some non-UNIX MIPS operating systems), so that
68 the existence of this call in MIPS operating systems is a de-facto
69 standard.
70 .SS Caveat
71 .BR cacheflush ()
72 should not be used in programs intended to be portable.
73 On Linux, this call first appeared on the MIPS architecture,
74 but nowadays, Linux provides a
75 .BR cacheflush ()
76 system call on some other architectures, but with different arguments.
77 .SH NOTES
78 .SS Architecture-specific variants
79 Glibc provides a wrapper for this system call,
80 with the prototype shown in SYNOPSIS,
81 for the following architectures:
82 ARC, CSKY, MIPS, and NIOS2.
83 .PP
84 On some other architectures,
85 Linux provides this system call, with different arguments:
86 .TP
87 M68K:
88 .nf
89 .BI "int cacheflush(unsigned long " addr ", int " scope ", int " cache ,
90 .BI " unsigned long " len );
91 .fi
92 .TP
93 SH:
94 .nf
95 .BI "int cacheflush(unsigned long " addr ", unsigned long " len ", int " op );
96 .fi
97 .TP
98 NDS32:
99 .nf
100 .BI "int cacheflush(unsigned int " start ", unsigned int " end ", int " cache );
101 .fi
102 .PP
103 On the above architectures,
104 glibc does not provide a wrapper for this system call; call it using
105 .BR syscall (2).
106 .SS GCC alternative
107 Unless you need the finer grained control that this system call provides,
108 you probably want to use the GCC built-in function
109 .BR __builtin___clear_cache (),
110 which provides a portable interface
111 across platforms supported by GCC and compatible compilers:
112 .PP
113 .in +4n
114 .EX
115 .BI "void __builtin___clear_cache(void *" begin ", void *" end );
116 .EE
117 .in
118 .PP
119 On platforms that don't require instruction cache flushes,
120 .BR __builtin___clear_cache ()
121 has no effect.
122 .PP
123 .IR Note :
124 On some GCC-compatible compilers,
125 the prototype for this built-in function uses
126 .I char *
127 instead of
128 .I void *
129 for the parameters.
130 .SH BUGS
131 Linux kernels older than version 2.6.11 ignore the
132 .I addr
133 and
134 .I nbytes
135 arguments, making this function fairly expensive.
136 Therefore, the whole cache is always flushed.
137 .PP
138 This function always behaves as if
139 .B BCACHE
140 has been passed for the
141 .I cache
142 argument and does not do any error checking on the
143 .I cache
144 argument.