]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: make ncgocall a global counter
authorTao Qingyun <qingyunha@gmail.com>
Tue, 22 Jun 2021 00:24:05 +0000 (00:24 +0000)
committerAlexander Rakoczy <alex@golang.org>
Fri, 25 Jun 2021 17:31:39 +0000 (17:31 +0000)
ncgocall was stored per M, runtime.NumCgoCall lost the counter when a M die.

Fixes #46789

Change-Id: I85831fbb2713f4c30d1800d07e1f47aa0031970e
GitHub-Last-Rev: cbc15fa870de776d3fbf3b62fc9a5e01792e6a26
GitHub-Pull-Request: golang/go#46842
Reviewed-on: https://go-review.googlesource.com/c/go/+/329729
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Alexander Rakoczy <alex@golang.org>

src/runtime/cgocall.go
src/runtime/debug.go
src/runtime/proc.go

index 0e287d0b8ede48f92fcaf919c3998f86db15bbae..8ffb48a888e7e4c155354e1fd48ac7dbefc2188c 100644 (file)
@@ -110,6 +110,8 @@ func syscall_cgocaller(fn unsafe.Pointer, args ...uintptr) uintptr {
        return as.retval
 }
 
+var ncgocall uint64 // number of cgo calls in total for dead m
+
 // Call from Go to C.
 //
 // This must be nosplit because it's used for syscalls on some
index f411b2267660f617411c0ab34d9af703b3e5f57e..82deefa200cdf7cf68d1af6fe7cd48534423d1ca 100644 (file)
@@ -45,7 +45,7 @@ func NumCPU() int {
 
 // NumCgoCall returns the number of cgo calls made by the current process.
 func NumCgoCall() int64 {
-       var n int64
+       var n = int64(atomic.Load64(&ncgocall))
        for mp := (*m)(atomic.Loadp(unsafe.Pointer(&allm))); mp != nil; mp = mp.alllink {
                n += int64(mp.ncgocall)
        }
index 8f1a4439456eff1d64eac8a5e463b2b63e0ba6af..4c92588a66e739cd936a6a1be89cf4d1bf9dd042 100644 (file)
@@ -1522,6 +1522,8 @@ found:
        }
        unlock(&sched.lock)
 
+       atomic.Xadd64(&ncgocall, int64(m.ncgocall))
+
        // Release the P.
        handoffp(releasep())
        // After this point we must not have write barriers.