]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix assist utilization computation
authorAustin Clements <austin@google.com>
Mon, 3 Aug 2015 22:06:05 +0000 (18:06 -0400)
committerAustin Clements <austin@google.com>
Tue, 4 Aug 2015 18:54:53 +0000 (18:54 +0000)
When commit 510fd13 enabled assists during the scan phase, it failed
to also update the code in the GC controller that computed the assist
CPU utilization and adjusted the trigger based on it. Fix that code so
it uses the start of the scan phase as the wall-clock time when
assists were enabled rather than the start of the mark phase.

Change-Id: I05013734b4448c3e2c730dc7b0b5ee28c86ed8cf
Reviewed-on: https://go-review.googlesource.com/13048
Reviewed-by: Rick Hudson <rlh@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
src/runtime/mgc.go

index 6d4799a9e299e2bb907a938917d85b0251ad5cf3..c8031d7db7026c420bf0ac5ca679eb4a16e7f221 100644 (file)
@@ -348,6 +348,10 @@ type gcControllerState struct {
        // that the background mark phase started.
        bgMarkStartTime int64
 
+       // assistTime is the absolute start time in nanoseconds that
+       // mutator assists were enabled.
+       assistStartTime int64
+
        // heapGoal is the goal memstats.heap_live for when this cycle
        // ends. This is computed at the beginning of each cycle.
        heapGoal uint64
@@ -500,15 +504,19 @@ func (c *gcControllerState) endCycle() {
        // growth if we had the desired CPU utilization). The
        // difference between this estimate and the GOGC-based goal
        // heap growth is the error.
+       //
+       // TODO(austin): next_gc is based on heap_reachable, not
+       // heap_marked, which means the actual growth ratio
+       // technically isn't comparable to the trigger ratio.
        goalGrowthRatio := float64(gcpercent) / 100
        actualGrowthRatio := float64(memstats.heap_live)/float64(memstats.heap_marked) - 1
-       duration := nanotime() - c.bgMarkStartTime
+       assistDuration := nanotime() - c.assistStartTime
 
        // Assume background mark hit its utilization goal.
        utilization := gcGoalUtilization
        // Add assist utilization; avoid divide by zero.
-       if duration > 0 {
-               utilization += float64(c.assistTime) / float64(duration*int64(gomaxprocs))
+       if assistDuration > 0 {
+               utilization += float64(c.assistTime) / float64(assistDuration*int64(gomaxprocs))
        }
 
        triggerError := goalGrowthRatio - c.triggerRatio - utilization/gcGoalUtilization*(actualGrowthRatio-c.triggerRatio)
@@ -979,6 +987,7 @@ func gc(mode int) {
                        now = nanotime()
                        pauseNS += now - pauseStart
                        tScan = now
+                       gcController.assistStartTime = now
                        gcscan_m()
 
                        // Enter mark phase.