lkml.org 
[lkml]   [2004]   [Jan]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH] Fine tune the time conversion to eliminate conversion errors.
Andrew,

The time conversion code is erroring on the side of a bit too small. The
attached patch forces any error to be on the high side. The current code will
convert 1 nanosecond to zero jiffies (standard says that should be 1). It also
is around 1 nanosecond late on each roll to the next jiffie.

I have done some error checks with this patch applied and get the following
errors in PPB ( Parts Per Billion):

HZ nano sec conversion microsecond conversion
1000 315 45
1024 227 40
100 28 317

In all cases the error is on the high side, which means that the final shift
will, most likely, eliminate the error bits.

--
George Anzinger george@mvista.com
High-res-timers: http://sourceforge.net/projects/high-res-timers/
Preemption patch: http://www.kernel.org/pub/linux/kernel/people/rml
--- linux-2.6.1-org/include/linux/time.h 2003-08-11 13:48:55.000000000 -0700
+++ linux/include/linux/time.h 2004-01-27 00:29:12.000000000 -0800
@@ -148,14 +148,14 @@
#endif
#define NSEC_JIFFIE_SC (SEC_JIFFIE_SC + 29)
#define USEC_JIFFIE_SC (SEC_JIFFIE_SC + 19)
-#define SEC_CONVERSION ((unsigned long)((((u64)NSEC_PER_SEC << SEC_JIFFIE_SC))\
- / (u64)TICK_NSEC))
+#define SEC_CONVERSION ((unsigned long)((((u64)NSEC_PER_SEC << SEC_JIFFIE_SC) +\
+ TICK_NSEC -1) / (u64)TICK_NSEC))

-#define NSEC_CONVERSION ((unsigned long)((((u64)1 << NSEC_JIFFIE_SC))\
- / (u64)TICK_NSEC))
+#define NSEC_CONVERSION ((unsigned long)((((u64)1 << NSEC_JIFFIE_SC) +\
+ TICK_NSEC -1) / (u64)TICK_NSEC))
#define USEC_CONVERSION \
- ((unsigned long)((((u64)NSEC_PER_USEC << USEC_JIFFIE_SC)) \
- / (u64)TICK_NSEC))
+ ((unsigned long)((((u64)NSEC_PER_USEC << USEC_JIFFIE_SC) +\
+ TICK_NSEC -1) / (u64)TICK_NSEC))
/*
* USEC_ROUND is used in the timeval to jiffie conversion. See there
* for more details. It is the scaled resolution rounding value. Note
\
 
 \ /
  Last update: 2005-03-22 14:00    [W:0.074 / U:0.076 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site