xref: /freebsd/share/man/man9/swi.9 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
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.\"
24ed02be35SMitchell Horne.Dd October 12, 2022
25dc4e9f1aSJohn Baldwin.Dt SWI 9
26dc4e9f1aSJohn Baldwin.Os
27dc4e9f1aSJohn Baldwin.Sh NAME
289ebce8e5SJohn Baldwin.Nm swi_add ,
29eb55f31bSSergey Kandaurov.Nm swi_remove ,
309ebce8e5SJohn Baldwin.Nm swi_sched
31dc4e9f1aSJohn Baldwin.Nd register and schedule software interrupt handlers
32dc4e9f1aSJohn Baldwin.Sh SYNOPSIS
3332eef9aeSRuslan Ermilov.In sys/param.h
3432eef9aeSRuslan Ermilov.In sys/bus.h
3532eef9aeSRuslan Ermilov.In sys/interrupt.h
3652116a1cSSergey Kandaurov.Vt "extern struct intr_event *clk_intr_event" ;
379ebce8e5SJohn Baldwin.Ft int
389ebce8e5SJohn Baldwin.Fo swi_add
394b47ece9SSergey Kandaurov.Fa "struct intr_event **eventp"
40dc4e9f1aSJohn Baldwin.Fa "const char *name"
41dc4e9f1aSJohn Baldwin.Fa "driver_intr_t handler"
42dc4e9f1aSJohn Baldwin.Fa "void *arg"
43dc4e9f1aSJohn Baldwin.Fa "int pri"
449ebce8e5SJohn Baldwin.Fa "enum intr_type flags"
459ebce8e5SJohn Baldwin.Fa "void **cookiep"
46dc4e9f1aSJohn Baldwin.Fc
47eb55f31bSSergey Kandaurov.Ft int
48eb55f31bSSergey Kandaurov.Fn swi_remove "void *cookie"
499ebce8e5SJohn Baldwin.Ft void
5068ca7644SJoseph Koshy.Fn swi_sched "void *cookie" "int flags"
51dc4e9f1aSJohn Baldwin.Sh DESCRIPTION
52dc4e9f1aSJohn BaldwinThese functions are used to register and schedule software interrupt handlers.
53dc4e9f1aSJohn BaldwinSoftware interrupt handlers are attached to a software interrupt thread, just
54dc4e9f1aSJohn Baldwinas hardware interrupt handlers are attached to a hardware interrupt thread.
559ebce8e5SJohn BaldwinMultiple handlers can be attached to the same thread.
56dc4e9f1aSJohn BaldwinSoftware interrupt handlers can be used to queue up less critical processing
57dc4e9f1aSJohn Baldwininside of hardware interrupt handlers so that the work can be done at a later
58dc4e9f1aSJohn Baldwintime.
59dc4e9f1aSJohn BaldwinSoftware interrupt threads are different from other kernel threads in that they
60dc4e9f1aSJohn Baldwinare treated as an interrupt thread.
61dc4e9f1aSJohn BaldwinThis means that time spent executing these threads is counted as interrupt
629ebce8e5SJohn Baldwintime, and that they can be run via a lightweight context switch.
63dc4e9f1aSJohn Baldwin.Pp
64dc4e9f1aSJohn BaldwinThe
659ebce8e5SJohn Baldwin.Fn swi_add
664b47ece9SSergey Kandaurovfunction is used to add a new software interrupt handler to a specified
674b47ece9SSergey Kandaurovinterrupt event.
68dc4e9f1aSJohn BaldwinThe
694b47ece9SSergey Kandaurov.Fa eventp
70dc4e9f1aSJohn Baldwinargument is an optional pointer to a
714b47ece9SSergey Kandaurov.Vt struct intr_event
72dc4e9f1aSJohn Baldwinpointer.
734b47ece9SSergey KandaurovIf this argument points to an existing event that holds a list of
744b47ece9SSergey Kandaurovinterrupt handlers, then this handler will be attached to that event.
754b47ece9SSergey KandaurovOtherwise a new event will be created, and if
764b47ece9SSergey Kandaurov.Fa eventp
77dc4e9f1aSJohn Baldwinis not
78dc4e9f1aSJohn Baldwin.Dv NULL ,
79dc4e9f1aSJohn Baldwinthen the pointer at that address to will be modified to point to the
804b47ece9SSergey Kandaurovnewly created event.
81dc4e9f1aSJohn BaldwinThe
829ebce8e5SJohn Baldwin.Fa name
839ebce8e5SJohn Baldwinargument is used to associate a name with a specific handler.
849ebce8e5SJohn BaldwinThis name is appended to the name of the software interrupt thread that this
859ebce8e5SJohn Baldwinhandler is attached to.
869ebce8e5SJohn BaldwinThe
87dc4e9f1aSJohn Baldwin.Fa handler
889ebce8e5SJohn Baldwinargument is the function that will be executed when the handler is scheduled
899ebce8e5SJohn Baldwinto run.
90dc4e9f1aSJohn BaldwinThe
91dc4e9f1aSJohn Baldwin.Fa arg
92dc4e9f1aSJohn Baldwinparameter will be passed in as the only parameter to
93dc4e9f1aSJohn Baldwin.Fa handler
94dc4e9f1aSJohn Baldwinwhen the function is executed.
95dc4e9f1aSJohn BaldwinThe
96dc4e9f1aSJohn Baldwin.Fa pri
979ebce8e5SJohn Baldwinvalue specifies the priority of this interrupt handler relative to other
989ebce8e5SJohn Baldwinsoftware interrupt handlers.
994b47ece9SSergey KandaurovIf an interrupt event is created, then this value is used as the vector,
100dc4e9f1aSJohn Baldwinand the
101dc4e9f1aSJohn Baldwin.Fa flags
102dc4e9f1aSJohn Baldwinargument is used to specify the attributes of a handler such as
103dc4e9f1aSJohn Baldwin.Dv INTR_MPSAFE .
1049ebce8e5SJohn BaldwinThe
10568ca7644SJoseph Koshy.Fa cookiep
1069ebce8e5SJohn Baldwinargument points to a
10779cd39f2SRuslan Ermilov.Vt void *
1089ebce8e5SJohn Baldwincookie.
1099ebce8e5SJohn BaldwinThis cookie will be set to a value that uniquely identifies this handler,
1109ebce8e5SJohn Baldwinand is used to schedule the handler for execution later on.
111dc4e9f1aSJohn Baldwin.Pp
112dc4e9f1aSJohn BaldwinThe
113eb55f31bSSergey Kandaurov.Fn swi_remove
114eb55f31bSSergey Kandaurovfunction is used to teardown an interrupt handler pointed to by the
115eb55f31bSSergey Kandaurov.Fa cookie
116eb55f31bSSergey Kandaurovargument.
117eb55f31bSSergey KandaurovIt detaches the interrupt handler from the associated interrupt event
118eb55f31bSSergey Kandaurovand frees its memory.
119eb55f31bSSergey Kandaurov.Pp
120eb55f31bSSergey KandaurovThe
1219ebce8e5SJohn Baldwin.Fn swi_sched
122dc4e9f1aSJohn Baldwinfunction is used to schedule an interrupt handler and its associated thread to
123dc4e9f1aSJohn Baldwinrun.
124dc4e9f1aSJohn BaldwinThe
1259ebce8e5SJohn Baldwin.Fa cookie
126dc4e9f1aSJohn Baldwinargument specifies which software interrupt handler should be scheduled to run.
127dc4e9f1aSJohn BaldwinThe
128dc4e9f1aSJohn Baldwin.Fa flags
129dc4e9f1aSJohn Baldwinargument specifies how and when the handler should be run and is a mask of one
130dc4e9f1aSJohn Baldwinor more of the following flags:
131aba10e13SAlexander Motin.Bl -tag -width SWI_FROMNMI
132dc4e9f1aSJohn Baldwin.It Dv SWI_DELAY
133dc4e9f1aSJohn BaldwinSpecifies that the kernel should mark the specified handler as needing to run,
134dc4e9f1aSJohn Baldwinbut the kernel should not schedule the software interrupt thread to run.
135dc4e9f1aSJohn BaldwinInstead,
136dc4e9f1aSJohn Baldwin.Fa handler
137dc4e9f1aSJohn Baldwinwill be executed the next time that the software interrupt thread runs after
138dc4e9f1aSJohn Baldwinbeing scheduled by another event.
139aba10e13SAlexander Motin.It Dv SWI_FROMNMI
140aba10e13SAlexander MotinSpecifies that
141aba10e13SAlexander Motin.Fn swi_sched
142aba10e13SAlexander Motinis called from NMI context and should be careful about used KPIs.
143aba10e13SAlexander MotinOn platforms allowing IPI sending from NMI context it immediately wakes
144aba10e13SAlexander Motin.Va clk_intr_event
145aba10e13SAlexander Motinvia the IPI, otherwise it works just like SWI_DELAY.
146dc4e9f1aSJohn Baldwin.El
147dc4e9f1aSJohn Baldwin.Pp
14852116a1cSSergey Kandaurov.Va clk_intr_event
14905b727feSMitchell Horneis a pointer to the
15005b727feSMitchell Horne.Vt struct intr_event
15105b727feSMitchell Horneused to hang delayed handlers off of the clock interrupt, and is invoked
15296b76a6aSMitchell Hornedirectly by
15396b76a6aSMitchell Horne.Xr hardclock 9 .
154dc4e9f1aSJohn Baldwin.Sh RETURN VALUES
155dc4e9f1aSJohn BaldwinThe
1569ebce8e5SJohn Baldwin.Fn swi_add
157eb55f31bSSergey Kandaurovand
158eb55f31bSSergey Kandaurov.Fn swi_remove
159eb55f31bSSergey Kandaurovfunctions return zero on success and non-zero on failure.
1609ebce8e5SJohn Baldwin.Sh ERRORS
1619ebce8e5SJohn BaldwinThe
1629ebce8e5SJohn Baldwin.Fn swi_add
1639ebce8e5SJohn Baldwinfunction will fail if:
1649ebce8e5SJohn Baldwin.Bl -tag -width Er
1659ebce8e5SJohn Baldwin.It Bq Er EAGAIN
1669ebce8e5SJohn BaldwinThe system-imposed limit on the total
1679ebce8e5SJohn Baldwinnumber of processes under execution would be exceeded.
1689ebce8e5SJohn BaldwinThe limit is given by the
1699ebce8e5SJohn Baldwin.Xr sysctl 3
1709ebce8e5SJohn BaldwinMIB variable
1719ebce8e5SJohn Baldwin.Dv KERN_MAXPROC .
1729ebce8e5SJohn Baldwin.It Bq Er EINVAL
1739ebce8e5SJohn BaldwinThe
1749ebce8e5SJohn Baldwin.Fa flags
17549fe354aSJohn Baldwinargument specifies
17649fe354aSJohn Baldwin.Dv INTR_ENTROPY .
1779ebce8e5SJohn Baldwin.It Bq Er EINVAL
1789ebce8e5SJohn BaldwinThe
1794b47ece9SSergey Kandaurov.Fa eventp
1809ebce8e5SJohn Baldwinargument points to a hardware interrupt thread.
1819ebce8e5SJohn Baldwin.It Bq Er EINVAL
1829ebce8e5SJohn BaldwinEither of the
1839ebce8e5SJohn Baldwin.Fa name
1849ebce8e5SJohn Baldwinor
1859ebce8e5SJohn Baldwin.Fa handler
1869ebce8e5SJohn Baldwinarguments are
1879ebce8e5SJohn Baldwin.Dv NULL .
1889ebce8e5SJohn Baldwin.It Bq Er EINVAL
1899ebce8e5SJohn BaldwinThe
1909ebce8e5SJohn Baldwin.Dv INTR_EXCL
1914b47ece9SSergey Kandaurovflag is specified and the interrupt event pointed to by
1924b47ece9SSergey Kandaurov.Fa eventp
1934b47ece9SSergey Kandaurovalready has at least one handler, or the interrupt event already has an
1949ebce8e5SJohn Baldwinexclusive handler.
1959ebce8e5SJohn Baldwin.El
196eb55f31bSSergey Kandaurov.Pp
197eb55f31bSSergey KandaurovThe
198eb55f31bSSergey Kandaurov.Fn swi_remove
199eb55f31bSSergey Kandaurovfunction will fail if:
200eb55f31bSSergey Kandaurov.Bl -tag -width Er
201eb55f31bSSergey Kandaurov.It Bq Er EINVAL
202eb55f31bSSergey KandaurovA software interrupt handler pointed to by
203eb55f31bSSergey Kandaurov.Fa cookie
204eb55f31bSSergey Kandaurovis
205eb55f31bSSergey Kandaurov.Dv NULL .
206eb55f31bSSergey Kandaurov.El
207dc4e9f1aSJohn Baldwin.Sh SEE ALSO
20896b76a6aSMitchell Horne.Xr hardclock 9 ,
209*3cdbaee3SMitchell Horne.Xr intr_event 9 ,
210dc4e9f1aSJohn Baldwin.Xr taskqueue 9
211dc4e9f1aSJohn Baldwin.Sh HISTORY
212dc4e9f1aSJohn BaldwinThe
2139ebce8e5SJohn Baldwin.Fn swi_add
2149ebce8e5SJohn Baldwinand
2159ebce8e5SJohn Baldwin.Fn swi_sched
216dc4e9f1aSJohn Baldwinfunctions first appeared in
217dc4e9f1aSJohn Baldwin.Fx 5.0 .
2189ebce8e5SJohn BaldwinThey replaced the
2199ebce8e5SJohn Baldwin.Fn register_swi
2209ebce8e5SJohn Baldwinfunction which appeared in
2219ebce8e5SJohn Baldwin.Fx 3.0
2229ebce8e5SJohn Baldwinand the
2239ebce8e5SJohn Baldwin.Fn setsoft* ,
2249ebce8e5SJohn Baldwinand
2259ebce8e5SJohn Baldwin.Fn schedsoft*
2269ebce8e5SJohn Baldwinfunctions which date back to at least
2279ebce8e5SJohn Baldwin.Bx 4.4 .
228eb55f31bSSergey KandaurovThe
229eb55f31bSSergey Kandaurov.Fn swi_remove
230eb55f31bSSergey Kandaurovfunction first appeared in
231eb55f31bSSergey Kandaurov.Fx 6.1 .
232