aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/proc.go
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2021-12-07 09:22:33 -0800
committerKeith Randall <khr@golang.org>2022-03-01 18:43:08 +0000
commit510ad4561f859f66e5a2d22a73ce8253d19ede3e (patch)
treee878180529be323c4928561b32a894ee8254b4c8 /src/runtime/proc.go
parentd9fd9201ad214e8da769a9338b9d3a5f3e1bc980 (diff)
downloadgo-510ad4561f859f66e5a2d22a73ce8253d19ede3e.tar.gz
go-510ad4561f859f66e5a2d22a73ce8253d19ede3e.zip
runtime: improve work stealing randomness
For certain values of GOMAXPROCS, the current code is less random than it looks. For example with GOMAXPROCS=12, there are 4 coprimes: 1 5 7 11. That's bad, as 12 and 4 are not relatively prime. So if pos == 2, then we always pick 7 as the inc. We want to pick pos and inc independently at random. Change-Id: I5c7e4f01f9223cbc2db12a685dc0bced2cf39abf Reviewed-on: https://go-review.googlesource.com/c/go/+/369976 Run-TryBot: Keith Randall <khr@golang.org> Trust: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
Diffstat (limited to 'src/runtime/proc.go')
-rw-r--r--src/runtime/proc.go2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/runtime/proc.go b/src/runtime/proc.go
index b997a467ba..df16e0f9b6 100644
--- a/src/runtime/proc.go
+++ b/src/runtime/proc.go
@@ -6138,7 +6138,7 @@ func (ord *randomOrder) start(i uint32) randomEnum {
return randomEnum{
count: ord.count,
pos: i % ord.count,
- inc: ord.coprimes[i%uint32(len(ord.coprimes))],
+ inc: ord.coprimes[i/ord.count%uint32(len(ord.coprimes))],
}
}