RE: [PATCH v2 2/2] sched_ext: Fix cpu_released while changing sched policy of the running task
From: liuwenfang
Date: Fri Jul 18 2025 - 05:23:54 EST
> Hello,
>
> On Sat, Jun 28, 2025 at 07:20:59AM +0000, liuwenfang wrote:
> > static void switched_from_scx(struct rq *rq, struct task_struct *p)
> > {
> > + switch_class(rq, p, true);
> > +
> > scx_ops_disable_task(p);
> > }
>
> Hmm... but this function can be called when @p is not currently running from
> setscheduler() path, and it wouldn't make sense to call switch_class() during
> that.
Yeah, task_current(rq, p) should be checked here.
>
> > static void wakeup_preempt_scx(struct rq *rq, struct task_struct
> > *p,int wake_flags) {} -static void switched_to_scx(struct rq *rq,
> > struct task_struct *p) {}
> > +static void switched_to_scx(struct rq *rq, struct task_struct *p) {
> > + lockdep_assert_rq_held(rq);
> > +
> > + if (static_branch_unlikely(&scx_ops_cpu_preempt) &&
> > + unlikely(rq->scx.cpu_released)) {
> > + /*
> > + * If the previous sched_class for the current CPU was not SCX,
> > + * notify the BPF scheduler that it again has control of the
> > + * core. This callback complements ->cpu_release(), which is
> > + * emitted in switch_class().
> > + */
> > + if (SCX_HAS_OP(cpu_acquire))
> > + SCX_CALL_OP(SCX_KF_REST, cpu_acquire, rq, cpu_of(rq), NULL);
> > + rq->scx.cpu_released = false;
> > + }
> > +}
>
> Ditto. This should only apply if @p is current, right?
task_current(rq, p) should be added.
>
> Thanks.
>
> --
> Tejun
Thanks.
--
Wenfang