Re: [PATCH v10 2/5] sched: CGroup tagging interface for core scheduling

From: Peter Zijlstra
Date: Thu Feb 04 2021 - 14:30:54 EST


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?

> +
> + task_rq_unlock(rq, p, &rf);
> +}