linux/drivers/char/hangcheck-timer.c
<<
="v3 ="v3
=" ="v3 Prefs =" v3
v3
="=v3
=v3
v3
v3
v3
   1/*
   2 * hangcheck-timer.c
   3 *
   4 * Driver for a little io fencing timer.
   5 *
   6 * Copyright (C) 2002, 2003 Oracle.  All rights reserved.
   7 *
   8 * Author: Joel Becker <joel.becker@oracle.com>
   9 *
  tiona> * This program is free software; you can redistribute it and/or
  11 * modify it under the terms of the GNU General Public
  12 * License version 2 as published by the Free Software Foundation.
  13 * 
  14 * This program is distributed in the hope that it will be useful,
  15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17 * General Public License for more details.
  18 * 
  19 * You should have received a copy of the GNU General Public
  2iona> * License along with this program; if not, write to the
  21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  22 * Boston, MA 021110-1307, USA.
  23 */
  24
  25/*
  26 * The hangcheck-timer driver uses the TSC to catch delays that
  27 * jiffies does not notice.  A timer is set.  When the timer fires, it
  28 * checks whether it was delayed and if that delay exceeds a given
  29 * margin of error.  The hangcheck_tick module parameter takes the timer
  3iona> * duration in seconds.  The hangcheck_margin parameter defines the
  31 * margin of error, in seconds.  The defaults are 60 seconds for the
  32 * timer and 180 seconds for the margin of error.  IOW, a timer is set
  33 * for 60 seconds.  When the timer fires, the callback checks the
  34 * actual duration that the timer waited.  If the duration exceeds the
  35 * alloted time and margin (here 60 + 180, or 240 seconds), the machine
  36 * is restarted.  A healthy machine will have the duration match the
  37 * expected timeout very closely.
  38 */
  39
  4iona>#include <linux/module.hona>>
  41ona>#include <linux/moduleparam.hona>>
  42ona>#include <linux/types.hona>>
  43ona>#include <linux/kernel.hona>>
  44ona>#include <linux/fs.hona>>
  45ona>#include <linux/mm.hona>>
  46ona>#include <linux/reboot.hona>>
  47ona>#include <linux/init.hona>>
  48ona>#include <linux/delay.hona>>
  49ona>#include <asm/uaccess.hona>>
  5iona>#include <linux/sysrq.hona>>
  51ona>#include <linux/timer.hona>>
  52ona>#include <linux/time.hona>>
  53
  54ona>#define VERSION_STRona> "0.9.1"
  55
  56ona>#define DEFAULT_IOFENCE_MARGINona> 60 v3    /* Default fudge factor, in seconds */
  57ona>#define DEFAULT_IOFENCE_TICKona> 180  v3    /* Default timer timeout, in seconds */
  58
  59ona>static int hangcheck_tickona> = DEFAULT_IOFENCE_TICKona>;
  60ona>static int hangcheck_marginona> = DEFAULT_IOFENCE_MARGINona>;
  61ona>static int hangcheck_rebootona>;  /* Defaults to not reboot */
  62ona>static int hangcheck_dump_tasksona>;  /* Defaults to not dumping SysRQ T */
  63
  64/* options - modular */
  65module_param(hangcheck_tickona>, int, 0);
  66MODULE_PARM_DESC(hangcheck_tickona>, "Timer delay.");
  67module_param(hangcheck_marginona>, int, 0);
  68MODULE_PARM_DESC(hangcheck_marginona>, "If the hangcheck timer has been delayed more than hangcheck_margin seconds, the driver will fire.");
  69module_param(hangcheck_rebootona>, int, 0);
  70MODULE_PARM_DESC(hangcheck_rebootona>, "If nonzero, the machine will reboot when the timer margin is exceeded.");
  71module_param(hangcheck_dump_tasksona>, int, 0);
  72MODULE_PARM_DESC(hangcheck_dump_tasksona>, "If nonzero, the machine will dump the system task state when the timer margin is exceeded.");
  73
  74MODULE_AUTHOR("Oracle");
  75MODULE_DESCRIPTION("Hangcheck-timer detects when the system has gone out to lunch past a certain margin.");
  76MODULE_LICENSE("GPL");
  77MODULE_VERSION(VERSION_STRona>);
  78
  79/* options - nonmodular */
  8iona>#ifndef MODULE
  81
  82ona>static int __initona> hangcheck_parse_tick(char *strona>)
  83{
  84  v3    int parona>;
  85  v3    if (get_option(&strona>,&parona>))
  86  v3      v3    hangcheck_tickona> = parona>;
  87  v3    return 1
  79  8iona9#ifnd9 int __initona> hangcheck_marginona>, classss="srstrona>)
  81  82ona9stati92 int parona>;
  83get_option(&strona>,&parona>))
  84hangcheck_marginona> = parona>;
  85  86  87__initona> hangcheck_rebootona>, classss="srstrona>)
   9<  tiona><#ifn><# int parona>;
  1101ifn><1 if (get_option(&strona>,&parona>))
  1202ifn><2   v3    hangcheck_rebootona>, parona>;
  1303ifn><3 return 1
  1404ifn><4f="d}ivers/char/hangcheck-timer.c#L878" id="L8r10 class="l0ine" name="L15">  1505ifn>  1606ifn><6int __initona> hangcheck_dump_taskso class class="srstrona>)
  1707ifn><7ef="drivers/char/hangcheck-timer.c#L84" id="L8410 class="l0ine" name="L18">  1808ifn><8 int parona>;
  1909ifn><9 if (get_option(&strona>,&parona>))
  tiona>>hangcheck_dump_tasksona>, parona>;
  11<1ifn>11 return 1
  12>  13>  14>__initona> "GPL" = );
