Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2713274pxb; Tue, 19 Jan 2021 04:24:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJx5p3SOiEtRR3zWIYn1EnFTTNeh38VgfrsLG3XK+N/GvXWKJV3F4Jg5w5wilt9/q4bXuqBh X-Received: by 2002:a05:6402:3192:: with SMTP id di18mr3058458edb.332.1611059064250; Tue, 19 Jan 2021 04:24:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611059064; cv=none; d=google.com; s=arc-20160816; b=lxXsrHNdcRvQFMbvWk2aa0/11qimHgdz07SiVg9VChrF0efxsbmIO43x199JXD/t2E zAy+l3uefDN7L17ylcgx7DX2PToqpgkJbHmA+JHB1v8/GfMWHpBcdaPmAJ9PFvb1RqVa MxNljQVeItn5JsuNT9Dh9Oxvu5CUwqlOpvvLIvg8PW74MOghD7DFyPgTr3HugJvRDd+k boigjHZG+ySc690GXLStpZAM09N8vF2JqLwDURSnY3PDPJDni57/X3OlT98t3Qh6WvDl 0QflBG5C/RX3g/rWX8U1UxNIB7U06O4LcSCftszuWdzHMr7zcD0NFjNuGiBTYsPxyYND RNTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=uI8GjfIfB+un1x/y3ECkKpERwX147z5af0ns4uCnw2M=; b=qnoMMYp0W1PR7UWta15nRp7KOv6uLmI1DcW6k0DvRLRNTx0c2XRO+QoS2zjmywE0jb 0BmP1n2F9zduVc4aMlvlziEMBnVWI911wyAlbDOY7J/uTwxD3YVaPrHt7Q2nV/nCXan/ Pbc9qg6vjtt80ej1oQ7h4YR/IO7nJMlx6Ym9NsNqR1HDrnjtFOpQRJlDMNnuLZkKSzXT m+u4OvQc83/Sr3/W617d+/IkzYlWgLe53kKij/w6cdOI7nHeSu8/yfdWxNgfoEf3Zr/9 58II1+6ltKy3TyAfubUH1h4mjMoayF9OYPF2BT+GVb0XKU0Tdnl3bZyQWabR4OMl4ik4 v9iA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b15si7917247ejc.100.2021.01.19.04.23.59; Tue, 19 Jan 2021 04:24:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391480AbhASLfN (ORCPT + 99 others); Tue, 19 Jan 2021 06:35:13 -0500 Received: from outbound-smtp38.blacknight.com ([46.22.139.221]:55355 "EHLO outbound-smtp38.blacknight.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390022AbhASLXK (ORCPT ); Tue, 19 Jan 2021 06:23:10 -0500 Received: from mail.blacknight.com (pemlinmail03.blacknight.ie [81.17.254.16]) by outbound-smtp38.blacknight.com (Postfix) with ESMTPS id 7C6222E22 for ; Tue, 19 Jan 2021 11:22:12 +0000 (GMT) Received: (qmail 4682 invoked from network); 19 Jan 2021 11:22:12 -0000 Received: from unknown (HELO stampy.112glenside.lan) (mgorman@techsingularity.net@[84.203.22.4]) by 81.17.254.9 with ESMTPA; 19 Jan 2021 11:22:12 -0000 From: Mel Gorman To: Peter Zijlstra , Ingo Molnar Cc: Vincent Guittot , Li Aubrey , Qais Yousef , LKML , Mel Gorman Subject: [PATCH 3/5] sched/fair: Make select_idle_cpu() proportional to cores Date: Tue, 19 Jan 2021 11:22:09 +0000 Message-Id: <20210119112211.3196-4-mgorman@techsingularity.net> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210119112211.3196-1-mgorman@techsingularity.net> References: <20210119112211.3196-1-mgorman@techsingularity.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Zijlstra (Intel) Instead of calculating how many (logical) CPUs to scan, compute how many cores to scan. This changes behaviour for anything !SMT2. Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Mel Gorman --- kernel/sched/core.c | 18 +++++++++++++----- kernel/sched/fair.c | 12 ++++++++++-- kernel/sched/sched.h | 2 ++ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 15d2562118d1..ada8faac2e4d 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -7444,11 +7444,19 @@ int sched_cpu_activate(unsigned int cpu) balance_push_set(cpu, false); #ifdef CONFIG_SCHED_SMT - /* - * When going up, increment the number of cores with SMT present. - */ - if (cpumask_weight(cpu_smt_mask(cpu)) == 2) - static_branch_inc_cpuslocked(&sched_smt_present); + do { + int weight = cpumask_weight(cpu_smt_mask(cpu)); + + if (weight > sched_smt_weight) + sched_smt_weight = weight; + + /* + * When going up, increment the number of cores with SMT present. + */ + if (weight == 2) + static_branch_inc_cpuslocked(&sched_smt_present); + + } while (0); #endif set_cpu_active(cpu, true); diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index c8d8e185cf3b..0811e2fe4f19 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -6010,6 +6010,8 @@ static inline int find_idlest_cpu(struct sched_domain *sd, struct task_struct *p DEFINE_STATIC_KEY_FALSE(sched_smt_present); EXPORT_SYMBOL_GPL(sched_smt_present); +int sched_smt_weight __read_mostly = 1; + static inline void set_idle_cores(int cpu, int val) { struct sched_domain_shared *sds; @@ -6124,6 +6126,8 @@ static int select_idle_smt(struct task_struct *p, struct sched_domain *sd, int t #else /* CONFIG_SCHED_SMT */ +#define sched_smt_weight 1 + static inline int select_idle_core(struct task_struct *p, struct sched_domain *sd, int target) { return -1; @@ -6136,6 +6140,8 @@ static inline int select_idle_smt(struct task_struct *p, struct sched_domain *sd #endif /* CONFIG_SCHED_SMT */ +#define sis_min_cores 2 + /* * Scan the LLC domain for idle CPUs; this is dynamically regulated by * comparing the average scan cost (tracked in sd->avg_scan_cost) against the @@ -6166,10 +6172,12 @@ static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, int t avg_cost = this_sd->avg_scan_cost + 1; span_avg = sd->span_weight * avg_idle; - if (span_avg > 4*avg_cost) + if (span_avg > sis_min_cores*avg_cost) nr = div_u64(span_avg, avg_cost); else - nr = 4; + nr = sis_min_cores; + + nr *= sched_smt_weight; time = cpu_clock(this); } diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 12ada79d40f3..29aabe98dd1d 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1107,6 +1107,8 @@ static inline void update_idle_core(struct rq *rq) __update_idle_core(rq); } +extern int sched_smt_weight; + #else static inline void update_idle_core(struct rq *rq) { } #endif -- 2.26.2