swi_addswi_sched
- register and schedule software interrupt handlers
SYNOPSIS
#include <sys/param.h>
#include <sys/bus.h>
#include <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 ;
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
swi_sched (void *cookie int flags);
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.
The
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
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
INTR_MPSAFE
The
Fa 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.
The
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:
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 performed by
setdelayed ();
in earlier versions of
Fx .
The
tty_ithd
and
clk_ithd
variables contain pointers to the software interrupt threads for the tty and
clock software interrupts, respectively.
tty_ithd
is used to hang tty software interrupt handlers off of the same thread.
clk_ithd
is used to hang delayed handlers off of the clock software interrupt thread so
that the functionality of
setdelayed ();
can be obtained in conjunction with
SWI_DELAY
The
net_ihsoftclock_ih
and
vm_ih
handler cookies are used to schedule software interrupt threads to run for the
networking stack, clock interrupt, and VM subsystem respectively.
RETURN VALUES
The
swi_add ();
function returns zero on success and non-zero on failure.
ERRORS
The
swi_add ();
function will fail if:
Bq Er EAGAIN
The system-imposed limit on the total
number of processes under execution would be exceeded.
The limit is given by the
sysctl(3)
MIB variable
KERN_MAXPROC
Bq Er EINVAL
The
Fa flags
argument specifies either
INTR_ENTROPY
or
INTR_FAST
Bq Er EINVAL
The
Fa ithdp
argument points to a hardware interrupt thread.
Bq Er EINVAL
Either of the
Fa name
or
Fa handler
arguments are
NULL
Bq Er EINVAL
The
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.
The
swi_add ();
and
swi_sched ();
functions first appeared in
Fx 5.0 .
They replaced the
register_swi ();
function which appeared in
Fx 3.0
and the
setsoft (* ,);
and
schedsoft (*);
functions which date back to at least
BSD 4.4
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
In sys/interrupt.h .