Tims Fastboot Tools

From eLinux.org
Revision as of 10:37, 31 October 2008 by Tim Bird (talk | contribs) (add safe_to_call_sched_clock.patch and grabserial sections)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This page has materials to support Tim Bird's presentation "Tools and Techniques for Reducing Bootup Time". This presentation was first delivered at the Embedded Linux Conference, Europe, in November of 2008.


This patch was used by Tim for several kernel versions, to address problems with the printk-times feature on ARM platforms. It is very simple, and consists of just adding a flag to avoid calling sched_clock() too early.

This patch appears (as of kernel version 2.6.27) to be obsolete. The 2.6.27 kernel now calls cpu_clock() for printk_times. This uses a similar mechanism to flag when it is safe to call.

Here's the patch:

On most platforms, printk_clock() calls sched_clock(), which provides good
timestamp resolution.  However, most ARM boards use a timer source for
sched_clock() which must be initialized at boot.  If sched_clock() is called
too early, the machine hangs. This code utilizes the default jiffies-based
value for printk_clock, until told that sched_clock() is safe.  This is
almost always 0 before the clock is initialized, so this patch causes
no loss of timing data, or confusing time switchover mid-boot.

OMAP support is included.  

To utilize this on other ARM platforms, just add "safe_to_call_sched_clock=1"
in the timer initialization code for your platform, when it is safe to call

Signed-off-by: Tim Bird <tim.bird@am.sony.com>

    Location: alp@oak--linux-3/alp-linux--dev-3--3.1
    First changlog version.
 arch/arm/kernel/time.c      |    8 	7 +	1 -	0 !
 arch/arm/mach-omap1/time.c  |    3 	3 +	0 -	0 !
 include/asm-arm/mach/time.h |    2 	2 +	0 -	0 !
 3 files changed, 12 insertions(+), 1 deletion(-)

Index: alp-linux/arch/arm/kernel/time.c
--- alp-linux.orig/arch/arm/kernel/time.c
+++ alp-linux/arch/arm/kernel/time.c
@@ -84,10 +84,16 @@ static unsigned long dummy_gettimeoffset
  * sched_clock().  This avoids non-bootable kernels when
  * printk_clock is enabled.
+int safe_to_call_sched_clock = 0;
 unsigned long long printk_clock(void)
-	return (unsigned long long)(jiffies - INITIAL_JIFFIES) *
+	if (likely(safe_to_call_sched_clock)) {
+		return sched_clock();
+	} else {
+		return (unsigned long long)(jiffies - INITIAL_JIFFIES) *
 			(1000000000 / HZ);
+	}
 static unsigned long next_rtc_update;
Index: alp-linux/arch/arm/mach-omap1/time.c
--- alp-linux.orig/arch/arm/mach-omap1/time.c
+++ alp-linux/arch/arm/mach-omap1/time.c
@@ -255,6 +255,9 @@ static void __init omap_init_clocksource
 	setup_irq(INT_TIMER2, &omap_mpu_timer2_irq);
 	omap_mpu_timer_start(1, ~0, 1);
+	/* allow calls to sched_clock now */
+	safe_to_call_sched_clock = 1;
 	if (clocksource_register(&clocksource_mpu))
 		printk(err, clocksource_mpu.name);
Index: alp-linux/include/asm-arm/mach/time.h
--- alp-linux.orig/include/asm-arm/mach/time.h
+++ alp-linux/include/asm-arm/mach/time.h
@@ -76,4 +76,6 @@ extern int (*set_rtc)(void);
 extern void save_time_delta(struct timespec *delta, struct timespec *rtc);
 extern void restore_time_delta(struct timespec *delta, struct timespec *rtc);
+extern int safe_to_call_sched_clock;


"grabserial" is a simple program to grab and display data from a specified serial port. It can place a timestamp on each line received, which makes it useful for reporting timing of events seen on a booting system's serial console output.

To download it, and for more detailed information and sample output, see: Grabserial