Re: [PATCH v2 2/2] sched_ext: Fix cpu_released while changing sched policy of the running task
From: 'Tejun Heo'
Date: Thu Jul 17 2025 - 17:49:39 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.
> 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?
Thanks.
--
tejun