From: Andrea Righi <arighi@nvidia.com>
To: Tejun Heo <tj@kernel.org>, David Vernet <void@manifault.com>,
Changwoo Min <changwoo@igalia.com>
Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/6] sched_ext: idle: Refactor scx_select_cpu_dfl()
Date: Fri, 7 Mar 2025 21:01:04 +0100 [thread overview]
Message-ID: <20250307200502.253867-3-arighi@nvidia.com> (raw)
In-Reply-To: <20250307200502.253867-1-arighi@nvidia.com>
Make scx_select_cpu_dfl() more consistent with the other idle-related
APIs by returning a negative value when an idle CPU isn't found.
Signed-off-by: Andrea Righi <arighi@nvidia.com>
---
kernel/sched/ext.c | 9 +++++----
kernel/sched/ext_idle.c | 38 +++++++++++++++++++-------------------
kernel/sched/ext_idle.h | 2 +-
3 files changed, 25 insertions(+), 24 deletions(-)
diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index 5cd878bbd0e39..8c9f36baf7dfd 100644
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -3393,16 +3393,17 @@ static int select_task_rq_scx(struct task_struct *p, int prev_cpu, int wake_flag
else
return prev_cpu;
} else {
- bool found;
s32 cpu;
- cpu = scx_select_cpu_dfl(p, prev_cpu, wake_flags, 0, &found);
- p->scx.selected_cpu = cpu;
- if (found) {
+ cpu = scx_select_cpu_dfl(p, prev_cpu, wake_flags, 0);
+ if (cpu >= 0) {
p->scx.slice = SCX_SLICE_DFL;
p->scx.ddsp_dsq_id = SCX_DSQ_LOCAL;
__scx_add_event(SCX_EV_ENQ_SLICE_DFL, 1);
+ } else {
+ cpu = prev_cpu;
}
+ p->scx.selected_cpu = cpu;
if (rq_bypass)
__scx_add_event(SCX_EV_BYPASS_DISPATCH, 1);
diff --git a/kernel/sched/ext_idle.c b/kernel/sched/ext_idle.c
index 16981456ec1ed..4f8a6e46a37a4 100644
--- a/kernel/sched/ext_idle.c
+++ b/kernel/sched/ext_idle.c
@@ -418,15 +418,13 @@ void scx_idle_update_selcpu_topology(struct sched_ext_ops *ops)
* NOTE: tasks that can only run on 1 CPU are excluded by this logic, because
* we never call ops.select_cpu() for them, see select_task_rq().
*/
-s32 scx_select_cpu_dfl(struct task_struct *p, s32 prev_cpu, u64 wake_flags, u64 flags, bool *found)
+s32 scx_select_cpu_dfl(struct task_struct *p, s32 prev_cpu, u64 wake_flags, u64 flags)
{
const struct cpumask *llc_cpus = NULL;
const struct cpumask *numa_cpus = NULL;
int node = scx_cpu_node_if_enabled(prev_cpu);
s32 cpu;
- *found = false;
-
/*
* This is necessary to protect llc_cpus.
*/
@@ -465,7 +463,7 @@ s32 scx_select_cpu_dfl(struct task_struct *p, s32 prev_cpu, u64 wake_flags, u64
if (cpus_share_cache(cpu, prev_cpu) &&
scx_idle_test_and_clear_cpu(prev_cpu)) {
cpu = prev_cpu;
- goto cpu_found;
+ goto out_unlock;
}
/*
@@ -487,7 +485,7 @@ s32 scx_select_cpu_dfl(struct task_struct *p, s32 prev_cpu, u64 wake_flags, u64
(!(flags & SCX_PICK_IDLE_IN_NODE) || (waker_node == node)) &&
!cpumask_empty(idle_cpumask(waker_node)->cpu)) {
if (cpumask_test_cpu(cpu, p->cpus_ptr))
- goto cpu_found;
+ goto out_unlock;
}
}
@@ -502,7 +500,7 @@ s32 scx_select_cpu_dfl(struct task_struct *p, s32 prev_cpu, u64 wake_flags, u64
if (cpumask_test_cpu(prev_cpu, idle_cpumask(node)->smt) &&
scx_idle_test_and_clear_cpu(prev_cpu)) {
cpu = prev_cpu;
- goto cpu_found;
+ goto out_unlock;
}
/*
@@ -511,7 +509,7 @@ s32 scx_select_cpu_dfl(struct task_struct *p, s32 prev_cpu, u64 wake_flags, u64
if (llc_cpus) {
cpu = pick_idle_cpu_in_node(llc_cpus, node, SCX_PICK_IDLE_CORE);
if (cpu >= 0)
- goto cpu_found;
+ goto out_unlock;
}
/*
@@ -520,7 +518,7 @@ s32 scx_select_cpu_dfl(struct task_struct *p, s32 prev_cpu, u64 wake_flags, u64
if (numa_cpus) {
cpu = pick_idle_cpu_in_node(numa_cpus, node, SCX_PICK_IDLE_CORE);
if (cpu >= 0)
- goto cpu_found;
+ goto out_unlock;
}
/*
@@ -533,7 +531,7 @@ s32 scx_select_cpu_dfl(struct task_struct *p, s32 prev_cpu, u64 wake_flags, u64
*/
cpu = scx_pick_idle_cpu(p->cpus_ptr, node, flags | SCX_PICK_IDLE_CORE);
if (cpu >= 0)
- goto cpu_found;
+ goto out_unlock;
/*
* Give up if we're strictly looking for a full-idle SMT
@@ -550,7 +548,7 @@ s32 scx_select_cpu_dfl(struct task_struct *p, s32 prev_cpu, u64 wake_flags, u64
*/
if (scx_idle_test_and_clear_cpu(prev_cpu)) {
cpu = prev_cpu;
- goto cpu_found;
+ goto out_unlock;
}
/*
@@ -559,7 +557,7 @@ s32 scx_select_cpu_dfl(struct task_struct *p, s32 prev_cpu, u64 wake_flags, u64
if (llc_cpus) {
cpu = pick_idle_cpu_in_node(llc_cpus, node, 0);
if (cpu >= 0)
- goto cpu_found;
+ goto out_unlock;
}
/*
@@ -568,7 +566,7 @@ s32 scx_select_cpu_dfl(struct task_struct *p, s32 prev_cpu, u64 wake_flags, u64
if (numa_cpus) {
cpu = pick_idle_cpu_in_node(numa_cpus, node, 0);
if (cpu >= 0)
- goto cpu_found;
+ goto out_unlock;
}
/*
@@ -581,13 +579,8 @@ s32 scx_select_cpu_dfl(struct task_struct *p, s32 prev_cpu, u64 wake_flags, u64
*/
cpu = scx_pick_idle_cpu(p->cpus_ptr, node, flags);
if (cpu >= 0)
- goto cpu_found;
+ goto out_unlock;
- cpu = prev_cpu;
- goto out_unlock;
-
-cpu_found:
- *found = true;
out_unlock:
rcu_read_unlock();
@@ -819,6 +812,9 @@ __bpf_kfunc int scx_bpf_cpu_node(s32 cpu)
__bpf_kfunc s32 scx_bpf_select_cpu_dfl(struct task_struct *p, s32 prev_cpu,
u64 wake_flags, bool *is_idle)
{
+#ifdef CONFIG_SMP
+ s32 cpu;
+#endif
if (!ops_cpu_valid(prev_cpu, NULL))
goto prev_cpu;
@@ -829,7 +825,11 @@ __bpf_kfunc s32 scx_bpf_select_cpu_dfl(struct task_struct *p, s32 prev_cpu,
goto prev_cpu;
#ifdef CONFIG_SMP
- return scx_select_cpu_dfl(p, prev_cpu, wake_flags, 0, is_idle);
+ cpu = scx_select_cpu_dfl(p, prev_cpu, wake_flags, 0);
+ if (cpu >= 0) {
+ *is_idle = true;
+ return cpu;
+ }
#endif
prev_cpu:
diff --git a/kernel/sched/ext_idle.h b/kernel/sched/ext_idle.h
index 5c1db6b315f7a..511cc2221f7a8 100644
--- a/kernel/sched/ext_idle.h
+++ b/kernel/sched/ext_idle.h
@@ -27,7 +27,7 @@ static inline s32 scx_pick_idle_cpu(const struct cpumask *cpus_allowed, int node
}
#endif /* CONFIG_SMP */
-s32 scx_select_cpu_dfl(struct task_struct *p, s32 prev_cpu, u64 wake_flags, u64 flags, bool *found);
+s32 scx_select_cpu_dfl(struct task_struct *p, s32 prev_cpu, u64 wake_flags, u64 flags);
void scx_idle_enable(struct sched_ext_ops *ops);
void scx_idle_disable(void);
int scx_idle_init(void);
--
2.48.1
next prev parent reply other threads:[~2025-03-07 20:05 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-07 20:01 [PATCHSET v2 sched_ext/for-6.15] sched_ext: Enhance built-in idle selection with allowed CPUs Andrea Righi
2025-03-07 20:01 ` [PATCH 1/6] sched_ext: idle: Honor idle flags in the built-in idle selection policy Andrea Righi
2025-03-07 20:01 ` Andrea Righi [this message]
2025-03-07 20:01 ` [PATCH 3/6] sched_ext: idle: Introduce the concept of allowed CPUs Andrea Righi
2025-03-07 22:17 ` Tejun Heo
2025-03-08 6:48 ` Andrea Righi
2025-03-09 14:56 ` Tejun Heo
2025-03-09 15:39 ` Andrea Righi
2025-03-10 16:07 ` Tejun Heo
2025-03-10 17:15 ` Andrea Righi
2025-03-07 20:01 ` [PATCH 4/6] sched_ext: idle: Introduce scx_bpf_select_cpu_and() Andrea Righi
2025-03-07 20:01 ` [PATCH 5/6] selftests/sched_ext: Add test for scx_bpf_select_cpu_and() Andrea Righi
2025-03-07 20:01 ` [PATCH 6/6] sched_ext: idle: Deprecate scx_bpf_select_cpu_dfl() Andrea Righi
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=20250307200502.253867-3-arighi@nvidia.com \
--to=arighi@nvidia.com \
--cc=bpf@vger.kernel.org \
--cc=changwoo@igalia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tj@kernel.org \
--cc=void@manifault.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