]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: convert p.statsSeq to internal atomic type
authorhopehook <hopehook.com@gmail.com>
Thu, 25 Aug 2022 02:13:03 +0000 (10:13 +0800)
committerMichael Knyszek <mknyszek@google.com>
Fri, 26 Aug 2022 15:35:13 +0000 (15:35 +0000)
For #53821.

Change-Id: I1cab3671a29c218b8a927aba9064e63b65900173
Reviewed-on: https://go-review.googlesource.com/c/go/+/425416
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Michael Pratt <mpratt@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: hopehook <hopehook@qq.com>

src/runtime/mstats.go
src/runtime/runtime2.go

index 458350da02ec8d015e01bba7c8b0db2303c00da0..d2a956deaec3b635698d5ac5a00888d3cf91043d 100644 (file)
@@ -759,7 +759,7 @@ type consistentHeapStats struct {
 //go:nosplit
 func (m *consistentHeapStats) acquire() *heapStatsDelta {
        if pp := getg().m.p.ptr(); pp != nil {
-               seq := atomic.Xadd(&pp.statsSeq, 1)
+               seq := pp.statsSeq.Add(1)
                if seq%2 == 0 {
                        // Should have been incremented to odd.
                        print("runtime: seq=", seq, "\n")
@@ -788,7 +788,7 @@ func (m *consistentHeapStats) acquire() *heapStatsDelta {
 //go:nosplit
 func (m *consistentHeapStats) release() {
        if pp := getg().m.p.ptr(); pp != nil {
-               seq := atomic.Xadd(&pp.statsSeq, 1)
+               seq := pp.statsSeq.Add(1)
                if seq%2 != 0 {
                        // Should have been incremented to even.
                        print("runtime: seq=", seq, "\n")
@@ -862,7 +862,7 @@ func (m *consistentHeapStats) read(out *heapStatsDelta) {
 
        for _, p := range allp {
                // Spin until there are no more writers.
-               for atomic.Load(&p.statsSeq)%2 != 0 {
+               for p.statsSeq.Load()%2 != 0 {
                }
        }
 
index 5e12ac73bc918f9ea2325cef065905ab0129a9f3..2d6602071bec38e95781dfcf5176dd4a7b817445 100644 (file)
@@ -708,7 +708,7 @@ type p struct {
 
        // statsSeq is a counter indicating whether this P is currently
        // writing any stats. Its value is even when not, odd when it is.
-       statsSeq uint32
+       statsSeq atomic.Uint32
 
        // Lock for timers. We normally access the timers while running
        // on this P, but the scheduler can also do it from a different P.