LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [RFC PATCH] Check if the Hangcheck-timer TSC source is stable
@ 2008-11-06 22:37 Michael Trimarchi
  2008-11-07  9:23 ` Joel Becker
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Trimarchi @ 2008-11-06 22:37 UTC (permalink / raw)
  To: linux-kernel; +Cc: joel.becker

[-- Attachment #1: Type: text/plain, Size: 1 bytes --]



[-- Attachment #2: hangcheck-timer-tsc-unstable-v2.pach --]
[-- Type: text/plain, Size: 4957 bytes --]

Check if the TSC source is stable otherwise fail registration.

Signed-off-by: Michael Trimarchi <trimarchimichael@yahoo.it>

---
diff --git a/drivers/char/hangcheck-timer.c b/drivers/char/hangcheck-timer.c
index 712d9f2..910a77a 100644
--- a/drivers/char/hangcheck-timer.c
+++ b/drivers/char/hangcheck-timer.c
@@ -10,12 +10,12 @@
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public
  * License version 2 as published by the Free Software Foundation.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public
  * License along with this program; if not, write to the
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
@@ -64,14 +64,18 @@ static int hangcheck_dump_tasks;  /* Defaults to not dumping SysRQ T */
 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_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_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_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_DESCRIPTION("Hangcheck-timer detects when the system has gone"
+		   " out to lunch past a certain margin.");
 MODULE_LICENSE("GPL");
 MODULE_VERSION(VERSION_STR);
 
@@ -81,7 +85,7 @@ MODULE_VERSION(VERSION_STR);
 static int __init hangcheck_parse_tick(char *str)
 {
 	int par;
-	if (get_option(&str,&par))
+	if (get_option(&str, &par))
 		hangcheck_tick = par;
 	return 1;
 }
@@ -89,7 +93,7 @@ static int __init hangcheck_parse_tick(char *str)
 static int __init hangcheck_parse_margin(char *str)
 {
 	int par;
-	if (get_option(&str,&par))
+	if (get_option(&str, &par))
 		hangcheck_margin = par;
 	return 1;
 }
@@ -97,7 +101,7 @@ static int __init hangcheck_parse_margin(char *str)
 static int __init hangcheck_parse_reboot(char *str)
 {
 	int par;
-	if (get_option(&str,&par))
+	if (get_option(&str, &par))
 		hangcheck_reboot = par;
 	return 1;
 }
@@ -105,7 +109,7 @@ static int __init hangcheck_parse_reboot(char *str)
 static int __init hangcheck_parse_dump_tasks(char *str)
 {
 	int par;
-	if (get_option(&str,&par))
+	if (get_option(&str, &par))
 		hangcheck_dump_tasks = par;
 	return 1;
 }
@@ -151,8 +155,10 @@ static void hangcheck_fire(unsigned long data)
 
 	if (cur_tsc > hangcheck_tsc)
 		tsc_diff = cur_tsc - hangcheck_tsc;
-	else
-		tsc_diff = (cur_tsc + (~0ULL - hangcheck_tsc)); /* or something */
+	else {
+		/* or samenthing */
+		tsc_diff = (cur_tsc + (~0ULL - hangcheck_tsc));
+	}
 
 	if (tsc_diff > hangcheck_tsc_margin) {
 		if (hangcheck_dump_tasks) {
@@ -172,15 +178,21 @@ static void hangcheck_fire(unsigned long data)
 	hangcheck_tsc = monotonic_clock();
 }
 
-
 static int __init hangcheck_init(void)
 {
-	printk("Hangcheck: starting hangcheck timer %s (tick is %d seconds, margin is %d seconds).\n",
+	printk(KERN_INFO "Hangcheck: starting hangcheck timer %s"
+			 " (tick is %d seconds, margin is %d seconds).\n",
 	       VERSION_STR, hangcheck_tick, hangcheck_margin);
-#if defined (HAVE_MONOTONIC)
-	printk("Hangcheck: Using monotonic_clock().\n");
+#if defined(HAVE_MONOTONIC)
+	printk(KERN_INFO "Hangcheck: Using monotonic_clock().\n");
 #else
-	printk("Hangcheck: Using get_cycles().\n");
+	if (!check_tsc_unstable())
+		printk(KERN_INFO "Hangcheck: Using get_cycles().\n");
+	else {
+		printk(KERN_ERR "Handcheck: Failed to register"
+		       " (Unstable TSC).\n");
+		return -ENODEV;
+	}
 #endif  /* HAVE_MONOTONIC */
 	hangcheck_tsc_margin =
 		(unsigned long long)(hangcheck_margin + hangcheck_tick);
@@ -196,7 +208,7 @@ static int __init hangcheck_init(void)
 static void __exit hangcheck_exit(void)
 {
 	del_timer_sync(&hangcheck_ticktock);
-        printk("Hangcheck: Stopped hangcheck timer.\n");
+	printk(KERN_INFO "Hangcheck: Stopped hangcheck timer.\n");
 }
 
 module_init(hangcheck_init);

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [RFC PATCH] Check if the Hangcheck-timer TSC source is stable
  2008-11-06 22:37 [RFC PATCH] Check if the Hangcheck-timer TSC source is stable Michael Trimarchi
@ 2008-11-07  9:23 ` Joel Becker
  2008-11-10  8:21   ` [RFC PATCH V2] " michael
  0 siblings, 1 reply; 3+ messages in thread
From: Joel Becker @ 2008-11-07  9:23 UTC (permalink / raw)
  To: Michael Trimarchi; +Cc: linux-kernel

On Thu, Nov 06, 2008 at 11:37:28PM +0100, Michael Trimarchi wrote:
> Check if the TSC source is stable otherwise fail registration.

	Good idea.

> @@ -151,8 +155,10 @@ static void hangcheck_fire(unsigned long data)
>  
>  	if (cur_tsc > hangcheck_tsc)
>  		tsc_diff = cur_tsc - hangcheck_tsc;
> -	else
> -		tsc_diff = (cur_tsc + (~0ULL - hangcheck_tsc)); /* or something */
> +	else {
> +		/* or samenthing */
> +		tsc_diff = (cur_tsc + (~0ULL - hangcheck_tsc));
> +	}

	This hunk isn't any good.  The comment spelling is messed up,
and really you can just remove the "or something".

Joel

-- 

"There is no sincerer love than the love of food."  
         - George Bernard Shaw 

Joel Becker
Principal Software Developer
Oracle
E-mail: joel.becker@oracle.com
Phone: (650) 506-8127

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC PATCH V2] Check if the Hangcheck-timer TSC source is stable
  2008-11-07  9:23 ` Joel Becker
