ia64/linux-2.6.18-xen.hg

annotate drivers/char/hangcheck-timer.c @ 798:b02a90bf5bbc

ACPI: Backport missing part for T-State MSR support

Part of below kernel commit was missed while packporting T-State
support.

commit f79f06ab9f86d7203006d2ec8992ac80df36a34e
Author: Zhao Yakui <yakui.zhao@intel.com>
Date: Thu Nov 15 17:06:36 2007 +0800

ACPI: Enable MSR (FixedHW) support for T-States

Add throttling control via MSR when T-states uses
the FixHW Control Status registers.

Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
Signed-off-by: Li Shaohua <shaohua.li@intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>

Signed-off-by: Wei Gang <gang.wei@intel.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Mar 02 10:53:59 2009 +0000 (2009-03-02)
parents 831230e53067
children
rev   line source
ian@0 1 /*
ian@0 2 * hangcheck-timer.c
ian@0 3 *
ian@0 4 * Driver for a little io fencing timer.
ian@0 5 *
ian@0 6 * Copyright (C) 2002, 2003 Oracle. All rights reserved.
ian@0 7 *
ian@0 8 * Author: Joel Becker <joel.becker@oracle.com>
ian@0 9 *
ian@0 10 * This program is free software; you can redistribute it and/or
ian@0 11 * modify it under the terms of the GNU General Public
ian@0 12 * License version 2 as published by the Free Software Foundation.
ian@0 13 *
ian@0 14 * This program is distributed in the hope that it will be useful,
ian@0 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ian@0 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ian@0 17 * General Public License for more details.
ian@0 18 *
ian@0 19 * You should have received a copy of the GNU General Public
ian@0 20 * License along with this program; if not, write to the
ian@0 21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
ian@0 22 * Boston, MA 021110-1307, USA.
ian@0 23 */
ian@0 24
ian@0 25 /*
ian@0 26 * The hangcheck-timer driver uses the TSC to catch delays that
ian@0 27 * jiffies does not notice. A timer is set. When the timer fires, it
ian@0 28 * checks whether it was delayed and if that delay exceeds a given
ian@0 29 * margin of error. The hangcheck_tick module paramter takes the timer
ian@0 30 * duration in seconds. The hangcheck_margin parameter defines the
ian@0 31 * margin of error, in seconds. The defaults are 60 seconds for the
ian@0 32 * timer and 180 seconds for the margin of error. IOW, a timer is set
ian@0 33 * for 60 seconds. When the timer fires, the callback checks the
ian@0 34 * actual duration that the timer waited. If the duration exceeds the
ian@0 35 * alloted time and margin (here 60 + 180, or 240 seconds), the machine
ian@0 36 * is restarted. A healthy machine will have the duration match the
ian@0 37 * expected timeout very closely.
ian@0 38 */
ian@0 39
ian@0 40 #include <linux/module.h>
ian@0 41 #include <linux/moduleparam.h>
ian@0 42 #include <linux/types.h>
ian@0 43 #include <linux/kernel.h>
ian@0 44 #include <linux/fs.h>
ian@0 45 #include <linux/mm.h>
ian@0 46 #include <linux/reboot.h>
ian@0 47 #include <linux/smp_lock.h>
ian@0 48 #include <linux/init.h>
ian@0 49 #include <linux/delay.h>
ian@0 50 #include <asm/uaccess.h>
ian@0 51 #include <linux/sysrq.h>
ian@0 52
ian@0 53
ian@0 54 #define VERSION_STR "0.9.0"
ian@0 55
ian@0 56 #define DEFAULT_IOFENCE_MARGIN 60 /* Default fudge factor, in seconds */
ian@0 57 #define DEFAULT_IOFENCE_TICK 180 /* Default timer timeout, in seconds */
ian@0 58
ian@0 59 static int hangcheck_tick = DEFAULT_IOFENCE_TICK;
ian@0 60 static int hangcheck_margin = DEFAULT_IOFENCE_MARGIN;
ian@0 61 static int hangcheck_reboot; /* Defaults to not reboot */
ian@0 62 static int hangcheck_dump_tasks; /* Defaults to not dumping SysRQ T */
ian@0 63
ian@0 64 /* options - modular */
ian@0 65 module_param(hangcheck_tick, int, 0);
ian@0 66 MODULE_PARM_DESC(hangcheck_tick, "Timer delay.");
ian@0 67 module_param(hangcheck_margin, int, 0);
ian@0 68 MODULE_PARM_DESC(hangcheck_margin, "If the hangcheck timer has been delayed more than hangcheck_margin seconds, the driver will fire.");
ian@0 69 module_param(hangcheck_reboot, int, 0);
ian@0 70 MODULE_PARM_DESC(hangcheck_reboot, "If nonzero, the machine will reboot when the timer margin is exceeded.");
ian@0 71 module_param(hangcheck_dump_tasks, int, 0);
ian@0 72 MODULE_PARM_DESC(hangcheck_dump_tasks, "If nonzero, the machine will dump the system task state when the timer margin is exceeded.");
ian@0 73
ian@0 74 MODULE_AUTHOR("Oracle");
ian@0 75 MODULE_DESCRIPTION("Hangcheck-timer detects when the system has gone out to lunch past a certain margin.");
ian@0 76 MODULE_LICENSE("GPL");
ian@0 77 MODULE_VERSION(VERSION_STR);
ian@0 78
ian@0 79 /* options - nonmodular */
ian@0 80 #ifndef MODULE
ian@0 81
ian@0 82 static int __init hangcheck_parse_tick(char *str)
ian@0 83 {
ian@0 84 int par;
ian@0 85 if (get_option(&str,&par))
ian@0 86 hangcheck_tick = par;
ian@0 87 return 1;
ian@0 88 }
ian@0 89
ian@0 90 static int __init hangcheck_parse_margin(char *str)
ian@0 91 {
ian@0 92 int par;
ian@0 93 if (get_option(&str,&par))
ian@0 94 hangcheck_margin = par;
ian@0 95 return 1;
ian@0 96 }
ian@0 97
ian@0 98 static int __init hangcheck_parse_reboot(char *str)
ian@0 99 {
ian@0 100 int par;
ian@0 101 if (get_option(&str,&par))
ian@0 102 hangcheck_reboot = par;
ian@0 103 return 1;
ian@0 104 }
ian@0 105
ian@0 106 static int __init hangcheck_parse_dump_tasks(char *str)
ian@0 107 {
ian@0 108 int par;
ian@0 109 if (get_option(&str,&par))
ian@0 110 hangcheck_dump_tasks = par;
ian@0 111 return 1;
ian@0 112 }
ian@0 113
ian@0 114 __setup("hcheck_tick", hangcheck_parse_tick);
ian@0 115 __setup("hcheck_margin", hangcheck_parse_margin);
ian@0 116 __setup("hcheck_reboot", hangcheck_parse_reboot);
ian@0 117 __setup("hcheck_dump_tasks", hangcheck_parse_dump_tasks);
ian@0 118 #endif /* not MODULE */
ian@0 119
ian@0 120 #if defined(CONFIG_X86_64) || defined(CONFIG_S390)
ian@0 121 # define HAVE_MONOTONIC
ian@0 122 # define TIMER_FREQ 1000000000ULL
ian@0 123 #elif defined(CONFIG_IA64)
ian@0 124 # define TIMER_FREQ ((unsigned long long)local_cpu_data->itc_freq)
ian@0 125 #else
ian@0 126 # define TIMER_FREQ (HZ*loops_per_jiffy)
ian@0 127 #endif
ian@0 128
ian@0 129 #ifdef HAVE_MONOTONIC
ian@0 130 extern unsigned long long monotonic_clock(void);
ian@0 131 #else
ian@0 132 static inline unsigned long long monotonic_clock(void)
ian@0 133 {
ian@0 134 return get_cycles();
ian@0 135 }
ian@0 136 #endif /* HAVE_MONOTONIC */
ian@0 137
ian@0 138
ian@0 139 /* Last time scheduled */
ian@0 140 static unsigned long long hangcheck_tsc, hangcheck_tsc_margin;
ian@0 141
ian@0 142 static void hangcheck_fire(unsigned long);
ian@0 143
ian@0 144 static DEFINE_TIMER(hangcheck_ticktock, hangcheck_fire, 0, 0);
ian@0 145
ian@0 146
ian@0 147 static void hangcheck_fire(unsigned long data)
ian@0 148 {
ian@0 149 unsigned long long cur_tsc, tsc_diff;
ian@0 150
ian@0 151 cur_tsc = monotonic_clock();
ian@0 152
ian@0 153 if (cur_tsc > hangcheck_tsc)
ian@0 154 tsc_diff = cur_tsc - hangcheck_tsc;
ian@0 155 else
ian@0 156 tsc_diff = (cur_tsc + (~0ULL - hangcheck_tsc)); /* or something */
ian@0 157
ian@0 158 if (tsc_diff > hangcheck_tsc_margin) {
ian@0 159 if (hangcheck_dump_tasks) {
ian@0 160 printk(KERN_CRIT "Hangcheck: Task state:\n");
ian@0 161 #ifdef CONFIG_MAGIC_SYSRQ
ian@0 162 handle_sysrq('t', NULL, NULL);
ian@0 163 #endif /* CONFIG_MAGIC_SYSRQ */
ian@0 164 }
ian@0 165 if (hangcheck_reboot) {
ian@0 166 printk(KERN_CRIT "Hangcheck: hangcheck is restarting the machine.\n");
ian@0 167 emergency_restart();
ian@0 168 } else {
ian@0 169 printk(KERN_CRIT "Hangcheck: hangcheck value past margin!\n");
ian@0 170 }
ian@0 171 }
ian@0 172 mod_timer(&hangcheck_ticktock, jiffies + (hangcheck_tick*HZ));
ian@0 173 hangcheck_tsc = monotonic_clock();
ian@0 174 }
ian@0 175
ian@0 176
ian@0 177 static int __init hangcheck_init(void)
ian@0 178 {
ian@0 179 printk("Hangcheck: starting hangcheck timer %s (tick is %d seconds, margin is %d seconds).\n",
ian@0 180 VERSION_STR, hangcheck_tick, hangcheck_margin);
ian@0 181 #if defined (HAVE_MONOTONIC)
ian@0 182 printk("Hangcheck: Using monotonic_clock().\n");
ian@0 183 #else
ian@0 184 printk("Hangcheck: Using get_cycles().\n");
ian@0 185 #endif /* HAVE_MONOTONIC */
ian@0 186 hangcheck_tsc_margin =
ian@0 187 (unsigned long long)(hangcheck_margin + hangcheck_tick);
ian@0 188 hangcheck_tsc_margin *= (unsigned long long)TIMER_FREQ;
ian@0 189
ian@0 190 hangcheck_tsc = monotonic_clock();
ian@0 191 mod_timer(&hangcheck_ticktock, jiffies + (hangcheck_tick*HZ));
ian@0 192
ian@0 193 return 0;
ian@0 194 }
ian@0 195
ian@0 196
ian@0 197 static void __exit hangcheck_exit(void)
ian@0 198 {
ian@0 199 del_timer_sync(&hangcheck_ticktock);
ian@0 200 printk("Hangcheck: Stopped hangcheck timer.\n");
ian@0 201 }
ian@0 202
ian@0 203 module_init(hangcheck_init);
ian@0 204 module_exit(hangcheck_exit);