19ebce8e5SJohn Baldwin.\" Copyright (c) 2000-2001 John H. Baldwin <jhb@FreeBSD.org> 2dc4e9f1aSJohn Baldwin.\" 3dc4e9f1aSJohn Baldwin.\" Redistribution and use in source and binary forms, with or without 4dc4e9f1aSJohn Baldwin.\" modification, are permitted provided that the following conditions 5dc4e9f1aSJohn Baldwin.\" are met: 6dc4e9f1aSJohn Baldwin.\" 1. Redistributions of source code must retain the above copyright 7dc4e9f1aSJohn Baldwin.\" notice, this list of conditions and the following disclaimer. 8dc4e9f1aSJohn Baldwin.\" 2. Redistributions in binary form must reproduce the above copyright 9dc4e9f1aSJohn Baldwin.\" notice, this list of conditions and the following disclaimer in the 10dc4e9f1aSJohn Baldwin.\" documentation and/or other materials provided with the distribution. 11dc4e9f1aSJohn Baldwin.\" 12dc4e9f1aSJohn Baldwin.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 13dc4e9f1aSJohn Baldwin.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14dc4e9f1aSJohn Baldwin.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 15dc4e9f1aSJohn Baldwin.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 16dc4e9f1aSJohn Baldwin.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 17dc4e9f1aSJohn Baldwin.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 18dc4e9f1aSJohn Baldwin.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 19dc4e9f1aSJohn Baldwin.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 20dc4e9f1aSJohn Baldwin.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 21dc4e9f1aSJohn Baldwin.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 22dc4e9f1aSJohn Baldwin.\" SUCH DAMAGE. 23dc4e9f1aSJohn Baldwin.\" 24dc4e9f1aSJohn Baldwin.\" $FreeBSD$ 25dc4e9f1aSJohn Baldwin.\" 26aba10e13SAlexander Motin.Dd July 25, 2020 27dc4e9f1aSJohn Baldwin.Dt SWI 9 28dc4e9f1aSJohn Baldwin.Os 29dc4e9f1aSJohn Baldwin.Sh NAME 309ebce8e5SJohn Baldwin.Nm swi_add , 31eb55f31bSSergey Kandaurov.Nm swi_remove , 329ebce8e5SJohn Baldwin.Nm swi_sched 33dc4e9f1aSJohn Baldwin.Nd register and schedule software interrupt handlers 34dc4e9f1aSJohn Baldwin.Sh SYNOPSIS 3532eef9aeSRuslan Ermilov.In sys/param.h 3632eef9aeSRuslan Ermilov.In sys/bus.h 3732eef9aeSRuslan Ermilov.In sys/interrupt.h 3852116a1cSSergey Kandaurov.Vt "extern struct intr_event *tty_intr_event" ; 3952116a1cSSergey Kandaurov.Vt "extern struct intr_event *clk_intr_event" ; 409ebce8e5SJohn Baldwin.Ft int 419ebce8e5SJohn Baldwin.Fo swi_add 424b47ece9SSergey Kandaurov.Fa "struct intr_event **eventp" 43dc4e9f1aSJohn Baldwin.Fa "const char *name" 44dc4e9f1aSJohn Baldwin.Fa "driver_intr_t handler" 45dc4e9f1aSJohn Baldwin.Fa "void *arg" 46dc4e9f1aSJohn Baldwin.Fa "int pri" 479ebce8e5SJohn Baldwin.Fa "enum intr_type flags" 489ebce8e5SJohn Baldwin.Fa "void **cookiep" 49dc4e9f1aSJohn Baldwin.Fc 50eb55f31bSSergey Kandaurov.Ft int 51eb55f31bSSergey Kandaurov.Fn swi_remove "void *cookie" 529ebce8e5SJohn Baldwin.Ft void 5368ca7644SJoseph Koshy.Fn swi_sched "void *cookie" "int flags" 54dc4e9f1aSJohn Baldwin.Sh DESCRIPTION 55dc4e9f1aSJohn BaldwinThese functions are used to register and schedule software interrupt handlers. 56dc4e9f1aSJohn BaldwinSoftware interrupt handlers are attached to a software interrupt thread, just 57dc4e9f1aSJohn Baldwinas hardware interrupt handlers are attached to a hardware interrupt thread. 589ebce8e5SJohn BaldwinMultiple handlers can be attached to the same thread. 59dc4e9f1aSJohn BaldwinSoftware interrupt handlers can be used to queue up less critical processing 60dc4e9f1aSJohn Baldwininside of hardware interrupt handlers so that the work can be done at a later 61dc4e9f1aSJohn Baldwintime. 62dc4e9f1aSJohn BaldwinSoftware interrupt threads are different from other kernel threads in that they 63dc4e9f1aSJohn Baldwinare treated as an interrupt thread. 64dc4e9f1aSJohn BaldwinThis means that time spent executing these threads is counted as interrupt 659ebce8e5SJohn Baldwintime, and that they can be run via a lightweight context switch. 66dc4e9f1aSJohn Baldwin.Pp 67dc4e9f1aSJohn BaldwinThe 689ebce8e5SJohn Baldwin.Fn swi_add 694b47ece9SSergey Kandaurovfunction is used to add a new software interrupt handler to a specified 704b47ece9SSergey Kandaurovinterrupt event. 71dc4e9f1aSJohn BaldwinThe 724b47ece9SSergey Kandaurov.Fa eventp 73dc4e9f1aSJohn Baldwinargument is an optional pointer to a 744b47ece9SSergey Kandaurov.Vt struct intr_event 75dc4e9f1aSJohn Baldwinpointer. 764b47ece9SSergey KandaurovIf this argument points to an existing event that holds a list of 774b47ece9SSergey Kandaurovinterrupt handlers, then this handler will be attached to that event. 784b47ece9SSergey KandaurovOtherwise a new event will be created, and if 794b47ece9SSergey Kandaurov.Fa eventp 80dc4e9f1aSJohn Baldwinis not 81dc4e9f1aSJohn Baldwin.Dv NULL , 82dc4e9f1aSJohn Baldwinthen the pointer at that address to will be modified to point to the 834b47ece9SSergey Kandaurovnewly created event. 84dc4e9f1aSJohn BaldwinThe 859ebce8e5SJohn Baldwin.Fa name 869ebce8e5SJohn Baldwinargument is used to associate a name with a specific handler. 879ebce8e5SJohn BaldwinThis name is appended to the name of the software interrupt thread that this 889ebce8e5SJohn Baldwinhandler is attached to. 899ebce8e5SJohn BaldwinThe 90dc4e9f1aSJohn Baldwin.Fa handler 919ebce8e5SJohn Baldwinargument is the function that will be executed when the handler is scheduled 929ebce8e5SJohn Baldwinto run. 93dc4e9f1aSJohn BaldwinThe 94dc4e9f1aSJohn Baldwin.Fa arg 95dc4e9f1aSJohn Baldwinparameter will be passed in as the only parameter to 96dc4e9f1aSJohn Baldwin.Fa handler 97dc4e9f1aSJohn Baldwinwhen the function is executed. 98dc4e9f1aSJohn BaldwinThe 99dc4e9f1aSJohn Baldwin.Fa pri 1009ebce8e5SJohn Baldwinvalue specifies the priority of this interrupt handler relative to other 1019ebce8e5SJohn Baldwinsoftware interrupt handlers. 1024b47ece9SSergey KandaurovIf an interrupt event is created, then this value is used as the vector, 103dc4e9f1aSJohn Baldwinand the 104dc4e9f1aSJohn Baldwin.Fa flags 105dc4e9f1aSJohn Baldwinargument is used to specify the attributes of a handler such as 106dc4e9f1aSJohn Baldwin.Dv INTR_MPSAFE . 1079ebce8e5SJohn BaldwinThe 10868ca7644SJoseph Koshy.Fa cookiep 1099ebce8e5SJohn Baldwinargument points to a 11079cd39f2SRuslan Ermilov.Vt void * 1119ebce8e5SJohn Baldwincookie. 1129ebce8e5SJohn BaldwinThis cookie will be set to a value that uniquely identifies this handler, 1139ebce8e5SJohn Baldwinand is used to schedule the handler for execution later on. 114dc4e9f1aSJohn Baldwin.Pp 115dc4e9f1aSJohn BaldwinThe 116eb55f31bSSergey Kandaurov.Fn swi_remove 117eb55f31bSSergey Kandaurovfunction is used to teardown an interrupt handler pointed to by the 118eb55f31bSSergey Kandaurov.Fa cookie 119eb55f31bSSergey Kandaurovargument. 120eb55f31bSSergey KandaurovIt detaches the interrupt handler from the associated interrupt event 121eb55f31bSSergey Kandaurovand frees its memory. 122eb55f31bSSergey Kandaurov.Pp 123eb55f31bSSergey KandaurovThe 1249ebce8e5SJohn Baldwin.Fn swi_sched 125dc4e9f1aSJohn Baldwinfunction is used to schedule an interrupt handler and its associated thread to 126dc4e9f1aSJohn Baldwinrun. 127dc4e9f1aSJohn BaldwinThe 1289ebce8e5SJohn Baldwin.Fa cookie 129dc4e9f1aSJohn Baldwinargument specifies which software interrupt handler should be scheduled to run. 130dc4e9f1aSJohn BaldwinThe 131dc4e9f1aSJohn Baldwin.Fa flags 132dc4e9f1aSJohn Baldwinargument specifies how and when the handler should be run and is a mask of one 133dc4e9f1aSJohn Baldwinor more of the following flags: 134aba10e13SAlexander Motin.Bl -tag -width SWI_FROMNMI 135dc4e9f1aSJohn Baldwin.It Dv SWI_DELAY 136dc4e9f1aSJohn BaldwinSpecifies that the kernel should mark the specified handler as needing to run, 137dc4e9f1aSJohn Baldwinbut the kernel should not schedule the software interrupt thread to run. 138dc4e9f1aSJohn BaldwinInstead, 139dc4e9f1aSJohn Baldwin.Fa handler 140dc4e9f1aSJohn Baldwinwill be executed the next time that the software interrupt thread runs after 141dc4e9f1aSJohn Baldwinbeing scheduled by another event. 142aba10e13SAlexander Motin.It Dv SWI_FROMNMI 143aba10e13SAlexander MotinSpecifies that 144aba10e13SAlexander Motin.Fn swi_sched 145aba10e13SAlexander Motinis called from NMI context and should be careful about used KPIs. 146aba10e13SAlexander MotinOn platforms allowing IPI sending from NMI context it immediately wakes 147aba10e13SAlexander Motin.Va clk_intr_event 148aba10e13SAlexander Motinvia the IPI, otherwise it works just like SWI_DELAY. 149dc4e9f1aSJohn Baldwin.El 150dc4e9f1aSJohn Baldwin.Pp 151dc4e9f1aSJohn BaldwinThe 15252116a1cSSergey Kandaurov.Va tty_intr_event 153dc4e9f1aSJohn Baldwinand 15452116a1cSSergey Kandaurov.Va clk_intr_event 15552116a1cSSergey Kandaurovvariables contain pointers to the software interrupt handlers for the tty and 156dc4e9f1aSJohn Baldwinclock software interrupts, respectively. 15752116a1cSSergey Kandaurov.Va tty_intr_event 158dc4e9f1aSJohn Baldwinis used to hang tty software interrupt handlers off of the same thread. 15952116a1cSSergey Kandaurov.Va clk_intr_event 160*96b76a6aSMitchell Horneis used to hang delayed handlers off of the clock interrupt, and is invoked 161*96b76a6aSMitchell Hornedirectly by 162*96b76a6aSMitchell Horne.Xr hardclock 9 . 163dc4e9f1aSJohn Baldwin.Sh RETURN VALUES 164dc4e9f1aSJohn BaldwinThe 1659ebce8e5SJohn Baldwin.Fn swi_add 166eb55f31bSSergey Kandaurovand 167eb55f31bSSergey Kandaurov.Fn swi_remove 168eb55f31bSSergey Kandaurovfunctions return zero on success and non-zero on failure. 1699ebce8e5SJohn Baldwin.Sh ERRORS 1709ebce8e5SJohn BaldwinThe 1719ebce8e5SJohn Baldwin.Fn swi_add 1729ebce8e5SJohn Baldwinfunction will fail if: 1739ebce8e5SJohn Baldwin.Bl -tag -width Er 1749ebce8e5SJohn Baldwin.It Bq Er EAGAIN 1759ebce8e5SJohn BaldwinThe system-imposed limit on the total 1769ebce8e5SJohn Baldwinnumber of processes under execution would be exceeded. 1779ebce8e5SJohn BaldwinThe limit is given by the 1789ebce8e5SJohn Baldwin.Xr sysctl 3 1799ebce8e5SJohn BaldwinMIB variable 1809ebce8e5SJohn Baldwin.Dv KERN_MAXPROC . 1819ebce8e5SJohn Baldwin.It Bq Er EINVAL 1829ebce8e5SJohn BaldwinThe 1839ebce8e5SJohn Baldwin.Fa flags 18449fe354aSJohn Baldwinargument specifies 18549fe354aSJohn Baldwin.Dv INTR_ENTROPY . 1869ebce8e5SJohn Baldwin.It Bq Er EINVAL 1879ebce8e5SJohn BaldwinThe 1884b47ece9SSergey Kandaurov.Fa eventp 1899ebce8e5SJohn Baldwinargument points to a hardware interrupt thread. 1909ebce8e5SJohn Baldwin.It Bq Er EINVAL 1919ebce8e5SJohn BaldwinEither of the 1929ebce8e5SJohn Baldwin.Fa name 1939ebce8e5SJohn Baldwinor 1949ebce8e5SJohn Baldwin.Fa handler 1959ebce8e5SJohn Baldwinarguments are 1969ebce8e5SJohn Baldwin.Dv NULL . 1979ebce8e5SJohn Baldwin.It Bq Er EINVAL 1989ebce8e5SJohn BaldwinThe 1999ebce8e5SJohn Baldwin.Dv INTR_EXCL 2004b47ece9SSergey Kandaurovflag is specified and the interrupt event pointed to by 2014b47ece9SSergey Kandaurov.Fa eventp 2024b47ece9SSergey Kandaurovalready has at least one handler, or the interrupt event already has an 2039ebce8e5SJohn Baldwinexclusive handler. 2049ebce8e5SJohn Baldwin.El 205eb55f31bSSergey Kandaurov.Pp 206eb55f31bSSergey KandaurovThe 207eb55f31bSSergey Kandaurov.Fn swi_remove 208eb55f31bSSergey Kandaurovfunction will fail if: 209eb55f31bSSergey Kandaurov.Bl -tag -width Er 210eb55f31bSSergey Kandaurov.It Bq Er EINVAL 211eb55f31bSSergey KandaurovA software interrupt handler pointed to by 212eb55f31bSSergey Kandaurov.Fa cookie 213eb55f31bSSergey Kandaurovis 214eb55f31bSSergey Kandaurov.Dv NULL . 215eb55f31bSSergey Kandaurov.El 216dc4e9f1aSJohn Baldwin.Sh SEE ALSO 217*96b76a6aSMitchell Horne.Xr hardclock 9 , 2189ebce8e5SJohn Baldwin.Xr ithread 9 , 219dc4e9f1aSJohn Baldwin.Xr taskqueue 9 220dc4e9f1aSJohn Baldwin.Sh HISTORY 221dc4e9f1aSJohn BaldwinThe 2229ebce8e5SJohn Baldwin.Fn swi_add 2239ebce8e5SJohn Baldwinand 2249ebce8e5SJohn Baldwin.Fn swi_sched 225dc4e9f1aSJohn Baldwinfunctions first appeared in 226dc4e9f1aSJohn Baldwin.Fx 5.0 . 2279ebce8e5SJohn BaldwinThey replaced the 2289ebce8e5SJohn Baldwin.Fn register_swi 2299ebce8e5SJohn Baldwinfunction which appeared in 2309ebce8e5SJohn Baldwin.Fx 3.0 2319ebce8e5SJohn Baldwinand the 2329ebce8e5SJohn Baldwin.Fn setsoft* , 2339ebce8e5SJohn Baldwinand 2349ebce8e5SJohn Baldwin.Fn schedsoft* 2359ebce8e5SJohn Baldwinfunctions which date back to at least 2369ebce8e5SJohn Baldwin.Bx 4.4 . 237eb55f31bSSergey KandaurovThe 238eb55f31bSSergey Kandaurov.Fn swi_remove 239eb55f31bSSergey Kandaurovfunction first appeared in 240eb55f31bSSergey Kandaurov.Fx 6.1 . 241dc4e9f1aSJohn Baldwin.Sh BUGS 242dc4e9f1aSJohn BaldwinMost of the global variables described in this manual page should not be 243dc4e9f1aSJohn Baldwinglobal, or at the very least should not be declared in 244fe08efe6SRuslan Ermilov.In sys/interrupt.h . 245