From aa0388f2ed937669e9f938da8a65c75ea144ebfd Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Mon, 15 Feb 2021 09:25:55 -0500 Subject: runtime: remove unnecessary writes to gp.sched.g A g's sched.g is set in newproc1: newg.sched.g = guintptr(unsafe.Pointer(newg)) After that, it never changes. Yet lots of assembly code does "g.sched.g = g" unnecessarily. Remove all those lines to avoid confusion about whether it ever changes. Also, split gogo into two functions, one that does the nil g check and a second that does the actual switch. This way, if the nil g check fails, we get a stack trace showing the call stack that led to the failure. (The SP write would otherwise cause the stack trace to abort.) Also restore the proper nil g check in a handful of assembly functions. (There is little point in checking for nil g *after* installing it as the real g.) Change-Id: I22866b093f901f765de1d074e36eeec10366abfb Reviewed-on: https://go-review.googlesource.com/c/go/+/292109 Trust: Russ Cox Reviewed-by: Cherry Zhang --- src/runtime/asm_arm.s | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'src/runtime/asm_arm.s') diff --git a/src/runtime/asm_arm.s b/src/runtime/asm_arm.s index c8c53e70db..92d7854306 100644 --- a/src/runtime/asm_arm.s +++ b/src/runtime/asm_arm.s @@ -208,21 +208,14 @@ TEXT runtime·asminit(SB),NOSPLIT,$0-0 // void gogo(Gobuf*) // restore state from Gobuf; longjmp -TEXT runtime·gogo(SB),NOSPLIT,$8-4 +TEXT runtime·gogo(SB),NOSPLIT|NOFRAME,$0-4 MOVW buf+0(FP), R1 MOVW gobuf_g(R1), R0 - BL setg<>(SB) + MOVW 0(R0), R2 // make sure g != nil + B gogo<>(SB) - // NOTE: We updated g above, and we are about to update SP. - // Until LR and PC are also updated, the g/SP/LR/PC quadruple - // are out of sync and must not be used as the basis of a traceback. - // Sigprof skips the traceback when SP is not within g's bounds, - // and when the PC is inside this function, runtime.gogo. - // Since we are about to update SP, until we complete runtime.gogo - // we must not leave this function. In particular, no calls - // after this point: it must be straight-line code until the - // final B instruction. - // See large comment in sigprof for more details. +TEXT gogo<>(SB),NOSPLIT|NOFRAME,$0 + BL setg<>(SB) MOVW gobuf_sp(R1), R13 // restore SP==R13 MOVW gobuf_lr(R1), LR MOVW gobuf_ret(R1), R0 @@ -246,7 +239,6 @@ TEXT runtime·mcall(SB),NOSPLIT|NOFRAME,$0-4 MOVW LR, (g_sched+gobuf_pc)(g) MOVW $0, R11 MOVW R11, (g_sched+gobuf_lr)(g) - MOVW g, (g_sched+gobuf_g)(g) // Switch to m->g0 & its stack, call fn. MOVW g, R1 @@ -537,7 +529,6 @@ TEXT gosave_systemstack_switch<>(SB),NOSPLIT|NOFRAME,$0 ADD $4, R11 // get past push {lr} MOVW R11, (g_sched+gobuf_pc)(g) MOVW R13, (g_sched+gobuf_sp)(g) - MOVW g, (g_sched+gobuf_g)(g) MOVW $0, R11 MOVW R11, (g_sched+gobuf_lr)(g) MOVW R11, (g_sched+gobuf_ret)(g) -- cgit v1.3