Skip to content

Commit 185e1a7

Browse files
committed
runtime: prioritize VDSO and libcall unwinding in profiler
In the profiler, when unwinding the stack, we have special handling for VDSO calls. Currently, the special handling is only used when the normal unwinding fails. If the signal lands in the function that makes the VDSO call (e.g. nanotime1) and after the stack switch, the normal unwinding doesn't fail but gets a stack trace with exactly one frame (the nanotime1 frame). The stack trace stops because of the stack switch. This 1-frame stack trace is not as helpful. Instead, if vdsoSP is set, we know we are in VDSO call or right before or after it, so use vdsoPC and vdsoSP for unwinding. Do the same for libcall. Also remove _TraceTrap for VDSO unwinding, as vdsoPC and vdsoSP correspond to a call, not an interrupted instruction. Fixes #56574. Change-Id: I799aa7644d0c1e2715ab038a9eef49481dd3a7f5 Reviewed-on: https://go-review.googlesource.com/c/go/+/455166 Run-TryBot: Cherry Mui <[email protected]> Reviewed-by: Michael Pratt <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent a5b10be commit 185e1a7

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

src/runtime/proc.go

+21-25
Original file line numberDiff line numberDiff line change
@@ -4719,37 +4719,33 @@ func sigprof(pc, sp, lr uintptr, gp *g, mp *m) {
47194719
if n > 0 {
47204720
n += cgoOff
47214721
}
4722+
} else if usesLibcall() && mp.libcallg != 0 && mp.libcallpc != 0 && mp.libcallsp != 0 {
4723+
// Libcall, i.e. runtime syscall on windows.
4724+
// Collect Go stack that leads to the call.
4725+
n = gentraceback(mp.libcallpc, mp.libcallsp, 0, mp.libcallg.ptr(), 0, &stk[n], len(stk[n:]), nil, nil, 0)
4726+
} else if mp != nil && mp.vdsoSP != 0 {
4727+
// VDSO call, e.g. nanotime1 on Linux.
4728+
// Collect Go stack that leads to the call.
4729+
n = gentraceback(mp.vdsoPC, mp.vdsoSP, 0, gp, 0, &stk[n], len(stk[n:]), nil, nil, _TraceJumpStack)
47224730
} else {
47234731
n = gentraceback(pc, sp, lr, gp, 0, &stk[0], len(stk), nil, nil, _TraceTrap|_TraceJumpStack)
47244732
}
47254733

47264734
if n <= 0 {
47274735
// Normal traceback is impossible or has failed.
4728-
// See if it falls into several common cases.
4729-
n = 0
4730-
if usesLibcall() && mp.libcallg != 0 && mp.libcallpc != 0 && mp.libcallsp != 0 {
4731-
// Libcall, i.e. runtime syscall on windows.
4732-
// Collect Go stack that leads to the call.
4733-
n = gentraceback(mp.libcallpc, mp.libcallsp, 0, mp.libcallg.ptr(), 0, &stk[0], len(stk), nil, nil, 0)
4734-
}
4735-
if n == 0 && mp != nil && mp.vdsoSP != 0 {
4736-
n = gentraceback(mp.vdsoPC, mp.vdsoSP, 0, gp, 0, &stk[0], len(stk), nil, nil, _TraceTrap|_TraceJumpStack)
4737-
}
4738-
if n == 0 {
4739-
// If all of the above has failed, account it against abstract "System" or "GC".
4740-
n = 2
4741-
if inVDSOPage(pc) {
4742-
pc = abi.FuncPCABIInternal(_VDSO) + sys.PCQuantum
4743-
} else if pc > firstmoduledata.etext {
4744-
// "ExternalCode" is better than "etext".
4745-
pc = abi.FuncPCABIInternal(_ExternalCode) + sys.PCQuantum
4746-
}
4747-
stk[0] = pc
4748-
if mp.preemptoff != "" {
4749-
stk[1] = abi.FuncPCABIInternal(_GC) + sys.PCQuantum
4750-
} else {
4751-
stk[1] = abi.FuncPCABIInternal(_System) + sys.PCQuantum
4752-
}
4736+
// Account it against abstract "System" or "GC".
4737+
n = 2
4738+
if inVDSOPage(pc) {
4739+
pc = abi.FuncPCABIInternal(_VDSO) + sys.PCQuantum
4740+
} else if pc > firstmoduledata.etext {
4741+
// "ExternalCode" is better than "etext".
4742+
pc = abi.FuncPCABIInternal(_ExternalCode) + sys.PCQuantum
4743+
}
4744+
stk[0] = pc
4745+
if mp.preemptoff != "" {
4746+
stk[1] = abi.FuncPCABIInternal(_GC) + sys.PCQuantum
4747+
} else {
4748+
stk[1] = abi.FuncPCABIInternal(_System) + sys.PCQuantum
47534749
}
47544750
}
47554751

0 commit comments

Comments
 (0)