Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp3915590rdb; Mon, 11 Dec 2023 04:03:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IFmkAL9DQzKbHcErnRWh7Ee4aIzc7hbDYqqbkYI6jixzJOH2Hid3IRhhAAZPmRwRpwH/F1M X-Received: by 2002:a17:903:2342:b0:1d0:700b:3f78 with SMTP id c2-20020a170903234200b001d0700b3f78mr6957197plh.50.1702296209754; Mon, 11 Dec 2023 04:03:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702296209; cv=none; d=google.com; s=arc-20160816; b=qgrKpfSyeiQ9DPrbusUa++6lnfGwQi1euxNtKBJH0RfUotCM+WZHxBljY5f31XKJqK hJOTvkqn1sbhr+y5eNAFZ3SfTZC8jwqCeGUSa83MhcC6xhXNBPIwbckOo17ovwjWAHz4 ZzwZhF+RB9Q/j/7Xto9iQnMERRzIAsIHo6g2ZtEamT8pjFUJTJPuJeQ6DFg2MSTYjbdv qX0QTUSHMDR/rI3HBYOeJaipjW0RBIHI0IxA28/JGlrCS8Iky4ZsrGetTg6dTzvvAYpt NxGI53ZAXGOzR82KnxU8P1+fk3qYplNLSXtWXdujXxWGna8ydw0uzFfWiNjALEEl512P BUpw== 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=wilCDEynqZbkhZw5c0fhbw3fOk7Rw6W8BTAGgqD4z4s=; fh=NErUFH/4K/5td6IQHgjAggJpB+xkVrnyVOKM6TqYXaQ=; b=tB6GmJKAUXbc7k1cd0p3I1ikJeXIQkZoFljvVhx0YJcX+6RoAdoIeaGXS0ReDVNXE4 A8Gr823iTtJazlD84WOHoLByuJhbetMPeawDP/ULVhK5Xj8+lV2FSBfnV3DIczKiqYwV ApHafjlLwKTQeowtDrxn2NEQfp/1lZLyHszFzBPTjCkJTJSWnyfGFpr1KKB4jFcFgV/w VRU0bDeYCSLFttdSxxfzlZrMG18WuGPaZz/vLNtXgPWk3Ww+UskI4L6wSjMLqmVnKtpu s9excjQPG3LfPe1ghyj8wJWQ4dZTIotP73ixp3IQiOBUSNIpDB2gnUsRTrr0fc+hPgcD atjw== 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 z5-20020a170902834500b001c9c967e77esi5904885pln.207.2023.12.11.04.03.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 04:03:29 -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 B320F8059E40; Mon, 11 Dec 2023 04:03:27 -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 S234889AbjLKMDR (ORCPT + 99 others); Mon, 11 Dec 2023 07:03:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234858AbjLKMCw (ORCPT ); Mon, 11 Dec 2023 07:02:52 -0500 Received: from mx9.didiglobal.com (mx9.didiglobal.com [111.202.70.124]) by lindbergh.monkeyblade.net (Postfix) with SMTP id DFD17130 for ; Mon, 11 Dec 2023 04:02:25 -0800 (PST) Received: from mail.didiglobal.com (unknown [10.79.65.12]) by mx9.didiglobal.com (MailData Gateway V2.8.8) with ESMTPS id 39CD418E5212AF; Mon, 11 Dec 2023 20:02:20 +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; Mon, 11 Dec 2023 20:02:19 +0800 Date: Mon, 11 Dec 2023 20:02:09 +0800 X-MD-Sfrom: tiozhang@didiglobal.com X-MD-SrcIP: 10.79.65.12 From: Tio Zhang To: , CC: , , , , , , , , , , , , , , Subject: [PATCH v4] sched/cputime: account ksoftirqd's time on SYSTEM in PREEMPT_RT Message-ID: <20231211120209.GA25877@didi-ThinkCentre-M930t-N000> Mail-Followup-To: bigeasy@linutronix.de, rostedt@goodmis.org, 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: <20231208092616.LcwLlOyE@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=-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]); Mon, 11 Dec 2023 04:03:27 -0800 (PST) In PREEMPT_RT kernel, we dont want ksoftirqd's time accounting on SOFTIRQ since it is available to the scheduler (while it is unpreemptable in mainline). So we put it into SYSTEM like any other task running in SYSTEM. With this patch, when ksoftirqd is taking CPU's time, we observe SYSTEM in /proc/stat would be bigger than before while SOFTIRQ would be less, which behaves in contract to mainline, but more suitable for PREEMPT_RT. Signed-off-by: Tio Zhang --- kernel/sched/cputime.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c index af7952f12e6c..6685bb46805d 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) && + (IS_ENABLED(CONFIG_PREEMPT_RT) || curr != this_cpu_ksoftirqd())) irqtime_account_delta(irqtime, delta, CPUTIME_SOFTIRQ); } @@ -391,7 +392,7 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick, cputime -= other; - if (this_cpu_ksoftirqd() == p) { + if (!IS_ENABLED(CONFIG_PREEMPT_RT) && this_cpu_ksoftirqd() == p) { /* * ksoftirqd time do not get accounted in cpu_softirq_time. * So, we have to handle it separately here. -- 2.17.1