[Skiboot] [PATCH] asm/head: balance branches to avoid link stack predictor mispredicts

Nicholas Piggin npiggin at gmail.com
Sun Apr 14 15:18:37 AEST 2019

The Linux wrapper for OPAL call and return is arranged like this:

      mflr   r0
      std    r0,PPC_STK_LROFF(r1)
      LOAD_REG_ADDR(r11, opal_return)
      mtlr   r11
      hrfid  -> OPAL

      ld     r0,PPC_STK_LROFF(r1)
      mtlr   r0

When skiboot returns to Linux, it branches to LR (i.e., opal_return)
with a blr. This unbalances the link stack predictor and will cause
mispredicts back up the return stack.

Signed-off-by: Nicholas Piggin <npiggin at gmail.com>
 asm/head.S | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/asm/head.S b/asm/head.S
index 0ed1acddd..07284bbef 100644
--- a/asm/head.S
+++ b/asm/head.S
@@ -1087,7 +1087,12 @@ opal_entry:
 	lwz	%r11,CPUTHREAD_IN_OPAL_CALL(%r12)
 	subi	%r11,%r11,1
 	stw	%r11,CPUTHREAD_IN_OPAL_CALL(%r12)
-	blr
+	/*
+	 * blr with BH=01b means it's not a function return, OPAL was entered
+	 * via (h)rfid not bl, so we don't have a corresponding link stack
+	 * prediction to return to here.
+	 */
+	bclr	20,0,1
 .global start_kernel

More information about the Skiboot mailing list