Re: [PATCH] KVM: x86: Reduce retpoline performance impact in slot_handle_level_range()
From: Paolo Bonzini
Date: Mon Feb 05 2018 - 10:15:56 EST
On 02/02/2018 19:50, Linus Torvalds wrote:
> On Fri, Feb 2, 2018 at 6:59 AM, David Woodhouse <dwmw@xxxxxxxxxxxx> wrote:
>> With retpoline, tight loops of "call this function for every XXX" are
>> very much pessimised by taking a prediction miss *every* time.
>>
>> This one showed up very high in our early testing, and it only has five
>> things it'll ever call so make it take an 'op' enum instead of a
>> function pointer and let's see how that works out...
> Umm. May I suggest a different workaround?
>
> Honestly, if this is so performance-critical, the *real* fix is to
> actually just mark all those "slot_handle_*()" functions as
> "always_inline".
I replied quickly from the phone before reading the rest of the
thread---yeah, always_inline is the way to go. I see the same
differences as Linus and David (slight improvement for slot_handle_*,
+1k if you add kvm_handle_hva and kvm_handle_hva_range).
At least for slot_handle_* it's a no-brainer. The others are basically
the MMU notifier implementation; in the perfect case it should actually
never be called (or at least it ought to be very rare), so I think we
can keep the indirect calls for now.
Paolo