]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: account mark worker time before gcMarkDone
authorAustin Clements <austin@google.com>
Mon, 26 Oct 2015 20:48:36 +0000 (16:48 -0400)
committerAustin Clements <austin@google.com>
Thu, 5 Nov 2015 21:23:49 +0000 (21:23 +0000)
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 <rlh@golang.org>
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/runtime/mgc.go

index 5db5941228267736d69ed03c39be83c0a65a51cb..ac1054d3881007c280975aa26bdc83cd4fbe5cf7 100644 (file)
@@ -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)
-               }
        }
 }