mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: fix CPU underutilization
Runqempty is a critical predicate for scheduler. If runqempty spuriously returns true, then scheduler can fail to schedule arbitrary number of runnable goroutines on idle Ps for arbitrary long time. With the addition of runnext runqempty predicate become broken (can spuriously return true). Consider that runnext is not nil and the main array is empty. Runqempty observes that the array is empty, then it is descheduled for some time. Then queue owner pushes another element to the queue evicting runnext into the array. Then queue owner pops runnext. Then runqempty resumes and observes runnext is nil and returns true. But there were no point in time when the queue was empty. Fix runqempty predicate to not return true spuriously. Change-Id: Ifb7d75a699101f3ff753c4ce7c983cf08befd31e Reviewed-on: https://go-review.googlesource.com/20858 Reviewed-by: Austin Clements <austin@google.com> Run-TryBot: Dmitry Vyukov <dvyukov@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
499cd33719
commit
fcd7c02c70
3 changed files with 63 additions and 2 deletions
|
|
@ -553,6 +553,24 @@ func TestSchedLocalQueueSteal(t *testing.T) {
|
|||
runtime.RunSchedLocalQueueStealTest()
|
||||
}
|
||||
|
||||
func TestSchedLocalQueueEmpty(t *testing.T) {
|
||||
if runtime.NumCPU() == 1 {
|
||||
// Takes too long and does not trigger the race.
|
||||
t.Skip("skipping on uniprocessor")
|
||||
}
|
||||
defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(4))
|
||||
|
||||
// If runtime triggers a forced GC during this test then it will deadlock,
|
||||
// since the goroutines can't be stopped/preempted during spin wait.
|
||||
defer debug.SetGCPercent(debug.SetGCPercent(-1))
|
||||
|
||||
iters := int(1e5)
|
||||
if testing.Short() {
|
||||
iters = 1e2
|
||||
}
|
||||
runtime.RunSchedLocalQueueEmptyTest(iters)
|
||||
}
|
||||
|
||||
func benchmarkStackGrowth(b *testing.B, rec int) {
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue