Skip to content

Commit

Permalink
mutex: Don't spin when the owner CPU is offline or other weird cases
Browse files Browse the repository at this point in the history
Due to recent load-balancer changes that delay the task migration to
the next wakeup, the adaptive mutex spinning ends up in a live lock
when the owner's CPU gets offlined because the cpu_online() check
lives before the owner running check.

This patch changes mutex_spin_on_owner() to return 0 (don't spin) in
any case where we aren't sure about the owner struct validity or CPU
number, and if the said CPU is offline. There is no point going back &
re-evaluate spinning in corner cases like that, let's just go to
sleep.

Signed-off-by: Benjamin Herrenschmidt <[email protected]>
Signed-off-by: Peter Zijlstra <[email protected]>
LKML-Reference: <1271212509.13059.135.camel@pasglop>
Signed-off-by: Ingo Molnar <[email protected]>
  • Loading branch information
ozbenh authored and Ingo Molnar committed Apr 23, 2010
1 parent d5a3045 commit 4b40221
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions kernel/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -3780,7 +3780,7 @@ int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner)
* the mutex owner just released it and exited.
*/
if (probe_kernel_address(&owner->cpu, cpu))
goto out;
return 0;
#else
cpu = owner->cpu;
#endif
Expand All @@ -3790,14 +3790,14 @@ int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner)
* the cpu field may no longer be valid.
*/
if (cpu >= nr_cpumask_bits)
goto out;
return 0;

/*
* We need to validate that we can do a
* get_cpu() and that we have the percpu area.
*/
if (!cpu_online(cpu))
goto out;
return 0;

rq = cpu_rq(cpu);

Expand All @@ -3816,7 +3816,7 @@ int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner)

cpu_relax();
}
out:

return 1;
}
#endif
Expand Down

0 comments on commit 4b40221

Please sign in to comment.