public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] calibrate_tsc should not use HZ
@ 2002-10-31 19:28 Jim Houston
  2002-10-31 19:52 ` george anzinger
  0 siblings, 1 reply; 2+ messages in thread
From: Jim Houston @ 2002-10-31 19:28 UTC (permalink / raw)
  To: linux-kernel, high-res-timers-discourse, jim.houston


Hi Everyone,

I noticed that the calibration time for calibrate_tsc() is 5 jiffies.
This means the result with 1000 Hz jiffies may be less accurate
then it was at 100 Hz.  The attached patch removes this dependency.

Jim Houston - Concurrent Computer Corp.

diff -X /usr1/jhouston/dontdiff -ur linux.orig/arch/i386/kernel/timers/timer_tsc.c linux.kdb/arch/i386/kernel/timers/timer_tsc.c
--- linux.orig/arch/i386/kernel/timers/timer_tsc.c	Wed Oct 23 00:54:19 2002
+++ linux.kdb/arch/i386/kernel/timers/timer_tsc.c	Thu Oct 31 14:18:21 2002
@@ -97,8 +97,13 @@
  * device.
  */
 
-#define CALIBRATE_LATCH	(5 * LATCH)
-#define CALIBRATE_TIME	(5 * 1000020/HZ)
+/*
+ * Pick the largest possible latch value (it is a 16 bit counter)
+ * and calculate the corresponding time.
+ */
+#define CALIBRATE_LATCH	(0xffff)	
+#define CALIBRATE_TIME	((int)((1000000LL*CALIBRATE_LATCH + \
+				CLOCK_TICK_RATE/2)/CLOCK_TICK_RATE)
 
 static unsigned long __init calibrate_tsc(void)
 {

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] calibrate_tsc should not use HZ
  2002-10-31 19:28 [PATCH] calibrate_tsc should not use HZ Jim Houston
@ 2002-10-31 19:52 ` george anzinger
  0 siblings, 0 replies; 2+ messages in thread
From: george anzinger @ 2002-10-31 19:52 UTC (permalink / raw)
  To: jim.houston; +Cc: linux-kernel, high-res-timers-discourse, jim.houston

Jim Houston wrote:
> 
> Hi Everyone,
> 
> I noticed that the calibration time for calibrate_tsc() is 5 jiffies.
> This means the result with 1000 Hz jiffies may be less accurate
> then it was at 100 Hz.  The attached patch removes this dependency.
> 
> Jim Houston - Concurrent Computer Corp.
> 
> diff -X /usr1/jhouston/dontdiff -ur linux.orig/arch/i386/kernel/timers/timer_tsc.c linux.kdb/arch/i386/kernel/timers/timer_tsc.c
> --- linux.orig/arch/i386/kernel/timers/timer_tsc.c      Wed Oct 23 00:54:19 2002
> +++ linux.kdb/arch/i386/kernel/timers/timer_tsc.c       Thu Oct 31 14:18:21 2002
> @@ -97,8 +97,13 @@
>   * device.
>   */
> 
> -#define CALIBRATE_LATCH        (5 * LATCH)
> -#define CALIBRATE_TIME (5 * 1000020/HZ)
> +/*
> + * Pick the largest possible latch value (it is a 16 bit counter)
> + * and calculate the corresponding time.
> + */
> +#define CALIBRATE_LATCH        (0xffff)
> +#define CALIBRATE_TIME ((int)((1000000LL*CALIBRATE_LATCH + \
> +                               CLOCK_TICK_RATE/2)/CLOCK_TICK_RATE)
> 
>  static unsigned long __init calibrate_tsc(void)
>  {
> 

And one step further, if you tack on a few zeros in the
numerator, you can pick up a couple of more bits of
precision in the tick rate, i.e.:

CLOCK_TICK_RATE is derived from 14.3181818Mhz/12 =
1.19318181667 so:
#define CALIBRATE_LATCH_1000 1193181817
#define CALIBRATE_TIME ((int)((1000000000LL*CALIBRATE_LATCH
+ \
                              
CLOCK_TICK_RATE_1000/2)/CLOCK_TICK_RATE_1000)
-- 
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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-10-31 19:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-10-31 19:28 [PATCH] calibrate_tsc should not use HZ Jim Houston
2002-10-31 19:52 ` george anzinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox