[U-Boot] [PATCH 1/4] Add microsecond boot time measurement

Simon Glass sjg at chromium.org
Fri May 13 22:52:00 CEST 2011


This defines the basics of a new boot time measurement feature. This allows
logging of very accurate time measurements as the boot proceeds, by using
an available microsecond counter.

Signed-off-by: Simon Glass <sjg at chromium.org>
---
 README              |   11 ++++++++
 common/Makefile     |    1 +
 common/bootstage.c  |   49 +++++++++++++++++++++++++++++++++++
 include/bootstage.h |   71 +++++++++++++++++++++++++++++++++++++++++++++++++++
 include/common.h    |    8 ++++++
 5 files changed, 140 insertions(+), 0 deletions(-)
 create mode 100644 common/bootstage.c
 create mode 100644 include/bootstage.h

diff --git a/README b/README
index 6f3748d..f9e4e65 100644
--- a/README
+++ b/README
@@ -2026,6 +2026,17 @@ The following options need to be configured:
 		example, some LED's) on your board. At the moment,
 		the following checkpoints are implemented:
 
+- Time boot progress
+		CONFIG_BOOTSTAGE
+
+		Define this option to enable microsecond boot stage timing
+		on supported platforms. For this to work your platform
+		needs to define a function timer_get_us() which returns the
+		number of microseconds since reset. This would normally
+		be done in your SOC or board timer.c file.
+
+		You can add calls to bootstage_mark() to set time markers.
+
 - Standalone program support:
 		CONFIG_STANDALONE_LOAD_ADDR
 
diff --git a/common/Makefile b/common/Makefile
index f81cff9..2c3bc9d 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -174,6 +174,7 @@ COBJS-$(CONFIG_LYNXKDI) += lynxkdi.o
 COBJS-$(CONFIG_MODEM_SUPPORT) += modem.o
 COBJS-$(CONFIG_UPDATE_TFTP) += update.o
 COBJS-$(CONFIG_USB_KEYBOARD) += usb_kbd.o
+COBJS-$(CONFIG_BOOTSTAGE) += bootstage.o
 
 
 COBJS	:= $(sort $(COBJS-y))
diff --git a/common/bootstage.c b/common/bootstage.c
new file mode 100644
index 0000000..10f1f34
--- /dev/null
+++ b/common/bootstage.c
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2011 The Chromium OS Authors.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * 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, Boston,
+ * MA 02111-1307 USA
+ */
+
+
+/*
+ * This module records the progress of boot and arbitrary commands, and
+ * permits accurate timestamping of each.
+ */
+
+#include <common.h>
+
+
+struct bootstage_record {
+	uint32_t time_us;
+	const char *name;
+};
+
+static struct bootstage_record record[BOOTSTAGE_COUNT];
+
+uint32_t bootstage_mark(enum bootstage_id id, const char *name)
+{
+	struct bootstage_record *rec = &record[id];
+
+	/* Only record the first event for each */
+	if (!rec->name) {
+		rec->time_us = (uint32_t)timer_get_us();
+		rec->name = name;
+	}
+	return rec->time_us;
+}
diff --git a/include/bootstage.h b/include/bootstage.h
new file mode 100644
index 0000000..ba656ff
--- /dev/null
+++ b/include/bootstage.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2011 The Chromium OS Authors.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * 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, Boston,
+ * MA 02111-1307 USA
+ */
+
+#ifndef __BOOTSTAGE_H
+#define __BOOTSTAGE_H
+
+/*
+ * These are the things that can be timestamped. There are some pre-defined
+ * by U-Boot, and some which are user defined.
+ */
+enum bootstage_id {
+	BOOTSTAGE_AWAKE,
+	BOOTSTAGE_START_UBOOT,
+	BOOTSTAGE_USB_START,
+	BOOTSTAGE_ETH_START,
+	BOOTSTAGE_BOOTP_START,
+	BOOTSTAGE_BOOTP_STOP,
+	BOOTSTAGE_KERNELREAD_START,
+	BOOTSTAGE_KERNELREAD_STOP,
+	BOOTSTAGE_BOOTM_START,
+	BOOTSTAGE_BOOTM_HANDOFF,
+
+	/* a few spare for the user, from here */
+	BOOTSTAGE_USER,
+
+	/*
+	 * Total number of entries - increase this at the cost of some BSS
+	 * and ATAG space.
+	 */
+	BOOTSTAGE_COUNT = 10
+};
+
+#ifdef CONFIG_BOOTSTAGE
+
+/**
+ * Mark a time stamp for the current boot stage.
+ *
+ * @param id	ID from enum bootstage_id
+ * @param name	name for this stage
+ * @returns timestamp in microseconds
+ */
+uint32_t bootstage_mark(enum bootstage_id id, const char *name);
+
+#else
+
+static inline uint32_t bootstage_mark(enum bootstage_id id, const char *name)
+{}
+
+#endif
+
+#endif
+
diff --git a/include/common.h b/include/common.h
index 1e4a6a5..04b0102 100644
--- a/include/common.h
+++ b/include/common.h
@@ -177,6 +177,14 @@ typedef void (interrupt_handler_t)(void *);
 #endif /* CONFIG_SERIAL_MULTI */
 
 /*
+ * Return the time since boot in microseconds, This is needed for bootstage
+ * and should be defined in CPU- or board-specific code.
+ */
+unsigned long timer_get_us(void);
+
+#include <bootstage.h>
+
+/*
  * General Purpose Utilities
  */
 #define min(X, Y)				\
-- 
1.7.3.1



More information about the U-Boot mailing list