x86/hpet: Use the FSEC_PER_SEC constant for femto-second periods
authorChris Wilson <chris@chris-wilson.co.uk>
Mon, 9 Aug 2010 21:20:10 +0000 (14:20 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 12 Aug 2010 16:53:39 +0000 (09:53 -0700)
The current computation, introduced with f12a15be63, of FSEC_PER_SEC using
the multiplication of (FSEC_PER_NSEC * NSEC_PER_SEC) is performed only
with 32bit integers on small machines, resulting in an overflow and a
*very* short intervals being programmed.  An interrupt storm follows.

Note that we also have to specify FSEC_PER_SEC as being long long to
overcome the same limitations.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: John Stultz <johnstul@us.ibm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Ingo Molnar <mingo@elte.hu>
Acked-by: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
arch/x86/kernel/hpet.c
include/linux/time.h

index 33dbcc4ec5ff285435c7c184be50e485c58a9ca2..351f9c0fea1f20714321d01260003173faf548dc 100644 (file)
@@ -582,7 +582,7 @@ static void init_one_hpet_msi_clockevent(struct hpet_dev *hdev, int cpu)
         * scaled math multiplication factor for nanosecond to hpet tick
         * conversion.
         */
-       hpet_freq = 1000000000000000ULL;
+       hpet_freq = FSEC_PER_SEC;
        do_div(hpet_freq, hpet_period);
        evt->mult = div_sc((unsigned long) hpet_freq,
                                      NSEC_PER_SEC, evt->shift);
@@ -837,7 +837,7 @@ static int hpet_clocksource_register(void)
         * cyc/sec = FSEC_PER_SEC/hpet_period(fsec/cyc)
         * cyc/sec = (FSEC_PER_NSEC * NSEC_PER_SEC)/hpet_period
         */
-       hpet_freq = FSEC_PER_NSEC * NSEC_PER_SEC;
+       hpet_freq = FSEC_PER_SEC;
        do_div(hpet_freq, hpet_period);
        clocksource_register_hz(&clocksource_hpet, (u32)hpet_freq);
 
index cb34e35fabac091f927184b786b0e3dd4550b3f7..12612701b1ae464c4e0591114a4f14a7d284e88a 100644 (file)
@@ -38,7 +38,7 @@ extern struct timezone sys_tz;
 #define NSEC_PER_MSEC  1000000L
 #define USEC_PER_SEC   1000000L
 #define NSEC_PER_SEC   1000000000L
-#define FSEC_PER_SEC   1000000000000000L
+#define FSEC_PER_SEC   1000000000000000LL
 
 #define TIME_T_MAX     (time_t)((1UL << ((sizeof(time_t) << 3) - 1)) - 1)