Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp182125rdb; Thu, 30 Nov 2023 01:42:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IFqvLECySs02BGLJTnME4Wp0Jt+xMxYS7argaimZ8hFcV2bAQ34fqiL6SaPfrT1FyxmmCdt X-Received: by 2002:a05:6a20:c523:b0:18b:3122:f818 with SMTP id gm35-20020a056a20c52300b0018b3122f818mr20412175pzb.38.1701337335896; Thu, 30 Nov 2023 01:42:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701337335; cv=none; d=google.com; s=arc-20160816; b=uPS4qHFwLqkCgw5bDfmNMXpfntE94EJO6x/xxwEDrps7nctDlkKk9LVLCPT/MXdcF/ SamuYMFbHKiIepKWeVYd1AOlW9JkUv1nIvkcepeZq/DpFRjpG2sozK6Jaad+51R+GTKw hiMK47bl4EKqxBHeyWZUvy+KhhkwsHLM69uN3ctnxX6DUtRnHmGkFtUctMaA0h+PRbIK IViVmhpPI+1PTdzSUEu6OdCPo/hZc0KAYEHGP7SFBQSgtnlHJrl9eJMw2p3rjYUx9PZW x7HZXkMrzpPN7CfMdVRIe6zE4OKBFG6iG5FIDWv2oRiNU1SHZ3xjYmFszH1YyD6aspCa wYxA== 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=viswfPf1m8hf+z6u61bbrtZgE2QR20xN7hjDYeY93Fc=; fh=FKa6Te0M6aK+eXsZh1UlGKyfZXWocaVeQVthCizYZ5A=; b=NA4exjF+e0FB8I4ZnkPe43xC2QFUjhGNvKC0fx89uWRIpCZHOrSXnxSNQLSnuL/KuH 7D1R51oR18vHgKqDVNxs3t7YeWWqjHLlzSwKF3f9GaHlGwNYFgvLMvm1bWv2jE7YMqxy jj8c1ZTueOJb4OLXDdBARbzJ3HAjTQya7Mu1PCZgWZTOLQZd/tCaLl1HLlX9s4359n8K Mq8u8n+jLh0lsbEOdtdnC/KvebVsr4FITzYHs56Ms7Uq/8YGEo6zjpu4qzWjdM+SLhE8 4yitQX/qLG8eVKSzgZjYc051cB283mC16nu5Iro2kTaEDplWK05B9Rnm8ZX74VpiBhJD uiAg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id cc11-20020a056a02074b00b005ad11a5ac8fsi947985pgb.323.2023.11.30.01.42.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 01:42:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id A5F3E806667D; Thu, 30 Nov 2023 01:42:14 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231889AbjK3JmC (ORCPT + 99 others); Thu, 30 Nov 2023 04:42:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231755AbjK3JmA (ORCPT ); Thu, 30 Nov 2023 04:42:00 -0500 Received: from mx9.didiglobal.com (mx9.didiglobal.com [111.202.70.124]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 03E1BD4A for ; Thu, 30 Nov 2023 01:42:05 -0800 (PST) Received: from mail.didiglobal.com (unknown [10.79.65.12]) by mx9.didiglobal.com (MailData Gateway V2.8.8) with ESMTPS id D6D701898505CF; Thu, 30 Nov 2023 17:41:59 +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; Thu, 30 Nov 2023 17:41:59 +0800 Date: Thu, 30 Nov 2023 17:41:47 +0800 X-MD-Sfrom: tiozhang@didiglobal.com X-MD-SrcIP: 10.79.65.12 From: tiozhang To: , , , , , , CC: , , , , , , , , , Subject: [PATCH v2] sched/cputime: exclude ktimers threads in irqtime_account_irq Message-ID: <20231130094130.GA12116@didi-ThinkCentre-M930t-N000> Mail-Followup-To: rostedt@goodmis.org, bigeasy@linutronix.de, tglx@linutronix.de, 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: <20231127130754.3affb908@gandalf.local.home> 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=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Thu, 30 Nov 2023 01:42:14 -0800 (PST) In CONFIG_PREEMPT_RT kernel, ktimers also calls __do_softirq, so when accounting CPUTIME_SOFTIRQ, ktimers need to be excluded as well as ksoftirqd. Also add this_cpu_ktimers to keep consistency with this_cpu_ksoftirqd. Signed-off-by: tiozhang --- include/linux/interrupt.h | 5 +++++ kernel/sched/cputime.c | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) 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..fd3610353e12 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); } -- 2.17.1