diff options
Diffstat (limited to 'drivers/char')
-rw-r--r-- | drivers/char/Kconfig | 2 | ||||
-rw-r--r-- | drivers/char/hangcheck-timer.c | 104 |
2 files changed, 96 insertions, 10 deletions
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig index 97ac4edf4655..e162dab64ffd 100644 --- a/drivers/char/Kconfig +++ b/drivers/char/Kconfig | |||
@@ -982,7 +982,7 @@ config MAX_RAW_DEVS | |||
982 | 982 | ||
983 | config HANGCHECK_TIMER | 983 | config HANGCHECK_TIMER |
984 | tristate "Hangcheck timer" | 984 | tristate "Hangcheck timer" |
985 | depends on X86_64 || X86 | 985 | depends on X86_64 || X86 || IA64 || PPC64 || ARCH_S390 |
986 | help | 986 | help |
987 | The hangcheck-timer module detects when the system has gone | 987 | The hangcheck-timer module detects when the system has gone |
988 | out to lunch past a certain margin. It can reboot the system | 988 | out to lunch past a certain margin. It can reboot the system |
diff --git a/drivers/char/hangcheck-timer.c b/drivers/char/hangcheck-timer.c index 83d6b37b36cd..78e650fc5b41 100644 --- a/drivers/char/hangcheck-timer.c +++ b/drivers/char/hangcheck-timer.c | |||
@@ -3,7 +3,7 @@ | |||
3 | * | 3 | * |
4 | * Driver for a little io fencing timer. | 4 | * Driver for a little io fencing timer. |
5 | * | 5 | * |
6 | * Copyright (C) 2002 Oracle Corporation. All rights reserved. | 6 | * Copyright (C) 2002, 2003 Oracle. All rights reserved. |
7 | * | 7 | * |
8 | * Author: Joel Becker <joel.becker@oracle.com> | 8 | * Author: Joel Becker <joel.becker@oracle.com> |
9 | * | 9 | * |
@@ -44,11 +44,14 @@ | |||
44 | #include <linux/fs.h> | 44 | #include <linux/fs.h> |
45 | #include <linux/mm.h> | 45 | #include <linux/mm.h> |
46 | #include <linux/reboot.h> | 46 | #include <linux/reboot.h> |
47 | #include <linux/smp_lock.h> | ||
47 | #include <linux/init.h> | 48 | #include <linux/init.h> |
49 | #include <linux/delay.h> | ||
48 | #include <asm/uaccess.h> | 50 | #include <asm/uaccess.h> |
51 | #include <linux/sysrq.h> | ||
49 | 52 | ||
50 | 53 | ||
51 | #define VERSION_STR "0.5.0" | 54 | #define VERSION_STR "0.9.0" |
52 | 55 | ||
53 | #define DEFAULT_IOFENCE_MARGIN 60 /* Default fudge factor, in seconds */ | 56 | #define DEFAULT_IOFENCE_MARGIN 60 /* Default fudge factor, in seconds */ |
54 | #define DEFAULT_IOFENCE_TICK 180 /* Default timer timeout, in seconds */ | 57 | #define DEFAULT_IOFENCE_TICK 180 /* Default timer timeout, in seconds */ |
@@ -56,18 +59,89 @@ | |||
56 | static int hangcheck_tick = DEFAULT_IOFENCE_TICK; | 59 | static int hangcheck_tick = DEFAULT_IOFENCE_TICK; |
57 | static int hangcheck_margin = DEFAULT_IOFENCE_MARGIN; | 60 | static int hangcheck_margin = DEFAULT_IOFENCE_MARGIN; |
58 | static int hangcheck_reboot; /* Defaults to not reboot */ | 61 | static int hangcheck_reboot; /* Defaults to not reboot */ |
62 | static int hangcheck_dump_tasks; /* Defaults to not dumping SysRQ T */ | ||
59 | 63 | ||
60 | /* Driver options */ | 64 | /* options - modular */ |
61 | module_param(hangcheck_tick, int, 0); | 65 | module_param(hangcheck_tick, int, 0); |
62 | MODULE_PARM_DESC(hangcheck_tick, "Timer delay."); | 66 | MODULE_PARM_DESC(hangcheck_tick, "Timer delay."); |
63 | module_param(hangcheck_margin, int, 0); | 67 | module_param(hangcheck_margin, int, 0); |
64 | MODULE_PARM_DESC(hangcheck_margin, "If the hangcheck timer has been delayed more than hangcheck_margin seconds, the driver will fire."); | 68 | MODULE_PARM_DESC(hangcheck_margin, "If the hangcheck timer has been delayed more than hangcheck_margin seconds, the driver will fire."); |
65 | module_param(hangcheck_reboot, int, 0); | 69 | module_param(hangcheck_reboot, int, 0); |
66 | MODULE_PARM_DESC(hangcheck_reboot, "If nonzero, the machine will reboot when the timer margin is exceeded."); | 70 | MODULE_PARM_DESC(hangcheck_reboot, "If nonzero, the machine will reboot when the timer margin is exceeded."); |
71 | module_param(hangcheck_dump_tasks, int, 0); | ||
72 | MODULE_PARM_DESC(hangcheck_dump_tasks, "If nonzero, the machine will dump the system task state when the timer margin is exceeded."); | ||
67 | 73 | ||
68 | MODULE_AUTHOR("Joel Becker"); | 74 | MODULE_AUTHOR("Oracle"); |
69 | MODULE_DESCRIPTION("Hangcheck-timer detects when the system has gone out to lunch past a certain margin."); | 75 | MODULE_DESCRIPTION("Hangcheck-timer detects when the system has gone out to lunch past a certain margin."); |
70 | MODULE_LICENSE("GPL"); | 76 | MODULE_LICENSE("GPL"); |
77 | MODULE_VERSION(VERSION_STR); | ||
78 | |||
79 | /* options - nonmodular */ | ||
80 | #ifndef MODULE | ||
81 | |||
82 | static int __init hangcheck_parse_tick(char *str) | ||
83 | { | ||
84 | int par; | ||
85 | if (get_option(&str,&par)) | ||
86 | hangcheck_tick = par; | ||
87 | return 1; | ||
88 | } | ||
89 | |||
90 | static int __init hangcheck_parse_margin(char *str) | ||
91 | { | ||
92 | int par; | ||
93 | if (get_option(&str,&par)) | ||
94 | hangcheck_margin = par; | ||
95 | return 1; | ||
96 | } | ||
97 | |||
98 | static int __init hangcheck_parse_reboot(char *str) | ||
99 | { | ||
100 | int par; | ||
101 | if (get_option(&str,&par)) | ||
102 | hangcheck_reboot = par; | ||
103 | return 1; | ||
104 | } | ||
105 | |||
106 | static int __init hangcheck_parse_dump_tasks(char *str) | ||
107 | { | ||
108 | int par; | ||
109 | if (get_option(&str,&par)) | ||
110 | hangcheck_dump_tasks = par; | ||
111 | return 1; | ||
112 | } | ||
113 | |||
114 | __setup("hcheck_tick", hangcheck_parse_tick); | ||
115 | __setup("hcheck_margin", hangcheck_parse_margin); | ||
116 | __setup("hcheck_reboot", hangcheck_parse_reboot); | ||
117 | __setup("hcheck_dump_tasks", hangcheck_parse_dump_tasks); | ||
118 | #endif /* not MODULE */ | ||
119 | |||
120 | #if defined(CONFIG_X86) || defined(CONFIG_X86_64) | ||
121 | # define HAVE_MONOTONIC | ||
122 | # define TIMER_FREQ 1000000000ULL | ||
123 | #elif defined(CONFIG_ARCH_S390) | ||
124 | /* FA240000 is 1 Second in the IBM time universe (Page 4-38 Principles of Op for zSeries */ | ||
125 | # define TIMER_FREQ 0xFA240000ULL | ||
126 | #elif defined(CONFIG_IA64) | ||
127 | # define TIMER_FREQ ((unsigned long long)local_cpu_data->itc_freq) | ||
128 | #elif defined(CONFIG_PPC64) | ||
129 | # define TIMER_FREQ (HZ*loops_per_jiffy) | ||
130 | #endif | ||
131 | |||
132 | #ifdef HAVE_MONOTONIC | ||
133 | extern unsigned long long monotonic_clock(void); | ||
134 | #else | ||
135 | static inline unsigned long long monotonic_clock(void) | ||
136 | { | ||
137 | # ifdef __s390__ | ||
138 | /* returns the TOD. see 4-38 Principles of Op of zSeries */ | ||
139 | return get_clock(); | ||
140 | # else | ||
141 | return get_cycles(); | ||
142 | # endif /* __s390__ */ | ||
143 | } | ||
144 | #endif /* HAVE_MONOTONIC */ | ||
71 | 145 | ||
72 | 146 | ||
73 | /* Last time scheduled */ | 147 | /* Last time scheduled */ |
@@ -78,7 +152,6 @@ static void hangcheck_fire(unsigned long); | |||
78 | static struct timer_list hangcheck_ticktock = | 152 | static struct timer_list hangcheck_ticktock = |
79 | TIMER_INITIALIZER(hangcheck_fire, 0, 0); | 153 | TIMER_INITIALIZER(hangcheck_fire, 0, 0); |
80 | 154 | ||
81 | extern unsigned long long monotonic_clock(void); | ||
82 | 155 | ||
83 | static void hangcheck_fire(unsigned long data) | 156 | static void hangcheck_fire(unsigned long data) |
84 | { | 157 | { |
@@ -92,6 +165,12 @@ static void hangcheck_fire(unsigned long data) | |||
92 | tsc_diff = (cur_tsc + (~0ULL - hangcheck_tsc)); /* or something */ | 165 | tsc_diff = (cur_tsc + (~0ULL - hangcheck_tsc)); /* or something */ |
93 | 166 | ||
94 | if (tsc_diff > hangcheck_tsc_margin) { | 167 | if (tsc_diff > hangcheck_tsc_margin) { |
168 | if (hangcheck_dump_tasks) { | ||
169 | printk(KERN_CRIT "Hangcheck: Task state:\n"); | ||
170 | #ifdef CONFIG_MAGIC_SYSRQ | ||
171 | handle_sysrq('t', NULL, NULL); | ||
172 | #endif /* CONFIG_MAGIC_SYSRQ */ | ||
173 | } | ||
95 | if (hangcheck_reboot) { | 174 | if (hangcheck_reboot) { |
96 | printk(KERN_CRIT "Hangcheck: hangcheck is restarting the machine.\n"); | 175 | printk(KERN_CRIT "Hangcheck: hangcheck is restarting the machine.\n"); |
97 | machine_restart(NULL); | 176 | machine_restart(NULL); |
@@ -108,10 +187,16 @@ static int __init hangcheck_init(void) | |||
108 | { | 187 | { |
109 | printk("Hangcheck: starting hangcheck timer %s (tick is %d seconds, margin is %d seconds).\n", | 188 | printk("Hangcheck: starting hangcheck timer %s (tick is %d seconds, margin is %d seconds).\n", |
110 | VERSION_STR, hangcheck_tick, hangcheck_margin); | 189 | VERSION_STR, hangcheck_tick, hangcheck_margin); |
111 | 190 | #if defined (HAVE_MONOTONIC) | |
112 | hangcheck_tsc_margin = hangcheck_margin + hangcheck_tick; | 191 | printk("Hangcheck: Using monotonic_clock().\n"); |
113 | hangcheck_tsc_margin *= 1000000000; | 192 | #elif defined(__s390__) |
114 | 193 | printk("Hangcheck: Using TOD.\n"); | |
194 | #else | ||
195 | printk("Hangcheck: Using get_cycles().\n"); | ||
196 | #endif /* HAVE_MONOTONIC */ | ||
197 | hangcheck_tsc_margin = | ||
198 | (unsigned long long)(hangcheck_margin + hangcheck_tick); | ||
199 | hangcheck_tsc_margin *= (unsigned long long)TIMER_FREQ; | ||
115 | 200 | ||
116 | hangcheck_tsc = monotonic_clock(); | 201 | hangcheck_tsc = monotonic_clock(); |
117 | mod_timer(&hangcheck_ticktock, jiffies + (hangcheck_tick*HZ)); | 202 | mod_timer(&hangcheck_ticktock, jiffies + (hangcheck_tick*HZ)); |
@@ -123,6 +208,7 @@ static int __init hangcheck_init(void) | |||
123 | static void __exit hangcheck_exit(void) | 208 | static void __exit hangcheck_exit(void) |
124 | { | 209 | { |
125 | del_timer_sync(&hangcheck_ticktock); | 210 | del_timer_sync(&hangcheck_ticktock); |
211 | printk("Hangcheck: Stopped hangcheck timer.\n"); | ||
126 | } | 212 | } |
127 | 213 | ||
128 | module_init(hangcheck_init); | 214 | module_init(hangcheck_init); |