]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: use maxprocs instead of stwprocs for GC CPU pause time metrics
authorMichael Anthony Knyszek <mknyszek@google.com>
Fri, 8 Mar 2024 23:02:34 +0000 (23:02 +0000)
committerGopher Robot <gobot@golang.org>
Mon, 8 Apr 2024 15:39:41 +0000 (15:39 +0000)
Currently we use stwprocs as the multiplier for the STW CPU time
computation, but this isn't the same as GOMAXPROCS, which is used for
the total time in the CPU metrics. The two numbers need to be
comparable, so this change switches to using maxprocs to make it so.

Change-Id: I423e3c441d05b1bd656353368cb323289661e302
Reviewed-on: https://go-review.googlesource.com/c/go/+/570256
Auto-Submit: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Nicolas Hillegeer <aktau@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

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

index 74a96768a7b8acb6c1ab9c3423b156b0081a1d09..1da6114ab89a8af02a1d52d1465b171b779760df 100644 (file)
@@ -748,7 +748,11 @@ func gcStart(trigger gcTrigger) {
                work.tMark = now
 
                // Update the CPU stats pause time.
-               work.cpuStats.accumulateGCPauseTime(now-work.tSweepTerm, work.stwprocs)
+               //
+               // Use maxprocs instead of stwprocs here because the total time
+               // computed in the CPU stats is based on maxprocs, and we want them
+               // to be comparable.
+               work.cpuStats.accumulateGCPauseTime(now-work.tSweepTerm, work.maxprocs)
 
                // Release the CPU limiter.
                gcCPULimiter.finishGCTransition(now)
@@ -1018,8 +1022,13 @@ func gcMarkTermination(stw worldStop) {
 
        // 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)
+       // Use maxprocs instead of stwprocs for GC pause time because the total time
+       // computed in the CPU stats is based on maxprocs, and we want them to be
+       // comparable.
+       //
+       // Pass gcMarkPhase=true to accumulate so we can get all the latest GC CPU stats
+       // in there too.
+       work.cpuStats.accumulateGCPauseTime(work.tEnd-work.tMarkTerm, work.maxprocs)
        work.cpuStats.accumulate(now, true)
 
        // Compute overall GC CPU utilization.
index f838d139b537baf574be5b2178ce5a5215a5836f..3d1471c576ff6bc3b645d102afa7524ea98673e2 100644 (file)
@@ -922,11 +922,11 @@ type cpuStats struct {
 }
 
 // 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,
+// the actual time spent paused, for orthogonality. maxProcs 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)
+func (s *cpuStats) accumulateGCPauseTime(dt int64, maxProcs int32) {
+       cpu := dt * int64(maxProcs)
        s.gcPauseTime += cpu
        s.gcTotalTime += cpu
 }