Skip to content

Commit d3aeba1

Browse files
prattmicgopherbot
authored andcommitted
runtime: switch p.gcFractionalMarkTime to atomic.Int64
atomic.Int64 automatically maintains proper alignment, avoiding the need to manually adjust alignment back and forth as fields above change. Change-Id: I6a6a636c4c3c366353f6dc8ecac473c075dd5cd9 Reviewed-on: https://go-review.googlesource.com/c/go/+/716700 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Michael Knyszek <[email protected]> Auto-Submit: Michael Pratt <[email protected]>
1 parent 8873e8b commit d3aeba1

File tree

4 files changed

+5
-6
lines changed

4 files changed

+5
-6
lines changed

src/runtime/align_runtime_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import "unsafe"
1414
// operations (all the *64 operations in internal/runtime/atomic).
1515
var AtomicFields = []uintptr{
1616
unsafe.Offsetof(m{}.procid),
17-
unsafe.Offsetof(p{}.gcFractionalMarkTime),
1817
unsafe.Offsetof(profBuf{}.overflow),
1918
unsafe.Offsetof(profBuf{}.overflowTime),
2019
unsafe.Offsetof(heapStatsDelta{}.tinyAllocCount),

src/runtime/mgc.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ func pollFractionalWorkerExit() bool {
316316
return true
317317
}
318318
p := getg().m.p.ptr()
319-
selfTime := p.gcFractionalMarkTime + (now - p.gcMarkWorkerStartTime)
319+
selfTime := p.gcFractionalMarkTime.Load() + (now - p.gcMarkWorkerStartTime)
320320
// Add some slack to the utilization goal so that the
321321
// fractional worker isn't behind again the instant it exits.
322322
return float64(selfTime)/float64(delta) > 1.2*gcController.fractionalUtilizationGoal
@@ -1858,7 +1858,7 @@ func gcBgMarkWorker(ready chan struct{}) {
18581858
pp.limiterEvent.stop(limiterEventIdleMarkWork, now)
18591859
}
18601860
if pp.gcMarkWorkerMode == gcMarkWorkerFractionalMode {
1861-
atomic.Xaddint64(&pp.gcFractionalMarkTime, duration)
1861+
pp.gcFractionalMarkTime.Add(duration)
18621862
}
18631863

18641864
// We'll releasem after this point and thus this P may run

src/runtime/mgcpacer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ func (c *gcControllerState) startCycle(markStartTime int64, procs int, trigger g
427427
// Clear per-P state
428428
for _, p := range allp {
429429
p.gcAssistTime = 0
430-
p.gcFractionalMarkTime = 0
430+
p.gcFractionalMarkTime.Store(0)
431431
}
432432

433433
if trigger.kind == gcTriggerTime {
@@ -830,7 +830,7 @@ func (c *gcControllerState) findRunnableGCWorker(pp *p, now int64) (*g, int64) {
830830
//
831831
// This should be kept in sync with pollFractionalWorkerExit.
832832
delta := now - c.markStartTime
833-
if delta > 0 && float64(pp.gcFractionalMarkTime)/float64(delta) > c.fractionalUtilizationGoal {
833+
if delta > 0 && float64(pp.gcFractionalMarkTime.Load())/float64(delta) > c.fractionalUtilizationGoal {
834834
// Nope. No need to run a fractional worker.
835835
gcBgMarkWorkerPool.push(&node.node)
836836
return nil, now

src/runtime/runtime2.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ type p struct {
794794

795795
// Per-P GC state
796796
gcAssistTime int64 // Nanoseconds in assistAlloc
797-
gcFractionalMarkTime int64 // Nanoseconds in fractional mark worker (atomic)
797+
gcFractionalMarkTime atomic.Int64 // Nanoseconds in fractional mark worker
798798

799799
// limiterEvent tracks events for the GC CPU limiter.
800800
limiterEvent limiterEvent

0 commit comments

Comments
 (0)