1 .\" $NetBSD: spl.9,v 1.35 2009/11/17 18:36:07 dyoung Exp $
3 .\" Copyright (c) 2000, 2001 Jason R. Thorpe. All rights reserved.
4 .\" Copyright (c) 1997 Michael Long.
5 .\" Copyright (c) 1997 Jonathan Stone.
6 .\" All rights reserved.
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
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. The name of the author may not be used to endorse or promote products
17 .\" derived from this software without specific prior written permission.
19 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46 .Nd modify system interrupt priority level
66 .Fn splsoftserial void
72 These functions raise and lower the interrupt priority level.
73 They are used by kernel code to block interrupts in critical
74 sections, in order to protect data structures.
76 In a multi-CPU system, these functions change the interrupt
77 priority level on the local CPU only.
78 In general, device drivers should not make use of these interfaces.
79 To ensure correct synchronization, device drivers should use the
86 Interrupt priorities are arranged in a strict hierarchy, although
87 sometimes levels may be equivalent (overlap).
88 The hierarchy means that raising the IPL to any level will block
89 interrupts at that level, and at all lower levels.
90 The hierarchy is used to minimize data loss due to interrupts not
91 being serviced in a timely fashion.
93 The levels may be divided into two groups: hard and soft.
94 Hard interrupts are generated by hardware devices.
95 Soft interrupts are a way of deferring hardware interrupts to do more
96 expensive processing at a lower interrupt priority, and are explicitly
97 scheduled by the higher-level interrupt handler.
98 Software interrupts are further described by
101 Note that hard interrupt handlers do not possess process (thread) context
102 and so it is not valid to use kernel facilities that may attempt to sleep
103 from a hardware interrupt.
104 For example, it is not possible to acquire a reader/writer lock from
105 a hardware interrupt.
106 Soft interrupt handlers possess limited process context and so may sleep
107 briefly in order to acquire a reader/writer lock or adaptive mutex,
108 but may not sleep for any other reason.
110 In order of highest to lowest priority, the priority-raising functions
111 along with their counterpart symbolic tags are:
112 .Bl -tag -width splsoft
113 .It Fn splhigh , IPL_HIGH
115 Blocks all hard and soft interrupts, including the highest level I/O
116 interrupts, such as interrupts from serial interfaces and the
117 statistics clock (if any).
118 It is also used for code that cannot tolerate any interrupts.
120 Code running at this level may not (in general) directly access
121 machine independent kernel services.
122 For example, it is illegal to call the kernel
124 function or to try and allocate memory.
125 The methods of synchronization available are: spin mutexes and
126 scheduling a soft interrupt.
127 Generally, all code run at this level must schedule additional
128 processing to run in a software interrupt.
130 Code with thread context running at this level must not use a kernel
131 interface that may cause the current LWP to sleep, such as the
135 Interrupt handlers at this level cannot acquire the global kernel_lock
136 and so must be coded to ensure correct synchronization on multiprocessor
138 .It Fn splsched , IPL_SCHED
140 Blocks all medium priority hardware interrupts, such as interrupts
141 from audio devices, and the clock interrupt.
143 Interrupt handlers running at this level endure the same restrictions as
144 at IPL_HIGH, but may access scheduler interfaces, and so may awaken LWPs
145 (light weight processes) using the
147 interfaces, and may schedule callouts using the
151 Code with thread context running at this level may sleep via the
153 interfaces, and may use other kernel facilities that could cause the
154 current LWP to sleep.
155 .It Fn splvm , IPL_VM
157 Blocks hard interrupts from
159 priority hardware interrupts, such
160 as interrupts from network, block I/O and tty devices.
162 Code running at this level endures the same restrictions as at IPL_SCHED,
163 but may use the deprecated
167 interfaces to allocate memory.
169 At the time of writing, the global
171 is automatically acquired for interrupts at this level, in order to
172 support device drivers that do not provide their own multiprocessor
174 A future release of the system may allow the automatic acquisition of
176 to be disabled for individual interrupt handlers.
177 .It Fn splsoftserial , IPL_SOFTSERIAL
179 Blocks soft interrupts at the IPL_SOFTSERIAL symbolic level.
181 This is the first of the software levels.
182 Soft interrupts at this level and lower may acquire reader/writer
183 locks or adaptive mutexes.
184 .It Fn splsoftnet , IPL_SOFTNET
186 Blocks soft interrupts at the IPL_SOFTNET symbolic level.
187 .It Fn splsoftbio , IPL_SOFTBIO
189 Blocks soft interrupts at the IPL_SOFTBIO symbolic level.
190 .It Fn splsoftclock , IPL_SOFTCLOCK
192 Blocks soft interrupts at the IPL_SOFTCLOCK symbolic level.
194 This is the priority at which callbacks generated by the
199 One function lowers the system priority level:
200 .Bl -tag -width splsoft
201 .It Fn spl0 , IPL_NONE
203 Unblocks all interrupts.
204 This should rarely be used directly;
206 should be used instead.
211 function restores the system priority level to the one encoded in
213 which must be a value previously returned by one of the other
219 function sets the system priority level to the one encoded in
223 is lower than the current level.
224 Otherwise, it does not change the level.
230 except in extraordinary circumstances.
234 function sets the system priority level to the one encoded in
238 is greater than the current level, and returns the previous level.
239 Otherwise, it does not change the level, and it returns the current level.
240 Except in extraordinary circumstances,
243 Use one of the priority-raising functions above, instead.
252 was used to block network software interrupts.
253 Most device drivers used
255 to block hardware interrupts.
256 To avoid unnecessarily blocking other interrupts, in
258 a new function was added that blocks only network hardware interrupts.
259 For consistency with other
263 function was renamed to
265 and the new function was named
270 lowered the system priority level.
274 .Fn spllowersoftclock
275 was introduced and the semantics of
281 call was removed from the kernel between
289 and code which abused the semantics of
291 was changed to not mix interrupt priority levels.
297 the hardware levels were reduced in number and a strict hierarchy