2005-11-24 11:24:01 +03:00
|
|
|
.\" $NetBSD: kcont.9,v 1.9 2005/11/24 08:24:01 yamt Exp $
|
2004-03-23 03:47:18 +03:00
|
|
|
.\"
|
|
|
|
.\" The author of this man page is Jonathan Stone (jonathan@dsg.stanford.edu)
|
|
|
|
.\"
|
|
|
|
.\" Copyright (c) 2003, 2004 Jonathan STone
|
|
|
|
.\"
|
|
|
|
.\" Permission to use, copy, and modify this software with or without fee
|
|
|
|
.\" is hereby granted, provided that this entire notice is included in
|
|
|
|
.\" all source code copies of any software which is or includes a copy or
|
|
|
|
.\" modification of this software.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
|
|
|
|
.\" IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
|
|
|
|
.\" REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
|
|
|
|
.\" MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
|
|
|
|
.\" PURPOSE.
|
|
|
|
.\"
|
|
|
|
.\"
|
|
|
|
.\"
|
2005-11-18 10:21:47 +03:00
|
|
|
.Dd November 17, 2005
|
2004-03-23 03:47:18 +03:00
|
|
|
.Dt KCONT 9
|
|
|
|
.Os
|
|
|
|
.Sh NAME
|
2004-03-23 09:00:08 +03:00
|
|
|
.Nm kcont
|
2004-03-23 14:46:59 +03:00
|
|
|
.Nd continuation-passing framework for deferring execution and for
|
|
|
|
notification of asynchronous events
|
2004-03-23 03:47:18 +03:00
|
|
|
.Sh SYNOPSIS
|
|
|
|
.In sys/kcont.h
|
|
|
|
.\"
|
2004-03-23 09:00:08 +03:00
|
|
|
.Ft struct kc *
|
|
|
|
.Fo kcont
|
|
|
|
.Fa "struct kc *"
|
|
|
|
.Fa "void (*fn) (void *kernel_obj, void *env_arg, int status)"
|
|
|
|
.Fa "void *env_arg"
|
2004-03-24 09:03:26 +03:00
|
|
|
.Fa "int desired_ipl"
|
2004-03-23 09:00:08 +03:00
|
|
|
.Fc
|
2004-03-23 03:47:18 +03:00
|
|
|
.\"
|
|
|
|
.Ft struct kc *
|
2004-03-23 09:00:08 +03:00
|
|
|
.Fo kcont_malloc
|
|
|
|
.Fa "int mallocflags"
|
|
|
|
.Fa "void (*fn) (void *kernel_obj, void *env_arg, int status)"
|
|
|
|
.Fa "void *env_arg"
|
2004-03-24 09:03:26 +03:00
|
|
|
.Fa "int desired_ipl"
|
2004-03-23 09:00:08 +03:00
|
|
|
.Fc
|
2004-03-23 03:47:18 +03:00
|
|
|
.\"
|
|
|
|
.Ft void
|
2004-03-23 09:00:08 +03:00
|
|
|
.Fo kcont_defer
|
|
|
|
.Fa "struct kc *kc"
|
|
|
|
.Fa "void (*fn) (void *kernel_obj, void *env_arg, int status)"
|
|
|
|
.Fa "void *kernel_obj"
|
|
|
|
.Fa "void *env_arg"
|
|
|
|
.Fa "int status"
|
2004-03-24 09:03:26 +03:00
|
|
|
.Fa "int desired_ipl"
|
2004-03-23 09:00:08 +03:00
|
|
|
.Fc
|
2004-03-23 03:47:18 +03:00
|
|
|
.Ft void
|
2004-03-23 09:00:08 +03:00
|
|
|
.Fo kcont_defer_malloc
|
|
|
|
.Fa "int mallocflags"
|
|
|
|
.Fa "void (*fn) (void *kernel_obj, void *env_arg, int status)"
|
|
|
|
.Fa "void *kernel_obj"
|
|
|
|
.Fa "void *env_arg"
|
|
|
|
.Fa "int status"
|
2004-03-24 09:03:26 +03:00
|
|
|
.Fa "int desired_ipl"
|
2004-03-23 09:00:08 +03:00
|
|
|
.Fc
|
2004-03-23 03:47:18 +03:00
|
|
|
.\"
|
|
|
|
.Ft void
|
|
|
|
.Fn kcont_enqueue "struct kcq *kcont_queue" "struct kc* kcont"
|
2004-03-24 09:03:26 +03:00
|
|
|
.\" "void (*fn) (void *kernel_obj, void *env_arg, int status)" "void *env_arg" "int desired_ipl"
|
2004-03-23 03:47:18 +03:00
|
|
|
.Ft void
|
|
|
|
.Fn kcont_run "kcq_t *kcq" "void *obj" "int status" "int curipl"
|
|
|
|
.Sh DESCRIPTION
|
2004-03-23 09:00:08 +03:00
|
|
|
.Nm
|
2004-03-23 03:47:18 +03:00
|
|
|
provides a method of asynchronous notification of kernel events
|
|
|
|
(such as I/O completion events) loosely modelled on the
|
|
|
|
continuation-passing model associated with functional languages such as
|
2004-03-23 09:00:08 +03:00
|
|
|
Scheme.
|
|
|
|
In the context of C and Unix kernels, a continuation can
|
2004-03-23 03:47:18 +03:00
|
|
|
be thought of as a combination of three items:
|
2004-03-23 09:00:08 +03:00
|
|
|
.Pp
|
|
|
|
.Bl -bullet -compact
|
|
|
|
.It
|
|
|
|
a function pointer, or
|
|
|
|
.Dq callback
|
|
|
|
function;
|
|
|
|
.It
|
|
|
|
an argument (or arguments) to that function; and
|
|
|
|
.It
|
|
|
|
other
|
|
|
|
.Dq environment
|
|
|
|
state which is passed into the function.
|
|
|
|
.El
|
2004-03-23 03:47:18 +03:00
|
|
|
.Pp
|
|
|
|
The continuations supported by
|
|
|
|
.Nm
|
|
|
|
can be used to defer execution from a high-priority context
|
|
|
|
(such as a hardware-priority interrupt handler) to a lower-priority
|
2004-03-23 09:00:08 +03:00
|
|
|
context (such as a software-interrupt callout queue specifically for
|
2004-03-23 03:47:18 +03:00
|
|
|
executing
|
|
|
|
.Nm
|
2004-03-23 09:00:08 +03:00
|
|
|
functions).
|
|
|
|
The
|
2004-03-23 03:47:18 +03:00
|
|
|
.Nm
|
|
|
|
mechanism can also be used to deliver notification of asynchronous
|
|
|
|
events, such as I/O completion.
|
|
|
|
.Sh TRADITIONAL I/O COMPLETION NOTIFICATION
|
2004-03-23 09:00:08 +03:00
|
|
|
The traditional Unix methods for asynchronous notification are
|
2004-03-23 03:47:18 +03:00
|
|
|
.Xr ltsleep 9 ,
|
|
|
|
.Xr tsleep 9 ,
|
|
|
|
and
|
2004-03-23 09:00:08 +03:00
|
|
|
.Xr wakeup 9 ,
|
2004-03-23 03:47:18 +03:00
|
|
|
which assume the operation or I/O request are being issued from process
|
2004-03-23 09:00:08 +03:00
|
|
|
context.
|
|
|
|
Once the I/O operation is actually issued, the requesting process
|
|
|
|
is suspended by issuing a
|
2004-03-23 03:47:18 +03:00
|
|
|
.Xr tsleep 9
|
2004-03-23 09:00:08 +03:00
|
|
|
on the address of the I/O buffer.
|
|
|
|
When the I/O operation completes, the I/O subsystem issues a
|
|
|
|
.Xr wakeup 9
|
|
|
|
call on the address of the I/O buffer.
|
|
|
|
The process is then awakened, rescheduled, and continues execution
|
|
|
|
from the
|
2004-03-23 14:46:59 +03:00
|
|
|
.Fn tsleep
|
2004-03-23 09:00:08 +03:00
|
|
|
function call, eventually returning to the function which requested I/O.
|
2004-03-23 03:47:18 +03:00
|
|
|
.Sh CONTINUATIONS
|
2004-03-23 09:00:08 +03:00
|
|
|
In contrast,
|
|
|
|
.Nm
|
|
|
|
constructs an object called a continuation -- a function representing
|
|
|
|
.Dq the rest of the program to be performed .
|
|
|
|
Continuations are constructed via the
|
2004-03-23 03:47:18 +03:00
|
|
|
.Fn kcont
|
|
|
|
and
|
2004-03-23 09:00:08 +03:00
|
|
|
.Fn kcont_malloc
|
2004-03-23 03:47:18 +03:00
|
|
|
functions, which use caller-supplied or dynamically-allocated space,
|
2004-03-23 09:00:08 +03:00
|
|
|
respectively.
|
|
|
|
In addition to the continuation-function, argument-object,
|
|
|
|
and environment, the constructor of each continuation specifies an
|
2004-03-23 03:47:18 +03:00
|
|
|
target interrupt priority (IPL) above which the continuation should not be run.
|
|
|
|
.Pp
|
|
|
|
Once constructed, the continuation can be destined for execution
|
2004-03-23 09:00:08 +03:00
|
|
|
in one of two ways.
|
|
|
|
First,
|
2004-03-23 03:47:18 +03:00
|
|
|
.Fn kcont_defer
|
|
|
|
or
|
2004-03-23 09:00:08 +03:00
|
|
|
.Fn kcont_defer_malloc
|
2004-03-23 03:47:18 +03:00
|
|
|
schedule a continuation for execution as soon as interrupt priority
|
|
|
|
falls to or below the target IPL of the continuation.
|
|
|
|
Alternatively, a
|
|
|
|
.Nm
|
2004-03-23 09:00:08 +03:00
|
|
|
can be passed by its creator across kernel interfaces which accept
|
2004-03-23 03:47:18 +03:00
|
|
|
.Nm
|
2004-03-23 09:00:08 +03:00
|
|
|
objects as methods for notifying the caller (i.e., the
|
|
|
|
.Nm
|
|
|
|
creator) on completion of an asynchronous operation.
|
2004-03-23 03:47:18 +03:00
|
|
|
.Sh DATA TYPES
|
|
|
|
.Ss Deferral Priorities
|
2004-03-23 09:00:08 +03:00
|
|
|
Arguments shown above with the name
|
2004-03-24 09:03:26 +03:00
|
|
|
.Ar desired_ipl
|
2004-03-23 09:00:08 +03:00
|
|
|
are drawn from the following namespace:
|
2004-03-23 14:46:59 +03:00
|
|
|
.Bl -tag -offset indent -width KC_IPL_DEFER_SOFTSERIALXX
|
2005-11-18 00:30:00 +03:00
|
|
|
.It Dv KC_IPL_IMMED
|
2004-03-23 09:00:08 +03:00
|
|
|
Execute the continuation as soon as possible, without regard to current IPL.
|
2005-11-18 00:30:00 +03:00
|
|
|
.It Dv KC_IPL_DEFER_SOFTSERIAL
|
2004-03-23 14:46:59 +03:00
|
|
|
Execute the continuation once IPL falls to
|
|
|
|
.Dv IPL_SOFTSERIAL
|
|
|
|
or below.
|
2005-11-18 00:30:00 +03:00
|
|
|
.It Dv KC_IPL_DEFER_SOFTCLOCK
|
2004-03-23 14:46:59 +03:00
|
|
|
Execute the continuation once IPL falls to
|
|
|
|
.Dv IPL_SOFTCLOCK
|
|
|
|
or below.
|
2005-11-18 00:30:00 +03:00
|
|
|
.It Dv KC_IPL_DEFER_SOFTNET
|
2004-03-23 14:46:59 +03:00
|
|
|
Execute the continuation once IPL falls to
|
|
|
|
.Dv IPL_SOFTNET
|
|
|
|
or below.
|
2005-11-18 00:30:00 +03:00
|
|
|
.It Dv KC_IPL_DEFER_PROCESS
|
2004-03-23 09:00:08 +03:00
|
|
|
Defer execution of the continuation to process context.
|
2004-03-23 03:47:18 +03:00
|
|
|
.El
|
|
|
|
.Sh NOTES
|
2004-03-23 14:46:59 +03:00
|
|
|
The
|
2004-03-24 09:03:26 +03:00
|
|
|
.Ar desired_ipl
|
2004-03-23 14:46:59 +03:00
|
|
|
argument should be interpreted as an upper-bound:
|
2004-03-23 09:00:08 +03:00
|
|
|
the continuation will not be executed before interrupt priority drops
|
|
|
|
to, or below, the requested level.
|
|
|
|
In particular, the current implementation uses
|
|
|
|
.Nx
|
|
|
|
generic software callouts.
|
|
|
|
On
|
|
|
|
.Nx
|
|
|
|
ports which lack generic software callouts, all
|
2004-03-23 03:47:18 +03:00
|
|
|
.Nm
|
2004-03-23 14:46:59 +03:00
|
|
|
continuations will always be deferred all the way to the context
|
|
|
|
of a
|
|
|
|
.Dq helper
|
|
|
|
kernel thread.
|
2004-03-23 03:47:18 +03:00
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr kthread 9 ,
|
|
|
|
.Xr spl 9 ,
|
|
|
|
.Xr tsleep 9 ,
|
2005-11-24 11:24:01 +03:00
|
|
|
.Xr wakeup 9 ,
|
|
|
|
.Xr workqueue 9
|
2004-03-23 03:47:18 +03:00
|
|
|
.Sh AUTHORS
|
|
|
|
The
|
|
|
|
.Nm
|
2004-03-23 14:46:59 +03:00
|
|
|
interface was designed and implemented by
|
|
|
|
.An Jonathan Stone .
|
2004-03-23 03:47:18 +03:00
|
|
|
Additional input on the
|
|
|
|
.Nm
|
|
|
|
design was provided by Jason Thorpe and Nathan Williams.
|