From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 338B0C77B73 for ; Tue, 30 May 2023 14:39:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232157AbjE3Ojn (ORCPT ); Tue, 30 May 2023 10:39:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232895AbjE3Ojh (ORCPT ); Tue, 30 May 2023 10:39:37 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C804125 for ; Tue, 30 May 2023 07:39:28 -0700 (PDT) Received: from canpemm500009.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4QVw221k4YzLnZf; Tue, 30 May 2023 22:36:26 +0800 (CST) Received: from [10.67.102.169] (10.67.102.169) by canpemm500009.china.huawei.com (7.192.105.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Tue, 30 May 2023 22:39:24 +0800 CC: , , , , , , , , , , , , , , , , , , , , <21cnbao@gmail.com>, , , Barry Song Subject: Re: [PATCH v8 2/2] sched/fair: Scan cluster before scanning LLC in wake-up path To: Peter Zijlstra References: <20230530070253.33306-1-yangyicong@huawei.com> <20230530070253.33306-3-yangyicong@huawei.com> <20230530115527.GC156198@hirez.programming.kicks-ass.net> From: Yicong Yang Message-ID: <8fcba5d4-eea5-d7c4-2bf7-482321b333b7@huawei.com> Date: Tue, 30 May 2023 22:39:24 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.5.1 MIME-Version: 1.0 In-Reply-To: <20230530115527.GC156198@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.102.169] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500009.china.huawei.com (7.192.105.203) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2023/5/30 19:55, Peter Zijlstra wrote: > On Tue, May 30, 2023 at 03:02:53PM +0800, Yicong Yang wrote: > >> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c >> index 373ff5f55884..b8c129ed8b47 100644 >> --- a/kernel/sched/fair.c >> +++ b/kernel/sched/fair.c >> @@ -6994,6 +6994,30 @@ static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, bool >> } >> } >> >> + if (static_branch_unlikely(&sched_cluster_active)) { >> + struct sched_domain *sdc = rcu_dereference(per_cpu(sd_cluster, target)); >> + >> + if (sdc) { >> + for_each_cpu_wrap(cpu, sched_domain_span(sdc), target + 1) { >> + if (!cpumask_test_cpu(cpu, cpus)) >> + continue; >> + >> + if (has_idle_core) { >> + i = select_idle_core(p, cpu, cpus, &idle_cpu); >> + if ((unsigned int)i < nr_cpumask_bits) >> + return i; >> + } else { >> + if (--nr <= 0) >> + return -1; >> + idle_cpu = __select_idle_cpu(cpu, p); >> + if ((unsigned int)idle_cpu < nr_cpumask_bits) >> + return idle_cpu; >> + } >> + } >> + cpumask_andnot(cpus, cpus, sched_domain_span(sdc)); >> + } >> + } > > Would not this: > > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -6994,6 +6994,29 @@ static int select_idle_cpu(struct task_s > } > } > > + if (static_branch_unlikely(&sched_cluster_active)) { > + struct sched_group *sg = sd->groups; > + if (sg->flags & SD_CLUSTER) { > + for_each_cpu_wrap(cpu, sched_group_span(sg), target+1) { > + if (!cpumask_test_cpu(cpu, cpus)) > + continue; > + > + if (has_idle_core) { > + i = select_idle_core(p, cpu, cpus, &idle_cpu); > + if ((unsigned)i < nr_cpumask_bits) > + return 1; > + } else { > + if (--nr <= 0) > + return -1; > + idle_cpu = __select_idle_cpu(cpu, p); > + if ((unsigned)idle_cpu < nr_cpumask_bits) > + return idle_cpu; > + } > + } > + cpumask_andnot(cpus, cpus, sched_group_span(sg)); > + } > + } > + > for_each_cpu_wrap(cpu, cpus, target + 1) { > if (has_idle_core) { > i = select_idle_core(p, cpu, cpus, &idle_cpu); > > also work? Then we can avoid the extra sd_cluster per-cpu variable. > I thought it will be fine since sg->flags is derived from the child domain. But practically it doesn't. Tested on a 2P Skylake server with no clusters, add some debug messages to see how sg->flags appears: diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index 69968ed9ffb9..5c443b74abf5 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -90,8 +90,8 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level, cpumask_or(groupmask, groupmask, sched_group_span(group)); - printk(KERN_CONT " %d:{ span=%*pbl", - group->sgc->id, + printk(KERN_CONT " %d:{ cluster: %s span=%*pbl", + group->sgc->id, group->flags & SD_CLUSTER ? "true" : "false", cpumask_pr_args(sched_group_span(group))); if ((sd->flags & SD_OVERLAP) && Unfortunately the result doesn't match what I expected, the MC domain's sg->flags still marked as cluster: [ 8.886099] CPU0 attaching sched-domain(s): [ 8.889539] domain-0: span=0,40 level=SMT [ 8.893538] groups: 0:{ cluster: false span=0 }, 40:{ cluster: false span=40 } [ 8.897538] domain-1: span=0-19,40-59 level=MC [ 8.901538] groups: 0:{ cluster: true span=0,40 cap=2048 }, 1:{ cluster: true span=1,41 cap=2048 }, 2:{ cluster: true span=2,42 cap=2048 }, 3:{ cluster: true span=3,43 cap=2048 }, 4:{ cluster: true span=4,44 cap=2048 }, 5:{ cluster: true span=5,45 cap=2048 }, 6:{ cluster: true span=6,46 cap=2048 }, 7:{ cluster: true span=7,47 cap=2048 }, 8:{ cluster: true span=8,48 cap=2048 }, 9:{ cluster: true span=9,49 cap=2048 }, 10:{ cluster: true span=10,50 cap=2048 }, 11:{ cluster: true span=11,51 cap=2048 }, 12:{ cluster: true span=12,52 cap=2048 }, 13:{ cluster: true span=13,53 cap=2048 }, 14:{ cluster: true span=14,54 cap=2048 }, 15:{ cluster: true span=15,55 cap=2048 }, 16:{ cluster: true span=16,56 cap=2048 }, 17:{ cluster: true span=17,57 cap=2048 }, 18:{ cluster: true span=18,58 cap=2048 }, 19:{ cluster: true span=19,59 cap=2048 } [ 8.905538] domain-2: span=0-79 level=NUMA [ 8.909538] groups: 0:{ cluster: false span=0-19,40-59 cap=40960 }, 20:{ cluster: false span=20-39,60-79 cap=40960 } I assume we didn't handle the sg->flags correctly on the domain degeneration. Simply checked the code seems we've already make sg->flags = 0 on degeneration, maybe I need to check where's wrong. Thanks, Yicong