diff options
| author | David Chase <drchase@google.com> | 2017-02-02 11:53:41 -0500 |
|---|---|---|
| committer | David Chase <drchase@google.com> | 2017-03-08 18:52:12 +0000 |
| commit | d71f36b5aa1eadc6cd86ada2c0d5dd621bd9fd82 (patch) | |
| tree | 8ea9c296ba061883a35534a4b3df3162cce9785a /src/runtime/proc.go | |
| parent | 6fbedc1afead2de1fd554e72f6df47a4b7948b5a (diff) | |
| download | go-d71f36b5aa1eadc6cd86ada2c0d5dd621bd9fd82.tar.xz | |
cmd/compile: check loop rescheduling with stack bound, not counter
After benchmarking with a compiler modified to have better
spill location, it became clear that this method of checking
was actually faster on (at least) two different architectures
(ppc64 and amd64) and it also provides more timely interruption
of loops.
This change adds a modified FOR loop node "FORUNTIL" that
checks after executing the loop body instead of before (i.e.,
always at least once). This ensures that a pointer past the
end of a slice or array is not made visible to the garbage
collector.
Without the rescheduling checks inserted, the restructured
loop from this change apparently provides a 1% geomean
improvement on PPC64 running the go1 benchmarks; the
improvement on AMD64 is only 0.12%.
Inserting the rescheduling check exposed some peculiar bug
with the ssa test code for s390x; this was updated based on
initial code actually generated for GOARCH=s390x to use
appropriate OpArg, OpAddr, and OpVarDef.
NaCl is disabled in testing.
Change-Id: Ieafaa9a61d2a583ad00968110ef3e7a441abca50
Reviewed-on: https://go-review.googlesource.com/36206
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Diffstat (limited to 'src/runtime/proc.go')
| -rw-r--r-- | src/runtime/proc.go | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/src/runtime/proc.go b/src/runtime/proc.go index c9c451351c..f13746dee4 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -232,22 +232,18 @@ func forcegchelper() { } } -//go:nosplit - // Gosched yields the processor, allowing other goroutines to run. It does not // suspend the current goroutine, so execution resumes automatically. +//go:nosplit func Gosched() { mcall(gosched_m) } -var alwaysFalse bool - -// goschedguarded does nothing, but is written in a way that guarantees a preemption check in its prologue. -// Calls to this function are inserted by the compiler in otherwise uninterruptible loops (see insertLoopReschedChecks). +// goschedguarded yields the processor like gosched, but also checks +// for forbidden states and opts out of the yield in those cases. +//go:nosplit func goschedguarded() { - if alwaysFalse { - goschedguarded() - } + mcall(goschedguarded_m) } // Puts the current goroutine into a waiting state and calls unlockf. @@ -2294,6 +2290,19 @@ func gosched_m(gp *g) { goschedImpl(gp) } +// goschedguarded is a forbidden-states-avoided version of gosched_m +func goschedguarded_m(gp *g) { + + if gp.m.locks != 0 || gp.m.mallocing != 0 || gp.m.preemptoff != "" || gp.m.p.ptr().status != _Prunning { + gogo(&gp.sched) // never return + } + + if trace.enabled { + traceGoSched() + } + goschedImpl(gp) +} + func gopreempt_m(gp *g) { if trace.enabled { traceGoPreempt() |
