123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- #include <linux/module.h>
- #include <linux/moduleparam.h>
- #include <linux/types.h>
- #include <linux/kernel.h>
- #include <linux/fs.h>
- #include <linux/mm.h>
- #include <linux/reboot.h>
- #include <linux/init.h>
- #include <linux/delay.h>
- #include <asm/uaccess.h>
- #include <linux/sysrq.h>
- #include <linux/timer.h>
- #include <linux/hrtimer.h>
- #define VERSION_STR "0.9.1"
- #define DEFAULT_IOFENCE_MARGIN 60
- #define DEFAULT_IOFENCE_TICK 180
- static int hangcheck_tick = DEFAULT_IOFENCE_TICK;
- static int hangcheck_margin = DEFAULT_IOFENCE_MARGIN;
- static int hangcheck_reboot;
- static int hangcheck_dump_tasks;
- module_param(hangcheck_tick, int, 0);
- MODULE_PARM_DESC(hangcheck_tick, "Timer delay.");
- module_param(hangcheck_margin, int, 0);
- MODULE_PARM_DESC(hangcheck_margin, "If the hangcheck timer has been delayed more than hangcheck_margin seconds, the driver will fire.");
- module_param(hangcheck_reboot, int, 0);
- MODULE_PARM_DESC(hangcheck_reboot, "If nonzero, the machine will reboot when the timer margin is exceeded.");
- module_param(hangcheck_dump_tasks, int, 0);
- MODULE_PARM_DESC(hangcheck_dump_tasks, "If nonzero, the machine will dump the system task state when the timer margin is exceeded.");
- MODULE_AUTHOR("Oracle");
- MODULE_DESCRIPTION("Hangcheck-timer detects when the system has gone out to lunch past a certain margin.");
- MODULE_LICENSE("GPL");
- MODULE_VERSION(VERSION_STR);
- #ifndef MODULE
- static int __init hangcheck_parse_tick(char *str)
- {
- int par;
- if (get_option(&str,&par))
- hangcheck_tick = par;
- return 1;
- }
- static int __init hangcheck_parse_margin(char *str)
- {
- int par;
- if (get_option(&str,&par))
- hangcheck_margin = par;
- return 1;
- }
- static int __init hangcheck_parse_reboot(char *str)
- {
- int par;
- if (get_option(&str,&par))
- hangcheck_reboot = par;
- return 1;
- }
- static int __init hangcheck_parse_dump_tasks(char *str)
- {
- int par;
- if (get_option(&str,&par))
- hangcheck_dump_tasks = par;
- return 1;
- }
- __setup("hcheck_tick", hangcheck_parse_tick);
- __setup("hcheck_margin", hangcheck_parse_margin);
- __setup("hcheck_reboot", hangcheck_parse_reboot);
- __setup("hcheck_dump_tasks", hangcheck_parse_dump_tasks);
- #endif
- #define TIMER_FREQ 1000000000ULL
- static unsigned long long hangcheck_tsc, hangcheck_tsc_margin;
- static void hangcheck_fire(unsigned long);
- static DEFINE_TIMER(hangcheck_ticktock, hangcheck_fire, 0, 0);
- static void hangcheck_fire(unsigned long data)
- {
- unsigned long long cur_tsc, tsc_diff;
- cur_tsc = ktime_get_ns();
- if (cur_tsc > hangcheck_tsc)
- tsc_diff = cur_tsc - hangcheck_tsc;
- else
- tsc_diff = (cur_tsc + (~0ULL - hangcheck_tsc));
- if (tsc_diff > hangcheck_tsc_margin) {
- if (hangcheck_dump_tasks) {
- printk(KERN_CRIT "Hangcheck: Task state:\n");
- #ifdef CONFIG_MAGIC_SYSRQ
- handle_sysrq('t');
- #endif
- }
- if (hangcheck_reboot) {
- printk(KERN_CRIT "Hangcheck: hangcheck is restarting the machine.\n");
- emergency_restart();
- } else {
- printk(KERN_CRIT "Hangcheck: hangcheck value past margin!\n");
- }
- }
- #if 0
-
- 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));
- hangcheck_tsc = ktime_get_ns();
- }
- static int __init hangcheck_init(void)
- {
- printk("Hangcheck: starting hangcheck timer %s (tick is %d seconds, margin is %d seconds).\n",
- VERSION_STR, hangcheck_tick, hangcheck_margin);
- hangcheck_tsc_margin =
- (unsigned long long)hangcheck_margin + hangcheck_tick;
- hangcheck_tsc_margin *= TIMER_FREQ;
- hangcheck_tsc = ktime_get_ns();
- mod_timer(&hangcheck_ticktock, jiffies + (hangcheck_tick*HZ));
- return 0;
- }
- static void __exit hangcheck_exit(void)
- {
- del_timer_sync(&hangcheck_ticktock);
- printk("Hangcheck: Stopped hangcheck timer.\n");
- }
- module_init(hangcheck_init);
- module_exit(hangcheck_exit);
|