Skip to contentSkip to conversation

sched_ext: Fix dsp_local_on selftest on UP systems

PATCH Applied Andrea Righi 2 participants 5 messages Jan 25, 2025 – Jan 27, 2025

Subsystems (2)
lore
Share & tools
lore

Andrea Righi

author reviewer
#0 lore raw

cover sched_ext: Fix dsp_local_on selftest on UP systems

Introduce a new portable scx helper to check whether a task can migrate and use it in the dsp_local_on selftest, so that it can run also on UP systems.

Andrea Righi (2):
tools/sched_ext: Add helper to check task migration state
sched_ext: selftests/dsp_local_on: Fix selftest on UP systems

 tools/sched_ext/include/scx/common.bpf.h             | 11 +++++++++++
 tools/testing/selftests/sched_ext/dsp_local_on.bpf.c |  2 +-
 2 files changed, 12 insertions(+), 1 deletion(-)
author reviewer
#1 lore raw

PATCH 1/2 tools/sched_ext: Add helper to check task migration state

Introduce a new helper for BPF schedulers to determine whether a task can migrate or not (supporting both SMP and UP systems).

Fixes e9fe182772dc ("sched_ext: selftests/dsp_local_on: Fix sporadic failures")
---
 tools/sched_ext/include/scx/common.bpf.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
tools/sched_ext/include/scx/common.bpf.h +11 -0
index f3e15e9efa76..745440f38f84 100644
@@ -404,6 +404,17 @@ static __always_inline const struct cpumask *cast_mask(struct bpf_cpumask *mask)
 	return (const struct cpumask *)mask;
 }
 
+/*
+ * Return true if task @p cannot migrate to a different CPU, false
+ * otherwise.
+ */
+static bool is_migration_disabled(const struct task_struct *p)
+{
+	if (bpf_core_field_exists(p->migration_disabled))
+		return p->migration_disabled;
+	return false;
+}
+
 /* rcu */
 void bpf_rcu_read_lock(void) __ksym;
 void bpf_rcu_read_unlock(void) __ksym;
Signature · 1 line
2.48.1
author reviewer
#2 lore raw

PATCH v2 1/2 tools/sched_ext: Add helper to check task migration state

Introduce a new helper for BPF schedulers to determine whether a task can migrate or not (supporting both SMP and UP systems).

Fixes e9fe182772dc ("sched_ext: selftests/dsp_local_on: Fix sporadic failures")
---
 tools/sched_ext/include/scx/common.bpf.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

ChangeLog v1 -> v2:
- add missing inline

tools/sched_ext/include/scx/common.bpf.h +11 -0
index f3e15e9efa76..f254a39b86a5 100644
@@ -404,6 +404,17 @@ static __always_inline const struct cpumask *cast_mask(struct bpf_cpumask *mask)
 	return (const struct cpumask *)mask;
 }
 
+/*
+ * Return true if task @p cannot migrate to a different CPU, false
+ * otherwise.
+ */
+static inline bool is_migration_disabled(const struct task_struct *p)
+{
+	if (bpf_core_field_exists(p->migration_disabled))
+		return p->migration_disabled;
+	return false;
+}
+
 /* rcu */
 void bpf_rcu_read_lock(void) __ksym;
 void bpf_rcu_read_unlock(void) __ksym;
Signature · 1 line
2.48.1
author reviewer
#3 lore raw

PATCH 2/2 sched_ext: selftests/dsp_local_on: Fix selftest on UP systems

In reply to Andrea Righi

In UP systems p->migration_disabled is not available. Fix this by using the portable helper is_migration_disabled(p).

Fixes e9fe182772dc ("sched_ext: selftests/dsp_local_on: Fix sporadic failures")
---
 tools/testing/selftests/sched_ext/dsp_local_on.bpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/sched_ext/dsp_local_on.bpf.c +1 -1
index 758b479bd1ee..c02b2aa6fc64 100644
@@ -43,7 +43,7 @@ void BPF_STRUCT_OPS(dsp_local_on_dispatch, s32 cpu, struct task_struct *prev)
 	if (!p)
 		return;
 
-	if (p->nr_cpus_allowed == nr_cpus && !p->migration_disabled)
+	if (p->nr_cpus_allowed == nr_cpus && !is_migration_disabled(p))
 		target = bpf_get_prandom_u32() % nr_cpus;
 	else
 		target = scx_bpf_task_cpu(p);
Signature · 1 line
2.48.1
reviewer Applied
#4 lore raw
In reply to Andrea Righi
Quoted 6 lines · Andrea Righi

Introduce a new portable scx helper to check whether a task can migrate and use it in the dsp_local_on selftest, so that it can run also on UP systems.

Andrea Righi (2):
tools/sched_ext: Add helper to check task migration state
sched_ext: selftests/dsp_local_on: Fix selftest on UP systems

Ah, you already did.

Applied to sched_ext/for-6.14-fixes.

Thanks.

Signature · 1 line
tejun