Skip to content

Commit dcd1037

Browse files
committed
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 <[email protected]> Reviewed-by: Austin Clements <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent fe406c8 commit dcd1037

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

src/runtime/align_runtime_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ var AtomicFields = []uintptr{
2222
unsafe.Offsetof(schedt{}.pollUntil),
2323
unsafe.Offsetof(schedt{}.timeToRun),
2424
unsafe.Offsetof(gcControllerState{}.dedicatedMarkWorkersNeeded),
25-
unsafe.Offsetof(gcControllerState{}.idleMarkTime),
2625
unsafe.Offsetof(timeHistogram{}.underflow),
2726
unsafe.Offsetof(profBuf{}.overflow),
2827
unsafe.Offsetof(profBuf{}.overflowTime),

src/runtime/mgc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ func gcMarkTermination() {
11061106
sweepTermCpu,
11071107
gcController.assistTime.Load(),
11081108
gcController.dedicatedMarkTime.Load() + gcController.fractionalMarkTime.Load(),
1109-
gcController.idleMarkTime,
1109+
gcController.idleMarkTime.Load(),
11101110
markTermCpu,
11111111
} {
11121112
if i == 2 || i == 3 {

src/runtime/mgcpacer.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,9 @@ type gcControllerState struct {
281281
// running.
282282
fractionalMarkTime atomic.Int64
283283

284-
// idleMarkTime is the nanoseconds spent in idle marking
285-
// during this cycle. This is updated atomically throughout
286-
// the cycle.
287-
idleMarkTime int64
284+
// idleMarkTime is the nanoseconds spent in idle marking during this
285+
// cycle. This is updated throughout the cycle.
286+
idleMarkTime atomic.Int64
288287

289288
// markStartTime is the absolute start time in nanoseconds
290289
// that assists and background mark workers started.
@@ -420,7 +419,7 @@ func (c *gcControllerState) startCycle(markStartTime int64, procs int, trigger g
420419
c.assistTime.Store(0)
421420
c.dedicatedMarkTime.Store(0)
422421
c.fractionalMarkTime.Store(0)
423-
c.idleMarkTime = 0
422+
c.idleMarkTime.Store(0)
424423
c.markStartTime = markStartTime
425424

426425
// 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) {
671670
}
672671
idleUtilization := 0.0
673672
if assistDuration > 0 {
674-
idleUtilization = float64(c.idleMarkTime) / float64(assistDuration*int64(procs))
673+
idleUtilization = float64(c.idleMarkTime.Load()) / float64(assistDuration*int64(procs))
675674
}
676675
// Determine the cons/mark ratio.
677676
//
@@ -910,7 +909,7 @@ func (c *gcControllerState) markWorkerStop(mode gcMarkWorkerMode, duration int64
910909
case gcMarkWorkerFractionalMode:
911910
c.fractionalMarkTime.Add(duration)
912911
case gcMarkWorkerIdleMode:
913-
atomic.Xaddint64(&c.idleMarkTime, duration)
912+
c.idleMarkTime.Add(duration)
914913
c.removeIdleMarkWorker()
915914
default:
916915
throw("markWorkerStop: unknown mark worker mode")

0 commit comments

Comments
 (0)