2005-04-12 23:57:03

by Joel Becker

[permalink] [raw]
Subject: [PATCH] hangcheck-timer: Update to 0.9.0.

I recently realized that the in-kernel copy of hangcheck-timer
was quite stale. Here's the latest. It adds support for s390, ppc64,
and ia64 too.

Signed-off-by: Joel Becker <[email protected]>
---

Kconfig | 2 -
hangcheck-timer.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 96 insertions(+), 10 deletions(-)

Index: linux-2.6.12-rc2/drivers/char/hangcheck-timer.c
===================================================================
--- linux-2.6.12-rc2.orig/drivers/char/hangcheck-timer.c 2005-03-01 23:38:07.000000000 -0800
+++ linux-2.6.12-rc2/drivers/char/hangcheck-timer.c 2005-04-12 15:34:26.000000000 -0700
@@ -3,7 +3,7 @@
*
* Driver for a little io fencing timer.
*
- * Copyright (C) 2002 Oracle Corporation. All rights reserved.
+ * Copyright (C) 2002, 2003 Oracle. All rights reserved.
*
* Author: Joel Becker <[email protected]>
*
@@ -44,11 +44,14 @@
#include <linux/fs.h>
#include <linux/mm.h>
#include <linux/reboot.h>
+#include <linux/smp_lock.h>
#include <linux/init.h>
+#include <linux/delay.h>
#include <asm/uaccess.h>
+#include <linux/sysrq.h>


-#define VERSION_STR "0.5.0"
+#define VERSION_STR "0.9.0"

#define DEFAULT_IOFENCE_MARGIN 60 /* Default fudge factor, in seconds */
#define DEFAULT_IOFENCE_TICK 180 /* Default timer timeout, in seconds */
@@ -56,18 +59,89 @@
static int hangcheck_tick = DEFAULT_IOFENCE_TICK;
static int hangcheck_margin = DEFAULT_IOFENCE_MARGIN;
static int hangcheck_reboot; /* Defaults to not reboot */
+static int hangcheck_dump_tasks; /* Defaults to not dumping SysRQ T */

-/* Driver options */
+/* options - modular */
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("Joel Becker");
+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);
+
+/* options - nonmodular */
+#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 /* not MODULE */
+
+#if defined(__i386__) || defined(__x86_64__)
+# define HAVE_MONOTONIC
+# define TIMER_FREQ 1000000000ULL
+#elif defined(__s390__)
+/* FA240000 is 1 Second in the IBM time universe (Page 4-38 Principles of Op for zSeries */
+# define TIMER_FREQ 0xFA240000ULL
+#elif defined(__ia64__)
+# define TIMER_FREQ ((unsigned long long)local_cpu_data->itc_freq)
+#elif defined(__powerpc64__)
+# define TIMER_FREQ (HZ*loops_per_jiffy)
+#endif /* __s390__ */
+
+#ifdef HAVE_MONOTONIC
+extern unsigned long long monotonic_clock(void);
+#else
+static inline unsigned long long monotonic_clock(void)
+{
+# ifdef __s390__
+ /* returns the TOD. see 4-38 Principles of Op of zSeries */
+ return get_clock();
+# else
+ return get_cycles();
+# endif /* __s390__ */
+}
+#endif /* HAVE_MONOTONIC */


/* Last time scheduled */
@@ -78,7 +152,6 @@
static struct timer_list hangcheck_ticktock =
TIMER_INITIALIZER(hangcheck_fire, 0, 0);

-extern unsigned long long monotonic_clock(void);

