Skip to content

Commit 4bdada7

Browse files
author
Peter Zijlstra
committed
sched: Simplify sched_exec()
Use guards to reduce gotos and simplify control flow. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Valentin Schneider <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 857d315 commit 4bdada7

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

kernel/sched/core.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5498,23 +5498,20 @@ unsigned int nr_iowait(void)
54985498
void sched_exec(void)
54995499
{
55005500
struct task_struct *p = current;
5501-
unsigned long flags;
5501+
struct migration_arg arg;
55025502
int dest_cpu;
55035503

5504-
raw_spin_lock_irqsave(&p->pi_lock, flags);
5505-
dest_cpu = p->sched_class->select_task_rq(p, task_cpu(p), WF_EXEC);
5506-
if (dest_cpu == smp_processor_id())
5507-
goto unlock;
5504+
scoped_guard (raw_spinlock_irqsave, &p->pi_lock) {
5505+
dest_cpu = p->sched_class->select_task_rq(p, task_cpu(p), WF_EXEC);
5506+
if (dest_cpu == smp_processor_id())
5507+
return;
55085508

5509-
if (likely(cpu_active(dest_cpu))) {
5510-
struct migration_arg arg = { p, dest_cpu };
5509+
if (unlikely(!cpu_active(dest_cpu)))
5510+
return;
55115511

5512-
raw_spin_unlock_irqrestore(&p->pi_lock, flags);
5513-
stop_one_cpu(task_cpu(p), migration_cpu_stop, &arg);
5514-
return;
5512+
arg = (struct migration_arg){ p, dest_cpu };
55155513
}
5516-
unlock:
5517-
raw_spin_unlock_irqrestore(&p->pi_lock, flags);
5514+
stop_one_cpu(task_cpu(p), migration_cpu_stop, &arg);
55185515
}
55195516

55205517
#endif

0 commit comments

Comments
 (0)