xref: /freebsd/share/man/man9/swi.9 (revision 52116a1cb9d765e8cb035c136713c70b7342aa0d)
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.\"
27eb55f31bSSergey Kandaurov.Dd April 19, 2012
28dc4e9f1aSJohn Baldwin.Dt SWI 9
29dc4e9f1aSJohn Baldwin.Os
30dc4e9f1aSJohn Baldwin.Sh NAME
319ebce8e5SJohn Baldwin.Nm swi_add ,
32eb55f31bSSergey 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
39*52116a1cSSergey Kandaurov.Vt "extern struct intr_event *tty_intr_event" ;
40*52116a1cSSergey Kandaurov.Vt "extern struct intr_event *clk_intr_event" ;
419ebce8e5SJohn Baldwin.Vt "extern void *vm_ih" ;
429ebce8e5SJohn Baldwin.Ft int
439ebce8e5SJohn Baldwin.Fo swi_add
444b47ece9SSergey Kandaurov.Fa "struct intr_event **eventp"
45dc4e9f1aSJohn Baldwin.Fa "const char *name"
46dc4e9f1aSJohn Baldwin.Fa "driver_intr_t handler"
47dc4e9f1aSJohn Baldwin.Fa "void *arg"
48dc4e9f1aSJohn Baldwin.Fa "int pri"
499ebce8e5SJohn Baldwin.Fa "enum intr_type flags"
509ebce8e5SJohn Baldwin.Fa "void **cookiep"
51dc4e9f1aSJohn Baldwin.Fc
52eb55f31bSSergey Kandaurov.Ft int
53eb55f31bSSergey Kandaurov.Fn swi_remove "void *cookie"
549ebce8e5SJohn Baldwin.Ft void
5568ca7644SJoseph Koshy.Fn swi_sched "void *cookie" "int flags"
56dc4e9f1aSJohn Baldwin.Sh DESCRIPTION
57dc4e9f1aSJohn BaldwinThese functions are used to register and schedule software interrupt handlers.
58dc4e9f1aSJohn BaldwinSoftware interrupt handlers are attached to a software interrupt thread, just
59dc4e9f1aSJohn Baldwinas hardware interrupt handlers are attached to a hardware interrupt thread.
609ebce8e5SJohn BaldwinMultiple handlers can be attached to the same thread.
61dc4e9f1aSJohn BaldwinSoftware interrupt handlers can be used to queue up less critical processing
62dc4e9f1aSJohn Baldwininside of hardware interrupt handlers so that the work can be done at a later
63dc4e9f1aSJohn Baldwintime.
64dc4e9f1aSJohn BaldwinSoftware interrupt threads are different from other kernel threads in that they
65dc4e9f1aSJohn Baldwinare treated as an interrupt thread.
66dc4e9f1aSJohn BaldwinThis means that time spent executing these threads is counted as interrupt
679ebce8e5SJohn Baldwintime, and that they can be run via a lightweight context switch.
68dc4e9f1aSJohn Baldwin.Pp
69dc4e9f1aSJohn BaldwinThe
709ebce8e5SJohn Baldwin.Fn swi_add
714b47ece9SSergey Kandaurovfunction is used to add a new software interrupt handler to a specified
724b47ece9SSergey Kandaurovinterrupt event.
73dc4e9f1aSJohn BaldwinThe
744b47ece9SSergey Kandaurov.Fa eventp
75dc4e9f1aSJohn Baldwinargument is an optional pointer to a
764b47ece9SSergey Kandaurov.Vt struct intr_event
77dc4e9f1aSJohn Baldwinpointer.
784b47ece9SSergey KandaurovIf this argument points to an existing event that holds a list of
794b47ece9SSergey Kandaurovinterrupt handlers, then this handler will be attached to that event.
804b47ece9SSergey KandaurovOtherwise a new event will be created, and if
814b47ece9SSergey Kandaurov.Fa eventp
82dc4e9f1aSJohn Baldwinis not
83dc4e9f1aSJohn Baldwin.Dv NULL ,
84dc4e9f1aSJohn Baldwinthen the pointer at that address to will be modified to point to the
854b47ece9SSergey Kandaurovnewly created event.
86dc4e9f1aSJohn BaldwinThe
879ebce8e5SJohn Baldwin.Fa name
889ebce8e5SJohn Baldwinargument is used to associate a name with a specific handler.
899ebce8e5SJohn BaldwinThis name is appended to the name of the software interrupt thread that this
909ebce8e5SJohn Baldwinhandler is attached to.
919ebce8e5SJohn BaldwinThe
92dc4e9f1aSJohn Baldwin.Fa handler
939ebce8e5SJohn Baldwinargument is the function that will be executed when the handler is scheduled
949ebce8e5SJohn Baldwinto run.
95dc4e9f1aSJohn BaldwinThe
96dc4e9f1aSJohn Baldwin.Fa arg
97dc4e9f1aSJohn Baldwinparameter will be passed in as the only parameter to
98dc4e9f1aSJohn Baldwin.Fa handler
99dc4e9f1aSJohn Baldwinwhen the function is executed.
100dc4e9f1aSJohn BaldwinThe
101dc4e9f1aSJohn Baldwin.Fa pri
1029ebce8e5SJohn Baldwinvalue specifies the priority of this interrupt handler relative to other
1039ebce8e5SJohn Baldwinsoftware interrupt handlers.
1044b47ece9SSergey KandaurovIf an interrupt event is created, then this value is used as the vector,
105dc4e9f1aSJohn Baldwinand the
106dc4e9f1aSJohn Baldwin.Fa flags
107dc4e9f1aSJohn Baldwinargument is used to specify the attributes of a handler such as
108dc4e9f1aSJohn Baldwin.Dv INTR_MPSAFE .
1099ebce8e5SJohn BaldwinThe
11068ca7644SJoseph Koshy.Fa cookiep
1119ebce8e5SJohn Baldwinargument points to a
11279cd39f2SRuslan Ermilov.Vt void *
1139ebce8e5SJohn Baldwincookie.
1149ebce8e5SJohn BaldwinThis cookie will be set to a value that uniquely identifies this handler,
1159ebce8e5SJohn Baldwinand is used to schedule the handler for execution later on.
116dc4e9f1aSJohn Baldwin.Pp
117dc4e9f1aSJohn BaldwinThe
118eb55f31bSSergey Kandaurov.Fn swi_remove
119eb55f31bSSergey Kandaurovfunction is used to teardown an interrupt handler pointed to by the
120eb55f31bSSergey Kandaurov.Fa cookie
121eb55f31bSSergey Kandaurovargument.
122eb55f31bSSergey KandaurovIt detaches the interrupt handler from the associated interrupt event
123eb55f31bSSergey Kandaurovand frees its memory.
124eb55f31bSSergey Kandaurov.Pp
125eb55f31bSSergey KandaurovThe
1269ebce8e5SJohn Baldwin.Fn swi_sched
127dc4e9f1aSJohn Baldwinfunction is used to schedule an interrupt handler and its associated thread to
128dc4e9f1aSJohn Baldwinrun.
129dc4e9f1aSJohn BaldwinThe
1309ebce8e5SJohn Baldwin.Fa cookie
131dc4e9f1aSJohn Baldwinargument specifies which software interrupt handler should be scheduled to run.
132dc4e9f1aSJohn BaldwinThe
133dc4e9f1aSJohn Baldwin.Fa flags
134dc4e9f1aSJohn Baldwinargument specifies how and when the handler should be run and is a mask of one
135dc4e9f1aSJohn Baldwinor more of the following flags:
136a3672eeeSJohn Baldwin.Bl -tag -width SWI_DELAY
137dc4e9f1aSJohn Baldwin.It Dv SWI_DELAY
138dc4e9f1aSJohn BaldwinSpecifies that the kernel should mark the specified handler as needing to run,
139dc4e9f1aSJohn Baldwinbut the kernel should not schedule the software interrupt thread to run.
140dc4e9f1aSJohn BaldwinInstead,
141dc4e9f1aSJohn Baldwin.Fa handler
142dc4e9f1aSJohn Baldwinwill be executed the next time that the software interrupt thread runs after
143dc4e9f1aSJohn Baldwinbeing scheduled by another event.
144dc4e9f1aSJohn BaldwinAttaching a handler to the clock software interrupt thread and using this flag
145dc4e9f1aSJohn Baldwinwhen scheduling a software interrupt handler can be used to implement the
146a3672eeeSJohn Baldwinfunctionality performed by
147a3672eeeSJohn Baldwin.Fn setdelayed
148a3672eeeSJohn Baldwinin earlier versions of
149a3672eeeSJohn Baldwin.Fx .
150dc4e9f1aSJohn Baldwin.El
151dc4e9f1aSJohn Baldwin.Pp
152dc4e9f1aSJohn BaldwinThe
153*52116a1cSSergey Kandaurov.Va tty_intr_event
154dc4e9f1aSJohn Baldwinand
155*52116a1cSSergey Kandaurov.Va clk_intr_event
156*52116a1cSSergey Kandaurovvariables contain pointers to the software interrupt handlers for the tty and
157dc4e9f1aSJohn Baldwinclock software interrupts, respectively.
158*52116a1cSSergey Kandaurov.Va tty_intr_event
159dc4e9f1aSJohn Baldwinis used to hang tty software interrupt handlers off of the same thread.
160*52116a1cSSergey Kandaurov.Va clk_intr_event
161dc4e9f1aSJohn Baldwinis used to hang delayed handlers off of the clock software interrupt thread so
162dc4e9f1aSJohn Baldwinthat the functionality of
163dc4e9f1aSJohn Baldwin.Fn setdelayed
164559ff927SJens Schweikhardtcan be obtained in conjunction with
165dc4e9f1aSJohn Baldwin.Dv SWI_DELAY .
166dc4e9f1aSJohn BaldwinThe
167dc4e9f1aSJohn Baldwin.Va vm_ih
168*52116a1cSSergey Kandaurovhandler cookie is used to schedule software interrupt threads to run for the
169*52116a1cSSergey KandaurovVM subsystem.
170dc4e9f1aSJohn Baldwin.Sh RETURN VALUES
171dc4e9f1aSJohn BaldwinThe
1729ebce8e5SJohn Baldwin.Fn swi_add
173eb55f31bSSergey Kandaurovand
174eb55f31bSSergey Kandaurov.Fn swi_remove
175eb55f31bSSergey Kandaurovfunctions return zero on success and non-zero on failure.
1769ebce8e5SJohn Baldwin.Sh ERRORS
1779ebce8e5SJohn BaldwinThe
1789ebce8e5SJohn Baldwin.Fn swi_add
1799ebce8e5SJohn Baldwinfunction will fail if:
1809ebce8e5SJohn Baldwin.Bl -tag -width Er
1819ebce8e5SJohn Baldwin.It Bq Er EAGAIN
1829ebce8e5SJohn BaldwinThe system-imposed limit on the total
1839ebce8e5SJohn Baldwinnumber of processes under execution would be exceeded.
1849ebce8e5SJohn BaldwinThe limit is given by the
1859ebce8e5SJohn Baldwin.Xr sysctl 3
1869ebce8e5SJohn BaldwinMIB variable
1879ebce8e5SJohn Baldwin.Dv KERN_MAXPROC .
1889ebce8e5SJohn Baldwin.It Bq Er EINVAL
1899ebce8e5SJohn BaldwinThe
1909ebce8e5SJohn Baldwin.Fa flags
19149fe354aSJohn Baldwinargument specifies
19249fe354aSJohn Baldwin.Dv INTR_ENTROPY .
1939ebce8e5SJohn Baldwin.It Bq Er EINVAL
1949ebce8e5SJohn BaldwinThe
1954b47ece9SSergey Kandaurov.Fa eventp
1969ebce8e5SJohn Baldwinargument points to a hardware interrupt thread.
1979ebce8e5SJohn Baldwin.It Bq Er EINVAL
1989ebce8e5SJohn BaldwinEither of the
1999ebce8e5SJohn Baldwin.Fa name
2009ebce8e5SJohn Baldwinor
2019ebce8e5SJohn Baldwin.Fa handler
2029ebce8e5SJohn Baldwinarguments are
2039ebce8e5SJohn Baldwin.Dv NULL .
2049ebce8e5SJohn Baldwin.It Bq Er EINVAL
2059ebce8e5SJohn BaldwinThe
2069ebce8e5SJohn Baldwin.Dv INTR_EXCL
2074b47ece9SSergey Kandaurovflag is specified and the interrupt event pointed to by
2084b47ece9SSergey Kandaurov.Fa eventp
2094b47ece9SSergey Kandaurovalready has at least one handler, or the interrupt event already has an
2109ebce8e5SJohn Baldwinexclusive handler.
2119ebce8e5SJohn Baldwin.El
212eb55f31bSSergey Kandaurov.Pp
213eb55f31bSSergey KandaurovThe
214eb55f31bSSergey Kandaurov.Fn swi_remove
215eb55f31bSSergey Kandaurovfunction will fail if:
216eb55f31bSSergey Kandaurov.Bl -tag -width Er
217eb55f31bSSergey Kandaurov.It Bq Er EINVAL
218eb55f31bSSergey KandaurovA software interrupt handler pointed to by
219eb55f31bSSergey Kandaurov.Fa cookie
220eb55f31bSSergey Kandaurovis
221eb55f31bSSergey Kandaurov.Dv NULL .
222eb55f31bSSergey Kandaurov.El
223dc4e9f1aSJohn Baldwin.Sh SEE ALSO
2249ebce8e5SJohn Baldwin.Xr ithread 9 ,
225dc4e9f1aSJohn Baldwin.Xr taskqueue 9
226dc4e9f1aSJohn Baldwin.Sh HISTORY
227dc4e9f1aSJohn BaldwinThe
2289ebce8e5SJohn Baldwin.Fn swi_add
2299ebce8e5SJohn Baldwinand
2309ebce8e5SJohn Baldwin.Fn swi_sched
231dc4e9f1aSJohn Baldwinfunctions first appeared in
232dc4e9f1aSJohn Baldwin.Fx 5.0 .
2339ebce8e5SJohn BaldwinThey replaced the
2349ebce8e5SJohn Baldwin.Fn register_swi
2359ebce8e5SJohn Baldwinfunction which appeared in
2369ebce8e5SJohn Baldwin.Fx 3.0
2379ebce8e5SJohn Baldwinand the
2389ebce8e5SJohn Baldwin.Fn setsoft* ,
2399ebce8e5SJohn Baldwinand
2409ebce8e5SJohn Baldwin.Fn schedsoft*
2419ebce8e5SJohn Baldwinfunctions which date back to at least
2429ebce8e5SJohn Baldwin.Bx 4.4 .
243eb55f31bSSergey KandaurovThe
244eb55f31bSSergey Kandaurov.Fn swi_remove
245eb55f31bSSergey Kandaurovfunction first appeared in
246eb55f31bSSergey Kandaurov.Fx 6.1 .
247dc4e9f1aSJohn Baldwin.Sh BUGS
248dc4e9f1aSJohn BaldwinMost of the global variables described in this manual page should not be
249dc4e9f1aSJohn Baldwinglobal, or at the very least should not be declared in
250fe08efe6SRuslan Ermilov.In sys/interrupt.h .
251