1*e289bf6aSdlg.\" $OpenBSD: spl.9,v 1.26 2016/08/16 23:49:35 dlg Exp $ 2d69ffa73Skstailey.\" $NetBSD: spl.9,v 1.1 1997/03/11 06:15:05 mikel Exp $ 3d69ffa73Skstailey.\" 4d69ffa73Skstailey.\" Copyright (c) 1997 Michael Long. 5d69ffa73Skstailey.\" Copyright (c) 1997 Jonathan Stone. 6d69ffa73Skstailey.\" All rights reserved. 7d69ffa73Skstailey.\" 8d69ffa73Skstailey.\" Redistribution and use in source and binary forms, with or without 9d69ffa73Skstailey.\" modification, are permitted provided that the following conditions 10d69ffa73Skstailey.\" are met: 11d69ffa73Skstailey.\" 1. Redistributions of source code must retain the above copyright 12d69ffa73Skstailey.\" notice, this list of conditions and the following disclaimer. 13d69ffa73Skstailey.\" 2. Redistributions in binary form must reproduce the above copyright 14d69ffa73Skstailey.\" notice, this list of conditions and the following disclaimer in the 15d69ffa73Skstailey.\" documentation and/or other materials provided with the distribution. 16f7772c00Sjsg.\" 3. The name of the author may not be used to endorse or promote products 17d69ffa73Skstailey.\" derived from this software without specific prior written permission. 18d69ffa73Skstailey.\" 19d69ffa73Skstailey.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20d69ffa73Skstailey.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21d69ffa73Skstailey.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22d69ffa73Skstailey.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23d69ffa73Skstailey.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24d69ffa73Skstailey.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25d69ffa73Skstailey.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26d69ffa73Skstailey.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27d69ffa73Skstailey.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28d69ffa73Skstailey.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29d69ffa73Skstailey.\" 30*e289bf6aSdlg.Dd $Mdocdate: August 16 2016 $ 3133378d91Sjmc.Dt SPLX 9 32fc8533a3Saaron.Os 33d69ffa73Skstailey.Sh NAME 34*e289bf6aSdlg.Nm splraise , 3533378d91Sjmc.Nm splhigh , 3633378d91Sjmc.Nm splserial , 3733378d91Sjmc.Nm splsched , 3833378d91Sjmc.Nm splclock , 3933378d91Sjmc.Nm splstatclock , 4033378d91Sjmc.Nm splvm , 4133378d91Sjmc.Nm spltty , 4233378d91Sjmc.Nm splsofttty , 4333378d91Sjmc.Nm splnet , 4433378d91Sjmc.Nm splbio , 4533378d91Sjmc.Nm splsoftnet , 4633378d91Sjmc.Nm splsoftclock , 4733378d91Sjmc.Nm spllowersoftclock , 4833378d91Sjmc.Nm spl0 , 4933378d91Sjmc.Nm splx , 5033378d91Sjmc.Nm splassert 51d69ffa73Skstailey.Nd modify system interrupt priority level 52d69ffa73Skstailey.Sh SYNOPSIS 53dddd2645Sschwarze.In machine/intr.h 54d69ffa73Skstailey.Ft int 55*e289bf6aSdlg.Fn splraise "int ipl" 56*e289bf6aSdlg.Ft int 57d69ffa73Skstailey.Fn splhigh void 58d69ffa73Skstailey.Ft int 596dba9c1bSaaron.Fn splserial void 60d69ffa73Skstailey.Ft int 610c6491cfSho.Fn splsched void 62d69ffa73Skstailey.Ft int 63d69ffa73Skstailey.Fn splclock void 64d69ffa73Skstailey.Ft int 65d69ffa73Skstailey.Fn splstatclock void 66d69ffa73Skstailey.Ft int 67e4d2ad18Sart.Fn splvm void 68d69ffa73Skstailey.Ft int 69d69ffa73Skstailey.Fn spltty void 70d69ffa73Skstailey.Ft int 710c6491cfSho.Fn splsofttty void 72d69ffa73Skstailey.Ft int 73d69ffa73Skstailey.Fn splnet void 74d69ffa73Skstailey.Ft int 75d69ffa73Skstailey.Fn splbio void 76d69ffa73Skstailey.Ft int 77d69ffa73Skstailey.Fn splsoftnet void 78d69ffa73Skstailey.Ft int 79d69ffa73Skstailey.Fn splsoftclock void 80d69ffa73Skstailey.Ft int 810c6491cfSho.Fn spllowersoftclock void 820c6491cfSho.Ft int 83d69ffa73Skstailey.Fn spl0 void 84d69ffa73Skstailey.Ft void 85d69ffa73Skstailey.Fn splx "int s" 86fd8e4845Sart.Ft void 87fd8e4845Sart.Fn splassert "int s" 88d69ffa73Skstailey.Sh DESCRIPTION 89d69ffa73SkstaileyThese functions raise and lower the system priority level. 90efb80952SaaronThey are used by kernel code to block interrupts with priority less 91efb80952Saaronthan or equal to the named level (i.e., 92efb80952Saaron.Fn spltty 93efb80952Saaronblocks interrupts of priority less than or equal to 94efb80952Saaron.Dv IPL_TTY ) . 95efb80952SaaronThe code may then safely access variables and data structures which 96efb80952Saaronare used by kernel code that runs at an equal or lower priority level. 97d69ffa73Skstailey.Pp 9812a1f8a1SjmcAn 99*e289bf6aSdlg.Nm spl 100d69ffa73Skstaileyfunction exists for each distinct priority level which can exist in 101ab967380Saaronthe system. 102ab967380SaaronThese macros and the corresponding priority levels are 103d69ffa73Skstaileyused for various defined purposes, and may be divided into two main 104ab967380Saarontypes: hard and soft. 105ab967380SaaronHard interrupts are generated by hardware 106d69ffa73Skstaileydevices, while soft interrupts are generated by callouts and called 107d69ffa73Skstaileyfrom the kernel's periodic timer interrupt service routine. 108d69ffa73Skstailey.Pp 109d69ffa73SkstaileyIn order of highest to lowest priority, the priority-raising macros 110d69ffa73Skstaileyare: 1110c6491cfSho.Bl -tag -width splsoftclockXX 112d69ffa73Skstailey.It Fn splhigh 113ab967380Saaronblocks all hard and soft interrupts. 114ab967380SaaronIt is used for code that cannot 115ab967380Saarontolerate any interrupts, like hardware context switching code and the 116d69ffa73Skstailey.Xr ddb 4 117d69ffa73Skstaileyin-kernel debugger. 1186dba9c1bSaaron.It Fn splserial 119ab967380Saaronblocks hard interrupts from serial interfaces. 120ab967380SaaronCode running at this level may not access the tty subsystem. 121d69ffa73Skstailey.It Fn splsched 122ab967380Saaronblocks interrupts that may access scheduler data structures. 12351e884f5SniklasSpecifically the clock interrupt that invokes the 12451e884f5Sniklas.Fn schedclock 12512211036Sjmcfunction needs to be blocked. 12612211036SjmcOn some systems this is a separate clock; 12712211036Sjmcon others it is the same as the statistics clock and, on these, 12851e884f5Sniklas.Fn splsched 12951e884f5Sniklasmust block everything that 13051e884f5Sniklas.Fn splstatclock 13151e884f5Sniklasdoes. 132ab967380SaaronCode running at or above this level may not call 13316b67135Smk.Xr tsleep 9 134d69ffa73Skstaileyor 13516b67135Smk.Xr wakeup 9 , 136d69ffa73Skstaileynor may it post signals. 13751f379f7SangelosNote that "running" means invoked by an interrupt handler that 13851f379f7Sangelosoperates at this level or higher. 13951f379f7SangelosKernel code that operates in the context of a process and has called 14051f379f7Sangelos.Fn splhigh 14151f379f7Sangelosfor blocking purposes can use 14216b67135Smk.Xr tsleep 9 14351f379f7Sangelosor 14416b67135Smk.Xr wakeup 9 . 145d69ffa73Skstailey.It Fn splclock 146ab967380Saaronblocks the hardware clock interrupt. 147ab967380SaaronIt is used by 148d69ffa73Skstailey.Fn hardclock 149d69ffa73Skstaileyto update kernel and process times, and must be used by any other code 150d69ffa73Skstaileythat accesses time-related data. 151d69ffa73Skstailey.It Fn splstatclock 152ab967380Saaronblocks the hardware statistics clock interrupt. 153ab967380SaaronIt is used by 154d69ffa73Skstailey.Fn statclock 155d69ffa73Skstaileyto update kernel profiling and other statistics, and must be used by 156d69ffa73Skstaileyany code that accesses that data. 157d69ffa73SkstaileyThis level is identical to 158d69ffa73Skstailey.Fn splclock 159d69ffa73Skstaileyif there is no separate statistics clock. 160e4d2ad18Sart.It Fn splvm 161d69ffa73Skstaileyblocks hard interrupts from all devices that are allowed to use the 162d69ffa73Skstaileykernel 163d69ffa73Skstailey.Xr malloc 9 . 164d69ffa73SkstaileyThat includes all disk, network, and tty device interrupts. 165d69ffa73Skstailey.It Fn spltty 166d69ffa73Skstaileyblocks hard interrupts from TTY devices. 1670c6491cfSho.It Fn splsofttty 168d69ffa73Skstaileyblocks soft interrupts generated by serial devices. 169d69ffa73Skstailey.It Fn splnet 170d69ffa73Skstaileyblocks hard interrupts from network interfaces. 171d69ffa73Skstailey.It Fn splbio 172d69ffa73Skstaileyblocks hard interrupts from disks and other mass-storage devices. 173d69ffa73Skstailey.It Fn splsoftnet 174d69ffa73Skstaileyblocks soft network interrupts. 1750c6491cfSho.It Fn splsoftclock 1760c6491cfShoblocks soft clock interrupts. 177d69ffa73Skstailey.El 178d69ffa73Skstailey.Pp 179ab967380SaaronTwo macros lower the system priority level. 180ab967380SaaronThey are: 1810c6491cfSho.Bl -tag -width spllowersoftclockXX 1820c6491cfSho.It Fn spllowersoftclock 183d69ffa73Skstaileyunblocks all interrupts but the soft clock interrupt. 184d69ffa73Skstailey.It Fn spl0 185d69ffa73Skstaileyunblocks all interrupts. 186d69ffa73Skstailey.El 187d69ffa73Skstailey.Pp 188d69ffa73SkstaileyThe 189*e289bf6aSdlg.Fn splraise 190*e289bf6aSdlgmacro blocks interrupts at the interrupt priority level specified by 191*e289bf6aSdlg.Fa ipl . 192*e289bf6aSdlg.Pp 193*e289bf6aSdlgThe 194d69ffa73Skstailey.Fn splx 195d69ffa73Skstaileymacro restores the system priority level to the one encoded in 196d69ffa73Skstailey.Fa s , 197d69ffa73Skstaileywhich must be a value previously returned by one of the other 198*e289bf6aSdlg.Nm spl 199d69ffa73Skstaileymacros. 200fd8e4845Sart.Pp 201fd8e4845SartThe 202fd8e4845Sart.Fn splassert 203a8a320bfSnordinfunction checks that the system is running at a certain priority level. 204fd8e4845SartThe argument 205fd8e4845Sart.Fa s 206fd8e4845Sartshould be one of these constants: 20705772f00Sho.Pp 20805772f00Sho.Bl -tag -width IPL_SOFTCLOCKXX -compact -offset indent 20958c77bccSart.It Dv IPL_STATCLOCK 210f61df30bSgrange.It Dv IPL_SCHED 211fd8e4845Sart.It Dv IPL_CLOCK 212fd8e4845Sart.It Dv IPL_VM 213fd8e4845Sart.It Dv IPL_BIO 214fd8e4845Sart.It Dv IPL_TTY 215fd8e4845Sart.It Dv IPL_NET 216fd8e4845Sart.It Dv IPL_SOFTNET 217fd8e4845Sart.It Dv IPL_SOFTCLOCK 218f1d61b4aSart.It Dv IPL_NONE 219fd8e4845Sart.El 220fd8e4845Sart.Pp 221fd8e4845SartThe 222fd8e4845Sart.Fn splassert 223fd8e4845Sartfunction is optional and is not necessarily implemented on 224fd8e4845Sartall architectures nor enabled in all kernel configurations. 225ed24e521SjmcIt checks the current system priority level to see if it's 226fd8e4845Sartat least at the level specified in the argument 227fd8e4845Sart.Fa s . 228fd8e4845SartIf possible, it also checks if it hasn't been called from an 229fd8e4845Sartinterrupt handler with a level higher than the one requested, which 230fd8e4845Sartmust be an error (if some code is protected from 231fd8e4845Sart.Dv IPL_SOFTNET 232fd8e4845Sartinterrupts, but accessed from an 233fd8e4845Sart.Dv IPL_NET 234fd8e4845Sartinterrupt, it must be a design error in the code). 23505772f00Sho.Pp 236fd8e4845SartThe behavior of the 237fd8e4845Sart.Fn splassert 238fd8e4845Sartfunction is controlled by the kern.splassert 239fd8e4845Sart.Xr sysctl 8 . 24005772f00ShoValid values for it are: 24105772f00Sho.Pp 24205772f00Sho.Bl -tag -width 1nr -compact -offset indent 24305772f00Sho.It 0 24405772f00Shodisable error checking 24505772f00Sho.It 1 24605772f00Shoprint a message if an error is detected 24705772f00Sho.It 2 24805772f00Shoprint a message and a stack trace if possible 24905772f00Sho.It 3 25005772f00Sholike 2 but also drop into the kernel debugger 25105772f00Sho.El 25205772f00Sho.Pp 25305772f00ShoAny other value causes a system panic on errors. 254