hangcheck_parse_tick(char *  15>__initona> "GPL" = = );
hangcheck_marginona>, classss="sr  16>__initona> "GPL" =  );
hangcheck_rebootona>, classss="sr  17>__initona> "GPL" = na>, );
hangcheck_dump_taskso class class="sr  18>/* options - n Sys  19>  2iona1>hangcheck_dref="+df="+code=VERSION_STRCONFIG_S39ine" name=heck_dCONFIG_S39ief="drivers/char/hangcheck-timer.c#L83" id="L831" class="1line" name="L21">  21MODULE_PARMHAVE_MONOTONIrf="drivers/char/hangcheck-timer.c#L40" id="L401" class="liine" name="L12">  12<MODULE_PARMTIMER_FREQ retu><########ULLrivers/char/hangcheck-timer.c#L40" id="L401" class="lline" name="L23">  23  24
MODULE_PARMTIMER_FREQ retu><########ULLrivers/char/hangcheck-timer.c#L40" id="L401" class="lline" name="L25">  25  26  27MODULE_PARMHAVE_MONOTONIrf="drivers/char/hangcheck-timer.c#L40" id="L401" class="lline" name="L28">  28hangcheck_pm" Syonic_closrf="+cvoid"drivers/char/hangcheck-timer.c#L78" id="L781" class="1line" name="L29">  29  3iona1>">hangcheck_pin"L30 retuunsig"+d his phis pode=module_param" Syonic_closref">hangcheck_pm" Syonic_closrf="+cvoid"rivers/char/hangcheck-timer.c#L40" id="L401" class="1line" name="L31">  31  32hangcheck_p" idspecf="+code=hangcheck_ptref">hangcheck_dtsef="drivers/char/hangcheck-timer.c#L85" id="L851" class="1line" name="L33">  33get_optionrawm" Syonica href="+code=str" class=tref">hangcheck_dtsef=""drivers/char/hangcheck-timer.c#L78" id="L781" class="1line" name="L34">  34hangcheck_dt idspec_to_nra href="+code=str" class=tref">hangcheck_dtsef=""drivers/char/hangcheck-timer.c#L78" id="L781" class="lline" name="L35">  35  36/* options - nHAVE_MONOTONIr  37  38  39
/* options - nLin mrgin s.c#/a>(d  4iona1>#inc14 int  = get_option =  = hangcheck_marginona>,  41ona1>#inc14ef="drivers/char/hangcheck-timer.c#L82" id="L821" class="1line" name="L42">  42ona1>#inc14 int  = hangcheck_marginona>,  43ona1>#inc14ef="drivers/char/hangcheck-timer.c#L74" id="L741" class="1line" name="L44">  44ona1>#inc1ude &lhangcheck_mDEFIN
hangcheck_pickona> =  = hangcheck_marginona>,  45ona1>#inc14ef="drivers/char/hangcheck-timer.c#L56" id="L561" class="1line" name="L46">  46ona1>#inc14classrivers/char/hangcheck-timer.c#L40" id="L401" class="1line" name="L47">  47ona1>#inc1ude &l = hangcheck_marginona>,hangcheck_drataef="drivers/char/hangcheck-timer.c#L83" id="L831" class="1line" name="L48">  48ona1>#inc1ude &ldrivers/char/hangcheck-timer.c#L84" id="L841" class="1line" name="L49">  49ona1>#inc149 if (get_optionhangcheck_dtscsd="fef="drivers/char/hangcheck-timer.c#L85" id="L851" class="1line" name="L50">  5iona1>#inc1ude &lrivers/char/hangcheck-timer.c#L85" id="L851" class="1line" name="L51">  51ona1>#inc151 return 1
get_optionhangcheck_pm" Syonic_closrf="+c"drivers/char/hangcheck-timer.c#L72" id="L721" class="1line" name="L52">  52ona1>#inc1ude &lrivers/char/hangcheck-timer.c#L72" id="L721" class="1line" name="L53">  53
get_optionget_option =   54ona1>#def154   v3    hangcheck_dtscsd="fef=""+code=DEFAULT_IOFcur get_option = get_option =   55
  56ona1>#def15    v3    hangcheck_dtscsd="fef=""+ccode=get_option"cur get_option = get_option = /* options - nor sot" o */  57ona1>#def157f="drivers/char/hangcheck-timer.c#L40" id="L401" class="1line" name="L58">  58
