xref: /freebsd/share/man/man9/swi.9 (revision eb55f31bebbb9d7a1657a47b2d43aab480b37103)
19ebce8e5SJohn Baldwin.\" Copyright (c) 2000-2001 John H. Baldwin <jhb@FreeBSD.org>
2dc4e9f1aSJohn Baldwin.\" All rights reserved.
3dc4e9f1aSJohn Baldwin.\"
4dc4e9f1aSJohn Baldwin.\" Redistribution and use in source and binary forms, with or without
5dc4e9f1aSJohn Baldwin.\" modification, are permitted provided that the following conditions
6dc4e9f1aSJohn Baldwin.\" are met:
7dc4e9f1aSJohn Baldwin.\" 1. Redistributions of source code must retain the above copyright
8dc4e9f1aSJohn Baldwin.\"    notice, this list of conditions and the following disclaimer.
9dc4e9f1aSJohn Baldwin.\" 2. Redistributions in binary form must reproduce the above copyright
10dc4e9f1aSJohn Baldwin.\"    notice, this list of conditions and the following disclaimer in the
11dc4e9f1aSJohn Baldwin.\"    documentation and/or other materials provided with the distribution.
12dc4e9f1aSJohn Baldwin.\"
13dc4e9f1aSJohn Baldwin.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14dc4e9f1aSJohn Baldwin.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15dc4e9f1aSJohn Baldwin.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16dc4e9f1aSJohn Baldwin.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17dc4e9f1aSJohn Baldwin.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18dc4e9f1aSJohn Baldwin.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19dc4e9f1aSJohn Baldwin.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20dc4e9f1aSJohn Baldwin.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21dc4e9f1aSJohn Baldwin.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22dc4e9f1aSJohn Baldwin.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23dc4e9f1aSJohn Baldwin.\" SUCH DAMAGE.
24dc4e9f1aSJohn Baldwin.\"
25dc4e9f1aSJohn Baldwin.\" $FreeBSD$
26dc4e9f1aSJohn Baldwin.\"
27*eb55f31bSSergey Kandaurov.Dd April 19, 2012
28dc4e9f1aSJohn Baldwin.Dt SWI 9
29dc4e9f1aSJohn Baldwin.Os
30dc4e9f1aSJohn Baldwin.Sh NAME
319ebce8e5SJohn Baldwin.Nm swi_add ,
32*eb55f31bSSergey Kandaurov.Nm swi_remove ,
339ebce8e5SJohn Baldwin.Nm swi_sched
34dc4e9f1aSJohn Baldwin.Nd register and schedule software interrupt handlers
35dc4e9f1aSJohn Baldwin.Sh SYNOPSIS
3632eef9aeSRuslan Ermilov.In sys/param.h
3732eef9aeSRuslan Ermilov.In sys/bus.h
3832eef9aeSRuslan Ermilov.In sys/interrupt.h
39b77b3c00SRuslan Ermilov.Vt "extern struct ithd *tty_ithd" ;
40b77b3c00SRuslan Ermilov.Vt "extern struct ithd *clk_ithd" ;
419ebce8e5SJohn Baldwin.Vt "extern void *net_ih" ;
429ebce8e5SJohn Baldwin.Vt "extern void *softclock_ih" ;
439ebce8e5SJohn Baldwin.Vt "extern void *vm_ih" ;
449ebce8e5SJohn Baldwin.Ft int
459ebce8e5SJohn Baldwin.Fo swi_add
464b47ece9SSergey Kandaurov.Fa "struct intr_event **eventp"
47dc4e9f1aSJohn Baldwin.Fa "const char *name"
48dc4e9f1aSJohn Baldwin.Fa "driver_intr_t handler"
49dc4e9f1aSJohn Baldwin.Fa "void *arg"
50dc4e9f1aSJohn Baldwin.Fa "int pri"
519ebce8e5SJohn Baldwin.Fa "enum intr_type flags"
529ebce8e5SJohn Baldwin.Fa "void **cookiep"
53dc4e9f1aSJohn Baldwin.Fc
54*eb55f31bSSergey Kandaurov.Ft int
55*eb55f31bSSergey Kandaurov.Fn swi_remove "void *cookie"
569ebce8e5SJohn Baldwin.Ft void
5768ca7644SJoseph Koshy.Fn swi_sched "void *cookie" "int flags"
58dc4e9f1aSJohn Baldwin.Sh DESCRIPTION
59dc4e9f1aSJohn BaldwinThese functions are used to register and schedule software interrupt handlers.
60dc4e9f1aSJohn BaldwinSoftware interrupt handlers are attached to a software interrupt thread, just
61dc4e9f1aSJohn Baldwinas hardware interrupt handlers are attached to a hardware interrupt thread.
629ebce8e5SJohn BaldwinMultiple handlers can be attached to the same thread.
63dc4e9f1aSJohn BaldwinSoftware interrupt handlers can be used to queue up less critical processing
64dc4e9f1aSJohn Baldwininside of hardware interrupt handlers so that the work can be done at a later
65dc4e9f1aSJohn Baldwintime.
66dc4e9f1aSJohn BaldwinSoftware interrupt threads are different from other kernel threads in that they
67dc4e9f1aSJohn Baldwinare treated as an interrupt thread.
68dc4e9f1aSJohn BaldwinThis means that time spent executing these threads is counted as interrupt
699ebce8e5SJohn Baldwintime, and that they can be run via a lightweight context switch.
70dc4e9f1aSJohn Baldwin.Pp
71dc4e9f1aSJohn BaldwinThe
729ebce8e5SJohn Baldwin.Fn swi_add
734b47ece9SSergey Kandaurovfunction is used to add a new software interrupt handler to a specified
744b47ece9SSergey Kandaurovinterrupt event.
75dc4e9f1aSJohn BaldwinThe
764b47ece9SSergey Kandaurov.Fa eventp
77dc4e9f1aSJohn Baldwinargument is an optional pointer to a
784b47ece9SSergey Kandaurov.Vt struct intr_event
79dc4e9f1aSJohn Baldwinpointer.
804b47ece9SSergey KandaurovIf this argument points to an existing event that holds a list of
814b47ece9SSergey Kandaurovinterrupt handlers, then this handler will be attached to that event.
824b47ece9SSergey KandaurovOtherwise a new event will be created, and if
834b47ece9SSergey Kandaurov.Fa eventp
84dc4e9f1aSJohn Baldwinis not
85dc4e9f1aSJohn Baldwin.Dv NULL ,
86dc4e9f1aSJohn Baldwinthen the pointer at that address to will be modified to point to the
874b47ece9SSergey Kandaurovnewly created event.
88dc4e9f1aSJohn BaldwinThe
899ebce8e5SJohn Baldwin.Fa name
909ebce8e5SJohn Baldwinargument is used to associate a name with a specific handler.
919ebce8e5SJohn BaldwinThis name is appended to the name of the software interrupt thread that this
929ebce8e5SJohn Baldwinhandler is attached to.
939ebce8e5SJohn BaldwinThe
94dc4e9f1aSJohn Baldwin.Fa handler
959ebce8e5SJohn Baldwinargument is the function that will be executed when the handler is scheduled
969ebce8e5SJohn Baldwinto run.
97dc4e9f1aSJohn BaldwinThe
98dc4e9f1aSJohn Baldwin.Fa arg
99dc4e9f1aSJohn Baldwinparameter will be passed in as the only parameter to
100dc4e9f1aSJohn Baldwin.Fa handler
101dc4e9f1aSJohn Baldwinwhen the function is executed.
102dc4e9f1aSJohn BaldwinThe
103dc4e9f1aSJohn Baldwin.Fa pri
1049ebce8e5SJohn Baldwinvalue specifies the priority of this interrupt handler relative to other
1059ebce8e5SJohn Baldwinsoftware interrupt handlers.
1064b47ece9SSergey KandaurovIf an interrupt event is created, then this value is used as the vector,
107dc4e9f1aSJohn Baldwinand the
108dc4e9f1aSJohn Baldwin.Fa flags
109dc4e9f1aSJohn Baldwinargument is used to specify the attributes of a handler such as
110dc4e9f1aSJohn Baldwin.Dv INTR_MPSAFE .
1119ebce8e5SJohn BaldwinThe
11268ca7644SJoseph Koshy.Fa cookiep
1139ebce8e5SJohn Baldwinargument points to a
11479cd39f2SRuslan Ermilov.Vt void *
1159ebce8e5SJohn Baldwincookie.
1169ebce8e5SJohn BaldwinThis cookie will be set to a value that uniquely identifies this handler,
1179ebce8e5SJohn Baldwinand is used to schedule the handler for execution later on.
118dc4e9f1aSJohn Baldwin.Pp
119dc4e9f1aSJohn BaldwinThe
120*eb55f31bSSergey Kandaurov.Fn swi_remove
121*eb55f31bSSergey Kandaurovfunction is used to teardown an interrupt handler pointed to by the
122*eb55f31bSSergey Kandaurov.Fa cookie
123*eb55f31bSSergey Kandaurovargument.
124*eb55f31bSSergey KandaurovIt detaches the interrupt handler from the associated interrupt event
125*eb55f31bSSergey Kandaurovand frees its memory.
126*eb55f31bSSergey Kandaurov.Pp
127*eb55f31bSSergey KandaurovThe
1289ebce8e5SJohn Baldwin.Fn swi_sched
129dc4e9f1aSJohn Baldwinfunction is used to schedule an interrupt handler and its associated thread to
130dc4e9f1aSJohn Baldwinrun.
131dc4e9f1aSJohn BaldwinThe
1329ebce8e5SJohn Baldwin.Fa cookie
133dc4e9f1aSJohn Baldwinargument specifies which software interrupt handler should be scheduled to run.
134dc4e9f1aSJohn BaldwinThe
135dc4e9f1aSJohn Baldwin.Fa flags
136dc4e9f1aSJohn Baldwinargument specifies how and when the handler should be run and is a mask of one
137dc4e9f1aSJohn Baldwinor more of the following flags:
138a3672eeeSJohn Baldwin.Bl -tag -width SWI_DELAY
139dc4e9f1aSJohn Baldwin.It Dv SWI_DELAY
140dc4e9f1aSJohn BaldwinSpecifies that the kernel should mark the specified handler as needing to run,
141dc4e9f1aSJohn Baldwinbut the kernel should not schedule the software interrupt thread to run.
142dc4e9f1aSJohn BaldwinInstead,
143dc4e9f1aSJohn Baldwin.Fa handler
144dc4e9f1aSJohn Baldwinwill be executed the next time that the software interrupt thread runs after
145dc4e9f1aSJohn Baldwinbeing scheduled by another event.
146dc4e9f1aSJohn BaldwinAttaching a handler to the clock software interrupt thread and using this flag
147dc4e9f1aSJohn Baldwinwhen scheduling a software interrupt handler can be used to implement the
148a3672eeeSJohn Baldwinfunctionality performed by
149a3672eeeSJohn Baldwin.Fn setdelayed
150a3672eeeSJohn Baldwinin earlier versions of
151a3672eeeSJohn Baldwin.Fx .
152dc4e9f1aSJohn Baldwin.El
153dc4e9f1aSJohn Baldwin.Pp
154dc4e9f1aSJohn BaldwinThe
155dc4e9f1aSJohn Baldwin.Va tty_ithd
156dc4e9f1aSJohn Baldwinand
157dc4e9f1aSJohn Baldwin.Va clk_ithd
158dc4e9f1aSJohn Baldwinvariables contain pointers to the software interrupt threads for the tty and
159dc4e9f1aSJohn Baldwinclock software interrupts, respectively.
160dc4e9f1aSJohn Baldwin.Va tty_ithd
161dc4e9f1aSJohn Baldwinis used to hang tty software interrupt handlers off of the same thread.
162dc4e9f1aSJohn Baldwin.Va clk_ithd
163dc4e9f1aSJohn Baldwinis used to hang delayed handlers off of the clock software interrupt thread so
164dc4e9f1aSJohn Baldwinthat the functionality of
165dc4e9f1aSJohn Baldwin.Fn setdelayed
166559ff927SJens Schweikhardtcan be obtained in conjunction with
167dc4e9f1aSJohn Baldwin.Dv SWI_DELAY .
168dc4e9f1aSJohn BaldwinThe
169dc4e9f1aSJohn Baldwin.Va net_ih ,
170dc4e9f1aSJohn Baldwin.Va softclock_ih ,
171dc4e9f1aSJohn Baldwinand
172dc4e9f1aSJohn Baldwin.Va vm_ih
173dc4e9f1aSJohn Baldwinhandler cookies are used to schedule software interrupt threads to run for the
174dc4e9f1aSJohn Baldwinnetworking stack, clock interrupt, and VM subsystem respectively.
175dc4e9f1aSJohn Baldwin.Sh RETURN VALUES
176dc4e9f1aSJohn BaldwinThe
1779ebce8e5SJohn Baldwin.Fn swi_add
178*eb55f31bSSergey Kandaurovand
179*eb55f31bSSergey Kandaurov.Fn swi_remove
180*eb55f31bSSergey Kandaurovfunctions return zero on success and non-zero on failure.
1819ebce8e5SJohn Baldwin.Sh ERRORS
1829ebce8e5SJohn BaldwinThe
1839ebce8e5SJohn Baldwin.Fn swi_add
1849ebce8e5SJohn Baldwinfunction will fail if:
1859ebce8e5SJohn Baldwin.Bl -tag -width Er
1869ebce8e5SJohn Baldwin.It Bq Er EAGAIN
1879ebce8e5SJohn BaldwinThe system-imposed limit on the total
1889ebce8e5SJohn Baldwinnumber of processes under execution would be exceeded.
1899ebce8e5SJohn BaldwinThe limit is given by the
1909ebce8e5SJohn Baldwin.Xr sysctl 3
1919ebce8e5SJohn BaldwinMIB variable
1929ebce8e5SJohn Baldwin.Dv KERN_MAXPROC .
1939ebce8e5SJohn Baldwin.It Bq Er EINVAL
1949ebce8e5SJohn BaldwinThe
1959ebce8e5SJohn Baldwin.Fa flags
19649fe354aSJohn Baldwinargument specifies
19749fe354aSJohn Baldwin.Dv INTR_ENTROPY .
1989ebce8e5SJohn Baldwin.It Bq Er EINVAL
1999ebce8e5SJohn BaldwinThe
2004b47ece9SSergey Kandaurov.Fa eventp
2019ebce8e5SJohn Baldwinargument points to a hardware interrupt thread.
2029ebce8e5SJohn Baldwin.It Bq Er EINVAL
2039ebce8e5SJohn BaldwinEither of the
2049ebce8e5SJohn Baldwin.Fa name
2059ebce8e5SJohn Baldwinor
2069ebce8e5SJohn Baldwin.Fa handler
2079ebce8e5SJohn Baldwinarguments are
2089ebce8e5SJohn Baldwin.Dv NULL .
2099ebce8e5SJohn Baldwin.It Bq Er EINVAL
2109ebce8e5SJohn BaldwinThe
2119ebce8e5SJohn Baldwin.Dv INTR_EXCL
2124b47ece9SSergey Kandaurovflag is specified and the interrupt event pointed to by
2134b47ece9SSergey Kandaurov.Fa eventp
2144b47ece9SSergey Kandaurovalready has at least one handler, or the interrupt event already has an
2159ebce8e5SJohn Baldwinexclusive handler.
2169ebce8e5SJohn Baldwin.El
217*eb55f31bSSergey Kandaurov.Pp
218*eb55f31bSSergey KandaurovThe
219*eb55f31bSSergey Kandaurov.Fn swi_remove
220*eb55f31bSSergey Kandaurovfunction will fail if:
221*eb55f31bSSergey Kandaurov.Bl -tag -width Er
222*eb55f31bSSergey Kandaurov.It Bq Er EINVAL
223*eb55f31bSSergey KandaurovA software interrupt handler pointed to by
224*eb55f31bSSergey Kandaurov.Fa cookie
225*eb55f31bSSergey Kandaurovis
226*eb55f31bSSergey Kandaurov.Dv NULL .
227*eb55f31bSSergey Kandaurov.El
228dc4e9f1aSJohn Baldwin.Sh SEE ALSO
2299ebce8e5SJohn Baldwin.Xr ithread 9 ,
230dc4e9f1aSJohn Baldwin.Xr taskqueue 9
231dc4e9f1aSJohn Baldwin.Sh HISTORY
232dc4e9f1aSJohn BaldwinThe
2339ebce8e5SJohn Baldwin.Fn swi_add
2349ebce8e5SJohn Baldwinand
2359ebce8e5SJohn Baldwin.Fn swi_sched
236dc4e9f1aSJohn Baldwinfunctions first appeared in
237dc4e9f1aSJohn Baldwin.Fx 5.0 .
2389ebce8e5SJohn BaldwinThey replaced the
2399ebce8e5SJohn Baldwin.Fn register_swi
2409ebce8e5SJohn Baldwinfunction which appeared in
2419ebce8e5SJohn Baldwin.Fx 3.0
2429ebce8e5SJohn Baldwinand the
2439ebce8e5SJohn Baldwin.Fn setsoft* ,
2449ebce8e5SJohn Baldwinand
2459ebce8e5SJohn Baldwin.Fn schedsoft*
2469ebce8e5SJohn Baldwinfunctions which date back to at least
2479ebce8e5SJohn Baldwin.Bx 4.4 .
248*eb55f31bSSergey KandaurovThe
249*eb55f31bSSergey Kandaurov.Fn swi_remove
250*eb55f31bSSergey Kandaurovfunction first appeared in
251*eb55f31bSSergey Kandaurov.Fx 6.1 .
252dc4e9f1aSJohn Baldwin.Sh BUGS
253dc4e9f1aSJohn BaldwinMost of the global variables described in this manual page should not be
254dc4e9f1aSJohn Baldwinglobal, or at the very least should not be declared in
255fe08efe6SRuslan Ermilov.In sys/interrupt.h .
256