--M9NhX3UHpAaciwkO
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Disposition: inline
Hi,
It has been suggested that one of the steps towards a proper tickless kernel
would be the conversion of all the users of the various timeout API
to the use of the more rounded time units whenever possible, e.g. the
less precise and more rounded seconds instead of the more precise ticks. [0]
In the kernel, the most obvious and popular examples of such API
would be callout(9) and tsleep(9).
Since many current users of these API logically require an ms-based timer,
and the future granularity of a tick may be subject to change, it also
makes sense to introduce a millisecond (_ms) version of the API together with
the second (_s) addition.
It may be noted that OpenBSD already has had similar functions introduced
sometime in 2008 ([1], [2]): timeout_add_{tv,ts,bt,sec,msec,usec,nsec}.
Apart from _sec and _msec, the rest have no users (only _usec is used once),
and in the current environment, the us and ns timeouts would appear to serve
no purpose other than to mislead and confuse the developer.
On the other hand, timeout_add_sec is referenced in 142 kernel source files
in OpenBSD 4.7 as of 2010-03, and timeout_add_msec -- in 79.
Also, the standard SI abbreviation for second and millisecond
is s and ms, respectively, not sec and msec.
I think it may actually be reasonable to introduce a decisecond (ds)
version of the functions (in addition to the second and millisecond),
since that's what many millisecond-to-be users actually need, and _ds
would be more tickless-friendly compared to _ms anyways.
The centisecond (cs) may be considered as a more distant option. :-)
Please let me know what you think of these additions, and whether
similar _s and _ms sleep(9) functions should be added as well.
I'm also interested in the feedback regarding the potential _ds
addition.
Best regards,
Constantine.
[0] http://oss.intel.com/pdfs/maximum_tickless.pdf "Getting maximum mileage out of tickless" (2007)
[1] http://www.openbsd.org/cgi-bin/cvsweb/src/sys/kern/kern_timeout.c#rev1.27 "timeout_add_{tv,ts,bt,sec,usec,nsec}" (2008-07-11)
[2] http://www.openbsd.org/cgi-bin/cvsweb/src/sys/kern/kern_timeout.c#rev1.29 "timeout_add_msec" (2008-10-22)
--M9NhX3UHpAaciwkO
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline; filename="0001-callout-9-introduce-callout_reset_-m-s-similarly-to-.patch"
From 9c37d63b31d845553e5fe1b39d562cca815ef914 Mon Sep 17 00:00:00 2001
From: Constantine A. Murenin <cnst+dfly@bugmail.mojo.ru>
Date: Wed, 24 Feb 2010 18:23:50 -0500
Subject: [PATCH 1/2] callout(9): introduce callout_reset_{,m}s, similarly to timeout_add_{,m}sec on OpenBSD
---
sys/kern/kern_timeout.c | 26 ++++++++++++++++++++++++++
sys/sys/callout.h | 2 ++
2 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/sys/kern/kern_timeout.c b/sys/kern/kern_timeout.c
index 189ffb0..c296c1c 100644
--- a/sys/kern/kern_timeout.c
+++ b/sys/kern/kern_timeout.c
@@ -109,6 +109,8 @@
#include <sys/thread2.h>
#include <sys/mplock2.h>
+#include <machine/limits.h>
+
#ifndef MAX_SOFTCLOCK_STEPS
#define MAX_SOFTCLOCK_STEPS 100 /* Maximum allowed value of steps. */
#endif
@@ -385,6 +387,30 @@ callout_reset(struct callout *c, int to_ticks, void (*ftn)(void *),
crit_exit_gd(gd);
}
+void
+callout_reset_s(struct callout *c, int s, void (*ftn)(void *),
+ void *arg)
+{
+ uintmax_t t;
+
+ t = (uintmax_t)s * hz;
+ if (t > INT_MAX)
+ t = INT_MAX;
+ callout_reset(c, t, ftn, arg);
+}
+
+void
+callout_reset_ms(struct callout *c, int ms, void (*ftn)(void *),
+ void *arg)
+{
+ uintmax_t t;
+
+ t = (uintmax_t)ms * hz / 1000;
+ if (t > INT_MAX)
+ t = INT_MAX;
+ callout_reset(c, t, ftn, arg);
+}
+
/*
* Stop a running timer. WARNING! If called on a cpu other then the one
* the callout was started on this function will liveloop on its IPI to
diff --git a/sys/sys/callout.h b/sys/sys/callout.h
index 5113793..492c01e 100644
--- a/sys/sys/callout.h
+++ b/sys/sys/callout.h
@@ -92,6 +92,8 @@ void hardclock_softtick(struct globaldata *);
void callout_init (struct callout *);
void callout_init_mp (struct callout *);
void callout_reset (struct callout *, int, void (*)(void *), void *);
+void callout_reset_s (struct callout *, int, void (*)(void *), void *);
+void callout_reset_ms (struct callout *, int, void (*)(void *), void *);
int callout_stop (struct callout *);
#endif
--
1.6.6
--M9NhX3UHpAaciwkO
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline; filename="0002-callout.9-document-callout_reset_-m-s.patch"
From c91f755ee94d73b777749db3f5aa9b409f595f87 Mon Sep 17 00:00:00 2001
From: Constantine A. Murenin <cnst+dfly@bugmail.mojo.ru>
Date: Wed, 24 Feb 2010 22:03:51 -0500
Subject: [PATCH 2/2] callout.9: document callout_reset_{,m}s
---
share/man/man9/Makefile | 2 ++
share/man/man9/callout.9 | 15 +++++++++++++++
2 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/share/man/man9/Makefile b/share/man/man9/Makefile
index 3e52f7b..d00f220 100644
--- a/share/man/man9/Makefile
+++ b/share/man/man9/Makefile
@@ -332,6 +332,8 @@ MLINKS+=callout.9 callout_active.9 \
callout.9 callout_init_mp.9 \
callout.9 callout_pending.9 \
callout.9 callout_reset.9 \
+ callout.9 callout_reset_ms.9 \
+ callout.9 callout_reset_s.9 \
callout.9 callout_stop.9 \
callout.9 timeout.9 \
callout.9 untimeout.9
diff --git a/share/man/man9/callout.9 b/share/man/man9/callout.9
index 88191d1..f9c0e67 100644
--- a/share/man/man9/callout.9
+++ b/share/man/man9/callout.9
@@ -44,6 +44,8 @@
.Nm callout_init ,
.Nm callout_init_mp ,
.Nm callout_reset ,
+.Nm callout_reset_s ,
+.Nm callout_reset_ms ,
.Nm callout_stop ,
.Nm callout_active ,
.Nm callout_pending ,
@@ -61,6 +63,10 @@ typedef void timeout_t (void *);
.Fn callout_init_mp "struct callout *c"
.Ft void
.Fn callout_reset "struct callout *c" "int ticks" "timeout_t *func" "void *arg"
+.Ft void
+.Fn callout_reset_s "struct callout *c" "int s" "timeout_t *func" "void *arg"
+.Ft void
+.Fn callout_reset_ms "struct callout *c" "int ms" "timeout_t *func" "void *arg"
.Ft int
.Fn callout_stop "struct callout *c"
.Ft int
@@ -115,6 +121,15 @@ seconds, the function specified by
will be called with the argument
.Fa arg .
.Pp
+The
+.Fn callout_reset_s
+and
+.Fn callout_reset_ms
+functions can be used in place of the
+.Fn callout_reset
+function with the timeout value expressed
+in seconds and milliseconds, respectively.
+.Pp
The function
.Fn callout_stop
cancels the callout associated with the callout handle
--
1.6.6
--M9NhX3UHpAaciwkO--