]> Cypherpunks.ru repositories - gostls13.git/commitdiff
runtime: convert gcController.globalsScan to atomic type
authorMichael Pratt <mpratt@google.com>
Fri, 15 Jul 2022 18:33:16 +0000 (14:33 -0400)
committerMichael Pratt <mpratt@google.com>
Mon, 8 Aug 2022 14:11:40 +0000 (14:11 +0000)
For #53821.

Change-Id: I92bd33e355c868ae229395fd9c98fdb10768d03d
Reviewed-on: https://go-review.googlesource.com/c/go/+/417779
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
src/runtime/align_runtime_test.go
src/runtime/export_test.go
src/runtime/mgc.go
src/runtime/mgcpacer.go

index 9fe7b61c44070b9f756cf034ac1ef6ff63a02a1e..5d12616f89bf2aaa93792616247f5740447d71f1 100644 (file)
@@ -26,7 +26,6 @@ var AtomicFields = []uintptr{
        unsafe.Offsetof(gcControllerState{}.dedicatedMarkWorkersNeeded),
        unsafe.Offsetof(gcControllerState{}.fractionalMarkTime),
        unsafe.Offsetof(gcControllerState{}.idleMarkTime),
-       unsafe.Offsetof(gcControllerState{}.globalsScan),
        unsafe.Offsetof(timeHistogram{}.underflow),
        unsafe.Offsetof(profBuf{}.overflow),
        unsafe.Offsetof(profBuf{}.overflowTime),
index 473616367389a1b30bb41a3d06370a71188f5e94..81f60b3ada6909a14f012977e4dd98ffdeff29ed 100644 (file)
@@ -1323,7 +1323,7 @@ func (c *GCController) StartCycle(stackSize, globalsSize uint64, scannableFrac f
                trigger = c.heapMarked
        }
        c.maxStackScan.Store(stackSize)
-       c.globalsScan = globalsSize
+       c.globalsScan.Store(globalsSize)
        c.heapLive.Store(trigger)
        c.heapScan.Add(int64(float64(trigger-c.heapMarked) * scannableFrac))
        c.startCycle(0, gomaxprocs, gcTrigger{kind: gcTriggerHeap})
index b1657482a0735222095998b766fda8c26001c011..0a0de568e3e499cc1a928d759b1093f780f4a801 100644 (file)
@@ -1121,7 +1121,7 @@ func gcMarkTermination() {
                        work.heap0>>20, "->", work.heap1>>20, "->", work.heap2>>20, " MB, ",
                        gcController.lastHeapGoal>>20, " MB goal, ",
                        gcController.maxStackScan.Load()>>20, " MB stacks, ",
-                       gcController.globalsScan>>20, " MB globals, ",
+                       gcController.globalsScan.Load()>>20, " MB globals, ",
                        work.maxprocs, " P")
                if work.userForced {
                        print(" (forced)")
index fe31d6fbd851faaee1f951072f92a86a89441871..da74263ba48d6f6f593f0d06a03d204aea122c71 100644 (file)
@@ -231,9 +231,7 @@ type gcControllerState struct {
 
        // globalsScan is the total amount of global variable space
        // that is scannable.
-       //
-       // Read and updated atomically.
-       globalsScan uint64
+       globalsScan atomic.Uint64
 
        // heapMarked is the number of bytes marked by the previous
        // GC. After mark termination, heapLive == heapMarked, but
@@ -555,14 +553,14 @@ func (c *gcControllerState) revise() {
 
        // The expected scan work is computed as the amount of bytes scanned last
        // GC cycle (both heap and stack), plus our estimate of globals work for this cycle.
-       scanWorkExpected := int64(c.lastHeapScan + c.lastStackScan.Load() + c.globalsScan)
+       scanWorkExpected := int64(c.lastHeapScan + c.lastStackScan.Load() + c.globalsScan.Load())
 
        // maxScanWork is a worst-case estimate of the amount of scan work that
        // needs to be performed in this GC cycle. Specifically, it represents
        // the case where *all* scannable memory turns out to be live, and
        // *all* allocated stack space is scannable.
        maxStackScan := c.maxStackScan.Load()
-       maxScanWork := int64(scan + maxStackScan + c.globalsScan)
+       maxScanWork := int64(scan + maxStackScan + c.globalsScan.Load())
        if work > scanWorkExpected {
                // We've already done more scan work than expected. Because our expectation
                // is based on a steady-state scannable heap size, we assume this means our
@@ -738,7 +736,7 @@ func (c *gcControllerState) endCycle(now int64, procs int, userForced bool) {
                printlock()
                goal := gcGoalUtilization * 100
                print("pacer: ", int(utilization*100), "% CPU (", int(goal), " exp.) for ")
-               print(c.heapScanWork.Load(), "+", c.stackScanWork.Load(), "+", c.globalsScanWork.Load(), " B work (", c.lastHeapScan+c.lastStackScan.Load()+c.globalsScan, " B exp.) ")
+               print(c.heapScanWork.Load(), "+", c.stackScanWork.Load(), "+", c.globalsScanWork.Load(), " B work (", c.lastHeapScan+c.lastStackScan.Load()+c.globalsScan.Load(), " B exp.) ")
                live := c.heapLive.Load()
                print("in ", c.triggered, " B -> ", live, " B (∆goal ", int64(live)-int64(c.lastHeapGoal), ", cons/mark ", oldConsMark, ")")
                if !ok {
@@ -953,7 +951,7 @@ func (c *gcControllerState) addScannableStack(pp *p, amount int64) {
 }
 
 func (c *gcControllerState) addGlobals(amount int64) {
-       atomic.Xadd64(&c.globalsScan, amount)
+       c.globalsScan.Add(amount)
 }
 
 // heapGoal returns the current heap goal.
@@ -1255,7 +1253,7 @@ func (c *gcControllerState) commit(isSweepDone bool) {
        // plus additional runway for non-heap sources of GC work.
        gcPercentHeapGoal := ^uint64(0)
        if gcPercent := c.gcPercent.Load(); gcPercent >= 0 {
-               gcPercentHeapGoal = c.heapMarked + (c.heapMarked+c.lastStackScan.Load()+atomic.Load64(&c.globalsScan))*uint64(gcPercent)/100
+               gcPercentHeapGoal = c.heapMarked + (c.heapMarked+c.lastStackScan.Load()+c.globalsScan.Load())*uint64(gcPercent)/100
        }
        // Apply the minimum heap size here. It's defined in terms of gcPercent
        // and is only updated by functions that call commit.
@@ -1287,7 +1285,7 @@ func (c *gcControllerState) commit(isSweepDone bool) {
        // Furthermore, by setting the runway so that CPU resources are divided
        // this way, assuming that the cons/mark ratio is correct, we make that
        // division a reality.
-       c.runway.Store(uint64((c.consMark * (1 - gcGoalUtilization) / (gcGoalUtilization)) * float64(c.lastHeapScan+c.lastStackScan.Load()+c.globalsScan)))
+       c.runway.Store(uint64((c.consMark * (1 - gcGoalUtilization) / (gcGoalUtilization)) * float64(c.lastHeapScan+c.lastStackScan.Load()+c.globalsScan.Load())))
 }
 
 // setGCPercent updates gcPercent. commit must be called after.