Skip to contentSkip to conversation

printk: add halt_delay parameter for printk delay in halt phase

PATCH Superseded Dave Young 3 participants 6 messages Jun 2, 2009 – Jun 12, 2009 Library code

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Dave Young

author
#0 lore raw

PATCH 1/1 printk: add halt_delay parameter for printk delay in halt phase

Add a halt_delay module parameter in printk.c used to read the printk messages in halt/poweroff/restart phase, delay each printk messages by halt_delay milliseconds. It is useful for debugging if there's no other way to dump kernel messages that time.

halt_delay default value is 0, change it by:

echo xxx > /sys/module/printk/parameters/halt_delay

---

kernel/printk.c   |   21 +++++++++++++++++++++
lib/Kconfig.debug |   10 ++++++++++
2 files changed, 31 insertions(+)
kernel/printk.c +21 -0
@@ -250,6 +250,26 @@ static inline void boot_delay_msec(void)
 }
 #endif
 
+#ifdef CONFIG_HALT_PRINTK_DELAY
+/* msecs delay after each halt/poweroff/restart phase printk */
+static unsigned int halt_delay;
+
+static inline void halt_delay_msec(void)
+{
+	if (halt_delay == 0 || !(system_state == SYSTEM_HALT
+				|| system_state == SYSTEM_POWER_OFF
+				|| system_state == SYSTEM_RESTART))
+		return;
+
+	mdelay(halt_delay);
+}
+
+module_param(halt_delay, int, S_IRUGO | S_IWUSR);
+#else
+static inline void halt_delay_msec(void)
+{
+}
+#endif
 /*
  * Commands to do_syslog:
  *
@@ -649,6 +669,7 @@ asmlinkage int vprintk(const char *fmt,
 	char *p;
 
 	boot_delay_msec();
+	halt_delay_msec();
 
 	preempt_disable();
 	/* This stops the holder of console_sem just where we want him */
lib/Kconfig.debug +10 -0
@@ -647,6 +647,16 @@ config BOOT_PRINTK_DELAY
 	  BOOT_PRINTK_DELAY also may cause DETECT_SOFTLOCKUP to detect
 	  what it believes to be lockup conditions.
 
+config HALT_PRINTK_DELAY
+	bool "Delay halt/poweroff/restart printk message by N milliseconds"
+	depends on DEBUG_KERNEL && PRINTK && SYSFS
+	default n
+	help
+	  This build option allows you to read kernel messages in
+	  halt/poweroff/restart phase by inserting a short delay after
+	  each one.  The delay is specified in milliseconds on the
+	  module parameter: /sys/module/printk/halt_delay.
+
 config RCU_TORTURE_TEST
 	tristate "torture tests for RCU"
 	depends on DEBUG_KERNEL
#1 lore raw
Quoted 4 lines · Dave Young

Add a halt_delay module parameter in printk.c used to read the printk messages in halt/poweroff/restart phase, delay each printk messages by halt_delay milliseconds. It is useful for debugging if there's no other way to dump kernel messages that time.

nice idea! We frequently have kernel-death warnings/messages that scroll off too fast and which cannot be captured.

Quoted 13 lines

halt_delay default value is 0, change it by:

echo xxx > /sys/module/printk/parameters/halt_delay

---

kernel/printk.c   |   21 +++++++++++++++++++++
lib/Kconfig.debug |   10 ++++++++++
2 files changed, 31 insertions(+)

kernel/printk.c static inline void boot_delay_msec(void) · line 253

Quoted 4 lines
kernel/printk.c +1 -0
@@ -250,6 +250,26 @@ static inline void boot_delay_msec(void)
 }
 #endif
 
+#ifdef CONFIG_HALT_PRINTK_DELAY

