Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1850172rdb; Thu, 7 Dec 2023 10:18:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IEQG86qQfPUBNtes1Sks18B8JTiPop8Qc28kmavLtKmSzpbig/rb4aOMPhOTQ/8E0taSodJ X-Received: by 2002:a17:902:d2cb:b0:1d0:8db6:17d0 with SMTP id n11-20020a170902d2cb00b001d08db617d0mr2868895plc.25.1701973087370; Thu, 07 Dec 2023 10:18:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701973087; cv=none; d=google.com; s=arc-20160816; b=SKnXIwrbqmTIqietpKzEXsv8sJwE4ull+7JgZDJV9jSzm+Y5MZiL+0sY7b8DS6g9Rl zcGCJ38qLBlmU+Y10EaQSAljk/GGeur+wqVOTr6Nf6Gk2Ez9uNDLNdZiOZRfkWUj9/eV vDQ3qYgJ+j7RdKkvPzUv4G6KM6SnG9Rg2PC9IeQK+AYw32fD02/eBYZpwCuq1kC1zC7y vehtkRr/S2zsSEt++4DthYAcflVU7YBoA1HuIWkuNi0a22t9VWAImT8woIk/8cY/Ggsa H7R9yGKaKX20EVBaMbeiG699jtZJtAdf0hdtH6vxh/BLrJxI3P1FHBoP+al0nA/omgKb e3Nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=F6/RdJqaTCDJBuQvr6Q6kW0BAYj0C3Z2spwk50Idsyg=; fh=v69VnqqMwJ+0FbOnFEBo6POn6bgnTVenb7+x/6f09Nk=; b=hyrl+T1ut7+/lJw9YqALVs8ZEWK9kUrIP8ZnTPlEWQEvtSjGc3+OSCxTYtuZfPDkDU PEKHMJ/HMNZWbBI/YmSZWrO6Dn1IExErs08oyTHqv+zNMPlwkBNBJF6RBi/5lZ6uCnuS oA+7nIvsGmEBGp0HvfU0q1bn+6QXsmSihW7P6pN2ehVLReo7AdV6UmQrUYf64j7T6ZD0 izvJBhOGHsmw9/pihEFabniOMxlkFEEzrQa87xgcvfaS/uhREZ70YcWFOidu0nSnW6bK 8iCJj7zzcBb2hC3nJC7ATM76moVoV0uJLuCmt3YeKuD6Ajs6I0GqV+QTrSxkgNp0hRdb VVRw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id z1-20020a17090abd8100b002773d013d02si1460879pjr.140.2023.12.07.10.17.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 10:18:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 0D436802A3EA; Thu, 7 Dec 2023 10:17:57 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443685AbjLGSRh convert rfc822-to-8bit (ORCPT + 99 others); Thu, 7 Dec 2023 13:17:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1443464AbjLGSRg (ORCPT ); Thu, 7 Dec 2023 13:17:36 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B03A6170C for ; Thu, 7 Dec 2023 10:17:42 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1125C433C8; Thu, 7 Dec 2023 18:17:40 +0000 (UTC) Date: Thu, 7 Dec 2023 13:18:11 -0500 From: Steven Rostedt To: Yuanhan Zhang Cc: Sebastian Andrzej Siewior , zyhtheonly@yeah.net, tglx@linutronix.de, mingo@redhat.com, Venkatesh Pallipadi , 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 Subject: Re: [PATCH v3] sched/cputime: let ktimers align with ksoftirqd in accounting CPUTIME_SOFTIRQ Message-ID: <20231207131811.08145840@gandalf.local.home> In-Reply-To: References: <20231201073240.T9bFNCkU@linutronix.de> <20231201080522.GA31309@didi-ThinkCentre-M930t-N000> <20231201161640.Z0cJLUi3@linutronix.de> <20231205153146.OSpCIs1G@linutronix.de> <20231207103536.30ae05aa@gandalf.local.home> X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT 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 groat.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 (groat.vger.email [0.0.0.0]); Thu, 07 Dec 2023 10:17:57 -0800 (PST) On Thu, 7 Dec 2023 12:19:28 -0500 Yuanhan Zhang wrote: > Hi, > > Steven Rostedt 于2023年12月7日周四 10:35写道: > > > > On Thu, 7 Dec 2023 18:43:47 +0800 > > Yuanhan Zhang wrote: > > > > > It results in if we do not handle ksoftirqd like this, we will have a > > > bigger SYSTEM and less SOFTIRQ. > > > > And honestly that's what we want. Interrupts and softirqs that execute in > > interrupts and softirq context take away from the system. That is, if they > > are not explicitly blocked (local_irq_disable/local_bh_disable) they > > interrupt the current task and take up the time of the current task. We > > need to differentiate this because this context has no "task" context to > > measure. > > > > We do not want to add ksoftirqd or threaded interrupt handlers / softirqs > > to this measurement. Sure, they are handling interrupt and softirq code, > > but they have their own context that can be measured like any other task. > > > > If we blur this with real irqs and softirqs, then we will not know what > > those real irqs and softirqs are measuring. > > Yes you say clearly enough and it makes some sense to me! > So my understanding is that in PREEMPT_RT, it is better to put ksoftirqd's time > into SYSTEM since they are just in their "task" context. > > If my understanding is right, how about we just exclude ksoftirqd > like what I do in the last email? > (something like > else if (in_serving_softirq() && > (IS_ENABLED(CONFIG_PREEMPT_RT) || curr != this_cpu_ksoftirqd())) > > If this looks okay to you, I'm happy to send a new patch for this :) Hmm, looking at the code in mainline, I may have misspoken. Although, honestly, I don't know why we want this. In irqtime_account_process_tick() there's: if (this_cpu_ksoftirqd() == p) { /* * ksoftirqd time do not get accounted in cpu_softirq_time. * So, we have to handle it separately here. * Also, p->stime needs to be updated for ksoftirqd. */ account_system_index_time(p, cputime, CPUTIME_SOFTIRQ); Which to me looks like it is counting ksoftirqd for SOFTIRQ time. But honestly, why do we care about that? What's the difference if ksoftirqd were to run or softirqd were to pass work off to a workqueue? ksoftirqd runs in vanilla Linux as SCHED_OTHER. The work it does doesn't interrupt processes any more than any other kernel thread. I don't know why we make it "special". I guess the better question I need to ask is, what is this information used for? I thought it was how much time was take away from tasks. As current would be a task, and we do care if a real softirq is running, as we do not want to add that to the current task accounting. But for ksoftirqd, that's not the case, and I don't really care if it's running a softirq or not. As that time isn't interrupting actual tasks. Not to mention, one could simply look at the ksoftirqd tasks to see how much time they take up. > > > > > > So my point is if we do not align ktimers, ktimers would act like > > > **observation on *not-excluded ksoftirq patched* kernel** part in the > > > above example, > > > and this might make SOFTIRQ less than expected, /proc/stat less accurate. > > > > No it does not. When a softirq kicks off it's work to a thread (ksoftirq, > > threaded softirqd, or simply a workqueue), it's no longer running in > > softirq context, and should not be measured as such. > > > > The measurement is not about how much work the softirq is doing (otherwise > > we need to add workqueues started by softirqs too), it's about measuring > > the actual irq and softirq context. In PREEMPT_RT, we try to eliminate that > > context as much as possible. > > Thanks anyway, I think I begin to learn a bit more about PREEMPT_RT... Well, I may have been wrong in this information. I would like to know who is using this information and for what purpose. Ideally, I would love to make ksoftirqd *not* report its time as handling SOFTIRQ. -- Steve