summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--share/man/man9/timeout.958
-rw-r--r--sys/kern/kern_timeout.c17
-rw-r--r--sys/sys/timeout.h13
3 files changed, 63 insertions, 25 deletions
diff --git a/share/man/man9/timeout.9 b/share/man/man9/timeout.9
index 8717783c97e..2935a428d79 100644
--- a/share/man/man9/timeout.9
+++ b/share/man/man9/timeout.9
@@ -1,4 +1,4 @@
-.\" $OpenBSD: timeout.9,v 1.49 2019/12/02 21:47:54 cheloha Exp $
+.\" $OpenBSD: timeout.9,v 1.50 2020/01/03 02:16:38 cheloha Exp $
.\"
.\" Copyright (c) 2000 Artur Grabowski <art@openbsd.org>
.\" All rights reserved.
@@ -23,12 +23,12 @@
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd $Mdocdate: December 2 2019 $
+.Dd $Mdocdate: January 3 2020 $
.Dt TIMEOUT_SET 9
.Os
.Sh NAME
.Nm timeout_set ,
-.Nm timeout_set_proc ,
+.Nm timeout_set_flags ,
.Nm timeout_add ,
.Nm timeout_add_sec ,
.Nm timeout_add_msec ,
@@ -43,7 +43,8 @@
.Nm timeout_pending ,
.Nm timeout_initialized ,
.Nm timeout_triggered ,
-.Nm TIMEOUT_INITIALIZER
+.Nm TIMEOUT_INITIALIZER ,
+.Nm TIMEOUT_INITIALIZER_FLAGS
.Nd execute a function after a specified period of time
.Sh SYNOPSIS
.In sys/types.h
@@ -51,7 +52,12 @@
.Ft void
.Fn timeout_set "struct timeout *to" "void (*fn)(void *)" "void *arg"
.Ft void
-.Fn timeout_set_proc "struct timeout *to" "void (*fn)(void *)" "void *arg"
+.Fo timeout_set_flags
+.Fa "struct timeout *to"
+.Fa "void (*fn)(void *)"
+.Fa "void *arg"
+.Fa "int flags"
+.Fc
.Ft int
.Fn timeout_add "struct timeout *to" "int ticks"
.Ft int
@@ -81,6 +87,7 @@
.Ft int
.Fn timeout_add_nsec "struct timeout *to" "int nsec"
.Fn TIMEOUT_INITIALIZER "void (*fn)(void *)" "void *arg"
+.Fn TIMEOUT_INITIALIZER_FLAGS "void (*fn)(void *)" "void *arg" "int flags"
.Sh DESCRIPTION
The
.Nm timeout
@@ -94,11 +101,9 @@ times a second.
It is the responsibility of the caller to provide these functions with
pre-allocated timeout structures.
.Pp
-The functions
+The
.Fn timeout_set
-and
-.Fn timeout_set_proc
-prepare the timeout structure
+function prepares the timeout structure
.Fa to
to be used in future calls to
.Fn timeout_add
@@ -120,6 +125,20 @@ and
and does not need to be reinitialized unless
the function called and/or its argument must change.
.Pp
+The
+.Fn timeout_set_flags
+function is similar to
+.Fn timeout_set
+but it additionally accepts the bitwise OR of zero or more of the
+following
+.Fa flags :
+.Bl -tag -width TIMEOUT_PROC -offset indent
+.It Dv TIMEOUT_PROC
+Runs the timeout in a process context instead of the default
+.Dv IPL_SOFTCLOCK
+interrupt context.
+.El
+.Pp
The function
.Fn timeout_add
schedules the execution of the
@@ -140,11 +159,11 @@ The timeout in the
argument must be already initialized by
.Fn timeout_set
or
-.Fn timeout_set_proc
+.Fn timeout_set_flags
and may not be used in calls to
.Fn timeout_set
or
-.Fn timeout_set_proc
+.Fn timeout_set_flags
until it has timed out or been removed with
.Fn timeout_del .
If the timeout in the
@@ -216,10 +235,19 @@ argument with the
.Fa void *
argument given in
.Fa arg .
+.Pp
+The
+.Fn TIMEOUT_INITIALIZER_FLAGS
+macro is similar to
+.Fn TIMEOUT_INITIALIZER ,
+but it accepts additional flags.
+See the
+.Fn timeout_set_flags
+function for details.
.Sh CONTEXT
.Fn timeout_set
and
-.Fn timeout_set_proc
+.Fn timeout_set_flags
can be called during autoconf, from process context, or from interrupt
context.
.Pp
@@ -249,10 +277,12 @@ When the timeout runs, the
argument to
.Fn timeout_set
or
-.Fn timeout_set_proc
+.Fn timeout_set_flags
will be called in an interrupt context at
.Dv IPL_SOFTCLOCK
-or a process context, respectively.
+or a process context if the
+.Dv TIMEOUT_PROC
+flag was given at initialization.
.Sh RETURN VALUES
.Fn timeout_add ,
.Fn timeout_add_sec ,
diff --git a/sys/kern/kern_timeout.c b/sys/kern/kern_timeout.c
index 293659ac7aa..9239d8e5f8b 100644
--- a/sys/kern/kern_timeout.c
+++ b/sys/kern/kern_timeout.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_timeout.c,v 1.68 2020/01/03 01:16:12 cheloha Exp $ */
+/* $OpenBSD: kern_timeout.c,v 1.69 2020/01/03 02:16:38 cheloha Exp $ */
/*
* Copyright (c) 2001 Thomas Nordin <nordin@openbsd.org>
* Copyright (c) 2000-2001 Artur Grabowski <art@openbsd.org>
@@ -224,16 +224,21 @@ timeout_proc_init(void)
void
timeout_set(struct timeout *new, void (*fn)(void *), void *arg)
{
- new->to_func = fn;
- new->to_arg = arg;
- new->to_flags = TIMEOUT_INITIALIZED;
+ timeout_set_flags(new, fn, arg, 0);
+}
+
+void
+timeout_set_flags(struct timeout *to, void (*fn)(void *), void *arg, int flags)
+{
+ to->to_func = fn;
+ to->to_arg = arg;
+ to->to_flags = flags | TIMEOUT_INITIALIZED;
}
void
timeout_set_proc(struct timeout *new, void (*fn)(void *), void *arg)
{
- timeout_set(new, fn, arg);
- SET(new->to_flags, TIMEOUT_PROC);
+ timeout_set_flags(new, fn, arg, TIMEOUT_PROC);
}
int
diff --git a/sys/sys/timeout.h b/sys/sys/timeout.h
index 88c0cb7c5e4..1cd9fca9e06 100644
--- a/sys/sys/timeout.h
+++ b/sys/sys/timeout.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: timeout.h,v 1.35 2020/01/03 01:16:12 cheloha Exp $ */
+/* $OpenBSD: timeout.h,v 1.36 2020/01/03 02:16:38 cheloha Exp $ */
/*
* Copyright (c) 2000-2001 Artur Grabowski <art@openbsd.org>
* All rights reserved.
@@ -101,17 +101,20 @@ int timeout_sysctl(void *, size_t *, void *, size_t);
#define timeout_initialized(to) ((to)->to_flags & TIMEOUT_INITIALIZED)
#define timeout_triggered(to) ((to)->to_flags & TIMEOUT_TRIGGERED)
-#define TIMEOUT_INITIALIZER(_f, _a) { \
+#define TIMEOUT_INITIALIZER_FLAGS(fn, arg, flags) { \
.to_list = { NULL, NULL }, \
- .to_func = (_f), \
- .to_arg = (_a), \
+ .to_func = (fn), \
+ .to_arg = (arg), \
.to_time = 0, \
- .to_flags = TIMEOUT_INITIALIZED \
+ .to_flags = (flags) | TIMEOUT_INITIALIZED \
}
+#define TIMEOUT_INITIALIZER(_f, _a) TIMEOUT_INITIALIZER_FLAGS((_f), (_a), 0)
+
struct bintime;
void timeout_set(struct timeout *, void (*)(void *), void *);
+void timeout_set_flags(struct timeout *, void (*)(void *), void *, int);
void timeout_set_proc(struct timeout *, void (*)(void *), void *);
int timeout_add(struct timeout *, int);
int timeout_add_tv(struct timeout *, const struct timeval *);