mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: don't send preemption signal if there is a signal pending
If multiple threads call preemptone to preempt the same M, it may send many signals to the same M such that it hardly make progress, causing live-lock problem. Only send a signal if there isn't already one pending. Fixes #37741. Change-Id: Id94adb0b95acbd18b23abe637a8dcd81ab41b452 Reviewed-on: https://go-review.googlesource.com/c/go/+/223737 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
parent
6412750f32
commit
0c0e8f224d
2 changed files with 13 additions and 1 deletions
|
|
@ -539,6 +539,10 @@ type m struct {
|
||||||
// requested, but fails. Accessed atomically.
|
// requested, but fails. Accessed atomically.
|
||||||
preemptGen uint32
|
preemptGen uint32
|
||||||
|
|
||||||
|
// Whether this is a pending preemption signal on this M.
|
||||||
|
// Accessed atomically.
|
||||||
|
signalPending uint32
|
||||||
|
|
||||||
dlogPerM
|
dlogPerM
|
||||||
|
|
||||||
mOS
|
mOS
|
||||||
|
|
|
||||||
|
|
@ -333,6 +333,7 @@ func doSigPreempt(gp *g, ctxt *sigctxt) {
|
||||||
|
|
||||||
// Acknowledge the preemption.
|
// Acknowledge the preemption.
|
||||||
atomic.Xadd(&gp.m.preemptGen, 1)
|
atomic.Xadd(&gp.m.preemptGen, 1)
|
||||||
|
atomic.Store(&gp.m.signalPending, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
const preemptMSupported = pushCallSupported
|
const preemptMSupported = pushCallSupported
|
||||||
|
|
@ -359,7 +360,14 @@ func preemptM(mp *m) {
|
||||||
// required).
|
// required).
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if atomic.Cas(&mp.signalPending, 0, 1) {
|
||||||
|
// If multiple threads are preempting the same M, it may send many
|
||||||
|
// signals to the same M such that it hardly make progress, causing
|
||||||
|
// live-lock problem. Apparently this could happen on darwin. See
|
||||||
|
// issue #37741.
|
||||||
|
// Only send a signal if there isn't already one pending.
|
||||||
signalM(mp, sigPreempt)
|
signalM(mp, sigPreempt)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// sigFetchG fetches the value of G safely when running in a signal handler.
|
// sigFetchG fetches the value of G safely when running in a signal handler.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue