Re: [PATCH v3 2/2] sched_ext: Add a selftest for scx_bpf_dsq_peek

Andrea Righi
2025-10-06T17:22:41Z

On Mon, Oct 06, 2025 at 06:17:50PM +0100, Christian Loehle wrote:
> On 10/6/25 18:04, Ryan Newton wrote:
> > From: Ryan Newton <newton@meta.com>
> >
> > Perform the most basic unit test: make sure an empty queue peeks as
> > empty, and when we put one element in the queue, make sure peek returns
> > that element.
> >
> > However, even this simple test is a little complicated by the different
> > behavior of scx_bpf_dsq_insert in different calling contexts:
> > - insert is for direct dispatch in enqueue
> > - insert is delayed when called from select_cpu
> >
> > In this case we split the insert and the peek that verifies the
> > result between enqueue/dispatch. As a second phase, we stress test by
> > performing many peeks on an array of user DSQs.
> >
> > Note: An alternative would be to call `scx_bpf_dsq_move_to_local` on an
> > empty queue, which in turn calls `flush_dispatch_buf`, in order to flush
> > the buffered insert. Unfortunately, this is not viable within the
> > enqueue path, as it attempts a voluntary context switch within an RCU
> > read-side critical section.
> >
> > Signed-off-by: Ryan Newton <newton@meta.com>
> > ---
> > kernel/sched/ext.c | 2 +
> > tools/testing/selftests/sched_ext/Makefile | 1 +
> > .../selftests/sched_ext/peek_dsq.bpf.c | 265 ++++++++++++++++++
> > tools/testing/selftests/sched_ext/peek_dsq.c | 230 +++++++++++++++
> > 4 files changed, 498 insertions(+)
> > create mode 100644 tools/testing/selftests/sched_ext/peek_dsq.bpf.c
> > create mode 100644 tools/testing/selftests/sched_ext/peek_dsq.c
> >
> > diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
> > index 6d3537e65001..ec7e791cd4c8 100644
> > --- a/kernel/sched/ext.c
> > +++ b/kernel/sched/ext.c
> > @@ -6120,6 +6120,7 @@ __bpf_kfunc struct task_struct *scx_bpf_dsq_peek(u64 dsq_id)
> > sch = rcu_dereference(scx_root);
> > if (unlikely(!sch))
> > return NULL;
> > +
>
> Accidental whitespace

Yeah, this should go in the previous patch.

>
> > if (unlikely(dsq_id & SCX_DSQ_FLAG_BUILTIN)) {
> > scx_error(sch, "peek disallowed on builtin DSQ 0x%llx", dsq_id);
> > return NULL;
> > @@ -6130,6 +6131,7 @@ __bpf_kfunc struct task_struct *scx_bpf_dsq_peek(u64 dsq_id)
> > scx_error(sch, "peek on non-existent DSQ 0x%llx", dsq_id);
> > return NULL;
> > }
> > +
>
> Accidental whitespace

Ditto.

>
> > return rcu_dereference(dsq->first_task);
> > }
> > [snip]

Thanks,
-Andrea