summaryrefslogtreecommitdiffstats
path: root/share/man/man9/swi.9
blob: 3d6018d33ca54bb2914586d2db8b317acaf1502b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
.\" Copyright (c) 2000-2001 John H. Baldwin <jhb@FreeBSD.org>
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" $FreeBSD$
.\"
.Dd October 30, 2000
.Dt SWI 9
.Os
.Sh NAME
.Nm swi_add ,
.Nm swi_sched
.Nd register and schedule software interrupt handlers
.Sh SYNOPSIS
.In sys/param.h
.In sys/bus.h
.In sys/interrupt.h
.Vt "extern	struct ithd *tty_ithd" ;
.Vt "extern	struct ithd *clk_ithd" ;
.Vt "extern	void *net_ih" ;
.Vt "extern	void *softclock_ih" ;
.Vt "extern	void *vm_ih" ;
.Ft int
.Fo swi_add
.Fa "struct ithd **ithdp"
.Fa "const char *name"
.Fa "driver_intr_t handler"
.Fa "void *arg"
.Fa "int pri"
.Fa "enum intr_type flags"
.Fa "void **cookiep"
.Fc
.Ft void
.Fn swi_sched "void *handler" "int flags"
.Sh DESCRIPTION
These functions are used to register and schedule software interrupt handlers.
Software interrupt handlers are attached to a software interrupt thread, just
as hardware interrupt handlers are attached to a hardware interrupt thread.
Multiple handlers can be attached to the same thread.
Software interrupt handlers can be used to queue up less critical processing
inside of hardware interrupt handlers so that the work can be done at a later
time.
Software interrupt threads are different from other kernel threads in that they
are treated as an interrupt thread.
This means that time spent executing these threads is counted as interrupt
time, and that they can be run via a lightweight context switch.
.Pp
The
.Fn swi_add
function is used to register a new software interrupt handler.
The
.Fa ithdp
argument is an optional pointer to a
.Vt struct ithd
pointer.
If this argument points to an existing software interrupt thread, then this
handler will be attached to that thread.
Otherwise a new thread will be created, and if
.Fa ithdp
is not
.Dv NULL ,
then the pointer at that address to will be modified to point to the
newly created thread.
The
.Fa name
argument is used to associate a name with a specific handler.
This name is appended to the name of the software interrupt thread that this
handler is attached to.
The
.Fa handler
argument is the function that will be executed when the handler is scheduled
to run.
The
.Fa arg
parameter will be passed in as the only parameter to
.Fa handler
when the function is executed.
The
.Fa pri
value specifies the priority of this interrupt handler relative to other
software interrupt handlers.
If an interrupt thread is created, then this value is used as the vector,
and the
.Fa flags
argument is used to specify the attributes of a handler such as
.Dv INTR_MPSAFE .
The
.Fn cookiep
argument points to a
.Vt void *
cookie.
This cookie will be set to a value that uniquely identifies this handler,
and is used to schedule the handler for execution later on.
.Pp
The
.Fn swi_sched
function is used to schedule an interrupt handler and its associated thread to
run.
The
.Fa cookie
argument specifies which software interrupt handler should be scheduled to run.
The
.Fa flags
argument specifies how and when the handler should be run and is a mask of one
or more of the following flags:
.Bl -tag -width SWI_NOSWITCH
.It Dv SWI_SWITCH
Specifies that the kernel should schedule the software interrupt thread
associated with the specified handler to run.  If lightweight context switches
are in place, then the kernel will switch to this thread and run it
immediately.
.It Dv SWI_NOSWITCH
Specifies that the kernel should schedule the software interrupt thread
associated with the specified handler to run, but it should not attempt to
switch to the thread immediately.
.It Dv SWI_DELAY
Specifies that the kernel should mark the specified handler as needing to run,
but the kernel should not schedule the software interrupt thread to run.
Instead,
.Fa handler
will be executed the next time that the software interrupt thread runs after
being scheduled by another event.
Attaching a handler to the clock software interrupt thread and using this flag
when scheduling a software interrupt handler can be used to implement the
functionality previously performed by
.Fn setdelayed .
.El
.Pp
The
.Va tty_ithd
and
.Va clk_ithd
variables contain pointers to the software interrupt threads for the tty and
clock software interrupts, respectively.
.Va tty_ithd
is used to hang tty software interrupt handlers off of the same thread.
.Va clk_ithd
is used to hang delayed handlers off of the clock software interrupt thread so
that the functionality of
.Fn setdelayed
can be obtained in conjuction with
.Dv SWI_DELAY .
The
.Va net_ih ,
.Va softclock_ih ,
and
.Va vm_ih
handler cookies are used to schedule software interrupt threads to run for the
networking stack, clock interrupt, and VM subsystem respectively.
.Sh RETURN VALUES
The
.Fn swi_add
function returns zero on success and non-zero on failure.
.Sh ERRORS
The
.Fn swi_add
function will fail if:
.Bl -tag -width Er
.It Bq Er EAGAIN
The system-imposed limit on the total
number of processes under execution would be exceeded.
The limit is given by the
.Xr sysctl 3
MIB variable
.Dv KERN_MAXPROC .
.It Bq Er EINVAL
The
.Fa flags
argument specifies either
.Dv INTR_ENTROPY
or
.Dv INTR_FAST .
.It Bq Er EINVAL
The
.Fa ithdp
argument points to a hardware interrupt thread.
.It Bq Er EINVAL
Either of the
.Fa name
or
.Fa handler
arguments are
.Dv NULL .
.It Bq Er EINVAL
The
.Dv INTR_EXCL
flag is specified and the interrupt thread pointed to by
.Fa ithdp
already has at least one handler, or the interrupt thread already has an
exclusive handler.
.El
.Sh SEE ALSO
.Xr ithread 9 ,
.Xr taskqueue 9
.Sh HISTORY
The
.Fn swi_add
and
.Fn swi_sched
functions first appeared in
.Fx 5.0 .
They replaced the
.Fn register_swi
function which appeared in
.Fx 3.0
and the
.Fn setsoft* ,
and
.Fn schedsoft*
functions which date back to at least
.Bx 4.4 .
.Sh BUGS
Most of the global variables described in this manual page should not be
global, or at the very least should not be declared in
.Aq Pa sys/interrupt.h .
OpenPOWER on IntegriCloud