@ 2008-11-10  8:21   ` michael
  0 siblings, 0 replies; 3+ messages in thread
From: michael @ 2008-11-10  8:21 UTC (permalink / raw)
  To: joel.becker, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 0 bytes --]



[-- Attachment #2: hangcheck-timer-tsc-unstable-v3.patch --]
[-- Type: text/x-patch, Size: 4918 bytes --]

Check if the TSC source is stable otherwise fail registration.

Signed-off-by: Michael Trimarchi <trimarchimichael@yahoo.it>

---
diff --git a/drivers/char/hangcheck-timer.c b/drivers/char/hangcheck-timer.c
index 712d9f2..8e6dabe 100644
--- a/drivers/char/hangcheck-timer.c
+++ b/drivers/char/hangcheck-timer.c
@@ -10,12 +10,12 @@
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public
  * License version 2 as published by the Free Software Foundation.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public
  * License along with this program; if not, write to the
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
@@ -64,14 +64,18 @@ static int hangcheck_dump_tasks;  /* Defaults to not dumping SysRQ T */
 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_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_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_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_DESCRIPTION("Hangcheck-timer detects when the system has gone"
+		   " out to lunch past a certain margin.");
 MODULE_LICENSE("GPL");
 MODULE_VERSION(VERSION_STR);
 
@@ -81,7 +85,7 @@ MODULE_VERSION(VERSION_STR);
 static int __init hangcheck_parse_tick(char *str)
 {
 	int par;
-	if (get_option(&str,&par))
+	if (get_option(&str, &par))
 		hangcheck_tick = par;
 	return 1;
 }
@@ -89,7 +93,7 @@ static int __init hangcheck_parse_tick(char *str)
 static int __init hangcheck_parse_margin(char *str)
 {
 	int par;
-	if (get_option(&str,&par))
+	if (get_option(&str, &par))
 		hangcheck_margin = par;
 	return 1;
 }
@@ -97,7 +101,7 @@ static int __init hangcheck_parse_margin(char *str)
 static int __init hangcheck_parse_reboot(char *str)
 {
 	int par;
-	if (get_option(&str,&par))
+	if (get_option(&str, &par))
 		hangcheck_reboot = par;
 	return 1;
 }
@@ -105,7 +109,7 @@ static int __init hangcheck_parse_reboot(char *str)
 static int __init hangcheck_parse_dump_tasks(char *str)
 {
 	int par;
-	if (get_option(&str,&par))
+	if (get_option(&str, &par))
 		hangcheck_dump_tasks = par;
 	return 1;
 }
@@ -152,7 +156,7 @@ static void hangcheck_fire(unsigned long data)
 	if (cur_tsc > hangcheck_tsc)
 		tsc_diff = cur_tsc - hangcheck_tsc;
 	else
-		tsc_diff = (cur_tsc + (~0ULL - hangcheck_tsc)); /* or something */
+		tsc_diff = (cur_tsc + (~0ULL - hangcheck_tsc));
 
 	if (tsc_diff > hangcheck_tsc_margin) {
 		if (hangcheck_dump_tasks) {
@@ -172,15 +176,21 @@ static void hangcheck_fire(unsigned long data)
 	hangcheck_tsc = monotonic_clock();
 }
 
-
 static int __init hangcheck_init(void)
 {
-	printk("Hangcheck: starting hangcheck timer %s (tick is %d seconds, margin is %d seconds).\n",
+	printk(KERN_INFO "Hangcheck: starting hangcheck timer %s"
+			 " (tick is %d seconds, margin is %d seconds).\n",
 	       VERSION_STR, hangcheck_tick, hangcheck_margin);
-#if defined (HAVE_MONOTONIC)
-	printk("Hangcheck: Using monotonic_clock().\n");
+#if defined(HAVE_MONOTONIC)
+	printk(KERN_INFO "Hangcheck: Using monotonic_clock().\n");
 #else
-	printk("Hangcheck: Using get_cycles().\n");
+	if (!check_tsc_unstable())
+		printk(KERN_INFO "Hangcheck: Using get_cycles().\n");
+	else {
+		printk(KERN_ERR "Handcheck: Failed to register"
+		       " (Unstable TSC).\n");
+		return -ENODEV;
+	}
 #endif  /* HAVE_MONOTONIC */
 	hangcheck_tsc_margin =
 		(unsigned long long)(hangcheck_margin + hangcheck_tick);
@@ -196,7 +206,7 @@ static int __init hangcheck_init(void)
 static void __exit hangcheck_exit(void)
 {
 	del_timer_sync(&hangcheck_ticktock);
-        printk("Hangcheck: Stopped hangcheck timer.\n");
+	printk(KERN_INFO "Hangcheck: Stopped hangcheck timer.\n");
 }
 
 module_init(hangcheck_init);

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-11-10  8:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-06 22:37 [RFC PATCH] Check if the Hangcheck-timer TSC source is stable Michael Trimarchi
2008-11-07  9:23 ` Joel Becker
2008-11-10  8:21   ` [RFC PATCH V2] " michael

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).