xref: /openbsd/share/man/man9/spl.9 (revision a8a320bf)
1.\"	$OpenBSD: spl.9,v 1.14 2002/07/28 20:55:00 nordin Exp $
2.\"	$NetBSD: spl.9,v 1.1 1997/03/11 06:15:05 mikel Exp $
3.\"
4.\" Copyright (c) 1997 Michael Long.
5.\" Copyright (c) 1997 Jonathan Stone.
6.\" All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\"    notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\"    notice, this list of conditions and the following disclaimer in the
15.\"    documentation and/or other materials provided with the distribution.
16.\" 3. All advertising materials mentioning features or use of this software
17.\"    must display the following acknowledgement:
18.\"        This product includes software developed by Michael Long.
19.\" 4. The name of the author may not be used to endorse or promote products
20.\"    derived from this software without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32.\"
33.Dd March 11, 1997
34.Dt SPL 9
35.Os
36.Sh NAME
37.Nm spl
38.Nd modify system interrupt priority level
39.Sh SYNOPSIS
40.Fd #include <machine/intr.h>
41.Ft int
42.Fn splhigh void
43.Ft int
44.Fn splserial void
45.Ft int
46.Fn splsched void
47.Ft int
48.Fn splclock void
49.Ft int
50.Fn splstatclock void
51.Ft int
52.Fn splvm void
53.Ft int
54.Fn spltty void
55.Ft int
56.Fn splsofttty void
57.Ft int
58.Fn splnet void
59.Ft int
60.Fn splbio void
61.Ft int
62.Fn splsoftnet void
63.Ft int
64.Fn splsoftclock void
65.Ft int
66.Fn spllowersoftclock void
67.Ft int
68.Fn spl0 void
69.Ft void
70.Fn splx "int s"
71.Ft void
72.Fn splassert "int s"
73.Sh DESCRIPTION
74These functions raise and lower the system priority level.
75They are used by kernel code to block interrupts with priority less
76than or equal to the named level (i.e.,
77.Fn spltty
78blocks interrupts of priority less than or equal to
79.Dv IPL_TTY ) .
80The code may then safely access variables and data structures which
81are used by kernel code that runs at an equal or lower priority level.
82.Pp
83A
84.Nm
85function exists for each distinct priority level which can exist in
86the system.
87These macros and the corresponding priority levels are
88used for various defined purposes, and may be divided into two main
89types: hard and soft.
90Hard interrupts are generated by hardware
91devices, while soft interrupts are generated by callouts and called
92from the kernel's periodic timer interrupt service routine.
93.Pp
94In order of highest to lowest priority, the priority-raising macros
95are:
96.Bl -tag -width splsoftclockXX
97.It Fn splhigh
98blocks all hard and soft interrupts.
99It is used for code that cannot
100tolerate any interrupts, like hardware context switching code and the
101.Xr ddb 4
102in-kernel debugger.
103.It Fn splserial
104blocks hard interrupts from serial interfaces.
105Code running at this level may not access the tty subsystem.
106.It Fn splsched
107blocks interrupts that may access scheduler data structures.
108Code running at or above this level may not call
109.Fn sleep ,
110.Fn tsleep ,
111or
112.Fn wakeup ,
113nor may it post signals.
114Note that "running" means invoked by an interrupt handler that
115operates at this level or higher.
116Kernel code that operates in the context of a process and has called
117.Fn splhigh
118for blocking purposes can use
119.Fn sleep ,
120.Fn tsleep ,
121or
122.Fn wakeup .
123.It Fn splclock
124blocks the hardware clock interrupt.
125It is used by
126.Fn hardclock
127to update kernel and process times, and must be used by any other code
128that accesses time-related data.
129.It Fn splstatclock
130blocks the hardware statistics clock interrupt.
131It is used by
132.Fn statclock
133to update kernel profiling and other statistics, and must be used by
134any code that accesses that data.
135This level is identical to
136.Fn splclock
137if there is no separate statistics clock.
138.It Fn splvm
139blocks hard interrupts from all devices that are allowed to use the
140kernel
141.Xr malloc 9 .
142That includes all disk, network, and tty device interrupts.
143.It Fn spltty
144blocks hard interrupts from TTY devices.
145.It Fn splsofttty
146blocks soft interrupts generated by serial devices.
147.It Fn splnet
148blocks hard interrupts from network interfaces.
149.It Fn splbio
150blocks hard interrupts from disks and other mass-storage devices.
151.It Fn splsoftnet
152blocks soft network interrupts.
153.It Fn splsoftclock
154blocks soft clock interrupts.
155.El
156.Pp
157Two macros lower the system priority level.
158They are:
159.Bl -tag -width spllowersoftclockXX
160.It Fn spllowersoftclock
161unblocks all interrupts but the soft clock interrupt.
162.It Fn spl0
163unblocks all interrupts.
164.El
165.Pp
166The
167.Fn splx
168macro restores the system priority level to the one encoded in
169.Fa s ,
170which must be a value previously returned by one of the other
171.Nm
172macros.
173.Pp
174The
175.Fn splassert
176function checks that the system is running at a certain priority level.
177The argument
178.Fa s
179should be one of these constants:
180.Bl -tag -width IPL_SOFTCLOCKXX
181.It Dv IPL_STATCLOCK
182.It Dv IPL_CLOCK
183.It Dv IPL_VM
184.It Dv IPL_BIO
185.It Dv IPL_TTY
186.It Dv IPL_NET
187.It Dv IPL_SOFTNET
188.It Dv IPL_SOFTCLOCK
189.It Dv IPL_NONE
190.El
191.Pp
192The
193.Fn splassert
194function is optional and is not necessarily implemented on
195all architectures nor enabled in all kernel configurations.
196It checks the current system priority level too see if it's
197at least at the level specified in the argument
198.Fa s .
199If possible, it also checks if it hasn't been called from an
200interrupt handler with a level higher than the one requested, which
201must be an error (if some code is protected from
202.Dv IPL_SOFTNET
203interrupts, but accessed from an
204.Dv IPL_NET
205interrupt, it must be a design error in the code).
206The behavior of the
207.Fn splassert
208function is controlled by the kern.splassert
209.Xr sysctl 8 .
210Set to 0 it disables error checking, set to 1 it prints an error message
211if error is detected, 2 prints a message and stack traceback if possible,
212any other value causes a system panic on errors.
213