]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: ignore SIGPROF if profiling disable for thread
authorIan Lance Taylor <iant@golang.org>
Wed, 9 Sep 2020 17:40:11 +0000 (10:40 -0700)
committerIan Lance Taylor <iant@golang.org>
Wed, 9 Sep 2020 18:04:10 +0000 (18:04 +0000)
This avoids a deadlock on prof.signalLock between setcpuprofilerate
and cpuprof.add if a SIGPROF is delivered to the thread between the
call to setThreadCPUProfiler and acquiring prof.signalLock.

Fixes #41014

Change-Id: Ie825e8594f93a19fb1a6320ed640f4e631553596
Reviewed-on: https://go-review.googlesource.com/c/go/+/253758
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/runtime/proc.go

index 341d52aea8e1b01258b706ee07b03215532065fa..739745aa265a4d1198267504f39f49c3e42ddaac 100644 (file)
@@ -3928,6 +3928,13 @@ func sigprof(pc, sp, lr uintptr, gp *g, mp *m) {
                return
        }
 
+       // If mp.profilehz is 0, then profiling is not enabled for this thread.
+       // We must check this to avoid a deadlock between setcpuprofilerate
+       // and the call to cpuprof.add, below.
+       if mp != nil && mp.profilehz == 0 {
+               return
+       }
+
        // On mips{,le}, 64bit atomics are emulated with spinlocks, in
        // runtime/internal/atomic. If SIGPROF arrives while the program is inside
        // the critical section, it creates a deadlock (when writing the sample).