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

From: Christophe Leroy (CS GROUP)

Date: Wed Feb 25 2026 - 13:01:26 EST




Le 25/02/2026 à 18:47, Shrikanth Hegde a écrit :
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.

Fine it is works, it means we found the real problem.

What about using the newly added vtime_reset() ? See below (untested)

diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index 9b3167274653..f4aef85106ac 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -377,7 +377,6 @@ void vtime_task_switch(struct task_struct *prev)
}
}

-#ifdef CONFIG_NO_HZ_COMMON
/**
* vtime_reset - Fast forward vtime entry clocks
*
@@ -394,6 +393,7 @@ void vtime_reset(void)
#endif
}

+#ifdef CONFIG_NO_HZ_COMMON
/**
* vtime_dyntick_start - Inform vtime about entry to idle-dynticks
*
@@ -931,6 +931,7 @@ static void __init set_decrementer_max(void)
static void __init init_decrementer_clockevent(void)
{
register_decrementer_clockevent(smp_processor_id());
+ vtime_reset();
}

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

/*



---

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();
 }

 /*