Re: [PATCH v7 16/23] sched: Add deactivated (sleeping) owner handling to find_proxy_task()

From: John Stultz
Date: Thu Jan 04 2024 - 18:25:53 EST


On Fri, Dec 22, 2023 at 12:33 AM Metin Kaya <metin.kaya@xxxxxxx> wrote:
> On 20/12/2023 12:18 am, John Stultz wrote:
> > @@ -3936,13 +4063,19 @@ void sched_ttwu_pending(void *arg)
> > update_rq_clock(rq);
> >
> > llist_for_each_entry_safe(p, t, llist, wake_entry.llist) {
> > + int wake_flags;
> > if (WARN_ON_ONCE(p->on_cpu))
> > smp_cond_load_acquire(&p->on_cpu, !VAL);
> >
> > if (WARN_ON_ONCE(task_cpu(p) != cpu_of(rq)))
> > set_task_cpu(p, cpu_of(rq));
> >
> > - ttwu_do_activate(rq, p, p->sched_remote_wakeup ? WF_MIGRATED : 0, &rf);
> > + wake_flags = p->sched_remote_wakeup ? WF_MIGRATED : 0;
> > + ttwu_do_activate(rq, p, wake_flags, &rf);
> > + rq_unlock(rq, &rf);
> > + activate_blocked_entities(rq, p, wake_flags);
>
> I'm unsure if it's a big deal, but IRQs are disabled here and
> activate_blocked_entities() disables them again.

Yeah. activate_blocked_entities() is also called from try_to_wakeup()
where we don't have irqs disabled, so we still need to make sure irqs
are off there.
But activate_blocked_entities does irqsave/restore so it should safely
put us back to the proper state. We could rq_unlock_irqrestore() in
the above, but it seems silly to enable irqs here just to disable them
shortly after.

But let me know if it seems I didn't quite get your concern here.


> > @@ -6663,19 +6797,6 @@ proxy_resched_idle(struct rq *rq, struct task_struct *next)
> > return rq->idle;
> > }
> >
> > -static bool proxy_deactivate(struct rq *rq, struct task_struct *next)
> > -{
> > - unsigned long state = READ_ONCE(next->__state);
> > -
> > - /* Don't deactivate if the state has been changed to TASK_RUNNING */
> > - if (state == TASK_RUNNING)
> > - return false;
> > - if (!try_to_deactivate_task(rq, next, state, true))
>
> Now we can drop the last argument (deactivate_cond) of
> try_to_deactivate_task() since it can be determined via
> !task_is_blocked(p) I think. IOW:

True. I'll add that into the "Drop proxy_deactivate" patch in my
fine-grained series.

Thanks again for the feedback!
-john