From nobody Sat Feb 7 21:14:46 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 55EF73EF0A3; Fri, 6 Feb 2026 14:24:48 +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=1770387888; cv=none; b=QWv98v+xHpa+4p14bos4FjELmtMzOq9sOEVKRhAOpj5BJf8Vxvegokib7xDwyWe441pwN6K14T0NjLCdpfMZwp00nB7OhiFnfoLTLRLURAMlHtuWS5IRFbr1kla2rqsaoM6BFIpvS99ksnDlfqsAoQCAwS9opZ5XqemAlXexJxI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770387888; c=relaxed/simple; bh=1a8G23aJDuAPjK+U9mKc7z3SxXZk+XIfUuQdAEaa5yE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tGN1wJ1tuqSdCl5DAwQWh4QRnygM1u/D//aSrYijRdpP8B7YE+3A9qAj/6JjtYazoMflUvxzov5G5G9j/2AWjp3hYNJxzKr0eQP1NWHurH8m70t6vz0I2+jRAkhJMc3JKAaLwXzQQ/cbCSBX4WSKlImQ7OqhMR+j5bZY5iaDUvo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pyvvjMdH; 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="pyvvjMdH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95E3AC19424; Fri, 6 Feb 2026 14:24:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1770387888; bh=1a8G23aJDuAPjK+U9mKc7z3SxXZk+XIfUuQdAEaa5yE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pyvvjMdH3hIzpy6aY54/LbDRrNWblh4tmt5l6YkK+fTkvt2lfzilz/SMkfwmrBCTa SdLlYowtBljkJ90q0VuzNj72diFgimT3w+ipxS9PtB8dSXBlzs4yP8OfTHShrVnSgr gIf5I4KVPgt8ITyocNbbNovtS1ms8WfLW13HT+LGC2E4XC8HPszlhfOeclfv2fM5jt dXpbutriVMuVXNcdLINPem/tHoz9daDrciUC3ojdNmBJ73HAVeG1sT48y3yzyYxiIE 55GK83AOK2oYqnpMm+ZYmC8nbn9afCH/50djVJ6jux706lusveFloWpWJaZDjViUcl ImbJ0ASRdg5Qw== 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 14/15] sched/cputime: Handle idle irqtime gracefully Date: Fri, 6 Feb 2026 15:22:44 +0100 Message-ID: <20260206142245.58987-15-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" The dyntick-idle cputime accounting always assumes that IRQ time accounting is enabled and consequently stops elapsing the idle time during dyntick-idle IRQs. This doesn't mix up well with disabled IRQ time accounting because then idle IRQs become a cputime blind-spot. Also this feature is disabled on most configurations and the overhead of pausing dyntick-idle accounting while in idle IRQs could then be avoided. Fix the situation with conditionally pausing dyntick-idle accounting during idle IRQs only if neither native vtime (which does IRQ time accounting) nor generic IRQ time accounting are enabled. Also make sure that the accumulated IRQ time is not accidentally substracted from later accounting. Signed-off-by: Frederic Weisbecker --- kernel/sched/cputime.c | 24 +++++++++++++++++++++--- kernel/sched/sched.h | 1 + 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c index d588a4a50e57..92fa2f037b6e 100644 --- a/kernel/sched/cputime.c +++ b/kernel/sched/cputime.c @@ -46,7 +46,8 @@ static void irqtime_account_delta(struct irqtime *irqtime= , u64 delta, u64_stats_update_begin(&irqtime->sync); cpustat[idx] +=3D delta; irqtime->total +=3D delta; - irqtime->tick_delta +=3D delta; + if (!irqtime->idle_dyntick) + irqtime->tick_delta +=3D delta; u64_stats_update_end(&irqtime->sync); } =20 @@ -81,6 +82,16 @@ void irqtime_account_irq(struct task_struct *curr, unsig= ned int offset) irqtime_account_delta(irqtime, delta, CPUTIME_SOFTIRQ); } =20 +static inline void irqtime_dyntick_start(void) +{ + __this_cpu_write(cpu_irqtime.idle_dyntick, true); +} + +static inline void irqtime_dyntick_stop(void) +{ + __this_cpu_write(cpu_irqtime.idle_dyntick, false); +} + static u64 irqtime_tick_accounted(u64 maxtime) { struct irqtime *irqtime =3D this_cpu_ptr(&cpu_irqtime); @@ -94,6 +105,9 @@ static u64 irqtime_tick_accounted(u64 maxtime) =20 #else /* !CONFIG_IRQ_TIME_ACCOUNTING: */ =20 +static inline void irqtime_dyntick_start(void) { } +static inline void irqtime_dyntick_stop(void) { } + static u64 irqtime_tick_accounted(u64 dummy) { return 0; @@ -444,6 +458,7 @@ void kcpustat_dyntick_stop(u64 now) WARN_ON_ONCE(!kc->idle_dyntick); kcpustat_idle_stop(kc, now); kc->idle_dyntick =3D false; + irqtime_dyntick_stop(); vtime_dyntick_stop(); steal_account_process_time(ULONG_MAX); } @@ -455,6 +470,7 @@ void kcpustat_dyntick_start(u64 now) =20 if (!vtime_generic_enabled_this_cpu()) { vtime_dyntick_start(); + irqtime_dyntick_start(); kc->idle_dyntick =3D true; kcpustat_idle_start(kc, now); } @@ -464,7 +480,8 @@ void kcpustat_irq_enter(u64 now) { struct kernel_cpustat *kc =3D kcpustat_this_cpu; =20 - if (!vtime_generic_enabled_this_cpu()) + if (!vtime_generic_enabled_this_cpu() && + (irqtime_enabled() || vtime_accounting_enabled_this_cpu())) kcpustat_idle_stop(kc, now); } =20 @@ -472,7 +489,8 @@ void kcpustat_irq_exit(u64 now) { struct kernel_cpustat *kc =3D kcpustat_this_cpu; =20 - if (!vtime_generic_enabled_this_cpu()) + if (!vtime_generic_enabled_this_cpu() && + (irqtime_enabled() || vtime_accounting_enabled_this_cpu())) kcpustat_idle_start(kc, now); } =20 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index d30cca6870f5..cf677ff12b10 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -3307,6 +3307,7 @@ static inline void sched_core_tick(struct rq *rq) { } #ifdef CONFIG_IRQ_TIME_ACCOUNTING =20 struct irqtime { + bool idle_dyntick; u64 total; u64 tick_delta; u64 irq_start_time; --=20 2.51.1