All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tim Chen <tim.c.chen@linux.intel.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Tim Chen <tim.c.chen@linux.intel.com>,
	Arjan Van De Ven <arjan.van.de.ven@intel.com>,
	Ricardo Neri <ricardo.neri@intel.com>,
	Len Brown <len.brown@intel.com>,
	Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>,
	Artem Bityutskiy <artem.bityutskiy@linux.intel.com>,
	Chen Yu <yu.c.chen@intel.com>,
	Song Bao Hua <song.bao.hua@hisilicon.com>,
	yangyicong <yangyicong@huawei.com>,
	Michael Larabel <Michael@MichaelLarabel.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 5/5] scheduler: Default cluster scheduling to off on x86 hybrid CPU
Date: Fri,  3 Dec 2021 12:32:42 -0800	[thread overview]
Message-ID: <0c69821b57261c10818fba146bd31ea88bb41093.1638563225.git.tim.c.chen@linux.intel.com> (raw)
In-Reply-To: <cover.1638563225.git.tim.c.chen@linux.intel.com>

For x86 hybrid CPUs like Alder Lake, the order of CPU selection should
be based stricly on CPU priority.  Turn off cluster scheduling
to avoid interference with such CPU selection order.

Signed-off-by: Tim Chen <tim.c.chen@linux.intel.com>
---
 arch/x86/kernel/smpboot.c    | 18 ++++++++++++++++++
 drivers/base/arch_topology.c | 10 ++++++++++
 include/linux/topology.h     |  6 ++++++
 kernel/sched/topology.c      |  4 +++-
 4 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index bab5251f8e03..4aa1c859dcea 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -46,6 +46,7 @@
 #include <linux/sched/topology.h>
 #include <linux/sched/hotplug.h>
 #include <linux/sched/task_stack.h>
+#include <linux/sched/sysctl.h>
 #include <linux/percpu.h>
 #include <linux/memblock.h>
 #include <linux/err.h>
@@ -135,6 +136,23 @@ void arch_rebuild_cpu_topology(void)
 	x86_topology_update = false;
 }
 
+#ifdef CONFIG_SCHED_CLUSTER
+void arch_set_def_cluster_topology(void)
+{
+	/*
+	 * For hybrid CPUs, scheduling order between the CPUs should be
+	 * based strictly on CPU priority. Turn off cluster scheduling
+	 * for hybrid CPUs.
+	 */
+	if (sysctl_sched_cluster > 1) {
+		if (cpu_feature_enabled(X86_FEATURE_HYBRID_CPU))
+			sysctl_sched_cluster = 0;
+		else
+			sysctl_sched_cluster = 1;
+	}
+}
+#endif
+
 static inline void smpboot_setup_warm_reset_vector(unsigned long start_eip)
 {
 	unsigned long flags;
diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c
index bb129929410b..a3668cc4b727 100644
--- a/drivers/base/arch_topology.c
+++ b/drivers/base/arch_topology.c
@@ -18,6 +18,7 @@
 #include <linux/init.h>
 #include <linux/rcupdate.h>
 #include <linux/sched.h>
+#include <linux/sched/sysctl.h>
 
 static DEFINE_PER_CPU(struct scale_freq_data __rcu *, sft_data);
 static struct cpumask scale_freq_counters_mask;
@@ -213,6 +214,15 @@ void __weak arch_rebuild_cpu_topology(void)
 	update_topology = 0;
 }
 
+#ifdef CONFIG_SCHED_CLUSTER
+void __weak arch_set_def_cluster_topology(void)
+{
+	/* Use cluster topology by default unless disabled in boot option */
+	if (sysctl_sched_cluster > 1)
+		sysctl_sched_cluster = 1;
+}
+#endif
+
 /*
  * Updating the sched_domains can't be done directly from cpufreq callbacks
  * due to locking, so queue the work for later.
diff --git a/include/linux/topology.h b/include/linux/topology.h
index 42bcfd5d9fdb..87d893c05f0c 100644
--- a/include/linux/topology.h
+++ b/include/linux/topology.h
@@ -46,6 +46,12 @@
 int arch_update_cpu_topology(void);
 void arch_rebuild_cpu_topology(void);
 
+#ifdef CONFIG_SCHED_CLUSTER
+void arch_set_def_cluster_topology(void);
+#else
+static inline void arch_set_def_sched_cluster(void) { };
+#endif
+
 /* Conform to ACPI 2.0 SLIT distance definitions */
 #define LOCAL_DISTANCE		10
 #define REMOTE_DISTANCE		20
diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
index 087854d505f7..07dfc4666c09 100644
--- a/kernel/sched/topology.c
+++ b/kernel/sched/topology.c
@@ -1660,6 +1660,8 @@ void set_sched_cluster(void)
 {
 	struct sched_domain_topology_level *tl;
 
+	arch_set_def_cluster_topology();
+
 	for (tl = sched_domain_topology; tl->mask; tl++) {
 		if (tl->sd_flags && (tl->sd_flags() & SD_CLUSTER)) {
 			if (!sysctl_sched_cluster)
@@ -1672,7 +1674,7 @@ void set_sched_cluster(void)
 }
 
 /* set via /proc/sys/kernel/sched_cluster */
-unsigned int __read_mostly sysctl_sched_cluster = 1;
+unsigned int __read_mostly sysctl_sched_cluster = 2;
 
 static DEFINE_MUTEX(sched_cluster_mutex);
 int sched_cluster_handler(struct ctl_table *table, int write,
-- 
2.20.1


  parent reply	other threads:[~2021-12-03 21:31 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-03 20:32 [PATCH 0/5] Make Cluster Scheduling Configurable Tim Chen
2021-12-03 20:32 ` [PATCH 1/5] scheduler: Create SDTL_SKIP flag to skip topology level Tim Chen
2021-12-03 20:32 ` [PATCH 2/5] scheduler: Add SD_CLUSTER topology flag to cluster sched domain Tim Chen
2021-12-03 20:32 ` [PATCH 3/5] scheduler: Add runtime knob sysctl_sched_cluster Tim Chen
2021-12-03 20:32 ` [PATCH 4/5] scheduler: Add boot time enabling/disabling of cluster scheduling Tim Chen
2021-12-04  6:47   ` Yicong Yang
2021-12-03 20:32 ` Tim Chen [this message]
2021-12-04  9:14 ` [PATCH 0/5] Make Cluster Scheduling Configurable Peter Zijlstra
2021-12-06 18:42   ` Tim Chen
2021-12-06 22:05   ` Ricardo Neri
2021-12-07 15:49   ` Tim Chen
2021-12-08 21:27   ` [tip: sched/urgent] sched,x86: Don't use cluster topology for x86 hybrid CPUs tip-bot2 for Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0c69821b57261c10818fba146bd31ea88bb41093.1638563225.git.tim.c.chen@linux.intel.com \
    --to=tim.c.chen@linux.intel.com \
    --cc=Michael@MichaelLarabel.com \
    --cc=arjan.van.de.ven@intel.com \
    --cc=artem.bityutskiy@linux.intel.com \
    --cc=len.brown@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=ricardo.neri@intel.com \
    --cc=song.bao.hua@hisilicon.com \
    --cc=srinivas.pandruvada@linux.intel.com \
    --cc=yangyicong@huawei.com \
    --cc=yu.c.chen@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.