Re: [PATCH 04/15] powerpc/time: Prepare to stop elapsing in dynticks-idle

Shrikanth Hegde
2026-02-25T17:48:34Z

Hi Christophe.

> I think I'm starting to understand now.
>
> I think the problem is that acct->starttime has an invalid value the
> very first time it is used.
>
> We are probably lacking an initial value in paca->accounting.starttime.
> This should likely be initialised from mftb in head_64.S in
> start_here_common for main CPU and __secondary_start for other CPUs or
> maybe at higher level in C in setup_arch() and start_secondary()
>
> Christophe

How about below? this works too.

---

diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index 18506740f4a4..af129645b7f7 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -928,9 +928,24 @@ static void __init set_decrementer_max(void)
bits, decrementer_max);
}

+#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
+/*
+ * This is done to initialize the starttime correctly. with this
+ * /proc/stat show correct values similar to CONFIG_VIRT_CPU_ACCOUNTING_GEN
+ */
+static void init_cpu_accounting_startime(void)
+{
+ struct cpu_accounting_data *acct = get_accounting(current);
+ acct->starttime = mftb();
+}
+#else
+static void init_cpu_accounting_startime(void) { };
+#endif
+
static void __init init_decrementer_clockevent(void)
{
register_decrementer_clockevent(smp_processor_id());
+ init_cpu_accounting_startime();
}

void secondary_cpu_time_init(void)
@@ -946,6 +961,8 @@ void secondary_cpu_time_init(void)
/* FIME: Should make unrelated change to move snapshot_timebase
* call here ! */
register_decrementer_clockevent(smp_processor_id());
+
+ init_cpu_accounting_startime();
}

/*