From dcd10375bc48d0389919b573485d2730445650fd Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Fri, 15 Jul 2022 16:49:50 -0400 Subject: [PATCH] runtime: convert gcController.idleMarkTime to atomic type For #53821. Change-Id: I2f2b462908096dacb97fba9973798036ea1d9b68 Reviewed-on: https://go-review.googlesource.com/c/go/+/417783 Run-TryBot: Michael Pratt Reviewed-by: Austin Clements TryBot-Result: Gopher Robot --- src/runtime/align_runtime_test.go | 1 - src/runtime/mgc.go | 2 +- src/runtime/mgcpacer.go | 13 ++++++------- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/runtime/align_runtime_test.go b/src/runtime/align_runtime_test.go index 98e1622e7a..cec0d76be2 100644 --- a/src/runtime/align_runtime_test.go +++ b/src/runtime/align_runtime_test.go @@ -22,7 +22,6 @@ var AtomicFields = []uintptr{ unsafe.Offsetof(schedt{}.pollUntil), unsafe.Offsetof(schedt{}.timeToRun), unsafe.Offsetof(gcControllerState{}.dedicatedMarkWorkersNeeded), - unsafe.Offsetof(gcControllerState{}.idleMarkTime), unsafe.Offsetof(timeHistogram{}.underflow), unsafe.Offsetof(profBuf{}.overflow), unsafe.Offsetof(profBuf{}.overflowTime), diff --git a/src/runtime/mgc.go b/src/runtime/mgc.go index 01eee16a4d..c3e91edb1f 100644 --- a/src/runtime/mgc.go +++ b/src/runtime/mgc.go @@ -1106,7 +1106,7 @@ func gcMarkTermination() { sweepTermCpu, gcController.assistTime.Load(), gcController.dedicatedMarkTime.Load() + gcController.fractionalMarkTime.Load(), - gcController.idleMarkTime, + gcController.idleMarkTime.Load(), markTermCpu, } { if i == 2 || i == 3 { diff --git a/src/runtime/mgcpacer.go b/src/runtime/mgcpacer.go index d687ffb657..4e3538762e 100644 --- a/src/runtime/mgcpacer.go +++ b/src/runtime/mgcpacer.go @@ -281,10 +281,9 @@ type gcControllerState struct { // running. fractionalMarkTime atomic.Int64 - // idleMarkTime is the nanoseconds spent in idle marking - // during this cycle. This is updated atomically throughout - // the cycle. - idleMarkTime int64 + // idleMarkTime is the nanoseconds spent in idle marking during this + // cycle. This is updated throughout the cycle. + idleMarkTime atomic.Int64 // markStartTime is the absolute start time in nanoseconds // that assists and background mark workers started. @@ -420,7 +419,7 @@ func (c *gcControllerState) startCycle(markStartTime int64, procs int, trigger g c.assistTime.Store(0) c.dedicatedMarkTime.Store(0) c.fractionalMarkTime.Store(0) - c.idleMarkTime = 0 + c.idleMarkTime.Store(0) c.markStartTime = markStartTime // TODO(mknyszek): This is supposed to be the actual trigger point for the heap, but @@ -671,7 +670,7 @@ func (c *gcControllerState) endCycle(now int64, procs int, userForced bool) { } idleUtilization := 0.0 if assistDuration > 0 { - idleUtilization = float64(c.idleMarkTime) / float64(assistDuration*int64(procs)) + idleUtilization = float64(c.idleMarkTime.Load()) / float64(assistDuration*int64(procs)) } // Determine the cons/mark ratio. // @@ -910,7 +909,7 @@ func (c *gcControllerState) markWorkerStop(mode gcMarkWorkerMode, duration int64 case gcMarkWorkerFractionalMode: c.fractionalMarkTime.Add(duration) case gcMarkWorkerIdleMode: - atomic.Xaddint64(&c.idleMarkTime, duration) + c.idleMarkTime.Add(duration) c.removeIdleMarkWorker() default: throw("markWorkerStop: unknown mark worker mode") -- 2.50.0