From nobody Sun Feb 8 18:27:53 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 09E0323D2B2; Fri, 16 Jan 2026 14:52:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768575170; cv=none; b=iyonIydXSJdi0/dwst94OINOnpiFuyZbL08SkC8/Ok+y3eXeic9dNyYWY8C3LUlU/LRSEk9h7xAYElPYnJYueUyvrGPO0J/1NrE+xdB4hME7tyxiL5M94J8H5LIGWoT8JhPHGCRVrPP4NhRYP3TuI1B1MXbvx0Zhw2OGdf+etKA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768575170; c=relaxed/simple; bh=vTAmht3VvCxwglnCR59QaOOlh1TAQz905bg6fnPgSy8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Au8HTO7EqnibuZrS30Ch3EBvh+0GnrSW2bLlvnRj0VYbPHt8Cz/7+1PlvweRd0A+C7afe9GwVSiwUV/uAzxLbLV7xCYs+FngrZGHftvPw9WfsCsDEepyBU4jSNuORLWDIq5oR/I7MroFt6Jy+/LJktTNWSfTDnurb53uRSHGDPo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UEoSi17t; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UEoSi17t" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A0DE8C16AAE; Fri, 16 Jan 2026 14:52:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768575169; bh=vTAmht3VvCxwglnCR59QaOOlh1TAQz905bg6fnPgSy8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UEoSi17t6WTlsc/9elJnbU5m2di5zQiFmaaEPydlxspyxVW8BJOvt2Px/1Q6krNYH 4p1ylHoqFM3zx3CX7/IHivpHfYGcmYHwb+auopjehxccS5rNt652IzTP2EJSdg2lJ1 xB568wT6GQPtqB716s6yLv8x+3ARbS6XrjSSYRzTUPQAN7+QvN2sQlW278sAbR3EqS BwDebrYlVQYnko+lQJGextI/w9bjBkkC5ED6q17ErxBNQWZn0hXmTr8im+4Q1PpOkM +HVFdPOXhG3ONyMe5zE3VuNlN36AK/qBTkGFXubevPai7RrYy3pms3o+EjKvAKuq93 +9q1kn/BXq43A== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , "Christophe Leroy (CS GROUP)" , "Rafael J. Wysocki" , Alexander Gordeev , Anna-Maria Behnsen , Ben Segall , Boqun Feng , Christian Borntraeger , Dietmar Eggemann , Heiko Carstens , Ingo Molnar , Jan Kiszka , Joel Fernandes , Juri Lelli , Kieran Bingham , Madhavan Srinivasan , Mel Gorman , Michael Ellerman , Neeraj Upadhyay , Nicholas Piggin , "Paul E . McKenney" , Peter Zijlstra , Steven Rostedt , Sven Schnelle , Thomas Gleixner , Uladzislau Rezki , Valentin Schneider , Vasily Gorbik , Vincent Guittot , Viresh Kumar , Xin Zhao , linux-pm@vger.kernel.org, linux-s390@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH 04/15] powerpc/time: Prepare to stop elapsing in dynticks-idle Date: Fri, 16 Jan 2026 15:51:57 +0100 Message-ID: <20260116145208.87445-5-frederic@kernel.org> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20260116145208.87445-1-frederic@kernel.org> References: <20260116145208.87445-1-frederic@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently the tick subsystem stores the idle cputime accounting in private fields, allowing cohabitation with architecture idle vtime accounting. The former is fetched on online CPUs, the latter on offline CPUs. For consolidation purpose, architecture vtime accounting will continue to account the cputime but will make a break when the idle tick is stopped. The dyntick cputime accounting will then be relayed by the tick subsystem so that the idle cputime is still seen advancing coherently even when the tick isn't there to flush the idle vtime. Prepare for that and introduce three new APIs which will be used in subsequent patches: _ vtime_dynticks_start() is deemed to be called when idle enters in dyntick mode. The idle cputime that elapsed so far is accumulated. - vtime_dynticks_stop() is deemed to be called when idle exits from dyntick mode. The vtime entry clocks are fast-forward to current time so that idle accounting restarts elapsing from now. - vtime_reset() is deemed to be called from dynticks idle IRQ entry to fast-forward the clock to current time so that the IRQ time is still accounted by vtime while nohz cputime is paused. Also accumulated vtime won't be flushed from dyntick-idle ticks to avoid accounting twice the idle cputime, along with nohz accounting. Signed-off-by: Frederic Weisbecker --- arch/powerpc/kernel/time.c | 41 ++++++++++++++++++++++++++++++++++++++ include/linux/vtime.h | 6 ++++++ 2 files changed, 47 insertions(+) diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c index 4bbeb8644d3d..9b3167274653 100644 --- a/arch/powerpc/kernel/time.c +++ b/arch/powerpc/kernel/time.c @@ -376,6 +376,47 @@ void vtime_task_switch(struct task_struct *prev) acct->starttime =3D acct0->starttime; } } + +#ifdef CONFIG_NO_HZ_COMMON +/** + * vtime_reset - Fast forward vtime entry clocks + * + * Called from dynticks idle IRQ entry to fast-forward the clocks to curre= nt time + * so that the IRQ time is still accounted by vtime while nohz cputime is = paused. + */ +void vtime_reset(void) +{ + struct cpu_accounting_data *acct =3D get_accounting(current); + + acct->starttime =3D mftb(); +#ifdef CONFIG_ARCH_HAS_SCALED_CPUTIME + acct->startspurr =3D read_spurr(now); +#endif +} + +/** + * vtime_dyntick_start - Inform vtime about entry to idle-dynticks + * + * Called when idle enters in dyntick mode. The idle cputime that elapsed = so far + * is accumulated and the tick subsystem takes over the idle cputime accou= nting. + */ +void vtime_dyntick_start(void) +{ + vtime_account_idle(current); +} + +/** + * vtime_dyntick_stop - Inform vtime about exit from idle-dynticks + * + * Called when idle exits from dyntick mode. The vtime entry clocks are + * fast-forward to current time so that idle accounting restarts elapsing = from + * now. + */ +void vtime_dyntick_stop(void) +{ + vtime_reset(); +} +#endif /* CONFIG_NO_HZ_COMMON */ #endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */ =20 void __no_kcsan __delay(unsigned long loops) diff --git a/include/linux/vtime.h b/include/linux/vtime.h index 737930f66c3e..10cdb08f960b 100644 --- a/include/linux/vtime.h +++ b/include/linux/vtime.h @@ -37,11 +37,17 @@ extern void vtime_account_irq(struct task_struct *tsk, = unsigned int offset); extern void vtime_account_softirq(struct task_struct *tsk); extern void vtime_account_hardirq(struct task_struct *tsk); extern void vtime_flush(struct task_struct *tsk); +extern void vtime_reset(void); +extern void vtime_dyntick_start(void); +extern void vtime_dyntick_stop(void); #else /* !CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */ static inline void vtime_account_irq(struct task_struct *tsk, unsigned int= offset) { } static inline void vtime_account_softirq(struct task_struct *tsk) { } static inline void vtime_account_hardirq(struct task_struct *tsk) { } static inline void vtime_flush(struct task_struct *tsk) { } +static inline void vtime_reset(void) { } +static inline void vtime_dyntick_start(void) { } +extern inline void vtime_dyntick_stop(void) { } #endif =20 /* --=20 2.51.1