From 2d99109cfcaef22b6872dc2e07e4582586c032a2 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Mon, 13 Feb 2023 16:20:54 -0500 Subject: runtime: replace all callback uses of gentraceback with unwinder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a really nice simplification for all of these call sites. It also achieves a nice performance improvement for stack copying: goos: linux goarch: amd64 pkg: runtime cpu: Intel(R) Xeon(R) CPU E5-2690 v3 @ 2.60GHz │ before │ after │ │ sec/op │ sec/op vs base │ StackCopyPtr-48 89.25m ± 1% 79.78m ± 1% -10.62% (p=0.000 n=20) StackCopy-48 83.48m ± 2% 71.88m ± 1% -13.90% (p=0.000 n=20) StackCopyNoCache-48 2.504m ± 2% 2.195m ± 1% -12.32% (p=0.000 n=20) StackCopyWithStkobj-48 21.66m ± 1% 21.02m ± 2% -2.95% (p=0.000 n=20) geomean 25.21m 22.68m -10.04% Updates #54466. Change-Id: I31715b7b6efd65726940041d3052bb1c0a1186f3 Reviewed-on: https://go-review.googlesource.com/c/go/+/468297 Run-TryBot: Austin Clements TryBot-Result: Gopher Robot Reviewed-by: Michael Pratt --- src/runtime/traceback.go | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'src/runtime/traceback.go') diff --git a/src/runtime/traceback.go b/src/runtime/traceback.go index 02dff5ccdf..665961f9b1 100644 --- a/src/runtime/traceback.go +++ b/src/runtime/traceback.go @@ -542,16 +542,16 @@ func (u *unwinder) finishInternal() { } // Generic traceback. Handles runtime stack prints (pcbuf == nil), -// the runtime.Callers function (pcbuf != nil), as well as the garbage -// collector (callback != nil). A little clunky to merge these, but avoids +// and the runtime.Callers function (pcbuf != nil). +// A little clunky to merge these, but avoids // duplicating the code and all its subtlety. // // The skip argument is only valid with pcbuf != nil and counts the number // of logical frames to skip rather than physical frames (with inlining, a // PC in pcbuf can represent multiple calls). func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max int, callback func(*stkframe, unsafe.Pointer) bool, v unsafe.Pointer, flags uint) int { - if skip > 0 && callback != nil { - throw("gentraceback callback cannot be used with non-zero skip") + if callback != nil { + throw("callback argument no longer supported") } // Translate flags @@ -559,7 +559,7 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in printing := pcbuf == nil && callback == nil if printing { uflags |= unwindPrintErrors - } else if callback == nil { + } else { uflags |= unwindSilentErrors } if flags&_TraceTrap != 0 { @@ -581,12 +581,6 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in frame := &u.frame f := frame.fn - if callback != nil { - if !callback((*stkframe)(noescape(unsafe.Pointer(frame))), v) { - return n - } - } - // Backup to the CALL instruction to read inlining info // // Normally, pc is a return address. In that case, we want to look up @@ -670,9 +664,7 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in u.cgoCtxt-- // skip only applies to Go frames. - // callback != nil only used when we only care - // about Go frames. - if skip == 0 && callback == nil { + if skip == 0 { n = tracebackCgoContext(pcbuf, printing, ctxt, n, max) } } -- cgit v1.3