On Thu, Feb 04, 2021 at 03:52:53PM +0100, Peter Zijlstra wrote:
> On Fri, Jan 22, 2021 at 08:17:01PM -0500, Joel Fernandes (Google) wrote:
> > +static void sched_core_update_cookie(struct task_struct *p, unsigned long 
> > cookie,
> > +                                enum sched_core_cookie_type cookie_type)
> > +{
> > +   struct rq_flags rf;
> > +   struct rq *rq;
> > +
> > +   if (!p)
> > +           return;
> > +
> > +   rq = task_rq_lock(p, &rf);
> > +
> > +   switch (cookie_type) {
> > +   case sched_core_task_cookie_type:
> > +           p->core_task_cookie = cookie;
> > +           break;
> > +   case sched_core_group_cookie_type:
> > +           p->core_group_cookie = cookie;
> > +           break;
> > +   default:
> > +           WARN_ON_ONCE(1);
> > +   }
> > +
> > +   /* Set p->core_cookie, which is the overall cookie */
> > +   __sched_core_update_cookie(p);
> > +
> > +   if (sched_core_enqueued(p)) {
> > +           sched_core_dequeue(rq, p);
> > +           if (!p->core_cookie) {
> > +                   task_rq_unlock(rq, p, &rf);
> > +                   return;
> > +           }
> > +   }
> > +
> > +   if (sched_core_enabled(rq) &&
> > +       p->core_cookie && task_on_rq_queued(p))
> > +           sched_core_enqueue(task_rq(p), p);
> > +
> > +   /*
> > +    * If task is currently running or waking, it may not be compatible
> > +    * anymore after the cookie change, so enter the scheduler on its CPU
> > +    * to schedule it away.
> > +    */
> > +   if (task_running(rq, p) || p->state == TASK_WAKING)
> > +           resched_curr(rq);
> 
> I'm not immediately seeing the need for that WAKING test. Since we're
> holding it's rq->lock, the only place that task can be WAKING is on the
> wake_list. And if it's there, it needs to acquire rq->lock to get
> enqueued, and rq->lock again to get scheduled.
> 
> What am I missing?

Hi Peter,

I did this way following a similar pattern in affine_move_task(). However, I
think you are right. Unlike in the case affine_move_task(), we have
schedule() to do the right thing for us in case of any races with wakeup. So
the TASK_WAKING test is indeed not needed and we can drop tha test. Apologies
for adding the extra test out of paranoia.

thanks,

 - Joel

Reply via email to