Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-1-5]: src/sys/kern Pull up rev. 1.62:
details: https://anonhg.NetBSD.org/src/rev/5cbf79eb81e4
branches: netbsd-1-5
changeset: 488495:5cbf79eb81e4
user: thorpej <thorpej%NetBSD.org@localhost>
date: Thu Jul 13 20:12:18 2000 +0000
description:
Pull up rev. 1.62:
New hzto() function from FreeBSD and Artur Grabowski <art%stacken.kth.se@localhost>.
Stops sleeps from returning early (by up to a clock tick), and return 0
ticks for timeouts that should happen now or in the past.
Returning 0 is different from the legacy hzto() interface, and callers
need to check for it.
diffstat:
sys/kern/kern_clock.c | 68 +++++++++++++++++++++++++++++++++++---------------
1 files changed, 47 insertions(+), 21 deletions(-)
diffs (90 lines):
diff -r e8091a8a6e2c -r 5cbf79eb81e4 sys/kern/kern_clock.c
--- a/sys/kern/kern_clock.c Thu Jul 13 16:42:34 2000 +0000
+++ b/sys/kern/kern_clock.c Thu Jul 13 20:12:18 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_clock.c,v 1.60 2000/06/03 20:42:42 thorpej Exp $ */
+/* $NetBSD: kern_clock.c,v 1.60.2.1 2000/07/13 20:12:18 thorpej Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -1110,34 +1110,60 @@
hzto(tv)
struct timeval *tv;
{
- long ticks, sec;
+ unsigned long ticks;
+ long sec, usec;
int s;
/*
- * If number of microseconds will fit in 32 bit arithmetic,
- * then compute number of microseconds to time and scale to
- * ticks. Otherwise just compute number of hz in time, rounding
- * times greater than representible to maximum value. (We must
- * compute in microseconds, because hz can be greater than 1000,
- * and thus tick can be less than one millisecond).
+ * If the number of usecs in the whole seconds part of the time
+ * difference fits in a long, then the total number of usecs will
+ * fit in an unsigned long. Compute the total and convert it to
+ * ticks, rounding up and adding 1 to allow for the current tick
+ * to expire. Rounding also depends on unsigned long arithmetic
+ * to avoid overflow.
*
- * Delta times less than 14 hours can be computed ``exactly''.
- * (Note that if hz would yeild a non-integral number of us per
- * tick, i.e. tickfix is nonzero, timouts can be a tick longer
- * than they should be.) Maximum value for any timeout in 10ms
- * ticks is 250 days.
+ * Otherwise, if the number of ticks in the whole seconds part of
+ * the time difference fits in a long, then convert the parts to
+ * ticks separately and add, using similar rounding methods and
+ * overflow avoidance. This method would work in the previous
+ * case, but it is slightly slower and assume that hz is integral.
+ *
+ * Otherwise, round the time difference down to the maximum
+ * representable value.
+ *
+ * If ints are 32-bit, then the maximum value for any timeout in
+ * 10ms ticks is 248 days.
*/
s = splclock();
sec = tv->tv_sec - time.tv_sec;
- if (sec <= 0x7fffffff / 1000000 - 1)
- ticks = ((tv->tv_sec - time.tv_sec) * 1000000 +
- (tv->tv_usec - time.tv_usec)) / tick;
- else if (sec <= 0x7fffffff / hz)
- ticks = sec * hz;
+ usec = tv->tv_usec - time.tv_usec;
+ splx(s);
+
+ if (usec < 0) {
+ sec--;
+ usec += 1000000;
+ }
+
+ if (sec < 0 || (sec == 0 && usec <= 0)) {
+ /*
+ * Would expire now or in the past. Return 0 ticks.
+ * This is different from the legacy hzto() interface,
+ * and callers need to check for it.
+ */
+ ticks = 0;
+ } else if (sec <= (LONG_MAX / 1000000))
+ ticks = (((sec * 1000000) + (unsigned long)usec + (tick - 1))
+ / tick) + 1;
+ else if (sec <= (LONG_MAX / hz))
+ ticks = (sec * hz) +
+ (((unsigned long)usec + (tick - 1)) / tick) + 1;
else
- ticks = 0x7fffffff;
- splx(s);
- return (ticks);
+ ticks = LONG_MAX;
+
+ if (ticks > INT_MAX)
+ ticks = INT_MAX;
+
+ return ((int)ticks);
}
/*
Home |
Main Index |
Thread Index |
Old Index