public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* slow down printk during boot.
@ 2007-07-05 21:13 Dave Jones
  2007-07-06  0:49 ` Jeff Garzik
  0 siblings, 1 reply; 4+ messages in thread
From: Dave Jones @ 2007-07-05 21:13 UTC (permalink / raw)
  To: Linux Kernel; +Cc: Randy Dunlap

This patch from Randy has proven quite useful from time to time,
and has been in Fedora kernels for a while for that reason.
I fixed up some checkpatch warnings, and rediffed it a bunch
of times, Randy did the heavy lifting.

---

This one delays each printk() during boot by a variable time
(from kernel command line), while system_state == SYSTEM_BOOTING.
Caveat:  it's not terribly SMP safe or SMP nice.
Any ideas for improvements (esp. in the SMP area) are appreciated.

---

From: Randy Dunlap <rdunlap@xenotime.net>

Optionally add a boot delay after each kernel printk() call,
crudely measured in milliseconds, with a maximum delay of
10 seconds per printk.

Enable CONFIG_BOOT_DELAY=y and then add (e.g.):
"lpj=loops_per_jiffy boot_delay=100"
to the kernel command line.

Signed-off-by: Randy Dunlap <rdunlap@xenotime.net>
Signed-off-by: Dave Jones <davej@redhat.com>

---

 init/calibrate.c  |    2 +-
 init/main.c       |   25 +++++++++++++++++++++++++
 kernel/printk.c   |   33 +++++++++++++++++++++++++++++++++
 lib/Kconfig.debug |   18 ++++++++++++++++++
 4 files changed, 77 insertions(+), 1 deletion(-)

--- linux-2.6.19.noarch/init/main.c~	2006-12-12 09:32:35.000000000 -0500
+++ linux-2.6.19.noarch/init/main.c	2006-12-12 09:33:32.000000000 -0500
@@ -685,6 +685,31 @@ static void __init do_initcalls(void)
 	flush_scheduled_work();
 }
 
+#ifdef CONFIG_BOOT_DELAY
+
+unsigned int boot_delay = 0; /* msecs delay after each printk during bootup */
+extern long preset_lpj;
+unsigned long long printk_delay_msec = 0; /* per msec, based on boot_delay */
+
+static int __init boot_delay_setup(char *str)
+{
+	unsigned long lpj = preset_lpj ? preset_lpj : 1000000; /* some guess */
+	unsigned long long loops_per_msec = lpj / 1000 * CONFIG_HZ;
+
+	get_option(&str, &boot_delay);
+	if (boot_delay > 10 * 1000)
+		boot_delay = 0;
+
+	printk_delay_msec = loops_per_msec;
+	printk(KERN_DEBUG "boot_delay: %u, preset_lpj: %ld, lpj: %lu, "
+		"CONFIG_HZ: %d, printk_delay_msec: %llu\n",
+		boot_delay, preset_lpj, lpj, CONFIG_HZ, printk_delay_msec);
+	return 1;
+}
+__setup("boot_delay=", boot_delay_setup);
+
+#endif
+
 /*
  * Ok, the machine is now initialized. None of the devices
  * have been touched yet, but the CPU subsystem is up and
--- linux-2615-work.orig/init/calibrate.c
+++ linux-2615-work/init/calibrate.c
@@ -10,7 +10,7 @@
 
 #include <asm/timex.h>
 
-static unsigned long preset_lpj;
+unsigned long preset_lpj;
 static int __init lpj_setup(char *str)
 {
 	preset_lpj = simple_strtoul(str,NULL,0);
--- linux-2.6.21.noarch/kernel/printk.c~	2007-05-27 23:01:29.000000000 -0400
+++ linux-2.6.21.noarch/kernel/printk.c	2007-05-27 23:01:37.000000000 -0400
@@ -22,6 +22,8 @@
 #include <linux/tty_driver.h>
 #include <linux/console.h>
 #include <linux/init.h>
+#include <linux/jiffies.h>
+#include <linux/nmi.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/interrupt.h>			/* For in_interrupt() */
@@ -201,6 +202,34 @@ out:
 
 __setup("log_buf_len=", log_buf_len_setup);
 
+#ifdef CONFIG_BOOT_DELAY
+
+extern unsigned int boot_delay; /* msecs to delay after each printk during bootup */
+extern long preset_lpj;
+extern unsigned long long printk_delay_msec;
+
+static void boot_delay_msec(int millisecs)
+{
+	unsigned long long k = printk_delay_msec * millisecs;
+	unsigned long timeout;
+
+	timeout = jiffies + msecs_to_jiffies(millisecs);
+	while (k) {
+		k--;
+		cpu_relax();
+		/*
+		 * use (volatile) jiffies to prevent
+		 * compiler reduction; loop termination via jiffies
+		 * is secondary and may or may not happen.
+		 */
+		if (time_after(jiffies, timeout))
+			break;
+		touch_nmi_watchdog();
+	}
+}
+
+#endif
+
 /*
  * Commands to do_syslog:
  *
@@ -520,6 +548,11 @@ asmlinkage int printk(const char *fmt, .
 	r = vprintk(fmt, args);
 	va_end(args);
 
+#ifdef CONFIG_BOOT_DELAY
+	if (boot_delay && system_state == SYSTEM_BOOTING)
+		boot_delay_msec(boot_delay);
+#endif
+
 	return r;
 }
 
--- linux-2.6.21.noarch/lib/Kconfig.debug~	2007-05-27 23:02:18.000000000 -0400
+++ linux-2.6.21.noarch/lib/Kconfig.debug	2007-05-27 23:03:14.000000000 -0400
@@ -394,6 +394,24 @@ config FORCED_INLINING
 	  become the default in the future, until then this option is there to
 	  test gcc for this.
 
+config BOOT_DELAY
+	bool "Delay each boot message by N milliseconds"
+	depends on DEBUG_KERNEL
+	help
+	  This build option allows you to read kernel boot messages
+	  by inserting a short delay after each one.  The delay is
+	  specified in milliseconds on the kernel command line,
+	  using "boot_delay=N".
+
+	  It is likely that you would also need to use "lpj=M" to preset
+	  the "loops per jiffie" value.
+	  See a previous boot log for the "lpj" value to use for your
+	  system, and then set "lpj=M" before setting "boot_delay=N".
+	  NOTE:  Using this option may adversely affect SMP systems.
+	  I.e., processors other than the first one may not boot up.
+	  BOOT_DELAY also may cause DETECT_SOFTLOCKUP to detect
+	  what it believes to be lockup conditions.
+
 config RCU_TORTURE_TEST
 	tristate "torture tests for RCU"
 	depends on DEBUG_KERNEL

-- 
http://www.codemonkey.org.uk

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

* Re: slow down printk during boot.
  2007-07-05 21:13 slow down printk during boot Dave Jones
@ 2007-07-06  0:49 ` Jeff Garzik
  0 siblings, 0 replies; 4+ messages in thread
