From d986bf27414161f4a4fc41c4c564bad26ebc57e7 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Mon, 26 Oct 2015 16:48:36 -0400 Subject: [PATCH] runtime: account mark worker time before gcMarkDone Currently gcMarkDone takes basically no time, so it's okay to account the worker time after calling it. However, gcMarkDone is about to take potentially *much* longer because it may perform all of mark termination. Prepare for this by swapping the order so we account the time before calling gcMarkDone. Change-Id: I90c7df68192acfc4fd02a7254dae739dda4e2fcb Reviewed-on: https://go-review.googlesource.com/16390 Reviewed-by: Rick Hudson Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot --- src/runtime/mgc.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/runtime/mgc.go b/src/runtime/mgc.go index 5db5941228..ac1054d388 100644 --- a/src/runtime/mgc.go +++ b/src/runtime/mgc.go @@ -1477,6 +1477,19 @@ func gcBgMarkWorker(p *p) { p.gcw.dispose() } + // Account for time. + duration := nanotime() - startTime + switch p.gcMarkWorkerMode { + case gcMarkWorkerDedicatedMode: + xaddint64(&gcController.dedicatedMarkTime, duration) + xaddint64(&gcController.dedicatedMarkWorkersNeeded, 1) + case gcMarkWorkerFractionalMode: + xaddint64(&gcController.fractionalMarkTime, duration) + xaddint64(&gcController.fractionalMarkWorkersNeeded, 1) + case gcMarkWorkerIdleMode: + xaddint64(&gcController.idleMarkTime, duration) + } + // Was this the last worker and did we run out // of work? incnwait := xadd(&work.nwait, +1) @@ -1491,18 +1504,6 @@ func gcBgMarkWorker(p *p) { if incnwait == work.nproc && !gcMarkWorkAvailable(nil) { gcMarkDone() } - - duration := nanotime() - startTime - switch p.gcMarkWorkerMode { - case gcMarkWorkerDedicatedMode: - xaddint64(&gcController.dedicatedMarkTime, duration) - xaddint64(&gcController.dedicatedMarkWorkersNeeded, 1) - case gcMarkWorkerFractionalMode: - xaddint64(&gcController.fractionalMarkTime, duration) - xaddint64(&gcController.fractionalMarkWorkersNeeded, 1) - case gcMarkWorkerIdleMode: - xaddint64(&gcController.idleMarkTime, duration) - } } }