Re: [PATCH 1/2] sched_ext: Add lazy preemption support

From: Andrea Righi

Date: Fri Sep 18 2026 - 02:28:18 EST


Hi Tejun,

On Thu, Sep 17, 2026 at 09:19:07AM -1000, Tejun Heo wrote:
> Hello, Andrea.
>
> Looks good overall. A few things:
>
> On Thu, Sep 17, 2026 at 09:02:52AM +0200, Andrea Righi wrote:
> > + /*
> > + * kick_one_cpu() clears the lazy bit of every cpu it visited
> > + * above; visit the remaining requests which contain lazy
> > + * preemption, see scx_kick_cpu().
> > + */
> > + for_each_cpu(cpu, pcpu->cpus_to_preempt_lazy)
> > + should_wait |= kick_one_cpu(cpu, pcpu, this_rq, ksyncs);
>
> Can this fold into the loop above with for_each_cpu_or()? As is, a
> lazy-only target keeps its cpus_to_kick_if_idle bit and gets locked a second
> time by the idle loop.

Good point, this also clears cpus_to_kick_if_idle for lazy-only targets and we
can avoid locking the rq again in the idle loop.

>
> > +__bpf_kfunc bool scx_bpf_task_set_slice_expiry(struct task_struct *p, bool lazy,
> > + const struct bpf_prog_aux *aux)
>
> The name reads a bit like it turns slice expiry on and off. Maybe something
> like scx_bpf_task_set_lazy_resched(), with the ops flag and the task field
> named to match?

Agreed, I like scx_bpf_task_set_lazy_resched() and at this point I'd also rename
the ops flag to SCX_OPS_LAZY_RESCHED.

>
> > + if (unlikely(flags & ~(SCX_KICK_IDLE | SCX_KICK_PREEMPT | SCX_KICK_WAIT |
> > + SCX_KICK_PREEMPT_LAZY))) {
> > + scx_error(sch, "invalid kick flags 0x%llx", flags);
> > + return;
> > + }
>
> Maybe add an enum with all the valid bits and test against that?

Ack.

>
> > + if (unlikely((flags & SCX_KICK_IDLE) &&
> > + (flags & (SCX_KICK_PREEMPT | SCX_KICK_PREEMPT_LAZY | SCX_KICK_WAIT)))) {
> > + scx_error(sch, "PREEMPT/WAIT cannot be used with SCX_KICK_IDLE");
> > + return;
> > + }
>
> Does this need to move out of the IDLE branch? It's two tests on IDLE instead
> of one, and as scx_error() aborts the scheduler anyway, the early return
> doesn't buy much.

Ok.

>
> > + * ops.enable(), after which scx_bpf_task_set_slice_expiry() may override
> > + * it per task.
> > + * A task in user space still reschedules on the way back from the tick; a
>
> Can you add a blank line between the paragraphs?

Ok.

>
> > + * compatibility wrapper is a no-op when the kfunc is unavailable. As with the
> > + * setters above, discard the kfunc's authority result for consistency.
> > + *
> > + * Keep the wrapper until pre-v7.4 kernels fall out of the sched_ext scheduler
> > + * support window.
> > + */
>
> Just noting the version it was added in is enough.

Ok.

Thanks for looking at this!
-Andrea