Skip to content

Commit 8f42ced

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
sched: Drop rq->lock from sched_exec()
Since we can now call select_task_rq() and set_task_cpu() with only p->pi_lock held, and sched_exec() load-balancing has always been optimistic, drop all rq->lock usage. Oleg also noted that need_migrate_task() will always be true for current, so don't bother calling that at all. Reviewed-by: Frank Rowand <[email protected]> Signed-off-by: Peter Zijlstra <[email protected]> Cc: Mike Galbraith <[email protected]> Cc: Nick Piggin <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Andrew Morton <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent ab2515c commit 8f42ced

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

kernel/sched.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3465,27 +3465,22 @@ void sched_exec(void)
34653465
{
34663466
struct task_struct *p = current;
34673467
unsigned long flags;
3468-
struct rq *rq;
34693468
int dest_cpu;
34703469

3471-
rq = task_rq_lock(p, &flags);
3470+
raw_spin_lock_irqsave(&p->pi_lock, flags);
34723471
dest_cpu = p->sched_class->select_task_rq(p, SD_BALANCE_EXEC, 0);
34733472
if (dest_cpu == smp_processor_id())
34743473
goto unlock;
34753474

3476-
/*
3477-
* select_task_rq() can race against ->cpus_allowed
3478-
*/
3479-
if (cpumask_test_cpu(dest_cpu, &p->cpus_allowed) &&
3480-
likely(cpu_active(dest_cpu)) && need_migrate_task(p)) {
3475+
if (likely(cpu_active(dest_cpu))) {
34813476
struct migration_arg arg = { p, dest_cpu };
34823477

3483-
task_rq_unlock(rq, p, &flags);
3484-
stop_one_cpu(cpu_of(rq), migration_cpu_stop, &arg);
3478+
raw_spin_unlock_irqrestore(&p->pi_lock, flags);
3479+
stop_one_cpu(task_cpu(p), migration_cpu_stop, &arg);
34853480
return;
34863481
}
34873482
unlock:
3488-
task_rq_unlock(rq, p, &flags);
3483+
raw_spin_unlock_irqrestore(&p->pi_lock, flags);
34893484
}
34903485

34913486
#endif

0 commit comments

Comments
 (0)