mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Kenan.Liu" <Kenan.Liu@linux.alibaba.com>
To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com,
	vincent.guittot@linaro.org, dietmar.eggemann@arm.com,
	rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de,
	bristot@redhat.com, vschneid@redhat.com
Cc: luoben@linux.alibaba.com, linux-kernel@vger.kernel.org
Subject: [RFC PATCH 2/2] sched/fair: Export a param to control the traverse len when select idle cpu.
Date: Thu, 20 Jul 2023 16:34:13 +0800	[thread overview]
Message-ID: <1689842053-5291-3-git-send-email-Kenan.Liu@linux.alibaba.com> (raw)
In-Reply-To: <1689842053-5291-1-git-send-email-Kenan.Liu@linux.alibaba.com>

From: "Kenan.Liu" <Kenan.Liu@linux.alibaba.com>

The variable 'nr' decides the length of traverse when we try to find an
idle cpu in function select_idle_cpu(). A fixed value such as 4 may not
perform well in all scenes and may lead to un-acceptable overhead. Export
two sysctl parameters to enable adjustments.

Signed-off-by: Kenan.Liu <Kenan.Liu@linux.alibaba.com>
Signed-off-by: Ben Luo <luoben@linux.alibaba.com>
---
 kernel/sched/fair.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 63 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index ad7c93f..e10de3b 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -125,6 +125,9 @@
 static unsigned int normalized_sysctl_sched_wakeup_granularity	= 1000000UL;
 
 const_debug unsigned int sysctl_sched_migration_cost	= 500000UL;
+unsigned int __read_mostly sysctl_sched_idle_search_nr_default = 4;
+unsigned int __read_mostly sysctl_sched_idle_search_nr_threshold = 4;
+
 static bool smt_neighbour_topo;
 static bool core_smt_topo_detect;
 static unsigned int smt_nr_cpu = 2;
@@ -207,6 +210,50 @@ int __weak arch_asym_cpu_priority(int cpu)
 #endif
 
 #ifdef CONFIG_SYSCTL
+static int sched_set_idle_search_nr_default(struct ctl_table *table, int write, void *buffer,
+		size_t *lenp, loff_t *ppos)
+{
+	static DEFINE_MUTEX(mutex);
+	unsigned int old_nr;
+	int ret;
+
+	mutex_lock(&mutex);
+	old_nr = sysctl_sched_idle_search_nr_default;
+	ret = proc_douintvec(table, write, buffer, lenp, ppos);
+	if (!ret && write) {
+		if (sysctl_sched_idle_search_nr_default == 0) {
+			sysctl_sched_idle_search_nr_default = old_nr;
+			mutex_unlock(&mutex);
+			return -EINVAL;
+		}
+	}
+
+	mutex_unlock(&mutex);
+	return ret;
+}
+
+static int sched_set_idle_search_nr_threshold(struct ctl_table *table, int write, void *buffer,
+		size_t *lenp, loff_t *ppos)
+{
+	static DEFINE_MUTEX(mutex);
+	unsigned int old_threshold;
+	int ret;
+
+	mutex_lock(&mutex);
+	old_threshold = sysctl_sched_idle_search_nr_threshold;
+	ret = proc_douintvec(table, write, buffer, lenp, ppos);
+	if (!ret && write) {
+		if (sysctl_sched_idle_search_nr_threshold == 0) {
+			sysctl_sched_idle_search_nr_threshold = old_threshold;
+			mutex_unlock(&mutex);
+			return -EINVAL;
+		}
+	}
+
+	mutex_unlock(&mutex);
+	return ret;
+}
+
 static struct ctl_table sched_fair_sysctls[] = {
 	{
 		.procname       = "sched_child_runs_first",
@@ -235,6 +282,20 @@ int __weak arch_asym_cpu_priority(int cpu)
 		.extra1		= SYSCTL_ZERO,
 	},
 #endif /* CONFIG_NUMA_BALANCING */
+	{
+		.procname	= "sched_cfs_idle_search_nr_default",
+		.data		= &sysctl_sched_idle_search_nr_default,
+		.maxlen		= sizeof(unsigned int),
+		.mode		= 0644,
+		.proc_handler	= sched_set_idle_search_nr_default,
+	},
+	{
+		.procname	= "sched_cfs_idle_search_nr_threshold",
+		.data		= &sysctl_sched_idle_search_nr_threshold,
+		.maxlen		= sizeof(unsigned int),
+		.mode		= 0644,
+		.proc_handler	= sched_set_idle_search_nr_threshold,
+	},
 	{}
 };
 
@@ -7027,10 +7088,10 @@ static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, bool
 		avg_cost = this_sd->avg_scan_cost + 1;
 
 		span_avg = sd->span_weight * avg_idle;
-		if (span_avg > 4*avg_cost)
+		if (span_avg > sysctl_sched_idle_search_nr_threshold * avg_cost)
 			nr = div_u64(span_avg, avg_cost);
 		else
-			nr = 4;
+			nr = sysctl_sched_idle_search_nr_default;
 
 		time = cpu_clock(this);
 	}
-- 
1.8.3.1


  parent reply	other threads:[~2023-07-20  8:58 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-20  8:34 [RFC PATCH 0/2] Adjust CFS loadbalance to adapt QEMU CPU topology Kenan.Liu
2023-07-20  8:34 ` [RFC PATCH 1/2] sched/fair: Adjust CFS loadbalance for machine with qemu native " Kenan.Liu
2023-07-20  8:34 ` Kenan.Liu [this message]
2023-07-20  8:50 ` [RFC PATCH 0/2] Adjust CFS loadbalance to adapt QEMU " Peter Zijlstra
2023-07-21  2:58   ` Kenan.Liu
2023-07-21  8:33     ` Vincent Guittot
2023-07-21  9:13       ` Peter Zijlstra
2023-07-24  6:57         ` luoben
2023-07-24 14:07           ` Peter Zijlstra
2023-07-21  9:11     ` 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=1689842053-5291-3-git-send-email-Kenan.Liu@linux.alibaba.com \
    --to=kenan.liu@linux.alibaba.com \
    --cc=bristot@redhat.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luoben@linux.alibaba.com \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®