hangcheck_dtscsd="fef=""f="dpode=module_paraickona> = hangcheck_marginona>,  59ona1>stat159   v3    hangcheck_dump_tasksona>,   60ona1>stat160   v3    hangcheck_pprintrf="+code=VERSION_STRKERN_CRITef">hangcheck_pKERN_CRITf="+co"string">"Hangcheck-timer dete: Then the t:\nn>);
  61ona1>stat161e <f="+code=MODULE" claCONFIG_MAGIC_SYSRQef">MODULE_PARMCONFIG_MAGIC_SYSRQf="drivers/char/hangcheck-timer.c#L40" id="L401" class="1line" name="L62">  62ona1>stat162   v3    hangcheck_dumpdle_>
class="string">"GPL&qu#39;tu#39;a href="drivers/char/hangcheck-timer.c#L77" id="L771" class="1line" name="L63">  63
/* options - nCONFIG_MAGIC_SYSRQ  64  65hangcheck_rebootona>,   16<#def16    v3    hangcheck_pprintrf="+code=VERSION_STRKERN_CRITef">hangcheck_pKERN_CRITf="+co"string">"Hangcheck-timer dete: imer.c#L8ed.  A heal/spanwill dump .\nn>);
  67hangcheck_peid=gency_ A healf="+c"drivers/char/hangcheck-timer.c#L72" id="L721" class="1line" name="L68">  68  69hangcheck_pprintrf="+code=VERSION_STRKERN_CRITef">hangcheck_pKERN_CRITf="+co"string">"Hangcheck-timer dete: imer.c#L8e3    tain mss="sr!\nn>);
  70  71  72  73
/*
  74 * actual duuuuuuuuu* Enablpan>
invA hige tiinspan>
  75 * alloted tuuuuuuuu* href="drivers/char/hangcheck-timer.c#L80" id="L801" class="1line" name="L76">  76hangcheck_pprintrf="+co"string">"Hangcheck-timer dete: ecksed u#37;Ld ns since lin mrgin (u#37;Ld ns oangchpan)\nn>);
  17<hangcheck_dtscsd="fef="epode=module_parahangcheck_dtscsd="fef=""-pode=module_paraickona> = <"sref">hangcheck_tickona> = MODULE_PARMTIMER_FREQ ret"drivers/char/hangcheck-timer.c#L77" id="L771" class="1line" name="L78">  78
  79hangcheck_pm"d_" id=a href="+code=str" class=ickona> = hangcheck_pickona> = hangcheck_ps not na hr"+ (ode=module_paraickona> = <"sref">hangcheck_tickona> = MODULE_PARMHZa hr));rivers/char/hangcheck-timer.c#L77" id="L771" class="1line" name="L80">  8iona1>#ifn180   v3     = get_option = hangcheck_pm" Syonic_closrf="+c"drivers/char/hangcheck-timer.c#L72" id="L721" class="1line" name="L81">  81
  82ona1>stat18de &lrivers/char/hangcheck-timer.c#L72" id="L721" class="1line" name="L83">  83{
  84  v318de &l__initona> __initona> arse_tick"="srf="+cvoid"rivers/char/hangcheck-timer.c#L40" id="L401" class="1line" name="L85">  85  v31   if drivers/char/hangcheck-timer.c#L84" id="L841" class="1line" name="L86">  86  v318    v3    hangcheck_pprintrf="+co"string">"Hangcheck-timer dete:  heal/spaimer.c#L8ets wheu#37;s ( parad. u#37;dhe driver xceeded.&qu#37;dhe drive).\nn>);
  87  v3187   v3    VERSION_STRona>);
 = <"sref">hangcheck_tickona>,  = ss="sref">hangcheck_marginona> =   18<
hangcheck_dref="+df="+ (ode=module_paraHAVE_MONOTONIref">MODULE_PARMHAVE_MONOTONIrf="d"rivers/char/hangcheck-timer.c#L40" id="L401" class="18ine" name="L79">  79hangcheck_pprintrf="+co"string">"Hangcheck-timer dete: Us/spam" Syonic_closr().\nn>);
  8iona19#ifn19ief="#elserivers/char/hangcheck-timer.c#L40" id="L4019 class="19ine" name="L81">  81hangcheck_pprintrf="+co"string">"Hangcheck-timer dete: Us/spa/a>rawm" Syonic().\nn>);
  82ona19stat192 int#end="++="comment">/* options - nHAVE_MONOTONIr  83 = hangcheck_marginona>,  84hangcheck_marginona>,  = <"sref">hangcheck_tickona>,   85 = hangcheck_marginona>,MODULE_PARMTIMER_FREQ retdrivers/char/hangcheck-timer.c#L72" id="L7219 class="19ine" name="L86">  86  87 = get_option = hangcheck_pm" Syonic_closrf="+c"drivers/char/hangcheck-timer.c#L72" id="L7219hangchec19-timer.c#L878jiffies do19s no198 return 1
hangcheck_pm"d_" id=a href="+code=str" class=ickona> = hangcheck_pickona> = hangcheck_ps not na hr"+ (ode=module_paraickona> = <"sref">hangcheck_tickona> = MODULE_PARMHZa hr));rivers/char/hangcheck-timer.c#L77" id="L7719class="l1iine" name="L9">   91<  tiona2<#ifn2<# int   11  12  13  14__initona> __initona> arse_tick"exsrf="+cvoid"rivers/char/hangcheck-timer.c#L40" id="L4020 class="20ine" name="L15">  15  16get_option = hangcheck_pickona> =   17hangcheck_pprintrf="+co"string">"Hangcheck-timer dete: Stopp+d imer.c#L8ets wh.\nn>);
  18  19  tiona2>(<="sref">__initona> m(<="srf="+code=VERSION_STRarse_tick"="sref">__initona> arse_tick"="srf="+"drivers/char/hangcheck-timer.c#L72" id="L722" class="2iine" name="L11">  11__initona> m" clasexsrf="+code=VERSION_STRarse_tick"exsref">__initona> arse_tick"exsrf="+"drivers/char/hangcheck-timer.c#L72" id="L722" class="2line" name="L12">  12


s arori"sral LXR softwnds byanwilivers/chahttp://sourceforge.net/projhe s/lx=e>LXR optu"srya hrepth.&quoperitional angche.no">lx=@lona>.noa hr.
lx=.lona>.no kindly hos verbyaivers/chahttp://www.redpill-lonpro.no">Redpill Lonpro ASa hrepprovider IOWLona> onsull/spa(heroperamodulaservices since 19e5.