static void hangcheck_fire(unsigned long data)
{
@@ -92,6 +165,12 @@
tsc_diff = (cur_tsc + (~0ULL - hangcheck_tsc)); /* or something */

if (tsc_diff > hangcheck_tsc_margin) {
+ if (hangcheck_dump_tasks) {
+ printk(KERN_CRIT "Hangcheck: Task state:\n");
+#ifdef CONFIG_MAGIC_SYSRQ
+ handle_sysrq('t', NULL, NULL);
+#endif /* CONFIG_MAGIC_SYSRQ */
+ }
if (hangcheck_reboot) {
printk(KERN_CRIT "Hangcheck: hangcheck is restarting the machine.\n");
machine_restart(NULL);
@@ -108,10 +187,16 @@
{
printk("Hangcheck: starting hangcheck timer %s (tick is %d seconds, margin is %d seconds).\n",
VERSION_STR, hangcheck_tick, hangcheck_margin);
-
- hangcheck_tsc_margin = hangcheck_margin + hangcheck_tick;
- hangcheck_tsc_margin *= 1000000000;
-
+#if defined (HAVE_MONOTONIC)
+ printk("Hangcheck: Using monotonic_clock().\n");
+#elif defined(__s390__)
+ printk("Hangcheck: Using TOD.\n");
+#else
+ printk("Hangcheck: Using get_cycles().\n");
+#endif /* HAVE_MONOTONIC */
+ hangcheck_tsc_margin =
+ (unsigned long long)(hangcheck_margin + hangcheck_tick);
+ hangcheck_tsc_margin *= (unsigned long long)TIMER_FREQ;

hangcheck_tsc = monotonic_clock();
mod_timer(&hangcheck_ticktock, jiffies + (hangcheck_tick*HZ));
@@ -123,6 +208,7 @@
static void __exit hangcheck_exit(void)
{
del_timer_sync(&hangcheck_ticktock);
+ printk("Hangcheck: Stopped hangcheck timer.\n");
}

module_init(hangcheck_init);
Index: linux-2.6.12-rc2/drivers/char/Kconfig
===================================================================
--- linux-2.6.12-rc2.orig/drivers/char/Kconfig 2005-04-12 15:33:39.000000000 -0700
+++ linux-2.6.12-rc2/drivers/char/Kconfig 2005-04-12 15:34:26.000000000 -0700
@@ -968,7 +968,7 @@

config HANGCHECK_TIMER
tristate "Hangcheck timer"
- depends on X86_64 || X86
+ depends on X86_64 || X86 || IA64 || PPC64 || ARCH_S390
help
The hangcheck-timer module detects when the system has gone
out to lunch past a certain margin. It can reboot the system
--

Life's Little Instruction Book #94

"Make it a habit to do nice things for people who
will never find out."

Joel Becker
Senior Member of Technical Staff
Oracle
E-mail: [email protected]
Phone: (650) 506-8127


2005-04-13 00:22:36

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH] hangcheck-timer: Update to 0.9.0.

Joel Becker <[email protected]> wrote:
>
> +#if defined(__i386__) || defined(__x86_64__)
> +# define HAVE_MONOTONIC
> +# define TIMER_FREQ 1000000000ULL
> +#elif defined(__s390__)
> +/* FA240000 is 1 Second in the IBM time universe (Page 4-38 Principles of Op for zSeries */
> +# define TIMER_FREQ 0xFA240000ULL
> +#elif defined(__ia64__)
> +# define TIMER_FREQ ((unsigned long long)local_cpu_data->itc_freq)
> +#elif defined(__powerpc64__)
> +# define TIMER_FREQ (HZ*loops_per_jiffy)
> +#endif /* __s390__ */

It's not very important, but it would be a bit more conventional to use
CONFIG_X86, CONFIG_ARCH_S390, CONFIG_IA64 and CONFIG_PPC64 for those cases
where such an ifdef is to be used.

In the above case specifically, no ifdefs should be needed - you can simply
define CONFIG_HANGCHECK_TIMER_FREQ in arch/*/Kconfig.

2005-04-13 00:46:17

by Joel Becker

[permalink] [raw]
Subject: Re: [PATCH] hangcheck-timer: Update to 0.9.0.

On Tue, Apr 12, 2005 at 05:18:01PM -0700, Andrew Morton wrote:
> It's not very important, but it would be a bit more conventional to use
> CONFIG_X86, CONFIG_ARCH_S390, CONFIG_IA64 and CONFIG_PPC64 for those cases
> where such an ifdef is to be used.

Well, yeah, silly me.

> Joel Becker <[email protected]> wrote:
> > +# define TIMER_FREQ 1000000000ULL
> > +# define TIMER_FREQ 0xFA240000ULL
> > +# define TIMER_FREQ ((unsigned long long)local_cpu_data->itc_freq)
> > +# define TIMER_FREQ (HZ*loops_per_jiffy)
>
> In the above case specifically, no ifdefs should be needed - you can simply
> define CONFIG_HANGCHECK_TIMER_FREQ in arch/*/Kconfig.

Kbuild foo help, please. I can't quite figure out how to
represent the non-constant values as code in Kbuild. I can represent
them as strings, but then they are strings, not code.

Joel

--

Life's Little Instruction Book #452

"Never compromise your integrity."

Joel Becker
Senior Member of Technical Staff
Oracle
E-mail: [email protected]
Phone: (650) 506-8127

2005-04-13 00:55:08

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH] hangcheck-timer: Update to 0.9.0.

Joel Becker <[email protected]> wrote:
>
> > Joel Becker <[email protected]> wrote:
> > > +# define TIMER_FREQ 1000000000ULL
> > > +# define TIMER_FREQ 0xFA240000ULL
> > > +# define TIMER_FREQ ((unsigned long long)local_cpu_data->itc_freq)
> > > +# define TIMER_FREQ (HZ*loops_per_jiffy)
> >
> > In the above case specifically, no ifdefs should be needed - you can simply
> > define CONFIG_HANGCHECK_TIMER_FREQ in arch/*/Kconfig.
>
> Kbuild foo help, please. I can't quite figure out how to
> represent the non-constant values as code in Kbuild. I can represent
> them as strings, but then they are strings, not code.

Oh, I missed that. Don't worry about it then. (It'd be nicer to put the
ifdeffery in a header file tho)

2005-04-14 23:44:02

by Joel Becker

[permalink] [raw]
Subject: [PATCH] hangcheck-timer: Update to 0.9.0.


I recently realized that the in-kernel copy of hangcheck-timer
was quite stale. Here's the latest. It adds support for s390, ppc64,
and ia64 too.

Signed-off-by: Joel Becker <[email protected]>
---

Kconfig | 2 -
hangcheck-timer.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 96 insertions(+), 10 deletions(-)

Index: linux-2.6.12-rc2/drivers/char/hangcheck-timer.c
===================================================================
--- linux-2.6.12-rc2.orig/drivers/char/hangcheck-timer.c 2005-03-01 23:38:07.000000000 -0800
+++ linux-2.6.12-rc2/drivers/char/hangcheck-timer.c 2005-04-14 15:32:03.000000000 -0700
@@ -3,7 +3,7 @@
*
* Driver for a little io fencing timer.
*
- * Copyright (C) 2002 Oracle Corporation. All rights reserved.
+ * Copyright (C) 2002, 2003 Oracle. All rights reserved.
*
* Author: Joel Becker <[email protected]>
*
@@ -44,11 +44,14 @@
#include <linux/fs.h>
#include <linux/mm.h>
#include <linux/reboot.h>
+#include <linux/smp_lock.h>
#include <linux/init.h>
+#include <linux/delay.h>
#include <asm/uaccess.h>
+#include <linux/sysrq.h>


-#define VERSION_STR "0.5.0"
+#define VERSION_STR "0.9.0"

#define DEFAULT_IOFENCE_MARGIN 60 /* Default fudge factor, in seconds */
#define DEFAULT_IOFENCE_TICK 180 /* Default timer timeout, in seconds */
@@ -56,18 +59,89 @@
static int hangcheck_tick = DEFAULT_IOFENCE_TICK;
static int hangcheck_margin = DEFAULT_IOFENCE_MARGIN;
static int hangcheck_reboot; /* Defaults to not reboot */
+static int hangcheck_dump_tasks; /* Defaults to not dumping SysRQ T */

-/* Driver options */
+/* options - modular */
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("Joel Becker");
+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);
+
+/* options - nonmodular */
+#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 /* not MODULE */
+
+#if defined(CONFIG_X86) || defined(CONFIG_X86_64)
+# define HAVE_MONOTONIC
+# define TIMER_FREQ 1000000000ULL
+#elif defined(CONFIG_ARCH_S390)
+/* FA240000 is 1 Second in the IBM time universe (Page 4-38 Principles of Op for zSeries */
+# define TIMER_FREQ 0xFA240000ULL
+#elif defined(CONFIG_IA64)
+# define TIMER_FREQ ((unsigned long long)local_cpu_data->itc_freq)
+#elif defined(CONFIG_PPC64)
+# define TIMER_FREQ (HZ*loops_per_jiffy)
+#endif
+
+#ifdef HAVE_MONOTONIC
+extern unsigned long long monotonic_clock(void);
+#else
+static inline unsigned long long monotonic_clock(void)
+{
+# ifdef __s390__
+ /* returns the TOD. see 4-38 Principles of Op of zSeries */
+ return get_clock();
+# else
+ return get_cycles();
+# endif /* __s390__ */
+}
+#endif /* HAVE_MONOTONIC */


/* Last time scheduled */
@@ -78,7 +152,6 @@
static struct timer_list hangcheck_ticktock =
TIMER_INITIALIZER(hangcheck_fire, 0, 0);

-extern unsigned long long monotonic_clock(void);

static void hangcheck_fire(unsigned long data)
{
@@ -92,6 +165,12 @@
tsc_diff = (cur_tsc + (~0ULL - hangcheck_tsc)); /* or something */

if (tsc_diff > hangcheck_tsc_margin) {
+ if (hangcheck_dump_tasks) {
+ printk(KERN_CRIT "Hangcheck: Task state:\n");
+#ifdef CONFIG_MAGIC_SYSRQ
+ handle_sysrq('t', NULL, NULL);
+#endif /* CONFIG_MAGIC_SYSRQ */
+ }
if (hangcheck_reboot) {
printk(KERN_CRIT "Hangcheck: hangcheck is restarting the machine.\n");
machine_restart(NULL);
@@ -108,10 +187,16 @@
{
printk("Hangcheck: starting hangcheck timer %s (tick is %d seconds, margin is %d seconds).\n",
VERSION_STR, hangcheck_tick, hangcheck_margin);
-
- hangcheck_tsc_margin = hangcheck_margin + hangcheck_tick;
- hangcheck_tsc_margin *= 1000000000;
-
+#if defined (HAVE_MONOTONIC)
+ printk("Hangcheck: Using monotonic_clock().\n");
+#elif defined(__s390__)
+ printk("Hangcheck: Using TOD.\n");
+#else
+ printk("Hangcheck: Using get_cycles().\n");
+#endif /* HAVE_MONOTONIC */
+ hangcheck_tsc_margin =
+ (unsigned long long)(hangcheck_margin + hangcheck_tick);
+ hangcheck_tsc_margin *= (unsigned long long)TIMER_FREQ;

hangcheck_tsc = monotonic_clock();
mod_timer(&hangcheck_ticktock, jiffies + (hangcheck_tick*HZ));
@@ -123,6 +208,7 @@
static void __exit hangcheck_exit(void)
{
del_timer_sync(&hangcheck_ticktock);
+ printk("Hangcheck: Stopped hangcheck timer.\n");
}

module_init(hangcheck_init);
Index: linux-2.6.12-rc2/drivers/char/Kconfig
===================================================================
--- linux-2.6.12-rc2.orig/drivers/char/Kconfig 2005-04-12 15:33:39.000000000 -0700
+++ linux-2.6.12-rc2/drivers/char/Kconfig 2005-04-12 15:34:26.000000000 -0700
@@ -968,7 +968,7 @@

config HANGCHECK_TIMER
tristate "Hangcheck timer"
- depends on X86_64 || X86
+ depends on X86_64 || X86 || IA64 || PPC64 || ARCH_S390
help
The hangcheck-timer module detects when the system has gone
out to lunch past a certain margin. It can reboot the system
--

Viro's Razor:
Any race condition, no matter how unlikely, will occur just
often enough to bite you.

Joel Becker
Senior Member of Technical Staff
Oracle
E-mail: [email protected]
Phone: (650) 506-8127

2005-05-01 17:46:02

by Arjan van de Ven

[permalink] [raw]
Subject: Re: [PATCH] hangcheck-timer: Update to 0.9.0.

> +
> +#if defined(CONFIG_X86) || defined(CONFIG_X86_64)
> +# define HAVE_MONOTONIC
> +# define TIMER_FREQ 1000000000ULL

this looks wrong!

does this work with HZ=100 ?
also there is a TSC config option which you want to use most likely
instead of CONFIG_X86 (and x86-64 has CONFIG_X86 defined too)




2005-05-02 08:49:12

by Joel Becker

[permalink] [raw]
Subject: Re: [PATCH] hangcheck-timer: Update to 0.9.0.

On Sun, May 01, 2005 at 01:45:37PM -0400, Arjan van de Ven wrote:
> > +
> > +#if defined(CONFIG_X86) || defined(CONFIG_X86_64)
> > +# define HAVE_MONOTONIC
> > +# define TIMER_FREQ 1000000000ULL
>
> this looks wrong!
>
> does this work with HZ=100 ?
> also there is a TSC config option which you want to use most likely
> instead of CONFIG_X86 (and x86-64 has CONFIG_X86 defined too)

It is right, though. monotonic_clock() is defined as returning
nanoseconds, not a value based on HZ. It's supported on x86 and x86-64,
hence using CONFIG_X86 to check. Someday, John will get it implemented
for the other platforms, and we'll have less mess in hangcheck-timer.c.
He already thinks that he should have the prototype in timer.h or so (so
I don't have to extern declare it), but he hasn't gotten around to it
yet.

Joel

--

Life's Little Instruction Book #30

"Never buy a house without a fireplace."

Joel Becker
Senior Member of Technical Staff
Oracle
E-mail: [email protected]
Phone: (650) 506-8127