aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/netpoll.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-10-31 17:56:14 +0100
committerDmitry Vyukov <dvyukov@google.com>2018-11-02 12:53:20 +0000
commit31e7842f3d3f85f7aec5ca72f59befce9f58a3b6 (patch)
tree8915fdc7b7d83b8d149ea590a220ac89212dd343 /src/runtime/netpoll.go
parentff51353c3887b9d83130d958fb503ff1f2291fde (diff)
downloadgo-31e7842f3d3f85f7aec5ca72f59befce9f58a3b6.tar.gz
go-31e7842f3d3f85f7aec5ca72f59befce9f58a3b6.zip
runtime: execute memory barrier conditionally when changing netpoll timers
We only need the memory barrier in poll_runtime_pollSetDeadline only when one of the timers has fired, which is not the expected case. Memory barrier can be somewhat expensive on some archs, so execute it only if one of the timers has in fact fired. name old time/op new time/op delta TCP4OneShotTimeout-6 17.0µs ± 0% 17.1µs ± 0% +0.35% (p=0.032 n=5+5) SetReadDeadline-6 232ns ± 0% 230ns ± 0% -1.03% (p=0.000 n=4+5) Update #25729 Change-Id: Ifce6f505b9e7ba3717bad8f454077a2e94ea6e75 Reviewed-on: https://go-review.googlesource.com/c/146343 Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/runtime/netpoll.go')
-rw-r--r--src/runtime/netpoll.go14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/runtime/netpoll.go b/src/runtime/netpoll.go
index 34e7c902eb..f914844cdf 100644
--- a/src/runtime/netpoll.go
+++ b/src/runtime/netpoll.go
@@ -254,12 +254,14 @@ func poll_runtime_pollSetDeadline(pd *pollDesc, d int64, mode int) {
}
// If we set the new deadline in the past, unblock currently pending IO if any.
var rg, wg *g
- atomicstorep(unsafe.Pointer(&wg), nil) // full memory barrier between stores to rd/wd and load of rg/wg in netpollunblock
- if pd.rd < 0 {
- rg = netpollunblock(pd, 'r', false)
- }
- if pd.wd < 0 {
- wg = netpollunblock(pd, 'w', false)
+ if pd.rd < 0 || pd.wd < 0 {
+ atomicstorep(unsafe.Pointer(&wg), nil) // full memory barrier between stores to rd/wd and load of rg/wg in netpollunblock
+ if pd.rd < 0 {
+ rg = netpollunblock(pd, 'r', false)
+ }
+ if pd.wd < 0 {
+ wg = netpollunblock(pd, 'w', false)
+ }
}
unlock(&pd.lock)
if rg != nil {