From 79ae97fe9bf44814f7bed7e6a6297150070817f3 Mon Sep 17 00:00:00 2001 From: Michael Anthony Knyszek Date: Fri, 17 Oct 2025 20:02:55 +0000 Subject: [PATCH] runtime: make procyieldAsm no longer loop infinitely if passed 0 Change-Id: I9f01692373623687e09bee54efebaac0ee361f81 Reviewed-on: https://go-review.googlesource.com/c/go/+/712664 Auto-Submit: Michael Knyszek Reviewed-by: Cherry Mui LUCI-TryBot-Result: Go LUCI --- src/runtime/asm_386.s | 3 +++ src/runtime/asm_amd64.s | 3 +++ src/runtime/asm_arm64.s | 2 ++ src/runtime/asm_ppc64x.s | 3 +++ src/runtime/stubs.go | 7 ------- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/runtime/asm_386.s b/src/runtime/asm_386.s index a54ca110e5..03f1a46b55 100644 --- a/src/runtime/asm_386.s +++ b/src/runtime/asm_386.s @@ -599,10 +599,13 @@ CALLFN(·call1073741824, 1073741824) TEXT runtime·procyieldAsm(SB),NOSPLIT,$0-0 MOVL cycles+0(FP), AX + TESTL AX, AX + JZ done again: PAUSE SUBL $1, AX JNZ again +done: RET TEXT ·publicationBarrier(SB),NOSPLIT,$0-0 diff --git a/src/runtime/asm_amd64.s b/src/runtime/asm_amd64.s index dbf54487a7..a4c6c53a90 100644 --- a/src/runtime/asm_amd64.s +++ b/src/runtime/asm_amd64.s @@ -817,10 +817,13 @@ CALLFN(·call1073741824, 1073741824) TEXT runtime·procyieldAsm(SB),NOSPLIT,$0-0 MOVL cycles+0(FP), AX + TESTL AX, AX + JZ done again: PAUSE SUBL $1, AX JNZ again +done: RET diff --git a/src/runtime/asm_arm64.s b/src/runtime/asm_arm64.s index 94a5b9ee6c..8bbb6b8a87 100644 --- a/src/runtime/asm_arm64.s +++ b/src/runtime/asm_arm64.s @@ -1038,10 +1038,12 @@ aesloop: TEXT runtime·procyieldAsm(SB),NOSPLIT,$0-0 MOVWU cycles+0(FP), R0 + CBZ R0, done again: YIELD SUBW $1, R0 CBNZ R0, again +done: RET // Save state of caller into g->sched, diff --git a/src/runtime/asm_ppc64x.s b/src/runtime/asm_ppc64x.s index e461764e55..aaa2e4346c 100644 --- a/src/runtime/asm_ppc64x.s +++ b/src/runtime/asm_ppc64x.s @@ -614,6 +614,8 @@ CALLFN(·call1073741824, 1073741824) TEXT runtime·procyieldAsm(SB),NOSPLIT|NOFRAME,$0-4 MOVW cycles+0(FP), R7 + CMP $0, R7 + BEQ done // POWER does not have a pause/yield instruction equivalent. // Instead, we can lower the program priority by setting the // Program Priority Register prior to the wait loop and set it @@ -625,6 +627,7 @@ again: CMP $0, R7 BNE again OR R6, R6, R6 // Set PPR priority back to medium-low +done: RET // Save state of caller into g->sched, diff --git a/src/runtime/stubs.go b/src/runtime/stubs.go index 1692283541..d5a35d15b2 100644 --- a/src/runtime/stubs.go +++ b/src/runtime/stubs.go @@ -283,13 +283,6 @@ func procyield(cycles uint32) { } // procyieldAsm is the assembly implementation of procyield. -// -// It may loop infinitely if called with cycles == 0. Prefer -// procyield, which will compile down to nothing in such cases, -// instead. -// -// FIXME: The implementation really should not loop infinitely if -// the number of cycles is 0. func procyieldAsm(cycles uint32) type neverCallThisFunction struct{} -- 2.52.0