Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp17477953rwd; Tue, 27 Jun 2023 03:42:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5egicdXPpRet//zv7gZm/xgFcWR9UB3BzG2EaPauEQv0XAl30k8hiNLMyuRpDZwxydNONn X-Received: by 2002:a17:907:6e1a:b0:991:cfce:7a09 with SMTP id sd26-20020a1709076e1a00b00991cfce7a09mr4144951ejc.67.1687862558504; Tue, 27 Jun 2023 03:42:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687862558; cv=none; d=google.com; s=arc-20160816; b=tWu2rEiDaZJfjQxcMJU/2LA2xeM1XZLwRTXkrR2lb+U1pvjLBzCjNJHxM1kyj+vvmA 6Bo2TibXex8YZU2NudF1SHc3oeZeogW82ksE9pMn8iMcTs+f7Y1ZkWF68wArXIRytqeT dDyAJWq22Cp34Ozu4pQztuL4+2ZD5NluEEFKRQ1UXAAreFxHYHlYUfuN3s+o3D7f+ShC +0LPP3UfBV78aoc+JBg62xcfOtzzuvcyu/+DYOfxgwZ4TCceYHmmNFhORBbesikjVdS6 D+l0jsv1SGgnq6eTalHsh2nqMIpWtB6qE/aCsy5KMT/hQH/je5rCtMdkLljVeV7L2uoR Qxjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=4zqNnV0CnsHhr55I3vwqjRbQalEDsGW/EKXeK+n995M=; fh=dtz6Aw7qYep8b82Dourbax6NmQC5x4VYPXkRERim6dE=; b=Fj3Zdx4pCpdoR3Xh419+qROpJOSIPxHeLZpl/JKtneze0YgZkU44OluZuMgbVHkYCx PnViiTjHaUXcSGs5iLRwRImZ1tPbhl3dv3xeXsjq396+wsT6OTsTRMPUGNZ3wcEFUxEy Lvh0eCwA9EpOVJeNuZXvJIUXdTAYkg3We+t8Y9kc8hjp1HBGhPzTw3kEGaYfrHiOHY9J bOaRFlE4SRK9EhL35ZPTPg73h9Kuw5pb4uHGtPP+M5pyumiXM7s/nIXw0AMa7KTdawmO r+/gLjI/NUO3gljZrB//vsKYSQSoqzYupgyGnNO1vZVLLHsLY164qYUPACuRQYfc0nCN Porw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=d3LfQiug; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c4-20020a170906924400b00991e0192079si1955695ejx.891.2023.06.27.03.42.13; Tue, 27 Jun 2023 03:42:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=d3LfQiug; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230468AbjF0KMG (ORCPT + 99 others); Tue, 27 Jun 2023 06:12:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232059AbjF0KLh (ORCPT ); Tue, 27 Jun 2023 06:11:37 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D714AC9 for ; Tue, 27 Jun 2023 03:11:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=4zqNnV0CnsHhr55I3vwqjRbQalEDsGW/EKXeK+n995M=; b=d3LfQiugbqmzx8tRj/MqnprqiY CtmJtlHIYPjvPL03cg26fQq6KMctnn4cWPxE8M5pSIKauVRCqdY6J2ca7Ll7R/y+YYGCl78OIqZM7 tgSbot++XFu2Dm5DZkXSXmPw7Z3kp1FUdVI3APcs2hwIhD3ZAz3yPc8HKclx41jOf0/26ZK8FrSyw Yma1VMRQLWzSZO4i23TGAH/QlqsYQT5JH4NumfAxHVfYrqyp7tkImws/4icIXGv7bWL7L+GiEWXRq aEX8YvMHFLWQWMrAxOD8Z+0XAGhOwTiYzkiG5uFbu1e3qL26Dx0Cc0T9CbnowySEios30HoShs3BP 6157kKIQ==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qE5ex-004ds7-2s; Tue, 27 Jun 2023 10:10:56 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 5815F3002C5; Tue, 27 Jun 2023 12:10:54 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id F2A582435114E; Tue, 27 Jun 2023 12:10:53 +0200 (CEST) Date: Tue, 27 Jun 2023 12:10:53 +0200 From: Peter Zijlstra To: Aaron Lu Cc: Chen Yu , Vincent Guittot , Ingo Molnar , Juri Lelli , Deng Pan , tim.c.chen@intel.com, linux-kernel@vger.kernel.org, tianyou.li@intel.com, yu.ma@intel.com, lipeng.zhu@intel.com, Tim Chen Subject: Re: [PATCH v2] sched/task_group: Re-layout structure to reduce false sharing Message-ID: <20230627101053.GX4253@hirez.programming.kicks-ass.net> References: <20230621081425.420607-1-pan.deng@intel.com> <20230626054756.GA435374@ziqianlu-dell> <20230626125335.GA508448@ziqianlu-dell> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230626125335.GA508448@ziqianlu-dell> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 On Mon, Jun 26, 2023 at 08:53:35PM +0800, Aaron Lu wrote: > On Mon, Jun 26, 2023 at 03:52:17PM +0800, Chen Yu wrote: > > Besides the cache line alignment, if the task is not a rt one, > > why do we have to touch that, I wonder if the following change can avoid that: > > > > diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h > > index ec7b3e0a2b20..067f1310bad2 100644 > > --- a/kernel/sched/sched.h > > +++ b/kernel/sched/sched.h > > @@ -1958,8 +1958,10 @@ static inline void set_task_rq(struct task_struct *p, unsigned int cpu) > > #endif > > > > #ifdef CONFIG_RT_GROUP_SCHED > > - p->rt.rt_rq = tg->rt_rq[cpu]; > > - p->rt.parent = tg->rt_se[cpu]; > > + if (p->sched_class = &rt_sched_class) { > == :-) > > > + p->rt.rt_rq = tg->rt_rq[cpu]; > > + p->rt.parent = tg->rt_se[cpu]; > > + } > > #endif > > } > > If a task starts life as a SCHED_NORMAL one and then after some time > it's changed to a RT one, then during its next ttwu(), if it didn't > migrate, then set_task_rq() will not be called and p->rt.rt_rq will > keep as NULL which will cause problem when this task gets enqueued as > a rt one. > > The follow diff seems to cure this issue: > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index c7db597e8175..8c57148e668c 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -7801,6 +7801,20 @@ static int __sched_setscheduler(struct task_struct *p, > } > __setscheduler_uclamp(p, attr); > > +#ifdef CONFIG_RT_GROUP_SCHED > + /* > + * Make sure when this task becomes a rt one, > + * its rt fields have valid value. > + */ > + if (rt_prio(newprio)) { > + struct task_group *tg = task_group(p); > + int cpu = cpu_of(rq); > + > + p->rt.rt_rq = tg->rt_rq[cpu]; > + p->rt.parent = tg->rt_se[cpu]; > + } > +#endif > + > if (queued) { > /* > * We enqueue to tail when the priority of a task is > > But I'm not sure if it's worth the trouble. Not sufficient, you can become RT through PI and not pass __sched_setscheduler(). The common code-path in this case would be check_class_changed(), that's called for oth PI and __sched_setscheduler(). Anyway, not against this per-se, but RT_GROUP_SCHED is utter shite and nobody should be using it. Also, if there's no measurable performance gain (as stated elsewhere IIRC) we shouldn't be adding complexity.