[PATCH 01/14] powerpc/time: Expose boot_tb via accessor

Athira Rajeev atrajeev at linux.ibm.com
Fri Aug 15 18:33:54 AEST 2025


From: Aboorva Devarajan <aboorvad at linux.ibm.com>

- Define accessor function get_boot_tb() to safely return boot_tb.
- Tag boot_tb as __ro_after_init (only initialized once and never updated).
- Add a debug log to output the boot timebase during initialization.

Signed-off-by: Aboorva Devarajan <aboorvad at linux.ibm.com>
---
 arch/powerpc/include/asm/time.h | 2 ++
 arch/powerpc/kernel/time.c      | 7 ++++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/include/asm/time.h b/arch/powerpc/include/asm/time.h
index f8885586efaf..31bb6be4d355 100644
--- a/arch/powerpc/include/asm/time.h
+++ b/arch/powerpc/include/asm/time.h
@@ -29,6 +29,8 @@ extern u64 decrementer_max;
 
 extern void generic_calibrate_decr(void);
 
+extern u64 get_boot_tb(void);
+
 /* Some sane defaults: 125 MHz timebase, 1GHz processor */
 extern unsigned long ppc_proc_freq;
 #define DEFAULT_PROC_FREQ	(DEFAULT_TB_FREQ * 8)
diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index 8224381c1dba..f5106b90e517 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -137,7 +137,7 @@ EXPORT_SYMBOL_GPL(rtc_lock);
 
 static u64 tb_to_ns_scale __read_mostly;
 static unsigned tb_to_ns_shift __read_mostly;
-static u64 boot_tb __read_mostly;
+static u64 boot_tb __ro_after_init;
 
 extern struct timezone sys_tz;
 static long timezone_offset;
@@ -639,6 +639,10 @@ notrace unsigned long long sched_clock(void)
 	return mulhdu(get_tb() - boot_tb, tb_to_ns_scale) << tb_to_ns_shift;
 }
 
+u64 get_boot_tb(void)
+{
+	return boot_tb;
+}
 
 #ifdef CONFIG_PPC_PSERIES
 
@@ -975,6 +979,7 @@ void __init time_init(void)
 	tb_to_ns_shift = shift;
 	/* Save the current timebase to pretty up CONFIG_PRINTK_TIME */
 	boot_tb = get_tb();
+	pr_debug("%s: timebase at boot: %llu\n", __func__, (unsigned long long)boot_tb);
 
 	/* If platform provided a timezone (pmac), we correct the time */
 	if (timezone_offset) {
-- 
2.47.1



More information about the Linuxppc-dev mailing list