(this #ifdef is ugly - see below.)

Quoted 5 lines
kernel/printk.c +5 -0
+/* msecs delay after each halt/poweroff/restart phase printk */
+static unsigned int halt_delay;
+
+static inline void halt_delay_msec(void)
+{

kernel/printk.c static inline void boot_delay_msec(void)

Quoted 10 lines
kernel/printk.c +7 -0
+	if (halt_delay == 0 || !(system_state == SYSTEM_HALT
+				|| system_state == SYSTEM_POWER_OFF
+				|| system_state == SYSTEM_RESTART))
+		return;
+
+	mdelay(halt_delay);
 
 
 	boot_delay_msec();
+	halt_delay_msec();

i think it should be done in boot_delay_msec() and the function should be renamed to print_delay_msec() or so.

Quoted 7 lines
kernel/printk.c +0 -0
 	preempt_disable();
 	/* This stops the holder of console_sem just where we want him */
lib/Kconfig.debug +0 -0
@@ -647,6 +647,16 @@ config BOOT_PRINTK_DELAY
 	  BOOT_PRINTK_DELAY also may cause DETECT_SOFTLOCKUP to detect
 	  what it believes to be lockup conditions.

lib/Kconfig.debug config BOOT_PRINTK_DELAY · line 658

Quoted 10 lines
lib/Kconfig.debug +9 -0
 
+config HALT_PRINTK_DELAY
+	bool "Delay halt/poweroff/restart printk message by N milliseconds"
+	depends on DEBUG_KERNEL && PRINTK && SYSFS
+	default n
+	help
+	  This build option allows you to read kernel messages in
+	  halt/poweroff/restart phase by inserting a short delay after
+	  each one.  The delay is specified in milliseconds on the
+	  module parameter: /sys/module/printk/halt_delay.

No need for a Kconfig option - this should be an unconditional feature like boot-delay.

This will further simplify the patch and will get rid of that ugly #ifdef.

Ingo

author
#2 lore raw
Quoted 10 lines · Ingo Molnar
Quoted 4 lines · Dave Young

Add a halt_delay module parameter in printk.c used to read the printk messages in halt/poweroff/restart phase, delay each printk messages by halt_delay milliseconds. It is useful for debugging if there's no other way to dump kernel messages that time.

nice idea! We frequently have kernel-death warnings/messages that scroll off too fast and which cannot be captured.

Thanks! It is for this case indeed.

Quoted 34 lines
Quoted 14 lines

halt_delay default value is 0, change it by:

echo xxx > /sys/module/printk/parameters/halt_delay

---
kernel/printk.c   |   21 +++++++++++++++++++++
lib/Kconfig.debug |   10 ++++++++++

2 files changed, 31 insertions(+)

kernel/printk.c 2009-06-02 17:45:54.000000000 +0800 static inline void boot_delay_msec(void) · line 253

Quoted 4 lines
kernel/printk.c 2009-06-02 17:45:54.000000000 +0800 renamed from kernel/printk.c    2009-04-09 16:23:03.000000000 +0800 +1 -0
@@ -250,6 +250,26 @@ static inline void boot_delay_msec(void)
  }
  #endif
 
+#ifdef CONFIG_HALT_PRINTK_DELAY

(this #ifdef is ugly - see below.)

Quoted 13 lines
kernel/printk.c 2009-06-02 17:45:54.000000000 +0800 renamed from kernel/printk.c    2009-04-09 16:23:03.000000000 +0800 +11 -0
+/* msecs delay after each halt/poweroff/restart phase printk */
+static unsigned int halt_delay;
+
+static inline void halt_delay_msec(void)
+{
+     if (halt_delay == 0 || !(system_state == SYSTEM_HALT
+                             || system_state == SYSTEM_POWER_OFF
+                             || system_state == SYSTEM_RESTART))
+             return;
+
+     mdelay(halt_delay);
 
 
Quoted 6 lines

kernel/printk.c 2009-06-02 17:45:54.000000000 +0800 static inline void boot_delay_msec(void) · line 268

Quoted 2 lines
kernel/printk.c 2009-06-02 17:45:54.000000000 +0800 renamed from kernel/printk.c    2009-04-09 16:23:03.000000000 +0800 +1 -0
       boot_delay_msec();
+     halt_delay_msec();

i think it should be done in boot_delay_msec() and the function should be renamed to print_delay_msec() or so.

I have two concerns:

1. boot_delay use a busy looping with lpj preset because it's too early that mdelay is probably not ready yet. Furthermore the delay is not accurate. For halt issue we can just use mdelay()

2. boot_delay is set by kernel boot paramenter, but IMHO, for halt delay use sysfs file is more convenient.

Quoted 22 lines
Quoted 9 lines

      preempt_disable();
      /* This stops the holder of console_sem just where we want him */

lib/Kconfig.debug       2009-06-02 17:50:15.000000000 +0800 renamed from lib/Kconfig.debug  2009-05-12 11:27:22.000000000 +0800 +0 -0
@@ -647,6 +647,16 @@ config BOOT_PRINTK_DELAY

        BOOT_PRINTK_DELAY also may cause DETECT_SOFTLOCKUP to detect what it believes to be lockup conditions.

Quoted 9 lines

+config HALT_PRINTK_DELAY
+     bool "Delay halt/poweroff/restart printk message by N milliseconds"
+     depends on DEBUG_KERNEL && PRINTK && SYSFS
+     default n
+     help
+       This build option allows you to read kernel messages in
+       halt/poweroff/restart phase by inserting a short delay after
+       each one.  The delay is specified in milliseconds on the
+       module parameter: /sys/module/printk/halt_delay.

No need for a Kconfig option - this should be an unconditional feature like boot-delay.

Quoted 2 lines

This will further simplify the patch and will get rid of that ugly #ifdef.

What do you think removing the Kconfig option, then unconditionally
use halt_delay functions?

Quoted 3 lines

       Ingo

Signature · 2 lines
Regards
dave
#3 lore raw
Quoted 86 lines · Dave Young
Quoted 10 lines · Ingo Molnar
Quoted 4 lines · Dave Young

Add a halt_delay module parameter in printk.c used to read the printk messages in halt/poweroff/restart phase, delay each printk messages by halt_delay milliseconds. It is useful for debugging if there's no other way to dump kernel messages that time.

nice idea! We frequently have kernel-death warnings/messages that scroll off too fast and which cannot be captured.

Thanks! It is for this case indeed.

Quoted 34 lines
Quoted 14 lines

halt_delay default value is 0, change it by:

echo xxx > /sys/module/printk/parameters/halt_delay

---
kernel/printk.c   |   21 +++++++++++++++++++++
lib/Kconfig.debug |   10 ++++++++++

2 files changed, 31 insertions(+)

kernel/printk.c 2009-06-02 17:45:54.000000000 +0800 static inline void boot_delay_msec(void) · line 253

Quoted 4 lines
kernel/printk.c 2009-06-02 17:45:54.000000000 +0800 renamed from kernel/printk.c    2009-04-09 16:23:03.000000000 +0800 +1 -0
@@ -250,6 +250,26 @@ static inline void boot_delay_msec(void)
  }
  #endif
 
+#ifdef CONFIG_HALT_PRINTK_DELAY

(this #ifdef is ugly - see below.)

Quoted 13 lines
kernel/printk.c 2009-06-02 17:45:54.000000000 +0800 renamed from kernel/printk.c    2009-04-09 16:23:03.000000000 +0800 +11 -0
+/* msecs delay after each halt/poweroff/restart phase printk */
+static unsigned int halt_delay;
+
+static inline void halt_delay_msec(void)
+{
+     if (halt_delay == 0 || !(system_state == SYSTEM_HALT
+                             || system_state == SYSTEM_POWER_OFF
+                             || system_state == SYSTEM_RESTART))
+             return;
+
+     mdelay(halt_delay);
 
 
Quoted 6 lines

kernel/printk.c 2009-06-02 17:45:54.000000000 +0800 static inline void boot_delay_msec(void) · line 268

Quoted 2 lines
kernel/printk.c 2009-06-02 17:45:54.000000000 +0800 renamed from kernel/printk.c    2009-04-09 16:23:03.000000000 +0800 +1 -0
       boot_delay_msec();
+     halt_delay_msec();

i think it should be done in boot_delay_msec() and the function should be renamed to print_delay_msec() or so.

I have two concerns:

1. boot_delay use a busy looping with lpj preset because it's too early that mdelay is probably not ready yet. Furthermore the delay is not accurate. For halt issue we can just use mdelay()

2. boot_delay is set by kernel boot paramenter, but IMHO, for halt delay use sysfs file is more convenient.

Quoted 22 lines
Quoted 9 lines

      preempt_disable();
      /* This stops the holder of console_sem just where we want him */

lib/Kconfig.debug       2009-06-02 17:50:15.000000000 +0800 renamed from lib/Kconfig.debug  2009-05-12 11:27:22.000000000 +0800 +0 -0
@@ -647,6 +647,16 @@ config BOOT_PRINTK_DELAY

        BOOT_PRINTK_DELAY also may cause DETECT_SOFTLOCKUP to detect what it believes to be lockup conditions.

Quoted 9 lines

+config HALT_PRINTK_DELAY
+     bool "Delay halt/poweroff/restart printk message by N milliseconds"
+     depends on DEBUG_KERNEL && PRINTK && SYSFS
+     default n
+     help
+       This build option allows you to read kernel messages in
+       halt/poweroff/restart phase by inserting a short delay after
+       each one.  The delay is specified in milliseconds on the
+       module parameter: /sys/module/printk/halt_delay.

No need for a Kconfig option - this should be an unconditional feature like boot-delay.

Quoted 5 lines
Quoted 2 lines

This will further simplify the patch and will get rid of that ugly #ifdef.

What do you think removing the Kconfig option, then unconditionally
use halt_delay functions?

that's fine too i think. The delay method assymetry between the two functions indeed calls for them to be separate.

Ingo

#4 lore raw
In reply to Dave Young
Quoted 8 lines · Dave Young

Add a halt_delay module parameter in printk.c used to read the printk messages in halt/poweroff/restart phase, delay each printk messages by halt_delay milliseconds. It is useful for debugging if there's no other way to dump kernel messages that time.

halt_delay default value is 0, change it by:

echo xxx > /sys/module/printk/parameters/halt_delay

Well, stopping oopses from scrolling offscreen was very useful for me in past.

kernel/printk.c static inline void boot_delay_msec(void) · line 264

Quoted 8 lines
kernel/printk.c +8 -0
+static inline void halt_delay_msec(void)
+{
+	if (halt_delay == 0 || !(system_state == SYSTEM_HALT
+				|| system_state == SYSTEM_POWER_OFF
+				|| system_state == SYSTEM_RESTART))
+		return;
+
+	mdelay(halt_delay);

...but this will not trigger for oops, right?
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
author
#5 lore raw
Quoted 13 lines · Pavel Machek
Quoted 8 lines · Dave Young

Add a halt_delay module parameter in printk.c used to read the printk messages in halt/poweroff/restart phase, delay each printk messages by halt_delay milliseconds. It is useful for debugging if there's no other way to dump kernel messages that time.

halt_delay default value is 0, change it by:

echo xxx > /sys/module/printk/parameters/halt_delay

Well, stopping oopses from scrolling offscreen was very useful for me in past.

Quoted 10 lines

kernel/printk.c static inline void boot_delay_msec(void) · line 264

Quoted 8 lines
kernel/printk.c +8 -0
+static inline void halt_delay_msec(void)
+{
+     if (halt_delay == 0 || !(system_state == SYSTEM_HALT
+                             || system_state == SYSTEM_POWER_OFF
+                             || system_state == SYSTEM_RESTART))
+             return;
+
+     mdelay(halt_delay);

...but this will not trigger for oops, right?

Hi, Pavel, this is for halt phase only.

Andrew suggest to make it a general feature, thus we can enable printk delay when we want. I will write a new patch for that.

Quoted 6 lines

                                                               Pavel

--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

Signature · 2 lines
Regards
dave