Skip to content

Conversation

cloehle
Copy link
Contributor

@cloehle cloehle commented Sep 4, 2025

The new scx_bpf_cpu_curr() is queued for v6.18.
Use them instead of the soon deprecated scx_bpf_cpu_rq().

Error handling (on NULL) is kept as is for the schedulers

This needs the queued:
https://lore.kernel.org/lkml/[email protected]/

Copy link
Contributor

@htejun htejun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, wait, you need to port the compat macro too.

@@ -325,13 +325,13 @@ static inline const struct cpumask *get_idle_smtmask(s32 cpu)
*/
static inline bool is_cpu_idle(s32 cpu)
{
struct rq *rq = scx_bpf_cpu_rq(cpu);
struct task_struct *p = __COMPAT_scx_bpf_cpu_curr(cpu);
Copy link
Contributor

@arighi arighi Sep 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add __COMPAT_scx_bpf_cpu_curr() https://git.kernel.org/pub/scm/linux/kernel/git/tj/sched_ext.git/tree/tools/sched_ext/include/scx/compat.bpf.h?h=for-6.18#n238 to scheds/include/scx/compat.bpf.h or this won't build.

Copy link
Contributor Author

@cloehle cloehle Sep 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I thought these were getting pulled in from the kernel source (at some point)?
Do we update both compat.bpf.h and common.h separately for kernel and scx repo?

Edit: Nevermind, I misunderstood the process, I've added the two commits (definitions and Andrea's compat helper) here now, i.e. this PR compiles and runs self-sufficient if the kernel includes the mentioned series.

return false;
}
return rq->curr->flags & PF_IDLE;
return !!(p->flags & PF_IDLE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we probably don't need !! here, since the result would be cast to bool anyway.

The new functions provide a safer way to access a rq or a remote
rq->curr respectively. They are both part of v6.18.

See kernel commits:
("sched_ext: Introduce scx_bpf_locked_rq()")
("sched_ext: Introduce scx_bpf_cpu_curr()")

Signed-off-by: Christian Loehle <[email protected]>
@cloehle cloehle force-pushed the cloehle/scx_bpf_cpu_rq-compat branch from 8d41e53 to 11bb34c Compare September 4, 2025 22:50
@multics69
Copy link
Contributor

Overall LGTM.

@cloehle cloehle force-pushed the cloehle/scx_bpf_cpu_rq-compat branch from 11bb34c to 9deff4b Compare September 4, 2025 23:32
@arighi arighi added this pull request to the merge queue Sep 6, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 6, 2025
Copy link
Contributor

@arighi arighi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... I'm a bit confused.

We have:

BTF_ID_FLAGS(func, scx_bpf_cpu_curr, KF_RET_NULL | KF_RCU)

I thought the verifier would complain if we try to use scx_bpf_cpu_curr() outside of a bpf_rcu_read_lock/unlock() section, which is exactly what we're doing here. But the verifier is still happy and the kernel is (correctly) complaining:

[    5.938735] =============================
[    5.939878] WARNING: suspicious RCU usage
[    5.941002] sched_ext: BPF scheduler "cosmos_1.0.2_gd0e71ca_x86_64_unknown_linux_gnu_debug" enabled
[    5.943254] 6.17.0-rc1 #1-NixOS Not tainted
[    5.944477] -----------------------------
[    5.945636] kernel/sched/ext.c:6415 suspicious rcu_dereference_check() usage!

So we can fix this PR adding the proper bpf_rcu_read_lock/unlock() around __COMPAT_scx_bpf_cpu_curr(), but I'd like to understand why the verifier is happy.

@etsal do you have any idea? Thanks.

Copy link
Contributor

@multics69 multics69 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! It looks good to me.

@cloehle cloehle force-pushed the cloehle/scx_bpf_cpu_rq-compat branch from 9deff4b to eb700fc Compare September 7, 2025 21:02
Introduce a compatibility helper that allows BPF schedulers to use
scx_bpf_cpu_curr() on older kernels.

See kernel commit
("sched_ext: Add compat helper for scx_bpf_cpu_curr()")

Signed-off-by: Andrea Righi <[email protected]>
Signed-off-by: Christian Loehle <[email protected]>
Use the new scx_bpf_cpu_curr() introduced in v6.18 as a safer way to
access rq->curr instead of the deprecated scx_bpf_cpu_rq().

Signed-off-by: Christian Loehle <[email protected]>
Use the new scx_bpf_cpu_curr() introduced in v6.18 as a safer way to
access rq->curr instead of the deprecated scx_bpf_cpu_rq().

Signed-off-by: Christian Loehle <[email protected]>
Use the new scx_bpf_cpu_curr() introduced in v6.18 as a safer way to
access rq->curr instead of the deprecated scx_bpf_cpu_rq().

Signed-off-by: Christian Loehle <[email protected]>
Use the new scx_bpf_cpu_curr() introduced in v6.18 as a safer way to
access rq->curr instead of the deprecated scx_bpf_cpu_rq().

Signed-off-by: Christian Loehle <[email protected]>
Use the new scx_bpf_cpu_curr() introduced in v6.18 as a safer way to
access rq->curr instead of the deprecated scx_bpf_cpu_rq().

Signed-off-by: Christian Loehle <[email protected]>
@cloehle cloehle force-pushed the cloehle/scx_bpf_cpu_rq-compat branch from eb700fc to 5cd7c5f Compare September 7, 2025 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants