aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/char')
-rw-r--r--drivers/char/Kconfig2
-rw-r--r--drivers/char/hangcheck-timer.c104
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
983config HANGCHECK_TIMER 983config 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 @@
56static int hangcheck_tick = DEFAULT_IOFENCE_TICK; 59static int hangcheck_tick = DEFAULT_IOFENCE_TICK;
57static int hangcheck_margin = DEFAULT_IOFENCE_MARGIN; 60static int hangcheck_margin = DEFAULT_IOFENCE_MARGIN;
58static int hangcheck_reboot; /* Defaults to not reboot */ 61static int hangcheck_reboot; /* Defaults to not reboot */
62static int hangcheck_dump_tasks; /* Defaults to not dumping SysRQ T */
59 63
60/* Driver options */ 64/* options - modular */
61module_param(hangcheck_tick, int, 0); 65module_param(hangcheck_tick, int, 0);
62MODULE_PARM_DESC(hangcheck_tick, "Timer delay."); 66MODULE_PARM_DESC(hangcheck_tick, "Timer delay.");
63module_param(hangcheck_margin, int, 0); 67module_param(hangcheck_margin, int, 0);
64MODULE_PARM_DESC(hangcheck_margin, "If the hangcheck timer has been delayed more than hangcheck_margin seconds, the driver will fire."); 68MODULE_PARM_DESC(hangcheck_margin, "If the hangcheck timer has been delayed more than hangcheck_margin seconds, the driver will fire.");
65module_param(hangcheck_reboot, int, 0); 69module_param(hangcheck_reboot, int, 0);
66MODULE_PARM_DESC(hangcheck_reboot, "If nonzero, the machine will reboot when the timer margin is exceeded."); 70MODULE_PARM_DESC(hangcheck_reboot, "If nonzero, the machine will reboot when the timer margin is exceeded.");
71module_param(hangcheck_dump_tasks, int, 0);
72MODULE_PARM_DESC(hangcheck_dump_tasks, "If nonzero, the machine will dump the system task state when the timer margin is exceeded.");
67 73
68MODULE_AUTHOR("Joel Becker"); 74MODULE_AUTHOR("Oracle");
69MODULE_DESCRIPTION("Hangcheck-timer detects when the system has gone out to lunch past a certain margin."); 75MODULE_DESCRIPTION("Hangcheck-timer detects when the system has gone out to lunch past a certain margin.");
70MODULE_LICENSE("GPL"); 76MODULE_LICENSE("GPL");
77MODULE_VERSION(VERSION_STR);
78
79/* options - nonmodular */
80#ifndef MODULE
81
82static 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
90static 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
98static 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
106static 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
133extern unsigned long long monotonic_clock(void);
134#else
135static 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);
78static struct timer_list hangcheck_ticktock = 152static struct timer_list hangcheck_ticktock =
79 TIMER_INITIALIZER(hangcheck_fire, 0, 0); 153 TIMER_INITIALIZER(hangcheck_fire, 0, 0);
80 154
81extern unsigned long long monotonic_clock(void);
82 155
83static void hangcheck_fire(unsigned long data) 156static 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)
123static void __exit hangcheck_exit(void) 208static 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
128module_init(hangcheck_init); 214module_init(hangcheck_init);