[U-Boot] [PATCH 2/4] Add bootstage progress report

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


You can call bootstage_report() at any time to print a report on boot stage
timings. It should ideally be called just before U-Boot hands off execution
to the next stage boot.

Signed-off-by: Simon Glass <sjg at chromium.org>
---
 common/bootstage.c  |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/bootstage.h |    3 +++
 2 files changed, 51 insertions(+), 0 deletions(-)

diff --git a/common/bootstage.c b/common/bootstage.c
index 10f1f34..5e0178a 100644
--- a/common/bootstage.c
+++ b/common/bootstage.c
@@ -47,3 +47,51 @@ uint32_t bootstage_mark(enum bootstage_id id, const char *name)
 	}
 	return rec->time_us;
 }
+
+static void print_time(unsigned long us_time)
+{
+	char str[12], *s;
+	int grab = 3;
+
+	/* We don't seem to have %'d in U-Boot */
+	sprintf(str, "%9ld", us_time);
+	for (s = str; *s; s += grab) {
+		if (s != str)
+			putc(s[-1] != ' ' ? ',' : ' ');
+		printf("%.*s", grab, s);
+		grab = 3;
+	}
+}
+
+static uint32_t print_time_record(enum bootstage_id id,
+			struct bootstage_record *rec, uint32_t prev)
+{
+	print_time(rec->time_us);
+	print_time(rec->time_us - prev);
+	if (rec->name)
+		printf("  %s\n", rec->name);
+	else
+		printf("  id=%d\n", id);
+	return rec->time_us;
+}
+
+void bootstage_report(void)
+{
+	int id;
+	uint32_t prev;
+
+	puts("Timer summary in microseconds:\n");
+	printf("%11s%11s  %s\n", "Mark", "Elapsed", "Stage");
+
+	/* Fake the first record - we could get it from early boot */
+	prev = 0;
+	record[BOOTSTAGE_AWAKE].name = "awake";
+
+	for (id = 0; id < BOOTSTAGE_COUNT; id++) {
+		struct bootstage_record *rec = &record[id];
+
+		if (id == BOOTSTAGE_AWAKE || rec->time_us != 0)
+			prev = print_time_record(id, rec, prev);
+	}
+}
+
diff --git a/include/bootstage.h b/include/bootstage.h
index ba656ff..b645434 100644
--- a/include/bootstage.h
+++ b/include/bootstage.h
@@ -60,6 +60,9 @@ enum bootstage_id {
  */
 uint32_t bootstage_mark(enum bootstage_id id, const char *name);
 
+/* Print a report about boot time */
+void bootstage_report(void);
+
 #else
 
 static inline uint32_t bootstage_mark(enum bootstage_id id, const char *name)
-- 
1.7.3.1



More information about the U-Boot mailing list