[lkml]   [2022]   [Apr]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[PATCH v9 06/21] openrisc: start CPU timer early in boot
In order to measure the boot process, the timer should be switched on as
early in boot as possible. This is necessary so that by the time the
setup code reaches random_init(), get_cycles() (by way of
random_get_entropy()) returns non-zero, indicating that it is actually
capable of counting. So this commit enables the timer immediately upon
booting up. As well, the commit define the get_cycles macro, like the
previous patches in this series, so that generic code is aware that it's
implemented by the platform, as is done on other archs.

Cc: Thomas Gleixner <>
Cc: Arnd Bergmann <>
Cc: Jonas Bonn <>
Cc: Stefan Kristiansson <>
Acked-by: Stafford Horne <>
Reported-by: Guenter Roeck <>
Signed-off-by: Jason A. Donenfeld <>
Changes v8->v9:
- Use Stafford's suggested assembly in head.S instead of doing this
later on in C, so that the cycle counter starts very early and thus
"measures" boot.

arch/openrisc/include/asm/timex.h | 1 +
arch/openrisc/kernel/head.S | 9 +++++++++
2 files changed, 10 insertions(+)

diff --git a/arch/openrisc/include/asm/timex.h b/arch/openrisc/include/asm/timex.h
index d52b4e536e3f..5487fa93dd9b 100644
--- a/arch/openrisc/include/asm/timex.h
+++ b/arch/openrisc/include/asm/timex.h
@@ -23,6 +23,7 @@ static inline cycles_t get_cycles(void)
return mfspr(SPR_TTCR);
+#define get_cycles get_cycles

/* This isn't really used any more */
#define CLOCK_TICK_RATE 1000
diff --git a/arch/openrisc/kernel/head.S b/arch/openrisc/kernel/head.S
index 15f1b38dfe03..871f4c858859 100644
--- a/arch/openrisc/kernel/head.S
+++ b/arch/openrisc/kernel/head.S
@@ -521,6 +521,15 @@ _start:
l.ori r3,r0,0x1
l.mtspr r0,r3,SPR_SR

+ /*
+ * Start the TTCR as early as possible, so that the RNG can make use of
+ * measurements of boot time from the earliest opportunity. Especially
+ * important is that the TTCR does not return zero by the time we reach
+ * rand_initialize().
+ */
+ l.movhi r3,hi(SPR_TTMR_CR)
+ l.mtspr r0,r3,SPR_TTMR
 \ /
  Last update: 2022-05-01 00:43    [W:0.033 / U:0.020 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site