From: Austin Clements Date: Mon, 3 Aug 2015 22:06:05 +0000 (-0400) Subject: runtime: fix assist utilization computation X-Git-Tag: go1.5rc1~30 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=e3870aa6f38b842ba5527a1ccd9433f8b6a4a2fe;p=gostls13.git runtime: fix assist utilization computation 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 Reviewed-by: Russ Cox --- diff --git a/src/runtime/mgc.go b/src/runtime/mgc.go index 6d4799a9e2..c8031d7db7 100644 --- a/src/runtime/mgc.go +++ b/src/runtime/mgc.go @@ -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.