diff options
| author | Russ Cox <rsc@golang.org> | 2021-02-15 09:25:55 -0500 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2021-02-19 00:02:23 +0000 |
| commit | aa0388f2ed937669e9f938da8a65c75ea144ebfd (patch) | |
| tree | 511a009cdb84a169c59d4f486a6791616aa7a19d /src/runtime/asm_mipsx.s | |
| parent | 6fe8981620aa61cb43476538f8230231623f9e13 (diff) | |
| download | go-aa0388f2ed937669e9f938da8a65c75ea144ebfd.tar.xz | |
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 <rsc@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Diffstat (limited to 'src/runtime/asm_mipsx.s')
| -rw-r--r-- | src/runtime/asm_mipsx.s | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/runtime/asm_mipsx.s b/src/runtime/asm_mipsx.s index 341da8e8d7..cf4b1b42cc 100644 --- a/src/runtime/asm_mipsx.s +++ b/src/runtime/asm_mipsx.s @@ -92,12 +92,15 @@ 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), R3 - MOVW gobuf_g(R3), g // make sure g is not nil - JAL runtime·save_g(SB) + MOVW gobuf_g(R3), R4 + MOVW 0(R4), R5 // make sure g != nil + JMP gogo<>(SB) - MOVW 0(g), R2 +TEXT gogo<>(SB),NOSPLIT|NOFRAME,$0 + MOVW R4, g + JAL runtime·save_g(SB) MOVW gobuf_sp(R3), R29 MOVW gobuf_lr(R3), R31 MOVW gobuf_ret(R3), R1 @@ -118,7 +121,6 @@ TEXT runtime·mcall(SB),NOSPLIT|NOFRAME,$0-4 MOVW R29, (g_sched+gobuf_sp)(g) MOVW R31, (g_sched+gobuf_pc)(g) MOVW R0, (g_sched+gobuf_lr)(g) - MOVW g, (g_sched+gobuf_g)(g) // Switch to m->g0 & its stack, call fn. MOVW g, R1 @@ -404,7 +406,6 @@ TEXT gosave_systemstack_switch<>(SB),NOSPLIT|NOFRAME,$0 MOVW R29, (g_sched+gobuf_sp)(g) MOVW R0, (g_sched+gobuf_lr)(g) MOVW R0, (g_sched+gobuf_ret)(g) - MOVW g, (g_sched+gobuf_g)(g) // Assert ctxt is zero. See func save. MOVW (g_sched+gobuf_ctxt)(g), R1 BEQ R1, 2(PC) |
