{"id":2235036,"url":"http://patchwork.ozlabs.org/api/1.2/covers/2235036/?format=json","web_url":"http://patchwork.ozlabs.org/project/linuxppc-dev/cover/20260508131647.43868-1-frederic@kernel.org/","project":{"id":2,"url":"http://patchwork.ozlabs.org/api/1.2/projects/2/?format=json","name":"Linux PPC development","link_name":"linuxppc-dev","list_id":"linuxppc-dev.lists.ozlabs.org","list_email":"linuxppc-dev@lists.ozlabs.org","web_url":"https://github.com/linuxppc/wiki/wiki","scm_url":"https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git","webscm_url":"https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git/","list_archive_url":"https://lore.kernel.org/linuxppc-dev/","list_archive_url_format":"https://lore.kernel.org/linuxppc-dev/{}/","commit_url_format":"https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git/commit/?id={}"},"msgid":"<20260508131647.43868-1-frederic@kernel.org>","list_archive_url":"https://lore.kernel.org/linuxppc-dev/20260508131647.43868-1-frederic@kernel.org/","date":"2026-05-08T13:16:32","name":"[00/15,v4] tick/sched: Refactor idle cputime accounting","submitter":{"id":79411,"url":"http://patchwork.ozlabs.org/api/1.2/people/79411/?format=json","name":"Frederic Weisbecker","email":"frederic@kernel.org"},"mbox":"http://patchwork.ozlabs.org/project/linuxppc-dev/cover/20260508131647.43868-1-frederic@kernel.org/mbox/","series":[{"id":503389,"url":"http://patchwork.ozlabs.org/api/1.2/series/503389/?format=json","web_url":"http://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=503389","date":"2026-05-08T13:16:32","name":"tick/sched: Refactor idle cputime accounting","version":4,"mbox":"http://patchwork.ozlabs.org/series/503389/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/covers/2235036/comments/","headers":{"Return-Path":"\n <linuxppc-dev+bounces-20610-incoming=patchwork.ozlabs.org@lists.ozlabs.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linuxppc-dev@lists.ozlabs.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256\n header.s=k20201202 header.b=MGP5FK9r;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org\n (client-ip=112.213.38.117; helo=lists.ozlabs.org;\n envelope-from=linuxppc-dev+bounces-20610-incoming=patchwork.ozlabs.org@lists.ozlabs.org;\n receiver=patchwork.ozlabs.org)","lists.ozlabs.org;\n arc=none smtp.remote-ip=172.234.252.31","lists.ozlabs.org;\n dmarc=pass (p=quarantine dis=none) header.from=kernel.org","lists.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256\n header.s=k20201202 header.b=MGP5FK9r;\n\tdkim-atps=neutral","lists.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=kernel.org\n (client-ip=172.234.252.31; helo=sea.source.kernel.org;\n envelope-from=frederic@kernel.org; receiver=lists.ozlabs.org)"],"Received":["from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1 raw public key)\n server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4gBqR01y3Xz1yJq\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 08 May 2026 23:17:15 +1000 (AEST)","from boromir.ozlabs.org (localhost [127.0.0.1])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 4gBqQy2FYCz2xfR;\n\tFri, 08 May 2026 23:17:14 +1000 (AEST)","from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n\t(No client certificate requested)\n\tby lists.ozlabs.org (Postfix) with ESMTPS id 4gBqQs1gygz2xQC\n\tfor <linuxppc-dev@lists.ozlabs.org>; Fri, 08 May 2026 23:17:09 +1000 (AEST)","from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58])\n\tby sea.source.kernel.org (Postfix) with ESMTP id DBA24437E8;\n\tFri,  8 May 2026 13:17:06 +0000 (UTC)","by smtp.kernel.org (Postfix) with ESMTPSA id CB1B3C2BCB0;\n\tFri,  8 May 2026 13:16:58 +0000 (UTC)"],"ARC-Seal":"i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1778246234;\n\tcv=none;\n b=dKuD0bz89ZCIB+EVYCwRfCG8ITH+1A+J8ZvdkAtrUwaPH/o6CjfN73cUyKLHIV7yj7II20ph2lvULeEscz7hQXg/ms7G15CfUoCA2IFL/4zQU34kqRDKiLrlwAszDZyC2Sd6zXQE4BwpC082p2ZLyqa/VDpKI5HESlfzWJi24RHQkMip/fIZlJmPsBREiE60iTEJhrj2xElWjXnqgobdwN0U7iQ1o82xOdAcsBOKIpThzThTK58JcrVqfHbgzYB2m6UWNNAHU2uu2Cctj4XFrf7UyZZdS66Hd5r9CS5AFCV24kowAJm656fxmuc/wE448X6IVh0FSA+TPsOxpHKNlQ==","ARC-Message-Signature":"i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707;\n\tt=1778246234; c=relaxed/relaxed;\n\tbh=KSR3buBUoGn7h6QUFUsLNU/EqeWQM09a7paH2USs2Dg=;\n\th=From:To:Cc:Subject:Date:Message-ID:MIME-Version;\n b=FfLLVWFKt9xleLo0U1WKHFmVBkStTYXh+5kpsY/8+aBz0B2Wpo7VFciTMJLKuW5UA4KzjRId32cZ8YUTQtGXwopND0Iplgm5Ov45RAdRmmksBz9hJKYWIwPwQMdW6j3r9KIC5UUm7q2X8q+hukVpTDZ0Y8Gk1FZLYSeSXHf2PTLtw1++nhjDkxp/blIRxUUUOH9bbuZBiCmA48F5/yMW7O/wTsCN0TeiC6/FMPZMBjxWrWUkOzQax9+xmRYPBw0zTnqokCcyQ0enM3juoc0Bh9qZCoksw9on+XUdGLTjcOni31u+CrOAkJ1EfRP2l4bazsiFAvhyPYowMCMQ9aUmSQ==","ARC-Authentication-Results":"i=1; lists.ozlabs.org;\n dmarc=pass (p=quarantine dis=none) header.from=kernel.org;\n dkim=pass (2048-bit key;\n unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256\n header.s=k20201202 header.b=MGP5FK9r; dkim-atps=neutral;\n spf=pass (client-ip=172.234.252.31; helo=sea.source.kernel.org;\n envelope-from=frederic@kernel.org;\n receiver=lists.ozlabs.org) smtp.mailfrom=kernel.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;\n\ts=k20201202; t=1778246226;\n\tbh=Vta7hllmwFIumsR7obeWKsvWVRLZq990abYtI1WVcNk=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=MGP5FK9r9QEOy860Im4ejrteL4FwEhVVu14vipu9Z+cC0I316uNQwgOy0hPfLaVhY\n\t zQhpMRfoyyqaX7J92xkQ+LLBJPltZMpkOyxK8CW1LDab4vsyBS15jl9dAajLFcYQ+d\n\t kK5YF3Hom2fADVLNDaSgsqvXA0DaQeukbeZ8GVvmIZvU7rBkXPEHxGdUBBENsvirza\n\t ARd5MU8U0tleul+fXPjitjj+XOBfZwXLfuLAE6K8/NWnjBl5m1NH7Ymk0sokSPUqTJ\n\t I2DswfY8YWOGs4TB0lt1eaRgSZBvqBl+VOwwXu2m22zdvgatVVuQ0wwR7N55pFdd2N\n\t d+E2RmzRgmsqQ==","From":"Frederic Weisbecker <frederic@kernel.org>","To":"LKML <linux-kernel@vger.kernel.org>","Cc":"Frederic Weisbecker <frederic@kernel.org>,\n\tMadhavan Srinivasan <maddy@linux.ibm.com>,\n\tPeter Zijlstra <peterz@infradead.org>,\n\tJan Kiszka <jan.kiszka@siemens.com>,\n\tDietmar Eggemann <dietmar.eggemann@arm.com>,\n\tShrikanth Hegde <sshegde@linux.ibm.com>,\n\tNicholas Piggin <npiggin@gmail.com>,\n\tAlexander Gordeev <agordeev@linux.ibm.com>,\n\tBen Segall <bsegall@google.com>,\n\tThomas Gleixner <tglx@linutronix.de>,\n\tVasily Gorbik <gor@linux.ibm.com>,\n\t\"Rafael J. Wysocki\" <rafael@kernel.org>, linux-pm@vger.kernel.org,\n\tSashiko@lists.ozlabs.org, Ingo Molnar <mingo@kernel.org>,\n\tMichael Ellerman <mpe@ellerman.id.au>,\n\tBoqun Feng <boqun.feng@gmail.com>,\n\tValentin Schneider <vschneid@redhat.com>,\n\tlinuxppc-dev@lists.ozlabs.org, Sven Schnelle <svens@linux.ibm.com>,\n\tIngo Molnar <mingo@redhat.com>,\n\tVincent Guittot <vincent.guittot@linaro.org>,\n\tChristian Borntraeger <borntraeger@linux.ibm.com>,\n\tMel Gorman <mgorman@suse.de>, Steven Rostedt <rostedt@goodmis.org>,\n\tJoel Fernandes <joelagnelf@nvidia.com>,\n\t\"Paul E . McKenney\" <paulmck@kernel.org>,\n\tNeeraj Upadhyay <neeraj.upadhyay@kernel.org>,\n\tAnna-Maria Behnsen <anna-maria@linutronix.de>,\n\t\"Christophe Leroy (CS GROUP)\" <chleroy@kernel.org>,\n\tJuri Lelli <juri.lelli@redhat.com>,\n\tUladzislau Rezki <urezki@gmail.com>,\n\tViresh Kumar <viresh.kumar@linaro.org>,\n\tKieran Bingham <kbingham@kernel.org>,\n\tXin Zhao <jackzxcui1989@163.com>, linux-s390@vger.kernel.org,\n\tHeiko Carstens <hca@linux.ibm.com>","Subject":"[PATCH 00/15 v4] tick/sched: Refactor idle cputime accounting","Date":"Fri,  8 May 2026 15:16:32 +0200","Message-ID":"<20260508131647.43868-1-frederic@kernel.org>","X-Mailer":"git-send-email 2.53.0","X-Mailing-List":"linuxppc-dev@lists.ozlabs.org","List-Id":"<linuxppc-dev.lists.ozlabs.org>","List-Help":"<mailto:linuxppc-dev+help@lists.ozlabs.org>","List-Owner":"<mailto:linuxppc-dev+owner@lists.ozlabs.org>","List-Post":"<mailto:linuxppc-dev@lists.ozlabs.org>","List-Archive":"<https://lore.kernel.org/linuxppc-dev/>,\n  <https://lists.ozlabs.org/pipermail/linuxppc-dev/>","List-Subscribe":"<mailto:linuxppc-dev+subscribe@lists.ozlabs.org>,\n  <mailto:linuxppc-dev+subscribe-digest@lists.ozlabs.org>,\n  <mailto:linuxppc-dev+subscribe-nomail@lists.ozlabs.org>","List-Unsubscribe":"<mailto:linuxppc-dev+unsubscribe@lists.ozlabs.org>","Precedence":"list","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-Spam-Status":"No, score=-0.6 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED,\n\tDKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS\n\tautolearn=disabled version=4.0.1 OzLabs 8","X-Spam-Checker-Version":"SpamAssassin 4.0.1 (2024-03-25) on lists.ozlabs.org"},"content":"Hi,\n\nAfter the issue reported here:\n\n        https://lore.kernel.org/all/20251210083135.3993562-1-jackzxcui1989@163.com/\n\nIt occurs that the idle cputime accounting is a big mess that\naccumulates within two concurrent statistics, each having their own\nshortcomings:\n\n* The accounting for online CPUs which is based on the delta between\n  tick_nohz_start_idle() and tick_nohz_stop_idle().\n\n  Pros:\n       - Works when the tick is off\n\n       - Has nsecs granularity\n\n  Cons:\n       - Account idle steal time but doesn't substract it from idle\n         cputime.\n\n       - Assumes CONFIG_IRQ_TIME_ACCOUNTING by not accounting IRQs but\n         the IRQ time is simply ignored when\n         CONFIG_IRQ_TIME_ACCOUNTING=n\n\n       - The windows between 1) idle task scheduling and the first call\n         to tick_nohz_start_idle() and 2) idle task between the last\n         tick_nohz_stop_idle() and the rest of the idle time are\n         blindspots wrt. cputime accounting (though mostly insignificant\n         amount)\n\n       - Relies on private fields outside of kernel stats, with specific\n         accessors.\n\n* The accounting for offline CPUs which is based on ticks and the\n  jiffies delta during which the tick was stopped.\n\n  Pros:\n       - Handles steal time correctly\n\n       - Handle CONFIG_IRQ_TIME_ACCOUNTING=y and\n         CONFIG_IRQ_TIME_ACCOUNTING=n correctly.\n\n       - Handles the whole idle task\n\n       - Accounts directly to kernel stats, without midlayer accumulator.\n\n   Cons:\n       - Doesn't elapse when the tick is off, which doesn't make it\n         suitable for online CPUs.\n\n       - Has TICK_NSEC granularity (jiffies)\n\n       - Needs to track the dyntick-idle ticks that were accounted and\n         substract them from the total jiffies time spent while the tick\n         was stopped. This is an ugly workaround.\n\nHaving two different accounting for a single context is not the only\nproblem: since those accountings are of different natures, it is\npossible to observe the global idle time going backward after a CPU goes\noffline, as reported by Xin Zhao.\n\nClean up the situation with introducing a hybrid approach that stays\ncoherent, fixes the backward jumps and works for both online and offline\nCPUs:\n\n* Tick based or native vtime accounting operate before the tick is\n  stopped and resumes once the tick is restarted.\n\n* When the idle loop starts, switch to dynticks-idle accounting as is\n  done currently, except that the statistics accumulate directly to the\n  relevant kernel stat fields.\n\n* Private dyntick cputime accounting fields are removed.\n\n* Works on both online and offline case.\n\n* Move most of the relevant code to the common sched/cputime subsystem\n\n* Handle CONFIG_IRQ_TIME_ACCOUNTING=n correctly such that the\n  dynticks-idle accounting still elapses while on IRQs.\n\n* Correctly substract idle steal cputime from idle time\n\nChanges since v3 (among which a lot of relevant reviews from Sashiko):\n\n- Add new tags\n\n- Rebase on latest -rc1\n\n- Add \"tick/sched: Fix TOCTOU in nohz idle time fetch\" (Sashiko)\n\n- Fix buggy state refetch in kcpustat_cpu_fetch_vtime() (Sashiko)\n\n- Fix build issue on powerpc (Christophe Leroy)\n\n- Fix s390 lost steal time occuring on idle IRQs (call vtime_flush() on\n  vtime_account_hardirq() and vtime_account_softirq()) (Sashiko)\n\n- Fix build issue on s390\n\n- Fix uninitialized idle_sleeptime_seq (Sashiko)\n\n- Fix irqtime being disabled or enabled in the middle of an idle IRQ\n  (Sashiko)\n  \n- Fix tick restart and then restop in the same idle loop (Sashiko)\n\n- Fix \"sched/cputime: Handle idle irqtime gracefully\" changelog (Sashiko)\n\n- Fix idle steal time substracted from the wrong index between idle and\n  iowait kcpustat. (Sashiko)\n\ngit://git.kernel.org/pub/scm/linux/kernel/git/frederic/linux-dynticks.git\n\ttimers/core-v4\n\nHEAD: e64ba052ce04e363ff76d3cb8bedc5f812188acb\nThanks,\n\tFrederic\n---\n\nFrederic Weisbecker (15):\n      tick/sched: Fix TOCTOU in nohz idle time fetch\n      sched/idle: Handle offlining first in idle loop\n      sched/cputime: Remove superfluous and error prone kcpustat_field() parameter\n      sched/cputime: Correctly support generic vtime idle time\n      powerpc/time: Prepare to stop elapsing in dynticks-idle\n      s390/time: Prepare to stop elapsing in dynticks-idle\n      tick/sched: Unify idle cputime accounting\n      tick/sched: Remove nohz disabled special case in cputime fetch\n      tick/sched: Move dyntick-idle cputime accounting to cputime code\n      tick/sched: Remove unused fields\n      tick/sched: Account tickless idle cputime only when tick is stopped\n      tick/sched: Consolidate idle time fetching APIs\n      sched/cputime: Provide get_cpu_[idle|iowait]_time_us() off-case\n      sched/cputime: Handle idle irqtime gracefully\n      sched/cputime: Handle dyntick-idle steal time correctly\n\n arch/powerpc/kernel/time.c         |  41 +++++\n arch/s390/include/asm/idle.h       |   2 +\n arch/s390/kernel/idle.c            |   5 +-\n arch/s390/kernel/vtime.c           |  75 ++++++++-\n drivers/cpufreq/cpufreq.c          |  29 +---\n drivers/cpufreq/cpufreq_governor.c |   6 +-\n drivers/macintosh/rack-meter.c     |   2 +-\n fs/proc/stat.c                     |  40 +----\n fs/proc/uptime.c                   |   8 +-\n include/linux/kernel_stat.h        |  76 +++++++--\n include/linux/tick.h               |   4 -\n include/linux/vtime.h              |  22 ++-\n kernel/rcu/tree.c                  |   9 +-\n kernel/rcu/tree_stall.h            |   7 +-\n kernel/sched/core.c                |   6 +-\n kernel/sched/cputime.c             | 308 +++++++++++++++++++++++++++++++------\n kernel/sched/idle.c                |  13 +-\n kernel/time/tick-sched.c           | 212 ++++++-------------------\n kernel/time/tick-sched.h           |  12 --\n kernel/time/timer_list.c           |   6 +-\n scripts/gdb/linux/timerlist.py     |   4 -\n 21 files changed, 529 insertions(+), 358 deletions(-)"}