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

Nicholas Piggin npiggin at gmail.com
Wed Apr 17 18:11:48 AEST 2019


Stewart Smith's on April 17, 2019 5:39 pm:
> Nicholas Piggin <npiggin at gmail.com> writes:
>> The Linux wrapper for OPAL call and return is arranged like this:
>>
>>   __opal_call:
>>       mflr   r0
>>       std    r0,PPC_STK_LROFF(r1)
>>       LOAD_REG_ADDR(r11, opal_return)
>>       mtlr   r11
>>       hrfid  -> OPAL
>>
>>   opal_return:
>>       ld     r0,PPC_STK_LROFF(r1)
>>       mtlr   r0
>>       blr
>>
>> 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.
> 
> Okay, wow. Also, cool. I'm guessing you spent some time with instruction
> traces. Merged to master as of 32a23ae6b0d3549bec7338e439e504db263dc390
> 
> I also now feel even worse about the multiple seconds that can be spent
> in some OPAL calls in pathalogical cases.

Don't feel too bad, I recently redid the OPAL entry/exit in Linux
(75d9fc7fd94e) and it slowed things down more than I've been able
to make up (but fixed a few bugs and made things generally a bit
saner).

This patch was mostly about tying up the loose end of that change.

One day we might sit down and come up with a v4 calling convention,
if we really want to optimise things, but I don't think that's really
a priority. It's probably something we'd do if some other reasons
came up that required it (e.g., if we execute firmware with MMU on).

Thanks,
Nick



More information about the Skiboot mailing list