NetBSD/share/man/man9/callout.9

200 lines
5.9 KiB
Groff

.\" $NetBSD: callout.9,v 1.8 2003/02/04 01:22:36 thorpej Exp $
.\"
.\" Copyright (c) 2000, 2003 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Jason R. Thorpe.
.\"
.\" 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.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the NetBSD
.\" Foundation, Inc. and its contributors.
.\" 4. Neither the name of The NetBSD Foundation nor the names of its
.\" contributors may be used to endorse or promote products derived
.\" from this software without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
.\"
.Dd February 3, 2003
.Dt CALLOUT 9
.Os
.Sh NAME
.Nm callout_init ,
.Nm callout_reset ,
.Nm callout_schedule ,
.Nm callout_setfunc ,
.Nm callout_stop ,
.Nm CALLOUT_INITIALIZER ,
.Nm CALLOUT_INITIALIZER_SETFUNC
.Nd execute a function after a specified length of time
.Sh SYNOPSIS
.Fd #include \*[Lt]sys/callout.h\*[Gt]
.Ft void
.Fn "callout_init" "struct callout *c"
.Ft void
.Fn "callout_reset" "struct callout *c" "int ticks" \
"void (*func)(void *)" "void *arg"
.Ft void
.Fn "callout_schedule" "struct callout *c" "int ticks"
.Ft void
.Fn "callout_setfunc" "struct callout *c" "void (*func)(void *)" "void *arg"
.Ft void
.Fn "callout_stop" "struct callout *c"
.Ft int
.Fn "callout_pending" "struct callout *c"
.Ft int
.Fn "callout_expired" "struct callout *c"
.Fd CALLOUT_INITIALIZER
.Pp
.Fd CALLOUT_INITIALIZER_SETFUNC(func, arg)
.Sh DESCRIPTION
The
.Nm callout
facility provides a mechanism to execute a function at a given time.
The timer is based on the hardclock timer which ticks
.Dv hz
times per second.
The function is called at softclock interrupt level.
.Pp
Clients of the
.Nm callout
facility are responsible for providing pre-allocated
callout structures, or
.Dq handles .
The
.Nm callout
facility replaces the historic
.Bx
functions
.Fn timeout
and
.Fn untimeout .
.Pp
The
.Fn callout_init
function initializes the callout handle
.Fa c
for use.
If it is inconvenient to call
.Fn callout_init ,
statically-allocated callout handles may be initialized by assigning
the value
.Dv CALLOUT_INITIALIZER
to them.
.Pp
The
.Fn callout_reset
function resets and starts the timer associated with the callout handle
.Fa c .
When the timer expires after
.Fa ticks Ns No /hz
seconds, the function specified by
.Fa func
will be called with the argument
.Fa arg .
If the timer associated with the callout handle is already running,
the callout will simply be rescheduled to execute at the newly specified
time.
Once the timer is started, the callout handle is marked as
.Em PENDING .
Once the timer expires,
the handle is marked at
.Em EXPIRED
and the
.Em PENDING
status is cleared.
.Pp
The
.Fn callout_setfunc
function initializes the callout handle
.Fa c
for use and sets the function and argument to
.Fa func
and
.Fa arg
respectively.
If a callout will always be used with the same function and argument,
then
.Fn callout_setfunc
used in conjunction with
.Fn callout_schedule
is slightly more efficient than using
.Fn callout_init
and
.Fn callout_reset .
If it is inconvenient to call
.Fn callout_setfunc ,
statically-allocated callout handles may be initialized by assigning
the value
.Dv CALLOUT_INITIALIZER_SETFUNC
to them, passing the function and argument to the initializer.
.Pp
The
.Fn callout_stop
function stops the timer associated the callout handle
.Fa c .
The
.Em PENDING
status for the callout handle is cleared.
The
.Em EXPIRED
status is not affected.
It is safe to call
.Fn callout_stop
on a callout handle that is not pending, so long as it is initialized.
.Pp
The
.Fn callout_pending
function tests the
.Em PENDING
status of the callout handle
.Fa c .
A
.Em PENDING
callout is one that has been started and whose function has not yet
been called.
Note that it is possible for a callout's timer to have expired without
its function being called if interrupt level has not dropped low enough
to let softclock interrupts through.
Note that it is only safe to test
.Em PENDING
status when at softclock interrupt level or higher.
.Pp
The
.Fn callout_expired
function tests to see if the callout's timer has expired and its
function called.
.Sh SEE ALSO
.Xr hz 9
.Sh HISTORY
The
.Nm callout
facility was implemented by Artur Grabowski and Thomas Nordin, based
on the work of G. Varghese and A. Lauck, described in the paper
Hashed and Hierarchical Timing Wheels: Data Structures for the
Efficient Implementation of a Timer Facility
in the Proceedings of the 11th ACM Annual Symposium on Operating System
Principles, Austin, Texas, November 1987.
It was adapted to the
.Nx
kernel by Jason R. Thorpe.