Skip to content

Commit 5b90958

Browse files
rhyshprattmic
authored andcommitted
runtime: move sigprofNonGo
The sigprofNonGo and sigprofNonGoPC functions are only used on unix-like platforms. In preparation for unix-specific changes to sigprofNonGo, move it (plus its close relative) to a unix-specific file. Updates #35057 Change-Id: I9c814127c58612ea9a9fbd28a992b04ace5c604d Reviewed-on: https://go-review.googlesource.com/c/go/+/351790 Run-TryBot: Rhys Hiltner <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Michael Pratt <[email protected]> Trust: David Chase <[email protected]>
1 parent 8cfd8c3 commit 5b90958

File tree

2 files changed

+40
-39
lines changed

2 files changed

+40
-39
lines changed

src/runtime/proc.go

-39
Original file line numberDiff line numberDiff line change
@@ -4705,45 +4705,6 @@ func sigprof(pc, sp, lr uintptr, gp *g, mp *m) {
47054705
getg().m.mallocing--
47064706
}
47074707

4708-
// If the signal handler receives a SIGPROF signal on a non-Go thread,
4709-
// it tries to collect a traceback into sigprofCallers.
4710-
// sigprofCallersUse is set to non-zero while sigprofCallers holds a traceback.
4711-
var sigprofCallers cgoCallers
4712-
var sigprofCallersUse uint32
4713-
4714-
// sigprofNonGo is called if we receive a SIGPROF signal on a non-Go thread,
4715-
// and the signal handler collected a stack trace in sigprofCallers.
4716-
// When this is called, sigprofCallersUse will be non-zero.
4717-
// g is nil, and what we can do is very limited.
4718-
//go:nosplit
4719-
//go:nowritebarrierrec
4720-
func sigprofNonGo() {
4721-
if prof.hz != 0 {
4722-
n := 0
4723-
for n < len(sigprofCallers) && sigprofCallers[n] != 0 {
4724-
n++
4725-
}
4726-
cpuprof.addNonGo(sigprofCallers[:n])
4727-
}
4728-
4729-
atomic.Store(&sigprofCallersUse, 0)
4730-
}
4731-
4732-
// sigprofNonGoPC is called when a profiling signal arrived on a
4733-
// non-Go thread and we have a single PC value, not a stack trace.
4734-
// g is nil, and what we can do is very limited.
4735-
//go:nosplit
4736-
//go:nowritebarrierrec
4737-
func sigprofNonGoPC(pc uintptr) {
4738-
if prof.hz != 0 {
4739-
stk := []uintptr{
4740-
pc,
4741-
abi.FuncPCABIInternal(_ExternalCode) + sys.PCQuantum,
4742-
}
4743-
cpuprof.addNonGo(stk)
4744-
}
4745-
}
4746-
47474708
// setcpuprofilerate sets the CPU profiling rate to hz times per second.
47484709
// If hz <= 0, setcpuprofilerate turns off CPU profiling.
47494710
func setcpuprofilerate(hz int32) {

src/runtime/signal_unix.go

+40
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ package runtime
1010
import (
1111
"internal/abi"
1212
"runtime/internal/atomic"
13+
"runtime/internal/sys"
1314
"unsafe"
1415
)
1516

@@ -469,6 +470,45 @@ func sigtrampgo(sig uint32, info *siginfo, ctx unsafe.Pointer) {
469470
}
470471
}
471472

473+
// If the signal handler receives a SIGPROF signal on a non-Go thread,
474+
// it tries to collect a traceback into sigprofCallers.
475+
// sigprofCallersUse is set to non-zero while sigprofCallers holds a traceback.
476+
var sigprofCallers cgoCallers
477+
var sigprofCallersUse uint32
478+
479+
// sigprofNonGo is called if we receive a SIGPROF signal on a non-Go thread,
480+
// and the signal handler collected a stack trace in sigprofCallers.
481+
// When this is called, sigprofCallersUse will be non-zero.
482+
// g is nil, and what we can do is very limited.
483+
//go:nosplit
484+
//go:nowritebarrierrec
485+
func sigprofNonGo() {
486+
if prof.hz != 0 {
487+
n := 0
488+
for n < len(sigprofCallers) && sigprofCallers[n] != 0 {
489+
n++
490+
}
491+
cpuprof.addNonGo(sigprofCallers[:n])
492+
}
493+
494+
atomic.Store(&sigprofCallersUse, 0)
495+
}
496+
497+
// sigprofNonGoPC is called when a profiling signal arrived on a
498+
// non-Go thread and we have a single PC value, not a stack trace.
499+
// g is nil, and what we can do is very limited.
500+
//go:nosplit
501+
//go:nowritebarrierrec
502+
func sigprofNonGoPC(pc uintptr) {
503+
if prof.hz != 0 {
504+
stk := []uintptr{
505+
pc,
506+
abi.FuncPCABIInternal(_ExternalCode) + sys.PCQuantum,
507+
}
508+
cpuprof.addNonGo(stk)
509+
}
510+
}
511+
472512
// adjustSignalStack adjusts the current stack guard based on the
473513
// stack pointer that is actually in use while handling a signal.
474514
// We do this in case some non-Go code called sigaltstack.

0 commit comments

Comments
 (0)