Re: [PATCH 1/2] sched_ext: Add lazy preemption support
From: Tejun Heo
Date: Thu Sep 17 2026 - 15:37:20 EST
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.
> +__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?
> + 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?
> + 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.
> + * 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?
> + * 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.
Thanks.
--
tejun