From: Jeff Garzik @ 2007-07-06  0:49 UTC (permalink / raw)
  To: Dave Jones, Linux Kernel, Randy Dunlap

Dave Jones wrote:
> This patch from Randy has proven quite useful from time to time,
> and has been in Fedora kernels for a while for that reason.
> I fixed up some checkpatch warnings, and rediffed it a bunch
> of times, Randy did the heavy lifting.
> 
> ---
> 
> This one delays each printk() during boot by a variable time
> (from kernel command line), while system_state == SYSTEM_BOOTING.
> Caveat:  it's not terribly SMP safe or SMP nice.
> Any ideas for improvements (esp. in the SMP area) are appreciated.
> 
> ---
> 
> From: Randy Dunlap <rdunlap@xenotime.net>
> 
> Optionally add a boot delay after each kernel printk() call,
> crudely measured in milliseconds, with a maximum delay of
> 10 seconds per printk.
> 
> Enable CONFIG_BOOT_DELAY=y and then add (e.g.):
> "lpj=loops_per_jiffy boot_delay=100"
> to the kernel command line.
> 
> Signed-off-by: Randy Dunlap <rdunlap@xenotime.net>
> Signed-off-by: Dave Jones <davej@redhat.com>
> 
> ---
> 
>  init/calibrate.c  |    2 +-
>  init/main.c       |   25 +++++++++++++++++++++++++
>  kernel/printk.c   |   33 +++++++++++++++++++++++++++++++++
>  lib/Kconfig.debug |   18 ++++++++++++++++++
>  4 files changed, 77 insertions(+), 1 deletion(-)

