Commit b434bbd0 authored by Kirill Smelkov's avatar Kirill Smelkov

X spin a bit on stopm to avoid large penalty on wakeup

https://github.com/golang/go/issues/18023#issuecomment-328194383
parent 43c6e810
......@@ -133,6 +133,17 @@ func notewakeup(n *note) {
print("notewakeup - double wakeup (", old, ")\n")
throw("notewakeup - double wakeup")
}
// spin a bit hoping waiter was also spinning and woke up
/*
for i := 0; i < 10000; i++ {
if atomic.Load(key32(&n.key)) == 0 {
return // waiter woke up and called noteclear
}
}
*/
// no luck -> go to kernel
futexwakeup(key32(&n.key), 1)
}
......@@ -146,7 +157,13 @@ func notesleep(n *note) {
// Sleep for an arbitrary-but-moderate interval to poll libc interceptors.
ns = 10e6
}
for atomic.Load(key32(&n.key)) == 0 {
for spin := 0; atomic.Load(key32(&n.key)) == 0; spin++ {
// spin a bit hoping we'll get wakup soon
if spin < 10000 {
continue
}
// no luck -> go to sleep heavily to kernel
gp.m.blocked = true
futexsleep(key32(&n.key), 0, ns)
if *cgo_yield != nil {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment