Commit 7a50f766 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Ingo Molnar

sched: Simplify yield_to()

Use guards to reduce gotos and simplify control flow.
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 92c2ec5b
...@@ -8888,55 +8888,46 @@ int __sched yield_to(struct task_struct *p, bool preempt) ...@@ -8888,55 +8888,46 @@ int __sched yield_to(struct task_struct *p, bool preempt)
{ {
struct task_struct *curr = current; struct task_struct *curr = current;
struct rq *rq, *p_rq; struct rq *rq, *p_rq;
unsigned long flags;
int yielded = 0; int yielded = 0;
local_irq_save(flags); scoped_guard (irqsave) {
rq = this_rq(); rq = this_rq();
again: again:
p_rq = task_rq(p); p_rq = task_rq(p);
/* /*
* If we're the only runnable task on the rq and target rq also * If we're the only runnable task on the rq and target rq also
* has only one task, there's absolutely no point in yielding. * has only one task, there's absolutely no point in yielding.
*/ */
if (rq->nr_running == 1 && p_rq->nr_running == 1) { if (rq->nr_running == 1 && p_rq->nr_running == 1)
yielded = -ESRCH; return -ESRCH;
goto out_irq;
}
double_rq_lock(rq, p_rq); guard(double_rq_lock)(rq, p_rq);
if (task_rq(p) != p_rq) { if (task_rq(p) != p_rq)
double_rq_unlock(rq, p_rq); goto again;
goto again;
}
if (!curr->sched_class->yield_to_task) if (!curr->sched_class->yield_to_task)
goto out_unlock; return 0;
if (curr->sched_class != p->sched_class) if (curr->sched_class != p->sched_class)
goto out_unlock; return 0;
if (task_on_cpu(p_rq, p) || !task_is_running(p)) if (task_on_cpu(p_rq, p) || !task_is_running(p))
goto out_unlock; return 0;
yielded = curr->sched_class->yield_to_task(rq, p); yielded = curr->sched_class->yield_to_task(rq, p);
if (yielded) { if (yielded) {
schedstat_inc(rq->yld_count); schedstat_inc(rq->yld_count);
/* /*
* Make p's CPU reschedule; pick_next_entity takes care of * Make p's CPU reschedule; pick_next_entity
* fairness. * takes care of fairness.
*/ */
if (preempt && rq != p_rq) if (preempt && rq != p_rq)
resched_curr(p_rq); resched_curr(p_rq);
}
} }
out_unlock: if (yielded)
double_rq_unlock(rq, p_rq);
out_irq:
local_irq_restore(flags);
if (yielded > 0)
schedule(); schedule();
return yielded; return yielded;
......
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