Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp37154214rwd; Tue, 11 Jul 2023 10:06:30 -0700 (PDT) X-Google-Smtp-Source: APBJJlFL4o7CfkO3EHbYCtYiPZOG7y8q8tMG79hDOT1P4fcthhu+D2+ErTvMnHoksw/l5OWT+CKd X-Received: by 2002:a17:902:f814:b0:1ad:f138:b2f6 with SMTP id ix20-20020a170902f81400b001adf138b2f6mr17200987plb.16.1689095189717; Tue, 11 Jul 2023 10:06:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689095189; cv=none; d=google.com; s=arc-20160816; b=xU3rjSTVzhi7P+d8fyz8+fQMEv1b0hR2c014T0OWbW1d84xnQUDnz/+pHmjnzKAsOq b601s+oElxxGQM6jhXght6ehUxGJ0qrKZNM4TgeLjqV3v2yYiRUH+qs+TZLLnBzlPrgQ KinaIN65ZzQLDB+t33ynecQFPUfbP5PAdqzujvACf6hwayFr+bfaFNkn0M7/qPX6YGFO pQmdylBcDfbvDToBMYfVqaMP2zUiB552fbmYX5PBRI53BY+SzeUXIyM1TZoZmWVVruBC 46LSVcNmF0XIx/9IdLFH/P6pvmgpe3tXIWy+5Iiic7h/1zLmpfuK3PX6/DUF6wXPrVW+ pPEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=UN85ICE+xLArR2hggD9TowNUniYHx8hG+Jj8mnDNG4A=; fh=FHz2JdmqxqOmF1AE2xeWGMCv1kNQeiXejnYifEwuwQw=; b=FvvtmL/wIZgqn1hTqrdumeS05bH+LA5Pg9E6/mIAuFLfoJwMni0L73tQ0XwGNXLEwB XJMmGLoKHp22PnxqBiIG9OwTvUhaEOmVQlOeP75Fz4HfwAg5IiLt5BniRjTyeYzQ/w0+ ht4depqL/R6EksectLfDqH9214RAjmYID856C/lVfhyoNy0dZ4HJXGSsScN+sgVbzv87 4C0gaH26lnKNWeOppNx2SSNGWQTG5AeGiSVhpf62OtuOwNh4OqAFUdUvxLNwSnpWz6IZ vZyMBklVQybU/qidEfhzxolt8u/qmgT9A0UmFd2CD10LViCWDuxAX849COx7Cyt9TkWG D08w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MHo83Ukw; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c3-20020a170903234300b001b8b2865f38si1913588plh.170.2023.07.11.10.06.16; Tue, 11 Jul 2023 10:06:29 -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=@intel.com header.s=Intel header.b=MHo83Ukw; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233191AbjGKQem (ORCPT + 99 others); Tue, 11 Jul 2023 12:34:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233133AbjGKQe1 (ORCPT ); Tue, 11 Jul 2023 12:34:27 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF947172A for ; Tue, 11 Jul 2023 09:33:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689093236; x=1720629236; h=message-id:subject:from:to:cc:date:in-reply-to: references:content-transfer-encoding:mime-version; bh=RqB/lQPtyNAxJD2ZFNWUjUErQGFsTV+U4+xcKMWsCRg=; b=MHo83UkwoHjbnVWWggVWwwClxdNpOTHuWsphgI/kqsdscKVo8b0VJVIq 2S468RjTboIDAnkfgBFdsHLjuK/FWCXOhZye1nxrcKh881x7qqWLCSGbG uSqwprxRlaC5i9mRpW+3mDHNXsgWuQv+93eCnZzGOg8OCTDFYQaXZDQL6 ybOkkOUP9EbFKA59decA8LYHirkgfKDwHWhbiwWCly0SqCfg2Jqef7UVy 2dLwATmIFj7KCOSoWSldddgTO1GFcVpAeckyKvMCXaXq0zq8HB4zDt8sX fETmDUtdhwra+uIXJ8nanBxszzh15RO1B6ciid0H0gpRgCQSFY/yLOxag w==; X-IronPort-AV: E=McAfee;i="6600,9927,10768"; a="364708090" X-IronPort-AV: E=Sophos;i="6.01,196,1684825200"; d="scan'208";a="364708090" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2023 09:32:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10768"; a="715204775" X-IronPort-AV: E=Sophos;i="6.01,196,1684825200"; d="scan'208";a="715204775" Received: from araquino-mobl2.amr.corp.intel.com (HELO [10.209.35.37]) ([10.209.35.37]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2023 09:32:54 -0700 Message-ID: <53b65a17a8900cbe5b7e42e599390d62434205d8.camel@linux.intel.com> Subject: Re: [Patch v3 2/6] sched/topology: Record number of cores in sched group From: Tim Chen To: Peter Zijlstra Cc: Juri Lelli , Vincent Guittot , Ricardo Neri , "Ravi V . Shankar" , Ben Segall , Daniel Bristot de Oliveira , Dietmar Eggemann , Len Brown , Mel Gorman , "Rafael J . Wysocki" , Srinivas Pandruvada , Steven Rostedt , Valentin Schneider , Ionela Voinescu , x86@kernel.org, linux-kernel@vger.kernel.org, Shrikanth Hegde , Srikar Dronamraju , naveen.n.rao@linux.vnet.ibm.com, Yicong Yang , Barry Song , Chen Yu , Hillf Danton Date: Tue, 11 Jul 2023 09:32:54 -0700 In-Reply-To: <20230711113158.GJ3062772@hirez.programming.kicks-ass.net> References: <04641eeb0e95c21224352f5743ecb93dfac44654.1688770494.git.tim.c.chen@linux.intel.com> <4797e9147143decf561ede6b7658721d05dda4dc.camel@linux.intel.com> <20230711113158.GJ3062772@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4 (3.44.4-2.fc36) MIME-Version: 1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, 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 Tue, 2023-07-11 at 13:31 +0200, Peter Zijlstra wrote: > On Mon, Jul 10, 2023 at 03:40:34PM -0700, Tim Chen wrote: > > On Fri, 2023-07-07 at 15:57 -0700, Tim Chen wrote: > > > From: Tim C Chen > > >=20 > > > When balancing sibling domains that have different number of cores, > > > tasks in respective sibling domain should be proportional to the numb= er > > > of cores in each domain. In preparation of implementing such a policy= , > > > record the number of tasks in a scheduling group. > >=20 > > Caught a typo. Should be "the number of cores" instead of > > "the number of tasks" in a scheduling group. > >=20 > > Peter, should I send you another patch with the corrected commit log? >=20 > I'll fix it up, already had to fix the patch because due to robot > finding a compile fail for SCHED_SMT=3Dn builds. >=20 >=20 >=20 > > > @@ -1275,14 +1275,22 @@ build_sched_groups(struct sched_domain *sd, i= nt cpu) > > > static void init_sched_groups_capacity(int cpu, struct sched_domain = *sd) > > > { > > > struct sched_group *sg =3D sd->groups; > > > + struct cpumask *mask =3D sched_domains_tmpmask2; > > > =20 > > > WARN_ON(!sg); > > > =20 > > > do { > > > - int cpu, max_cpu =3D -1; > > > + int cpu, cores =3D 0, max_cpu =3D -1; > > > =20 > > > sg->group_weight =3D cpumask_weight(sched_group_span(sg)); > > > =20 > > > + cpumask_copy(mask, sched_group_span(sg)); > > > + for_each_cpu(cpu, mask) { > > > + cores++; > #ifdef CONFIG_SCHED_SMT > > > + cpumask_andnot(mask, mask, cpu_smt_mask(cpu)); > #else > __cpumask_clear_cpu(cpu, mask); Thanks for fixing up the non SCHED_SMT. I think "__cpumask_clear_cpu(cpu, mask);" can be removed. Since we have already considered the CPU in the iterator, clearing it is unnecessay. So effectively for_each_cpu(cpu, mask) { cores++; } should be good enough for the non SCHED_SMT case. =20 Or replace the patch with the patch below so we don't have #ifdef in the middle of code body. Either way is fine. --- From 9f19714db69739a7985e46bc1f8334d70a69cf2e Mon Sep 17 00:00:00 2001 Message-Id: <9f19714db69739a7985e46bc1f8334d70a69cf2e.1689092923.git.tim.c.= chen@linux.intel.com> In-Reply-To: References: From: Tim C Chen Date: Wed, 17 May 2023 09:09:54 -0700 Subject: [Patch v3 2/6] sched/topology: Record number of cores in sched gro= up To: Peter Zijlstra Cc: Juri Lelli , Vincent Guittot , Ricardo Neri , Ravi V. Shankar , Ben Segall , Daniel Bristot de Oliveira , Diet= mar Eggemann , Len Brown , M= el Gorman , Rafael J. Wysocki , Srinivas Pandruvada , Steven Rostedt , Tim Chen , Valentin Schneider , Ionela Voinescu , x86@kerne= l.org, linux-kernel@vger.kernel.org, Shrikanth Hegde , Srikar Dronamraju , naveen.n.rao@linux.vnet.ibm.com, Yicong Yang <= yangyicong@hisilicon.com>, Barry Song , Chen Yu , Hillf Danton When balancing sibling domains that have different number of cores, tasks in respective sibling domain should be proportional to the number of cores in each domain. In preparation of implementing such a policy, record the number of cores in a scheduling group. Signed-off-by: Tim Chen --- kernel/sched/sched.h | 1 + kernel/sched/topology.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 3d0eb36350d2..5f7f36e45b87 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1860,6 +1860,7 @@ struct sched_group { atomic_t ref; =20 unsigned int group_weight; + unsigned int cores; struct sched_group_capacity *sgc; int asym_prefer_cpu; /* CPU of highest priority in group */ int flags; diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index 6d5628fcebcf..4ecdaef3f8ab 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -1262,6 +1262,26 @@ build_sched_groups(struct sched_domain *sd, int cpu) return 0; } =20 +#ifdef CONFIG_SCHED_SMT +static inline int sched_group_cores(struct sched_group *sg) +{ + struct cpumask *mask =3D sched_domains_tmpmask2; + int cpu, cores =3D 0; + + cpumask_copy(mask, sched_group_span(sg)); + for_each_cpu(cpu, mask) { + cores++; + cpumask_andnot(mask, mask, cpu_smt_mask(cpu)); + } + return cores; +} +#else +static inline int sched_group_cores(struct sched_group *sg) +{ + return sg->group_weight; +} +#endif + /* * Initialize sched groups cpu_capacity. * @@ -1282,6 +1302,7 @@ static void init_sched_groups_capacity(int cpu, struc= t sched_domain *sd) int cpu, max_cpu =3D -1; =20 sg->group_weight =3D cpumask_weight(sched_group_span(sg)); + sg->cores =3D sched_group_cores(sg); =20 if (!(sd->flags & SD_ASYM_PACKING)) goto next; --=20 2.32.0