Commit 9204a97f authored by Peter Zijlstra's avatar Peter Zijlstra

sched: Change wait_task_inactive()s match_state

Make wait_task_inactive()'s @match_state work like ttwu()'s @state.

That is, instead of an equal comparison, use it as a mask. This allows
matching multiple block conditions.

(removes the unlikely; it doesn't make sense how it's only part of the
condition)
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20220822114648.856734578@infradead.org
parent 1fbcaa92
...@@ -3294,7 +3294,7 @@ unsigned long wait_task_inactive(struct task_struct *p, unsigned int match_state ...@@ -3294,7 +3294,7 @@ unsigned long wait_task_inactive(struct task_struct *p, unsigned int match_state
* is actually now running somewhere else! * is actually now running somewhere else!
*/ */
while (task_on_cpu(rq, p)) { while (task_on_cpu(rq, p)) {
if (match_state && unlikely(READ_ONCE(p->__state) != match_state)) if (match_state && !(READ_ONCE(p->__state) & match_state))
return 0; return 0;
cpu_relax(); cpu_relax();
} }
...@@ -3309,7 +3309,7 @@ unsigned long wait_task_inactive(struct task_struct *p, unsigned int match_state ...@@ -3309,7 +3309,7 @@ unsigned long wait_task_inactive(struct task_struct *p, unsigned int match_state
running = task_on_cpu(rq, p); running = task_on_cpu(rq, p);
queued = task_on_rq_queued(p); queued = task_on_rq_queued(p);
ncsw = 0; ncsw = 0;
if (!match_state || READ_ONCE(p->__state) == match_state) if (!match_state || (READ_ONCE(p->__state) & match_state))
ncsw = p->nvcsw | LONG_MIN; /* sets MSB */ ncsw = p->nvcsw | LONG_MIN; /* sets MSB */
task_rq_unlock(rq, p, &rf); task_rq_unlock(rq, p, &rf);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment