From patchwork Tue Nov 22 20:35:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Neri X-Patchwork-Id: 24548 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2424905wrr; Tue, 22 Nov 2022 12:30:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf4bu/nnp4rXW4fEpLjmZjch8XdsU0eVtcA3zqWHEzBUyPUpQPSWEJY0dbPSxCvirbWsHiId X-Received: by 2002:a50:ff0d:0:b0:461:c6e8:452e with SMTP id a13-20020a50ff0d000000b00461c6e8452emr12627199edu.298.1669149015080; Tue, 22 Nov 2022 12:30:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669149015; cv=none; d=google.com; s=arc-20160816; b=x91ZWMyRiz9b3SlrOWeNfN3by9kF6IM2XS2pCXhTQBwBxxjnG8rDYyPdYRSY9iMC5H AubpM75s42GFS6CKoAanToZ6McadU761CS0mRUhr3KDHD/1KXHSoNXjj/WBMoxvZe7Kp 5HzED1uu3XeL9LkDKxfDYlnTDZVTahLvwedu1PghJjx1tiHRjA7niUMpGis5ggSARqi+ Hqq6fKPzx+08uQdxqV+u2uns1R1lS76Er2Jct3vq+JY4lT9Sf6E/b9HprtMlgko+lXwF 4WAQont/sHr4ZLRzliOjhL5J39xNPXzChjDdsBsVw9GErJ/pTbOP0VePLDXm+uSZomhj 4h+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=qPGeA7JlzuAV3zVWS3gSd6xHntcrcFh/0jv3Qbp5gnI=; b=LfigE0yQPldWYHHMIZDo1ovM6l/q4qfx+s1xTtvYagZiPPwQCdyev20SG/j13hrp1w xRzJkaImRxccrs2qNb3S0Zg236x5nBywG9O/rrTMbH7SnWh3xOXxdxMztFEu5rBIbWPO X13rhrV6ws6ytW+QvxEC/5wypiLZFQHzftN7jUUJBdahTpFeUDwNj7/pu0BIFPAu7mXQ cCINYTyiQNYtFOcYJkasYXOGyprI6EyfBESEYoEQdJT9zp4aY87WUcPUTy9A2R4yR6X0 rSmDG2snYgYHZrxZcYyn0sIkHfWRlqFDG7H17JkTMmq/zJPS6wxeeTzR8GQz63TsqPUU MyBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MxSPRBvh; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jg27-20020a170907971b00b0073d81935416si15299232ejc.749.2022.11.22.12.29.50; Tue, 22 Nov 2022 12:30:15 -0800 (PST) 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=MxSPRBvh; 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 S234861AbiKVU2e (ORCPT + 99 others); Tue, 22 Nov 2022 15:28:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234490AbiKVU2O (ORCPT ); Tue, 22 Nov 2022 15:28:14 -0500 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FBB6165A6 for ; Tue, 22 Nov 2022 12:28:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669148894; x=1700684894; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=y/1MAtHpQYdgN3xn2hBOyK3a06TFyZ6nWBTd2NULu+4=; b=MxSPRBvh003O+2p68QIC1ZbnVoGu99y4zO9Yy24dMEH3kuTwg1Icre7+ uDKuvzxf3eCuDeyF9YK1i07kq+IddE+20oF8s7oJPrV7CCYBOzeKkWgQj FMqOqvYzzyOF/3GUulFs+iBLkZskZKp2GnSDeEslNnZ2TG6OSV/A18wku K6PFVnT+sBUZeZCwwjo1yUdvuIwZzxpNKSXXsy/iB/ufuEKPoecm48iDm 3F7/PFXNPKveqHQacpxV0IeK2bzGpzo9CeCcWW8rJ/k8VXzVij18OvEZ+ D831iiw0WsFamIkkW66TfCIuW0FOPLsrh9V5XmEG6WJHw/SRt+zleXnyn w==; X-IronPort-AV: E=McAfee;i="6500,9779,10539"; a="293616506" X-IronPort-AV: E=Sophos;i="5.96,185,1665471600"; d="scan'208";a="293616506" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Nov 2022 12:28:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10539"; a="816228127" X-IronPort-AV: E=Sophos;i="5.96,185,1665471600"; d="scan'208";a="816228127" Received: from ranerica-svr.sc.intel.com ([172.25.110.23]) by orsmga005.jf.intel.com with ESMTP; 22 Nov 2022 12:28:12 -0800 From: Ricardo Neri To: "Peter Zijlstra (Intel)" , Juri Lelli , Vincent Guittot Cc: Ricardo Neri , "Ravi V. Shankar" , Ben Segall , Daniel Bristot de Oliveira , Dietmar Eggemann , Len Brown , Mel Gorman , "Rafael J. Wysocki" , Srinivas Pandruvada , Steven Rostedt , Tim Chen , Valentin Schneider , x86@kernel.org, linux-kernel@vger.kernel.org, Ricardo Neri , "Tim C . Chen" Subject: [PATCH v2 2/7] sched: Prepare sched_asym_prefer() to handle idle state of SMT siblings Date: Tue, 22 Nov 2022 12:35:27 -0800 Message-Id: <20221122203532.15013-3-ricardo.neri-calderon@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221122203532.15013-1-ricardo.neri-calderon@linux.intel.com> References: <20221122203532.15013-1-ricardo.neri-calderon@linux.intel.com> 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,SPF_HELO_PASS, SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750229597858373862?= X-GMAIL-MSGID: =?utf-8?q?1750229597858373862?= The throughput of an SMT sibling decreases if one or more of its siblings are also busy. Idle, lower-priority cores can help. Thus, it is necessary to consider the idle state of the SMT siblings of CPUs when selecting by priority. In some cases, sched_asym_prefer() does not care about the idle state (when building sched domains or looking at the priority of the preferred CPU in a sched group). Add a new parameter to check the state of the SMT siblings of a CPU when applicable. While here, remove a spurious newline. Cc: Ben Segall Cc: Daniel Bristot de Oliveira Cc: Dietmar Eggemann Cc: Len Brown Cc: Mel Gorman Cc: Rafael J. Wysocki Cc: Srinivas Pandruvada Cc: Steven Rostedt Cc: Tim C. Chen Cc: Valentin Schneider Cc: x86@kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Ricardo Neri --- Changes since v1: * Introduced this patch --- kernel/sched/fair.c | 17 ++++++++++------- kernel/sched/sched.h | 8 ++++++-- kernel/sched/topology.c | 6 +++++- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 18c672ff39ef..d18947a9c03e 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -8921,7 +8921,7 @@ static bool asym_smt_can_pull_tasks(int dst_cpu, struct sd_lb_stats *sds, * can help if it has higher priority and is idle (i.e., * it has no running tasks). */ - return sched_asym_prefer(dst_cpu, sg->asym_prefer_cpu); + return sched_asym_prefer(dst_cpu, sg->asym_prefer_cpu, false); } /* @@ -8934,7 +8934,7 @@ static bool asym_smt_can_pull_tasks(int dst_cpu, struct sd_lb_stats *sds, * exactly one busy CPU. This covers SMT and non-SMT sched groups. */ if (sg_busy_cpus == 1 && !sds->local_stat.sum_nr_running) - return sched_asym_prefer(dst_cpu, sg->asym_prefer_cpu); + return sched_asym_prefer(dst_cpu, sg->asym_prefer_cpu, false); return false; #else @@ -8952,7 +8952,8 @@ sched_asym(struct lb_env *env, struct sd_lb_stats *sds, struct sg_lb_stats *sgs (group->flags & SD_SHARE_CPUCAPACITY)) return asym_smt_can_pull_tasks(env->dst_cpu, sds, sgs, group); - return sched_asym_prefer(env->dst_cpu, group->asym_prefer_cpu); + /* Neither env::dst_cpu nor group::asym_prefer_cpu have SMT siblings. */ + return sched_asym_prefer(env->dst_cpu, group->asym_prefer_cpu, false); } static inline bool @@ -9118,7 +9119,9 @@ static bool update_sd_pick_busiest(struct lb_env *env, case group_asym_packing: /* Prefer to move from lowest priority CPU's work */ - if (sched_asym_prefer(sg->asym_prefer_cpu, sds->busiest->asym_prefer_cpu)) + if (sched_asym_prefer(sg->asym_prefer_cpu, + sds->busiest->asym_prefer_cpu, + false)) return false; break; @@ -10060,7 +10063,7 @@ static struct rq *find_busiest_queue(struct lb_env *env, /* Make sure we only pull tasks from a CPU of lower priority */ if ((env->sd->flags & SD_ASYM_PACKING) && - sched_asym_prefer(i, env->dst_cpu) && + sched_asym_prefer(i, env->dst_cpu, true) && nr_running == 1) continue; @@ -10153,7 +10156,7 @@ asym_active_balance(struct lb_env *env) * highest priority CPUs. */ return env->idle != CPU_NOT_IDLE && (env->sd->flags & SD_ASYM_PACKING) && - sched_asym_prefer(env->dst_cpu, env->src_cpu); + sched_asym_prefer(env->dst_cpu, env->src_cpu, true); } static inline bool @@ -10889,7 +10892,7 @@ static void nohz_balancer_kick(struct rq *rq) * around. */ for_each_cpu_and(i, sched_domain_span(sd), nohz.idle_cpus_mask) { - if (sched_asym_prefer(i, cpu)) { + if (sched_asym_prefer(i, cpu, true)) { flags = NOHZ_STATS_KICK | NOHZ_BALANCE_KICK; goto unlock; } diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index a4a20046e586..0fc7c0130755 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -795,8 +795,12 @@ static inline long se_weight(struct sched_entity *se) return scale_load_down(se->load.weight); } - -static inline bool sched_asym_prefer(int a, int b) +/* + * Used to compare specific CPUs. Also when comparing the preferred CPU of a + * sched group or building the sched domains; in such cases checking the state + * of SMT siblings, if any, is not needed. + */ +static inline bool sched_asym_prefer(int a, int b, bool check_smt) { return arch_asym_cpu_priority(a) > arch_asym_cpu_priority(b); } diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index 8739c2a5a54e..8154ef590b9f 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -1282,7 +1282,11 @@ static void init_sched_groups_capacity(int cpu, struct sched_domain *sd) for_each_cpu(cpu, sched_group_span(sg)) { if (max_cpu < 0) max_cpu = cpu; - else if (sched_asym_prefer(cpu, max_cpu)) + /* + * We want the CPU priorities unaffected by the idle + * state of its SMT siblings, if any. + */ + else if (sched_asym_prefer(cpu, max_cpu, false)) max_cpu = cpu; } sg->asym_prefer_cpu = max_cpu;