From nobody Wed Apr 1 11:12:27 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 B0F3E3DFC86; Tue, 31 Mar 2026 13:17:10 +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=1774963030; cv=none; b=qYIE35yYiA8MKdD5MTEb13qEsL9iQ1snFwCnR1bdwIC2cJnzxHNKeL6Cwz4xIpXZb3cEcCaRK5d+Ptw64aMyPIZ2hE51ij/HDk2Ume9U6P/M+AaRdO4+9A42Q1l1ys9gyt4+j90CtWTPCfrWK1KLbGh2RTlNt2t/ezfD08J7LyY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774963030; c=relaxed/simple; bh=bK9FrHwYdtzlfjtR+gYpB517UvY6FDy8GPtD0U1/TCo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A7Q4vYTpqWB7j+TR8IDbeHATItqfUNpINI8/AE0rXoIq97Ew+E8QFOYtzEOcGZdwRaxLo9x4TnEnzTa9NztWnBq4loeM9WQ8y1XxrMNoQerOD5HnALMcAjuCUmMfA46wVmpRBx77g5T+8Fh71GEjpRT4Iio1PZGVQ6FWjjG93CI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QOr8z5aO; 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="QOr8z5aO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7ECAEC19423; Tue, 31 Mar 2026 13:17:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774963030; bh=bK9FrHwYdtzlfjtR+gYpB517UvY6FDy8GPtD0U1/TCo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QOr8z5aObamx4kProSnztxVwdQlHn9xLwz3QWRSh54AQnpHHqbKZLhGNZ8tOlSwht aJGFYaGh7Q8hKi6bouEvSeeWyEytZ8tkdEXdbWJeS17SWm9fmh2LJgL2pGW/wVorf+ YdlB4Zfd9HeHHgTa5TyngS/chK8jPejZkVxL69tKzNc7I0fQRRml/6UTYbWisjBoS1 xNp9oJkag50xrbV02FIhJ324cQz44XqfTCYVw9H+j3NYGcZWEGWNYp/YjAwqdhjjMp 1LF9/OTtA4QLU8bI0+lmlPgD8uU4C7vLjIiylBJx9BlT/+3U2dCvQd0TySn++3HPIo fCmn8xbE6Rdkg== 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 , Shrikanth Hegde , 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 05/14] s390/time: Prepare to stop elapsing in dynticks-idle Date: Tue, 31 Mar 2026 15:16:13 +0200 Message-ID: <20260331131622.30505-6-frederic@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260331131622.30505-1-frederic@kernel.org> References: <20260331131622.30505-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 and accounted. Also idle time accounting is ignored. - 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. Also idle time accounting is resumed. - 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 Co-developed-by: Heiko Carstens Signed-off-by: Heiko Carstens Tested-by: Shrikanth Hegde --- arch/s390/include/asm/idle.h | 2 ++ arch/s390/kernel/idle.c | 5 +++- arch/s390/kernel/vtime.c | 57 ++++++++++++++++++++++++++++++++---- 3 files changed, 57 insertions(+), 7 deletions(-) diff --git a/arch/s390/include/asm/idle.h b/arch/s390/include/asm/idle.h index 32536ee34aa0..e4ad09a22400 100644 --- a/arch/s390/include/asm/idle.h +++ b/arch/s390/include/asm/idle.h @@ -8,10 +8,12 @@ #ifndef _S390_IDLE_H #define _S390_IDLE_H =20 +#include #include #include =20 struct s390_idle_data { + bool idle_dyntick; unsigned long idle_count; unsigned long idle_time; unsigned long clock_idle_enter; diff --git a/arch/s390/kernel/idle.c b/arch/s390/kernel/idle.c index 1f1b06b6b4ef..4685d7c5bc51 100644 --- a/arch/s390/kernel/idle.c +++ b/arch/s390/kernel/idle.c @@ -31,7 +31,10 @@ void account_idle_time_irq(void) /* Account time spent with enabled wait psw loaded as idle time. */ __atomic64_add(idle_time, &idle->idle_time); __atomic64_add_const(1, &idle->idle_count); - account_idle_time(cputime_to_nsecs(idle_time)); + + /* Dyntick idle time accounted by nohz/scheduler */ + if (!idle->idle_dyntick) + account_idle_time(cputime_to_nsecs(idle_time)); } =20 void noinstr arch_cpu_idle(void) diff --git a/arch/s390/kernel/vtime.c b/arch/s390/kernel/vtime.c index bf48744d0912..b1c7700d082c 100644 --- a/arch/s390/kernel/vtime.c +++ b/arch/s390/kernel/vtime.c @@ -17,6 +17,7 @@ #include #include #include +#include #include =20 #include "entry.h" @@ -110,6 +111,16 @@ static void account_system_index_scaled(struct task_st= ruct *p, u64 cputime, account_system_index_time(p, cputime_to_nsecs(cputime), index); } =20 +static inline void vtime_reset_last_update(struct lowcore *lc) +{ + asm volatile( + " stpt %0\n" /* Store current cpu timer value */ + " stckf %1" /* Store current tod clock value */ + : "=3DQ" (lc->last_update_timer), + "=3DQ" (lc->last_update_clock) + : : "cc"); +} + /* * Update process times based on virtual cpu times stored by entry.S * to the lowcore fields user_timer, system_timer & steal_clock. @@ -121,12 +132,9 @@ static int do_account_vtime(struct task_struct *tsk) =20 timer =3D lc->last_update_timer; clock =3D lc->last_update_clock; - asm volatile( - " stpt %0\n" /* Store current cpu timer value */ - " stckf %1" /* Store current tod clock value */ - : "=3DQ" (lc->last_update_timer), - "=3DQ" (lc->last_update_clock) - : : "cc"); + + vtime_reset_last_update(lc); + clock =3D lc->last_update_clock - clock; timer -=3D lc->last_update_timer; =20 @@ -239,6 +247,43 @@ void vtime_account_hardirq(struct task_struct *tsk) get_lowcore()->hardirq_timer +=3D vtime_delta(); } =20 +#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) +{ + vtime_reset_last_update(get_lowcore()); +} + +/** + * 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 flushed and the tick subsystem takes over the idle cputime accountin= g. + */ +void vtime_dyntick_start(void) +{ + __this_cpu_write(s390_idle.idle_dyntick, true); + vtime_flush(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 and idle accounting resumes. + */ +void vtime_dyntick_stop(void) +{ + vtime_reset_last_update(get_lowcore()); + __this_cpu_write(s390_idle.idle_dyntick, false); +} +#endif /* CONFIG_NO_HZ_COMMON */ + /* * Sorted add to a list. List is linear searched until first bigger * element is found. --=20 2.53.0