From nobody Mon Dec 29 03:01:33 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8570C07E97 for ; Fri, 1 Dec 2023 08:05:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235171AbjLAIFv (ORCPT ); Fri, 1 Dec 2023 03:05:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229530AbjLAIFq (ORCPT ); Fri, 1 Dec 2023 03:05:46 -0500 Received: from mx10.didiglobal.com (mx10.didiglobal.com [111.202.70.125]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 48594170B for ; Fri, 1 Dec 2023 00:05:51 -0800 (PST) Received: from mail.didiglobal.com (unknown [10.79.65.12]) by mx10.didiglobal.com (MailData Gateway V2.8.8) with ESMTPS id E5D5A1808BB6B4; Fri, 1 Dec 2023 16:05:49 +0800 (CST) Received: from didi-ThinkCentre-M930t-N000 (10.79.64.101) by ZJY02-ACTMBX-02.didichuxing.com (10.79.65.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.32; Fri, 1 Dec 2023 16:05:49 +0800 Date: Fri, 1 Dec 2023 16:05:41 +0800 X-MD-Sfrom: tiozhang@didiglobal.com X-MD-SrcIP: 10.79.65.12 From: tiozhang To: , , , , , , CC: , , , , , , , , , Subject: [PATCH v3] sched/cputime: let ktimers align with ksoftirqd in accounting CPUTIME_SOFTIRQ Message-ID: <20231201080522.GA31309@didi-ThinkCentre-M930t-N000> Mail-Followup-To: bigeasy@linutronix.de, tglx@linutronix.de, rostedt@goodmis.org, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, linux-kernel@vger.kernel.org, dietmar.eggemann@arm.com, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, zyhtheonly@gmail.com, zyhtheonly@yeah.net MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20231201073240.T9bFNCkU@linutronix.de> User-Agent: Mutt/1.9.4 (2018-02-28) X-Originating-IP: [10.79.64.101] X-ClientProxiedBy: ZJY01-PUBMBX-01.didichuxing.com (10.79.64.32) To ZJY02-ACTMBX-02.didichuxing.com (10.79.65.12) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In CONFIG_PREEMPT_RT kernel, ktimers also calls __do_softirq, so when accounting CPUTIME_SOFTIRQ, ktimers need to be accounted the same as ksoftirqd. Signed-off-by: tiozhang --- include/linux/interrupt.h | 5 +++++ kernel/sched/cputime.c | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h index a5091ac97fc6..a88646acaf3f 100644 --- a/include/linux/interrupt.h +++ b/include/linux/interrupt.h @@ -621,6 +621,11 @@ static inline unsigned int local_pending_timers(void) return __this_cpu_read(pending_timer_softirq); } =20 +static inline struct task_struct *this_cpu_ktimers(void) +{ + return this_cpu_read(timersd); +} + #else static inline void raise_timer_softirq(void) { diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c index af7952f12e6c..2393c533314f 100644 --- a/kernel/sched/cputime.c +++ b/kernel/sched/cputime.c @@ -73,7 +73,8 @@ void irqtime_account_irq(struct task_struct *curr, unsign= ed int offset) */ if (pc & HARDIRQ_MASK) irqtime_account_delta(irqtime, delta, CPUTIME_IRQ); - else if ((pc & SOFTIRQ_OFFSET) && curr !=3D this_cpu_ksoftirqd()) + else if (((pc & SOFTIRQ_OFFSET) && curr !=3D this_cpu_ksoftirqd() && + (!IS_ENABLED(CONFIG_PREEMPT_RT) || curr !=3D this_cpu_ktimers())) irqtime_account_delta(irqtime, delta, CPUTIME_SOFTIRQ); } =20 @@ -391,7 +392,8 @@ static void irqtime_account_process_tick(struct task_st= ruct *p, int user_tick, =20 cputime -=3D other; =20 - if (this_cpu_ksoftirqd() =3D=3D p) { + if (this_cpu_ksoftirqd() =3D=3D p || + (IS_ENABLED(CONFIG_PREEMPT_RT) && this_cpu_ktimers() =3D=3D p)) { /* * ksoftirqd time do not get accounted in cpu_softirq_time. * So, we have to handle it separately here. --=20 2.17.1