Commit 6ffc787a4492ac627315aaeafdfdc0a5c3028582
Committed by
Linus Torvalds
1 parent
82f560874e
Exists in
master
and in
20 other branches
system timer: fix crash in <100Hz system timer
The kernel has a divide by zero crash when trying to run the system timer less than 100Hz. The problem is x/(HZ/USER_HZ) and related. Now x*(USER_HZ/HZ) will be used if HZ<USER_HZ. I'm running the Linux kernel under qemu and went to run a slower system timer to take less CPU (and battery) on the host. I found that the kernel paniced under emulation because of a divide by zero in three places. Here is the patch. The base git was updated today 01-05-2008. I went for a 20Hz system time by adding config HZ_20 etc to kernel/Kconfig.hz. With this patch I verified the system timer by looking at /proc/interrupts. [akpm@linux-foundation.org: partially clean up the macro maze] Signed-off-by: David Fries <david@fries.net> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 2 changed files with 13 additions and 2 deletions Side-by-side Diff
include/linux/acct.h
... | ... | @@ -173,7 +173,11 @@ |
173 | 173 | static inline u32 jiffies_to_AHZ(unsigned long x) |
174 | 174 | { |
175 | 175 | #if (TICK_NSEC % (NSEC_PER_SEC / AHZ)) == 0 |
176 | +# if HZ < AHZ | |
177 | + return x * (AHZ / HZ); | |
178 | +# else | |
176 | 179 | return x / (HZ / AHZ); |
180 | +# endif | |
177 | 181 | #else |
178 | 182 | u64 tmp = (u64)x * TICK_NSEC; |
179 | 183 | do_div(tmp, (NSEC_PER_SEC / AHZ)); |
kernel/time.c
... | ... | @@ -566,7 +566,11 @@ |
566 | 566 | clock_t jiffies_to_clock_t(long x) |
567 | 567 | { |
568 | 568 | #if (TICK_NSEC % (NSEC_PER_SEC / USER_HZ)) == 0 |
569 | +# if HZ < USER_HZ | |
570 | + return x * (USER_HZ / HZ); | |
571 | +# else | |
569 | 572 | return x / (HZ / USER_HZ); |
573 | +# endif | |
570 | 574 | #else |
571 | 575 | u64 tmp = (u64)x * TICK_NSEC; |
572 | 576 | do_div(tmp, (NSEC_PER_SEC / USER_HZ)); |
573 | 577 | |
... | ... | @@ -599,7 +603,12 @@ |
599 | 603 | u64 jiffies_64_to_clock_t(u64 x) |
600 | 604 | { |
601 | 605 | #if (TICK_NSEC % (NSEC_PER_SEC / USER_HZ)) == 0 |
606 | +# if HZ < USER_HZ | |
607 | + x *= USER_HZ; | |
608 | + do_div(x, HZ); | |
609 | +# else | |
602 | 610 | do_div(x, HZ / USER_HZ); |
611 | +# endif | |
603 | 612 | #else |
604 | 613 | /* |
605 | 614 | * There are better ways that don't overflow early, |
... | ... | @@ -611,7 +620,6 @@ |
611 | 620 | #endif |
612 | 621 | return x; |
613 | 622 | } |
614 | - | |
615 | 623 | EXPORT_SYMBOL(jiffies_64_to_clock_t); |
616 | 624 | |
617 | 625 | u64 nsec_to_clock_t(u64 x) |
... | ... | @@ -646,7 +654,6 @@ |
646 | 654 | } while (read_seqretry(&xtime_lock, seq)); |
647 | 655 | return ret; |
648 | 656 | } |
649 | - | |
650 | 657 | EXPORT_SYMBOL(get_jiffies_64); |
651 | 658 | #endif |
652 | 659 |