Commit 940370fc authored by Yury Polyanskiy's avatar Yury Polyanskiy Committed by Linus Torvalds

hangcheck-timer: fix x86_32 bugs

drivers/char/hangcheck-timer.c is doubly broken.  When the overflown value
of TIMER_FREQ is abnormally low, it spams the syslog with KERN_CRIT
messages "Hangcheck: hangcheck value past margin!" But whether it happens
or not depends on HZ and lpj in a complex way.  People have hit it
occasionally as far as google search can tell.

First, the following line overflows unsigned long:

# define TIMER_FREQ (HZ*loops_per_jiffy)

Second, and more importantly, loops_per_jiffy has little to do with the
con= version from the the time scale of get_cycles() (aka rdtsc) to the
time scale of jiffies.

The attached patch resolves both of the problems.
Acked-by: default avatarJoel Becker <joel.becker@oracle.com>
Cc: john stultz <johnstul@us.ibm.com>
Cc: Jan Glauber <jan.glauber@de.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent b3b77c8c
...@@ -49,8 +49,9 @@ ...@@ -49,8 +49,9 @@
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <linux/sysrq.h> #include <linux/sysrq.h>
#include <linux/timer.h> #include <linux/timer.h>
#include <linux/time.h>
#define VERSION_STR "0.9.0" #define VERSION_STR "0.9.1"
#define DEFAULT_IOFENCE_MARGIN 60 /* Default fudge factor, in seconds */ #define DEFAULT_IOFENCE_MARGIN 60 /* Default fudge factor, in seconds */
#define DEFAULT_IOFENCE_TICK 180 /* Default timer timeout, in seconds */ #define DEFAULT_IOFENCE_TICK 180 /* Default timer timeout, in seconds */
...@@ -119,10 +120,8 @@ __setup("hcheck_dump_tasks", hangcheck_parse_dump_tasks); ...@@ -119,10 +120,8 @@ __setup("hcheck_dump_tasks", hangcheck_parse_dump_tasks);
#if defined(CONFIG_S390) #if defined(CONFIG_S390)
# define HAVE_MONOTONIC # define HAVE_MONOTONIC
# define TIMER_FREQ 1000000000ULL # define TIMER_FREQ 1000000000ULL
#elif defined(CONFIG_IA64)
# define TIMER_FREQ ((unsigned long long)local_cpu_data->itc_freq)
#else #else
# define TIMER_FREQ (HZ*loops_per_jiffy) # define TIMER_FREQ 1000000000ULL
#endif #endif
#ifdef HAVE_MONOTONIC #ifdef HAVE_MONOTONIC
...@@ -130,7 +129,9 @@ extern unsigned long long monotonic_clock(void); ...@@ -130,7 +129,9 @@ extern unsigned long long monotonic_clock(void);
#else #else
static inline unsigned long long monotonic_clock(void) static inline unsigned long long monotonic_clock(void)
{ {
return get_cycles(); struct timespec ts;
getrawmonotonic(&ts);
return timespec_to_ns(&ts);
} }
#endif /* HAVE_MONOTONIC */ #endif /* HAVE_MONOTONIC */
...@@ -168,6 +169,13 @@ static void hangcheck_fire(unsigned long data) ...@@ -168,6 +169,13 @@ static void hangcheck_fire(unsigned long data)
printk(KERN_CRIT "Hangcheck: hangcheck value past margin!\n"); printk(KERN_CRIT "Hangcheck: hangcheck value past margin!\n");
} }
} }
#if 0
/*
* Enable to investigate delays in detail
*/
printk("Hangcheck: called %Ld ns since last time (%Ld ns overshoot)\n",
tsc_diff, tsc_diff - hangcheck_tick*TIMER_FREQ);
#endif
mod_timer(&hangcheck_ticktock, jiffies + (hangcheck_tick*HZ)); mod_timer(&hangcheck_ticktock, jiffies + (hangcheck_tick*HZ));
hangcheck_tsc = monotonic_clock(); hangcheck_tsc = monotonic_clock();
} }
...@@ -180,7 +188,7 @@ static int __init hangcheck_init(void) ...@@ -180,7 +188,7 @@ static int __init hangcheck_init(void)
#if defined (HAVE_MONOTONIC) #if defined (HAVE_MONOTONIC)
printk("Hangcheck: Using monotonic_clock().\n"); printk("Hangcheck: Using monotonic_clock().\n");
#else #else
printk("Hangcheck: Using get_cycles().\n"); printk("Hangcheck: Using getrawmonotonic().\n");
#endif /* HAVE_MONOTONIC */ #endif /* HAVE_MONOTONIC */
hangcheck_tsc_margin = hangcheck_tsc_margin =
(unsigned long long)(hangcheck_margin + hangcheck_tick); (unsigned long long)(hangcheck_margin + hangcheck_tick);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment