diff --git a/src/runtime/proc.go b/src/runtime/proc.go index 766784c07ed..2399f0a1d3d 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -2231,11 +2231,14 @@ top: // Consider stealing timers from p2. // This call to checkTimers is the only place where // we hold a lock on a different P's timers. - // Lock contention can be a problem here, so avoid - // grabbing the lock if p2 is running and not marked - // for preemption. If p2 is running and not being - // preempted we assume it will handle its own timers. - if i > 2 && shouldStealTimers(p2) { + // Lock contention can be a problem here, so + // initially avoid grabbing the lock if p2 is running + // and is not marked for preemption. If p2 is running + // and not being preempted we assume it will handle its + // own timers. + // If we're still looking for work after checking all + // the P's, then go ahead and steal from an active P. + if i > 2 || (i > 1 && shouldStealTimers(p2)) { tnow, w, ran := checkTimers(p2, now) now = tnow if w != 0 && (pollUntil == 0 || w < pollUntil) {