]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: initialize extra M for cgo during mstart
authorDavid Crawshaw <crawshaw@golang.org>
Tue, 24 Mar 2015 13:22:35 +0000 (09:22 -0400)
committerDavid Crawshaw <crawshaw@golang.org>
Tue, 24 Mar 2015 19:39:46 +0000 (19:39 +0000)
Previously the extra m needed for cgo callbacks was created on the
first callback. This works for cgo, however the cgocallback mechanism
is also borrowed by badsignal which can run before any cgo calls are
made.

Now we initialize the extra M at runtime startup before any signal
handlers are registered, so badsignal cannot be called until the
extra M is ready.

Updates #10207.

Change-Id: Iddda2c80db6dc52d8b60e2b269670fbaa704c7b3
Reviewed-on: https://go-review.googlesource.com/7978
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: David Crawshaw <crawshaw@golang.org>

src/runtime/cgocall.go
src/runtime/proc1.go
src/runtime/sigqueue.go

index e7aeb7bee3e40d6f1679bd8def595b2aa3d38a7a..052830de5ad1674dcfc4d10565835edb89b156d9 100644 (file)
@@ -101,11 +101,6 @@ func cgocall_errno(fn, arg unsafe.Pointer) int32 {
                racereleasemerge(unsafe.Pointer(&racecgosync))
        }
 
-       // Create an extra M for callbacks on threads not created by Go on first cgo call.
-       if needextram == 1 && cas(&needextram, 1, 0) {
-               systemstack(newextram)
-       }
-
        /*
         * Lock g to m to ensure we stay on the same stack if we do a
         * cgo callback. Add entry to defer stack in case of panic.
index 0ff3bafbdb8b27dad5de0b43048e9070cca93fd7..1c34e4b6917b86ef6189f6e069349ac5a6e771f8 100644 (file)
@@ -717,6 +717,11 @@ func mstart1() {
        // Install signal handlers; after minit so that minit can
        // prepare the thread to be able to handle the signals.
        if _g_.m == &m0 {
+               // Create an extra M for callbacks on threads not created by Go.
+               if needextram == 1 {
+                       needextram = 0
+                       newextram()
+               }
                initsig()
        }
 
index df3c9c0e612320d6790e6a8381c64b1d412385cc..9cfe2592db4d5ba6b22a13765831eb4e00fd4c0a 100644 (file)
@@ -165,14 +165,5 @@ func signal_ignore(s uint32) {
 // This runs on a foreign stack, without an m or a g.  No stack split.
 //go:nosplit
 func badsignal(sig uintptr) {
-       // Some external libraries, for example, OpenBLAS, create worker threads in
-       // a global constructor. If we're doing cpu profiling, and the SIGPROF signal
-       // comes to one of the foreign threads before we make our first cgo call, the
-       // call to cgocallback below will bring down the whole process.
-       // It's better to miss a few SIGPROF signals than to abort in this case.
-       // See http://golang.org/issue/9456.
-       if _SIGPROF != 0 && sig == _SIGPROF && needextram != 0 {
-               return
-       }
        cgocallback(unsafe.Pointer(funcPC(sigsend)), noescape(unsafe.Pointer(&sig)), unsafe.Sizeof(sig))
 }