]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: factor out GC pause time CPU stats update
authorMichael Anthony Knyszek <mknyszek@google.com>
Fri, 8 Mar 2024 22:59:46 +0000 (22:59 +0000)
committerGopher Robot <gobot@golang.org>
Mon, 8 Apr 2024 15:39:02 +0000 (15:39 +0000)
Currently this is done manually in two places. Replace these manual
updates with a method that also forces the caller to be mindful that the
number will be multiplied (and that it needs to be). This will make
follow-up changes simpler too.

Change-Id: I81ea844b47a40ff3470d23214b4b2fb5b71a4abe
Reviewed-on: https://go-review.googlesource.com/c/go/+/570255
Auto-Submit: Michael Knyszek <mknyszek@google.com>
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/runtime/mgc.go
src/runtime/mstats.go

index 6321254f26af9c604b3f8386efa4f078ff5a9c01..74a96768a7b8acb6c1ab9c3423b156b0081a1d09 100644 (file)
@@ -747,9 +747,8 @@ func gcStart(trigger gcTrigger) {
                work.pauseNS += now - stw.start
                work.tMark = now
 
-               sweepTermCpu := int64(work.stwprocs) * (work.tMark - work.tSweepTerm)
-               work.cpuStats.gcPauseTime += sweepTermCpu
-               work.cpuStats.gcTotalTime += sweepTermCpu
+               // Update the CPU stats pause time.
+               work.cpuStats.accumulateGCPauseTime(now-work.tSweepTerm, work.stwprocs)
 
                // Release the CPU limiter.
                gcCPULimiter.finishGCTransition(now)
@@ -1017,13 +1016,10 @@ func gcMarkTermination(stw worldStop) {
        memstats.pause_end[memstats.numgc%uint32(len(memstats.pause_end))] = uint64(unixNow)
        memstats.pause_total_ns += uint64(work.pauseNS)
 
-       markTermCpu := int64(work.stwprocs) * (work.tEnd - work.tMarkTerm)
-       work.cpuStats.gcPauseTime += markTermCpu
-       work.cpuStats.gcTotalTime += markTermCpu
-
        // Accumulate CPU stats.
        //
        // Pass gcMarkPhase=true so we can get all the latest GC CPU stats in there too.
+       work.cpuStats.accumulateGCPauseTime(work.tEnd-work.tMarkTerm, work.stwprocs)
        work.cpuStats.accumulate(now, true)
 
        // Compute overall GC CPU utilization.
@@ -1166,7 +1162,7 @@ func gcMarkTermination(stw worldStop) {
                        gcController.assistTime.Load(),
                        gcController.dedicatedMarkTime.Load() + gcController.fractionalMarkTime.Load(),
                        gcController.idleMarkTime.Load(),
-                       markTermCpu,
+                       int64(work.stwprocs) * (work.tEnd - work.tMarkTerm),
                } {
                        if i == 2 || i == 3 {
                                // Separate mark time components with /.
index 1b634bd81e607faaa5297b41212330321772daa5..f838d139b537baf574be5b2178ce5a5215a5836f 100644 (file)
@@ -921,6 +921,16 @@ type cpuStats struct {
        totalTime int64 // GOMAXPROCS * (monotonic wall clock time elapsed)
 }
 
+// accumulateGCPauseTime add dt*stwProcs to the GC CPU pause time stats. dt should be
+// the actual time spent paused, for orthogonality. stwProcs should be GOMAXPROCS,
+// not work.stwprocs, since this number must be comparable to a total time computed
+// from GOMAXPROCS.
+func (s *cpuStats) accumulateGCPauseTime(dt int64, stwProcs int32) {
+       cpu := dt * int64(stwProcs)
+       s.gcPauseTime += cpu
+       s.gcTotalTime += cpu
+}
+
 // accumulate takes a cpuStats and adds in the current state of all GC CPU
 // counters.
 //