Commit 4bdada79 authored by Peter Zijlstra's avatar Peter Zijlstra
Browse files

sched: Simplify sched_exec()



Use guards to reduce gotos and simplify control flow.

Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: default avatarValentin Schneider <vschneid@redhat.com>
Link: https://lore.kernel.org/r/20230801211812.168490417@infradead.org
parent 857d315f
Loading
Loading
Loading
Loading
+9 −12
Original line number Diff line number Diff line
@@ -5498,23 +5498,20 @@ unsigned int nr_iowait(void)
void sched_exec(void)
{
	struct task_struct *p = current;
	unsigned long flags;
	struct migration_arg arg;
	int dest_cpu;

	raw_spin_lock_irqsave(&p->pi_lock, flags);
	scoped_guard (raw_spinlock_irqsave, &p->pi_lock) {
		dest_cpu = p->sched_class->select_task_rq(p, task_cpu(p), WF_EXEC);
		if (dest_cpu == smp_processor_id())
		goto unlock;

	if (likely(cpu_active(dest_cpu))) {
		struct migration_arg arg = { p, dest_cpu };
			return;

		raw_spin_unlock_irqrestore(&p->pi_lock, flags);
		stop_one_cpu(task_cpu(p), migration_cpu_stop, &arg);
		if (unlikely(!cpu_active(dest_cpu)))
			return;

		arg = (struct migration_arg){ p, dest_cpu };
	}
unlock:
	raw_spin_unlock_irqrestore(&p->pi_lock, flags);
	stop_one_cpu(task_cpu(p), migration_cpu_stop, &arg);
}

#endif