From nobody Wed Apr 1 11:11:43 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 493BE1C3F0C; Tue, 31 Mar 2026 13:17:47 +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=1774963067; cv=none; b=DtarcMzh4SghU5W9ha/4EICzAHgjOsT+3ZNh/VtrRi9NWBg8T2yHKxF2s0cSRT7BFdvTF2YhazKIo9G4UTcvu1L2XS08LdbFG/SDDzk+8t7ENyl0Vub5r3Hz03X7fk/O6owUSYXY634jk9bZKKbjuKzj6OvAJdSMzqWNLLMyTqk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774963067; c=relaxed/simple; bh=b0ahYWXnH1OlnVL9k+U+tBmKrl/hr/iIMc+t5ZPZsTU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B1lWkEvLw76ozNmNMBEXfsilHEDxPpL7SZ3seIWeHAuPpsM7BctHgU5uz0KaVPxfqSaRg50+tiCE+JRKFRG/HvDKdRsgRAMVZBHzAWwGbJWd+W+ZjZrf+E4cuZ3bDyJZeIN/bU69zjhCzy3UnZaU2/wCs9hOhgd533ub6PCBSbE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=g247PlHX; 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="g247PlHX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED080C2BC9E; Tue, 31 Mar 2026 13:17:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774963066; bh=b0ahYWXnH1OlnVL9k+U+tBmKrl/hr/iIMc+t5ZPZsTU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g247PlHXKumCwTjBUEPH/OaEm97Ov8XRAiN+XxOLgKeikZwSsUuHEOpgz+lL1Fcll u4tm+fBpVaGBDmc+Hd0er8OJZozmuf1jab1eyiLVQOlghTUrrL9x5mwxzXyM+UX6Qo /r39+MUozV4AJUk4QEu9Y+cGMWBDwbm1O+8f4RsI70Az/uDlGYf6mBmuIFFiQmCxuT 8yPpijKwrB5RY8+Mkph0ycgLsCcaLpueAYAd24Jxu3ZIBVf2PGZU4/zHTjxMxe9eYx OThNyt16b8efCE5VXYwaKeNuCagh3SOO6uMCgpmfLBIEnVFdbN7icAFmqJn/EFfVgw nR8+ZCc/81b1w== 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 10/14] tick/sched: Account tickless idle cputime only when tick is stopped Date: Tue, 31 Mar 2026 15:16:18 +0200 Message-ID: <20260331131622.30505-11-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" 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 Tested-by: Shrikanth Hegde --- 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 0da83d9b324a..923cae35827a 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -1144,8 +1144,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); } @@ -1187,7 +1189,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(); @@ -1217,9 +1218,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); } @@ -1320,8 +1322,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) @@ -1351,7 +1356,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(); @@ -1360,18 +1364,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(); } @@ -1425,15 +1424,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. @@ -1442,8 +1439,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.53.0