Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp2454482rwb; Thu, 27 Jul 2023 07:28:48 -0700 (PDT) X-Google-Smtp-Source: APBJJlE6NrBaRV4owfcXO2pF3U+3u/mbbMgjvzJYWYMoMnGnowlFlXYr8mn3eco+Fg7nQSTygqFe X-Received: by 2002:a19:2d5e:0:b0:4fc:3755:37de with SMTP id t30-20020a192d5e000000b004fc375537demr1665192lft.3.1690468127705; Thu, 27 Jul 2023 07:28:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690468127; cv=none; d=google.com; s=arc-20160816; b=hKGlWPklabHViYCmSKhMjiel9lufUOOSx9QODdEIizHgIAFJ4f8dTPJT8tyNr5wUZv LOFnvwSDitJTYfznHjUND8FwRJ+8tkd9ffNJRHHWkfrfNq9ZdH8tr+xMlyttu4aMYPw2 fIvWTtDRJ4yuPN4M2zybw0Nt+HvXD4cZyU7EnfPsLcPUknFLdbmYdjBUFRtOfYDxfyHT 5gy0hbGpmQMc78UD8sLUaG+d13884v4oDkpyrDI9J0Mgl3QbvbC3j1AZ3qsEpN+j1nHs fGK9qmW3uYibNZxDONroL85eFUvn7oB/p2w8nn7yFshnng8iiJToB7wGG7zu3doqh6li AYzg== 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=B+oXy8/zh2jjtd/j00KzNZjlJiP6T7lRV0OGV/+3SWg=; fh=TtxqAhHph2OK0lnw0vDsktdK6hphIP9N62zKN22g+qE=; b=lkzr3Y+6R5EffdLYx1S8t25bomK1WQZFBLGEl8Dw8R+60+JaxbdA/Wnx5/tLTOSY9s ix7s4LLVQLOwaYdNN2pChp0isfbXnHvNjqbct2Bx1BmhJ2IB5EFZQqa9rHED5hOOKpMB e5sDD/a26YfJFFDUCbeA7u2JVrf2EHu0z5aCMZDCIe/oNib/AF1qiCuVAKj0H11yTJXm r7O24U0Amk0E3NUH/trrQ5bbn1M0sFbzxT3gI0YDvu85UR7eLdThWXS8Qx13ZeyEdA6m O8YAHuTlK6z3VbXXEgNCqSYp4oiwm7ZByjgFm++dA1+DEdUuwCT20pHJhAo8JljID5nr nswA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UNPdmmIM; 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 i26-20020a50fc1a000000b00522378a2e06si1106054edr.35.2023.07.27.07.28.21; Thu, 27 Jul 2023 07:28:47 -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=UNPdmmIM; 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 S233512AbjG0N6f (ORCPT + 99 others); Thu, 27 Jul 2023 09:58:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232141AbjG0N6c (ORCPT ); Thu, 27 Jul 2023 09:58:32 -0400 Received: from mgamail.intel.com (unknown [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C74E30D8 for ; Thu, 27 Jul 2023 06:58:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690466310; x=1722002310; h=message-id:subject:from:to:cc:date:in-reply-to: references:content-transfer-encoding:mime-version; bh=XN0HL492BWwqQUJmRY6mFdf1jif2qQBvqZI3+P1xBvo=; b=UNPdmmIMMZiE70aa6oon5YVgmyp+xFPIE71m9kIXndHMnbCteCO0vh3A DUNg/5lFHH+ESaL3ieWaoskaUoFzIptF+UyGGB1GIYYb/nXTMdHPS6m1R +d36qu4dI3nm19kI6zwVx4Zw0A1JodB81wiCQljgKmdt4jzZHoXy60yod 8UXIWD7PFGfMG8APSGdMxloKiFgwsiNMHxHFvF33jYO5GgF1BjSVfuUw8 Q4FXr8gHulHGH3+oYmY8xgQff6EFu0WRWbtDagsPxtMOfneTf8DlC2+dw /zqhKkfKgKaTOlS+nqfgrYEUgpY5wTyiW3J51dIk29QXnK/OTj2Y2D2Lb A==; X-IronPort-AV: E=McAfee;i="6600,9927,10784"; a="371005770" X-IronPort-AV: E=Sophos;i="6.01,235,1684825200"; d="scan'208";a="371005770" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jul 2023 06:33:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10784"; a="900884138" X-IronPort-AV: E=Sophos;i="6.01,235,1684825200"; d="scan'208";a="900884138" Received: from akhaw1-mobl2.gar.corp.intel.com (HELO [10.213.157.76]) ([10.213.157.76]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jul 2023 06:32:48 -0700 Message-ID: <6b20e0c0cd82d0d1aafc2a7fb14d9456e19c2c85.camel@linux.intel.com> Subject: Re: [PATCH] sched/fair: Add SMT4 group_smt_balance handling From: Tim Chen To: Shrikanth Hegde , peterz@infradead.org Cc: bristot@redhat.com, bsegall@google.com, dietmar.eggemann@arm.com, hdanton@sina.com, ionela.voinescu@arm.com, juri.lelli@redhat.com, len.brown@intel.com, linux-kernel@vger.kernel.org, mgorman@suse.de, naveen.n.rao@linux.vnet.ibm.com, rafael.j.wysocki@intel.com, ravi.v.shankar@intel.com, ricardo.neri@intel.com, rostedt@goodmis.org, srikar@linux.vnet.ibm.com, srinivas.pandruvada@linux.intel.com, v-songbaohua@oppo.com, vincent.guittot@linaro.org, vschneid@redhat.com, x86@kernel.org, yangyicong@hisilicon.com, yu.c.chen@intel.com Date: Thu, 27 Jul 2023 06:32:44 -0700 In-Reply-To: <804548a12363479d41dee19bb843002d9e105afd.camel@linux.intel.com> References: <20230717133718.GJ4253@hirez.programming.kicks-ass.net> <20230717145823.1531759-1-sshegde@linux.vnet.ibm.com> <804548a12363479d41dee19bb843002d9e105afd.camel@linux.intel.com> 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=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, 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 On Wed, 2023-07-26 at 20:11 -0700, Tim Chen wrote: > On Mon, 2023-07-17 at 20:28 +0530, Shrikanth Hegde wrote: > > From: Tim Chen > >=20 > > For SMT4, any group with more than 2 tasks will be marked as > > group_smt_balance. Retain the behaviour of group_has_spare by marking > > the busiest group as the group which has the least number of idle_cpus. > >=20 > > Also, handle rounding effect of adding (ncores_local + ncores_busy) > > when the local is fully idle and busy group has more than 2 tasks. > > Local group should try to pull at least 1 task in this case. > >=20 > > Originally-by: Tim Chen > > Signed-off-by: Tim Chen > > Signed-off-by: Shrikanth Hegde > > --- > > kernel/sched/fair.c | 13 ++++++++++++- > > 1 file changed, 12 insertions(+), 1 deletion(-) > >=20 > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > > index 932e7b78894a..9502013abe33 100644 > > --- a/kernel/sched/fair.c > > +++ b/kernel/sched/fair.c > > @@ -9532,7 +9532,7 @@ static inline long sibling_imbalance(struct lb_en= v *env, > > imbalance /=3D ncores_local + ncores_busiest; > >=20 > > /* Take advantage of resource in an empty sched group */ > > - if (imbalance =3D=3D 0 && local->sum_nr_running =3D=3D 0 && > > + if (imbalance <=3D 1 && local->sum_nr_running =3D=3D 0 && > > busiest->sum_nr_running > 1) > > imbalance =3D 2; > >=20 > > @@ -9720,6 +9720,17 @@ static bool update_sd_pick_busiest(struct lb_env= *env, > > break; > >=20 > > case group_smt_balance: > > + /* no idle cpus on both groups handled by group_fully_busy below */ > > + if (sgs->idle_cpus !=3D 0 || busiest->idle_cpus !=3D 0) { > > + if (sgs->idle_cpus > busiest->idle_cpus) > > + return false; > > + if (sgs->idle_cpus < busiest->idle_cpus) > > + return true; > > + if (sgs->sum_nr_running <=3D busiest->sum_nr_running) > > + return false; > > + } > > + break; Shrikanth and Peter, Sorry, I acked Shrikanth's fixup patch too quickly without seeing that Shri= kanth added a "break" in the patch above. My original code did not have that break sta= tement as I did intend the code to fall through to the "group_fully_busy" code path w= hen there are no idle cpus in both groups. To make the compiler happy and putt= ing in the correct logic, I refresh the patch as below. Thanks. Tim From: Tim Chen Date: Fri, 14 Jul 2023 16:09:30 -0700 Subject: [PATCH] sched/fair: Add SMT4 group_smt_balance handling For SMT4, any group with more than 2 tasks will be marked as group_smt_balance. Retain the behaviour of group_has_spare by marking the busiest group as the group which has the least number of idle_cpus. Also, handle rounding effect of adding (ncores_local + ncores_busy) when the local is fully idle and busy group has more than 2 tasks. Local group should try to pull at least 1 task in this case. Signed-off-by: Tim Chen --- kernel/sched/fair.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index a87988327f88..566686c5f2bd 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -9563,7 +9563,7 @@ static inline long sibling_imbalance(struct lb_env *e= nv, imbalance /=3D ncores_local + ncores_busiest; =20 /* Take advantage of resource in an empty sched group */ - if (imbalance =3D=3D 0 && local->sum_nr_running =3D=3D 0 && + if (imbalance <=3D 1 && local->sum_nr_running =3D=3D 0 && busiest->sum_nr_running > 1) imbalance =3D 2; =20 @@ -9751,6 +9751,20 @@ static bool update_sd_pick_busiest(struct lb_env *en= v, break; =20 case group_smt_balance: + /* no idle cpus on both groups handled by group_fully_busy below */ + if (sgs->idle_cpus !=3D 0 || busiest->idle_cpus !=3D 0) { + if (sgs->idle_cpus > busiest->idle_cpus) + return false; + if (sgs->idle_cpus < busiest->idle_cpus) + return true; + if (sgs->sum_nr_running <=3D busiest->sum_nr_running) + return false; + else + return true; + } + goto fully_busy; + break; + case group_fully_busy: /* * Select the fully busy group with highest avg_load. In @@ -9763,7 +9777,7 @@ static bool update_sd_pick_busiest(struct lb_env *env= , * select the 1st one, except if @sg is composed of SMT * siblings. */ - +fully_busy: if (sgs->avg_load < busiest->avg_load) return false; =20 --=20 2.32.0