Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp867935rdb; Fri, 1 Dec 2023 00:06:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IGjqYv6yzocjBBa0fuphiCGIsRPvBz8Vrrvgll9l+YhncBng0sCDglal//lu/lO5T96slen X-Received: by 2002:a17:903:25c7:b0:1d0:58d8:bb3f with SMTP id jc7-20020a17090325c700b001d058d8bb3fmr502534plb.49.1701417968444; Fri, 01 Dec 2023 00:06:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701417968; cv=none; d=google.com; s=arc-20160816; b=uB+ntXObvZJc3JjqD4BV7LXiIaptH9xtwGjq9hcSmXFPQ60V5BQAg61JlvgoF5dpbD RnVmZk1/dR7gAfsKTKWhRaPwzPGAYOPdOvY4jDe3N8IFroK6BD4EphqQdfz5XTNBGgsr 7R4pKVdGpFTlZMgshyaemF9ZQl2W23QqNgtjThW5ZsV+9ct06CPO1s8qA3Q46+6PUuXA AcCBMmul/OkI6G4DroUYPvF0kPJsAJIRCqEYemekBOVgS9GwfN+fIe2+T+5BdXLTeAPC etLIyRp5Jq4y16jt+mSI6OR4lDTAvh2sOINyI43wqZmh6PfLw7PnjqpeHXcvE/COeqNE 6/MQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:mail-followup-to:message-id:subject:cc:to:from:date; bh=+GhNo+PzN3pS917jmzPhzhkhCxB6B+YSxhJGrJsBPDU=; fh=uXBp9heUwR68xnOwG4S40A8HAdDYWJMCROb9t+9sw4U=; b=vnJa5gBRgJrk2GGUqVmnduKetYyZ/abGgvrVzb6I60O0bvZ18qa36Lh3jPBtrXNqHB 80WugE9m4l2Kx+j1x2pY/FEbBm/W7Jh/6gcGSdAmYdV32RjR8ZRXvoUoo1S2LxL7FGw6 0aYeBmrxz0rGl70VB73P+jcnVMIKu7gwje0zbXpPIfKJWnGqXP2e8iiLBj6BBB9Jf67L yFfeSrvY0LyKbT75GvWvlMU9LRRgr8pX/OdyC3arj58nw6oUloZA7vpPsVllmU23GogI QUKRlIhA7u0WR/TSiKwK6c1jLJNeB3HWGU6vlZym3onPb845tv2Sd1TGBZOI0cLkJE+R pAoQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id c7-20020a170902d48700b001c430af53b8si3002760plg.574.2023.12.01.00.06.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 00:06:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id EEAB187943B2; Fri, 1 Dec 2023 00:06:05 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232346AbjLAIFu (ORCPT + 99 others); Fri, 1 Dec 2023 03:05:50 -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-Type: text/plain; charset="us-ascii" 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) X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Fri, 01 Dec 2023 00:06:06 -0800 (PST) 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); } +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, unsigned int offset) */ if (pc & HARDIRQ_MASK) irqtime_account_delta(irqtime, delta, CPUTIME_IRQ); - else if ((pc & SOFTIRQ_OFFSET) && curr != this_cpu_ksoftirqd()) + else if (((pc & SOFTIRQ_OFFSET) && curr != this_cpu_ksoftirqd() && + (!IS_ENABLED(CONFIG_PREEMPT_RT) || curr != this_cpu_ktimers())) irqtime_account_delta(irqtime, delta, CPUTIME_SOFTIRQ); } @@ -391,7 +392,8 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick, cputime -= other; - if (this_cpu_ksoftirqd() == p) { + if (this_cpu_ksoftirqd() == p || + (IS_ENABLED(CONFIG_PREEMPT_RT) && this_cpu_ktimers() == p)) { /* * ksoftirqd time do not get accounted in cpu_softirq_time. * So, we have to handle it separately here. -- 2.17.1