From nobody Sat Feb 7 21:14:45 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 2B0AB3EFD1F; Fri, 6 Feb 2026 14:24:24 +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=1770387865; cv=none; b=DxuPm9nG5jSF/Zng/vhG8wVRngf/u+MMvHUxQ6giDydWQF3zgOZD1tLTqtIY+j2FPnEJD9ZvWknRL4ML/tXu4fEDbtgy72ixZ3A4eZetQu7WBBiYOS94aYWrkB2g5braKZRf7jk5kEgdLPAXfDmg8jpM8UGe7FyZodkORwmCVEQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770387865; c=relaxed/simple; bh=YMOHPjr/Wf/QWbFo/ZB5fJoqYZ8Q3rjy/SRpdY/7S30=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WapJsFSCVzZ+UhqSvlquFuHjAss1O7OtVgjy23G0SuLEcA4rxOXU8sULGT0yFMX6AyClIMphOPKi4stOicaoHhu59rHfn/h2at0jXdH1Pb7SxW1Emd7G6vDwdFLGWdFigzgC+TGZ9fgjWL03UxijnbukKVHpbMGELrajiZko9QI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Eyi386IP; 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="Eyi386IP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A780C2BC87; Fri, 6 Feb 2026 14:24:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1770387864; bh=YMOHPjr/Wf/QWbFo/ZB5fJoqYZ8Q3rjy/SRpdY/7S30=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Eyi386IPJs0ew93oNS6xfd09R1UlajX6a5KrKlsJtSf9mcz+6T9YaurId5Htp1MpM WfPcsKebHrzcgsjgE0wdSaJxcL5U22ixrgJXmJOUk4kOTrUiLwZqSH2+HSa1hX39PA TZnUSqQFUpP5k0z9UYebJ5CVWrFmZFi7DO3gefzrpsC0SOp2hl646yWhU4rhIC9f9k skSWd04NnZEEVztfQm/uZZ6OFk3onL1UtKxMAt694F/qSu98hH8tX/Hpfh1UrZjWaa rCknHJn0J9KvsyBu2m3Jgv0rO4T+0JHWddOoF3tCQ1uaB32OFIQCHv73caXhwphMV0 UHfCvUQvH8WUw== 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, Shrikanth Hegde Subject: [PATCH 11/15] tick/sched: Account tickless idle cputime only when tick is stopped Date: Fri, 6 Feb 2026 15:22:41 +0100 Message-ID: <20260206142245.58987-12-frederic@kernel.org> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20260206142245.58987-1-frederic@kernel.org> References: <20260206142245.58987-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" There is no real point in switching to dyntick-idle cputime accounting mode if the tick is not actually stopped. This just adds overhead, notably fetching the GTOD, on each idle exit and each idle IRQ entry for no reason during short idle trips. Signed-off-by: Frederic Weisbecker --- kernel/time/tick-sched.c | 44 ++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index aa36c8d218e2..bceed0c4dd2c 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -1141,8 +1141,10 @@ void tick_nohz_idle_stop_tick(void) ts->idle_sleeps++; ts->idle_expires =3D expires; =20 - if (!was_stopped && tick_sched_flag_test(ts, TS_FLAG_STOPPED)) + if (!was_stopped && tick_sched_flag_test(ts, TS_FLAG_STOPPED)) { + kcpustat_dyntick_start(ts->idle_entrytime); nohz_balance_enter_idle(cpu); + } } else { tick_nohz_retain_tick(ts); } @@ -1184,7 +1186,6 @@ void tick_nohz_idle_enter(void) WARN_ON_ONCE(ts->timer_expires_base); tick_sched_flag_set(ts, TS_FLAG_INIDLE); ts->idle_entrytime =3D ktime_get(); - kcpustat_dyntick_start(ts->idle_entrytime); tick_nohz_clock_sleep(ts); =20 local_irq_enable(); @@ -1214,9 +1215,10 @@ void tick_nohz_irq_exit(void) struct tick_sched *ts =3D this_cpu_ptr(&tick_cpu_sched); =20 if (tick_sched_flag_test(ts, TS_FLAG_INIDLE)) { - ts->idle_entrytime =3D ktime_get(); - kcpustat_irq_exit(ts->idle_entrytime); tick_nohz_clock_sleep(ts); + ts->idle_entrytime =3D ktime_get(); + if (tick_sched_flag_test(ts, TS_FLAG_STOPPED)) + kcpustat_irq_exit(ts->idle_entrytime); } else { tick_nohz_full_update_tick(ts); } @@ -1317,8 +1319,11 @@ void tick_nohz_idle_restart_tick(void) { struct tick_sched *ts =3D this_cpu_ptr(&tick_cpu_sched); =20 - if (tick_sched_flag_test(ts, TS_FLAG_STOPPED)) - tick_nohz_restart_sched_tick(ts, ktime_get()); + if (tick_sched_flag_test(ts, TS_FLAG_STOPPED)) { + ktime_t now =3D ktime_get(); + kcpustat_dyntick_stop(now); + tick_nohz_restart_sched_tick(ts, now); + } } =20 static void tick_nohz_idle_update_tick(struct tick_sched *ts, ktime_t now) @@ -1348,7 +1353,6 @@ static void tick_nohz_idle_update_tick(struct tick_sc= hed *ts, ktime_t now) void tick_nohz_idle_exit(void) { struct tick_sched *ts =3D this_cpu_ptr(&tick_cpu_sched); - bool idle_active, tick_stopped; ktime_t now; =20 local_irq_disable(); @@ -1357,18 +1361,13 @@ void tick_nohz_idle_exit(void) WARN_ON_ONCE(ts->timer_expires_base); =20 tick_sched_flag_clear(ts, TS_FLAG_INIDLE); - idle_active =3D tick_sched_flag_test(ts, TS_FLAG_IDLE_ACTIVE); - tick_stopped =3D tick_sched_flag_test(ts, TS_FLAG_STOPPED); + tick_nohz_clock_wakeup(ts); =20 - if (idle_active || tick_stopped) + if (tick_sched_flag_test(ts, TS_FLAG_STOPPED)) { now =3D ktime_get(); - - if (idle_active) - tick_nohz_clock_wakeup(ts); - - if (tick_stopped) + kcpustat_dyntick_stop(now); tick_nohz_idle_update_tick(ts, now); - kcpustat_dyntick_stop(now); + } =20 local_irq_enable(); } @@ -1422,15 +1421,13 @@ static inline void tick_nohz_irq_enter(void) struct tick_sched *ts =3D this_cpu_ptr(&tick_cpu_sched); ktime_t now; =20 - if (!tick_sched_flag_test(ts, TS_FLAG_STOPPED | TS_FLAG_IDLE_ACTIVE)) + tick_nohz_clock_wakeup(ts); + + if (!tick_sched_flag_test(ts, TS_FLAG_STOPPED)) return; =20 now =3D ktime_get(); - - if (tick_sched_flag_test(ts, TS_FLAG_IDLE_ACTIVE)) { - tick_nohz_clock_wakeup(ts); - kcpustat_irq_enter(now); - } + kcpustat_irq_enter(now); =20 /* * If all CPUs are idle we may need to update a stale jiffies value. @@ -1439,8 +1436,7 @@ static inline void tick_nohz_irq_enter(void) * rare case (typically stop machine). So we must make sure we have a * last resort. */ - if (tick_sched_flag_test(ts, TS_FLAG_STOPPED)) - tick_nohz_update_jiffies(now); + tick_nohz_update_jiffies(now); } =20 #else --=20 2.51.1