hey, that's pretty neat.

I've occasionally hand-hacked something similar, to achieve those effects.

	Jeff




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

* Re: slow down printk during boot.
       [not found] <8DGUc-ER-37@gated-at.bofh.it>
@ 2007-07-06  1:50 ` Bodo Eggert
  2007-07-06  1:55   ` Dave Jones
  0 siblings, 1 reply; 4+ messages in thread
From: Bodo Eggert @ 2007-07-06  1:50 UTC (permalink / raw)
  To: Dave Jones, Linux Kernel, Randy Dunlap

Dave Jones <davej@redhat.com> wrote:

> This patch from Randy has proven quite useful from time to time,
> and has been in Fedora kernels for a while for that reason.
> I fixed up some checkpatch warnings, and rediffed it a bunch
> of times, Randy did the heavy lifting.
> 
> ---
> 
> This one delays each printk() during boot by a variable time
> (from kernel command line), while system_state == SYSTEM_BOOTING.
> Caveat:  it's not terribly SMP safe or SMP nice.
> Any ideas for improvements (esp. in the SMP area) are appreciated.

I just created a different patch, which replaces the panic with one that
does allow scrolling and reading the messages. Maybe that would be the
better approach ...

The patch was sent in:
Subject: [RFC][PATCH] introduce panic_gently
Message-ID: Pine.LNX.4.58.0707060034330.18989@be1.lrz
news:8DICF-3CV-47@gated-at.bofh.it
-- 
Justify my text? I'm sorry but it has no excuse. 

Friß, Spammer: ij@drZsf.7eggert.dyndns.org 6.h@lFus97h.7eggert.dyndns.org
 9yTtaaH5@sLxhc.7eggert.dyndns.org dy3pwcw@rfhqOp7i.7eggert.dyndns.org

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

* Re: slow down printk during boot.
  2007-07-06  1:50 ` Bodo Eggert
@ 2007-07-06  1:55   ` Dave Jones
  0 siblings, 0 replies; 4+ messages in thread
From: Dave Jones @ 2007-07-06  1:55 UTC (permalink / raw)
  To: Bodo Eggert; +Cc: Linux Kernel, Randy Dunlap

On Fri, Jul 06, 2007 at 03:50:11AM +0200, Bodo Eggert wrote:
 > Dave Jones <davej@redhat.com> wrote:
 > 
 > > This patch from Randy has proven quite useful from time to time,
 > > and has been in Fedora kernels for a while for that reason.
 > > I fixed up some checkpatch warnings, and rediffed it a bunch
 > > of times, Randy did the heavy lifting.
 > > 
 > > ---
 > > 
 > > This one delays each printk() during boot by a variable time
 > > (from kernel command line), while system_state == SYSTEM_BOOTING.
 > > Caveat:  it's not terribly SMP safe or SMP nice.
 > > Any ideas for improvements (esp. in the SMP area) are appreciated.
 > 
 > I just created a different patch, which replaces the panic with one that
 > does allow scrolling and reading the messages. Maybe that would be the
 > better approach ...

I've used the 'slow down the printk' patch in situations where we
haven't panic'd, but silently rebooted instantly or hung with
a black screen.

	Dave

-- 
http://www.codemonkey.org.uk

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

end of thread, other threads:[~2007-07-06  1:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-05 21:13 slow down printk during boot Dave Jones
2007-07-06  0:49 ` Jeff Garzik
     [not found] <8DGUc-ER-37@gated-at.bofh.it>
2007-07-06  1:50 ` Bodo Eggert
2007-07-06  1:55   ` Dave Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox