xref: /freebsd/share/man/man9/swi.9 (revision 68ca7644cfd11ee5eabf08ef822b8fdae2160cb3)
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.\"
27dc4e9f1aSJohn Baldwin.Dd October 30, 2000
28dc4e9f1aSJohn Baldwin.Dt SWI 9
29dc4e9f1aSJohn Baldwin.Os
30dc4e9f1aSJohn Baldwin.Sh NAME
319ebce8e5SJohn Baldwin.Nm swi_add ,
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
38b77b3c00SRuslan Ermilov.Vt "extern struct ithd *tty_ithd" ;
39b77b3c00SRuslan Ermilov.Vt "extern struct ithd *clk_ithd" ;
409ebce8e5SJohn Baldwin.Vt "extern void *net_ih" ;
419ebce8e5SJohn Baldwin.Vt "extern void *softclock_ih" ;
429ebce8e5SJohn Baldwin.Vt "extern void *vm_ih" ;
439ebce8e5SJohn Baldwin.Ft int
449ebce8e5SJohn Baldwin.Fo swi_add
459ebce8e5SJohn Baldwin.Fa "struct ithd **ithdp"
46dc4e9f1aSJohn Baldwin.Fa "const char *name"
47dc4e9f1aSJohn Baldwin.Fa "driver_intr_t handler"
48dc4e9f1aSJohn Baldwin.Fa "void *arg"
49dc4e9f1aSJohn Baldwin.Fa "int pri"
509ebce8e5SJohn Baldwin.Fa "enum intr_type flags"
519ebce8e5SJohn Baldwin.Fa "void **cookiep"
52dc4e9f1aSJohn Baldwin.Fc
539ebce8e5SJohn Baldwin.Ft void
5468ca7644SJoseph Koshy.Fn swi_sched "void *cookie" "int flags"
55dc4e9f1aSJohn Baldwin.Sh DESCRIPTION
56dc4e9f1aSJohn BaldwinThese functions are used to register and schedule software interrupt handlers.
57dc4e9f1aSJohn BaldwinSoftware interrupt handlers are attached to a software interrupt thread, just
58dc4e9f1aSJohn Baldwinas hardware interrupt handlers are attached to a hardware interrupt thread.
599ebce8e5SJohn BaldwinMultiple handlers can be attached to the same thread.
60dc4e9f1aSJohn BaldwinSoftware interrupt handlers can be used to queue up less critical processing
61dc4e9f1aSJohn Baldwininside of hardware interrupt handlers so that the work can be done at a later
62dc4e9f1aSJohn Baldwintime.
63dc4e9f1aSJohn BaldwinSoftware interrupt threads are different from other kernel threads in that they
64dc4e9f1aSJohn Baldwinare treated as an interrupt thread.
65dc4e9f1aSJohn BaldwinThis means that time spent executing these threads is counted as interrupt
669ebce8e5SJohn Baldwintime, and that they can be run via a lightweight context switch.
67dc4e9f1aSJohn Baldwin.Pp
68dc4e9f1aSJohn BaldwinThe
699ebce8e5SJohn Baldwin.Fn swi_add
70dc4e9f1aSJohn Baldwinfunction is used to register a new software interrupt handler.
71dc4e9f1aSJohn BaldwinThe
729ebce8e5SJohn Baldwin.Fa ithdp
73dc4e9f1aSJohn Baldwinargument is an optional pointer to a
7479cd39f2SRuslan Ermilov.Vt struct ithd
75dc4e9f1aSJohn Baldwinpointer.
76dc4e9f1aSJohn BaldwinIf this argument points to an existing software interrupt thread, then this
77dc4e9f1aSJohn Baldwinhandler will be attached to that thread.
78dc4e9f1aSJohn BaldwinOtherwise a new thread will be created, and if
799ebce8e5SJohn Baldwin.Fa ithdp
80dc4e9f1aSJohn Baldwinis not
81dc4e9f1aSJohn Baldwin.Dv NULL ,
82dc4e9f1aSJohn Baldwinthen the pointer at that address to will be modified to point to the
83dc4e9f1aSJohn Baldwinnewly created thread.
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.
1029ebce8e5SJohn BaldwinIf an interrupt thread 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
1169ebce8e5SJohn Baldwin.Fn swi_sched
117dc4e9f1aSJohn Baldwinfunction is used to schedule an interrupt handler and its associated thread to
118dc4e9f1aSJohn Baldwinrun.
119dc4e9f1aSJohn BaldwinThe
1209ebce8e5SJohn Baldwin.Fa cookie
121dc4e9f1aSJohn Baldwinargument specifies which software interrupt handler should be scheduled to run.
122dc4e9f1aSJohn BaldwinThe
123dc4e9f1aSJohn Baldwin.Fa flags
124dc4e9f1aSJohn Baldwinargument specifies how and when the handler should be run and is a mask of one
125dc4e9f1aSJohn Baldwinor more of the following flags:
126a3672eeeSJohn Baldwin.Bl -tag -width SWI_DELAY
127dc4e9f1aSJohn Baldwin.It Dv SWI_DELAY
128dc4e9f1aSJohn BaldwinSpecifies that the kernel should mark the specified handler as needing to run,
129dc4e9f1aSJohn Baldwinbut the kernel should not schedule the software interrupt thread to run.
130dc4e9f1aSJohn BaldwinInstead,
131dc4e9f1aSJohn Baldwin.Fa handler
132dc4e9f1aSJohn Baldwinwill be executed the next time that the software interrupt thread runs after
133dc4e9f1aSJohn Baldwinbeing scheduled by another event.
134dc4e9f1aSJohn BaldwinAttaching a handler to the clock software interrupt thread and using this flag
135dc4e9f1aSJohn Baldwinwhen scheduling a software interrupt handler can be used to implement the
136a3672eeeSJohn Baldwinfunctionality performed by
137a3672eeeSJohn Baldwin.Fn setdelayed
138a3672eeeSJohn Baldwinin earlier versions of
139a3672eeeSJohn Baldwin.Fx .
140dc4e9f1aSJohn Baldwin.El
141dc4e9f1aSJohn Baldwin.Pp
142dc4e9f1aSJohn BaldwinThe
143dc4e9f1aSJohn Baldwin.Va tty_ithd
144dc4e9f1aSJohn Baldwinand
145dc4e9f1aSJohn Baldwin.Va clk_ithd
146dc4e9f1aSJohn Baldwinvariables contain pointers to the software interrupt threads for the tty and
147dc4e9f1aSJohn Baldwinclock software interrupts, respectively.
148dc4e9f1aSJohn Baldwin.Va tty_ithd
149dc4e9f1aSJohn Baldwinis used to hang tty software interrupt handlers off of the same thread.
150dc4e9f1aSJohn Baldwin.Va clk_ithd
151dc4e9f1aSJohn Baldwinis used to hang delayed handlers off of the clock software interrupt thread so
152dc4e9f1aSJohn Baldwinthat the functionality of
153dc4e9f1aSJohn Baldwin.Fn setdelayed
154559ff927SJens Schweikhardtcan be obtained in conjunction with
155dc4e9f1aSJohn Baldwin.Dv SWI_DELAY .
156dc4e9f1aSJohn BaldwinThe
157dc4e9f1aSJohn Baldwin.Va net_ih ,
158dc4e9f1aSJohn Baldwin.Va softclock_ih ,
159dc4e9f1aSJohn Baldwinand
160dc4e9f1aSJohn Baldwin.Va vm_ih
161dc4e9f1aSJohn Baldwinhandler cookies are used to schedule software interrupt threads to run for the
162dc4e9f1aSJohn Baldwinnetworking stack, clock interrupt, and VM subsystem respectively.
163dc4e9f1aSJohn Baldwin.Sh RETURN VALUES
164dc4e9f1aSJohn BaldwinThe
1659ebce8e5SJohn Baldwin.Fn swi_add
1669ebce8e5SJohn Baldwinfunction returns zero on success and non-zero on failure.
1679ebce8e5SJohn Baldwin.Sh ERRORS
1689ebce8e5SJohn BaldwinThe
1699ebce8e5SJohn Baldwin.Fn swi_add
1709ebce8e5SJohn Baldwinfunction will fail if:
1719ebce8e5SJohn Baldwin.Bl -tag -width Er
1729ebce8e5SJohn Baldwin.It Bq Er EAGAIN
1739ebce8e5SJohn BaldwinThe system-imposed limit on the total
1749ebce8e5SJohn Baldwinnumber of processes under execution would be exceeded.
1759ebce8e5SJohn BaldwinThe limit is given by the
1769ebce8e5SJohn Baldwin.Xr sysctl 3
1779ebce8e5SJohn BaldwinMIB variable
1789ebce8e5SJohn Baldwin.Dv KERN_MAXPROC .
1799ebce8e5SJohn Baldwin.It Bq Er EINVAL
1809ebce8e5SJohn BaldwinThe
1819ebce8e5SJohn Baldwin.Fa flags
1829ebce8e5SJohn Baldwinargument specifies either
1839ebce8e5SJohn Baldwin.Dv INTR_ENTROPY
1849ebce8e5SJohn Baldwinor
1859ebce8e5SJohn Baldwin.Dv INTR_FAST .
1869ebce8e5SJohn Baldwin.It Bq Er EINVAL
1879ebce8e5SJohn BaldwinThe
1889ebce8e5SJohn Baldwin.Fa ithdp
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
2009ebce8e5SJohn Baldwinflag is specified and the interrupt thread pointed to by
2019ebce8e5SJohn Baldwin.Fa ithdp
2029ebce8e5SJohn Baldwinalready has at least one handler, or the interrupt thread already has an
2039ebce8e5SJohn Baldwinexclusive handler.
2049ebce8e5SJohn Baldwin.El
205dc4e9f1aSJohn Baldwin.Sh SEE ALSO
2069ebce8e5SJohn Baldwin.Xr ithread 9 ,
207dc4e9f1aSJohn Baldwin.Xr taskqueue 9
208dc4e9f1aSJohn Baldwin.Sh HISTORY
209dc4e9f1aSJohn BaldwinThe
2109ebce8e5SJohn Baldwin.Fn swi_add
2119ebce8e5SJohn Baldwinand
2129ebce8e5SJohn Baldwin.Fn swi_sched
213dc4e9f1aSJohn Baldwinfunctions first appeared in
214dc4e9f1aSJohn Baldwin.Fx 5.0 .
2159ebce8e5SJohn BaldwinThey replaced the
2169ebce8e5SJohn Baldwin.Fn register_swi
2179ebce8e5SJohn Baldwinfunction which appeared in
2189ebce8e5SJohn Baldwin.Fx 3.0
2199ebce8e5SJohn Baldwinand the
2209ebce8e5SJohn Baldwin.Fn setsoft* ,
2219ebce8e5SJohn Baldwinand
2229ebce8e5SJohn Baldwin.Fn schedsoft*
2239ebce8e5SJohn Baldwinfunctions which date back to at least
2249ebce8e5SJohn Baldwin.Bx 4.4 .
225dc4e9f1aSJohn Baldwin.Sh BUGS
226dc4e9f1aSJohn BaldwinMost of the global variables described in this manual page should not be
227dc4e9f1aSJohn Baldwinglobal, or at the very least should not be declared in
228fe08efe6SRuslan Ermilov.In sys/interrupt.h .
229