Skip to content

Commit

Permalink
KVM: PPC: Book3S HV P9: Optimise hash guest SLB saving
Browse files Browse the repository at this point in the history
slbmfee/slbmfev instructions are very expensive, moreso than a regular
mfspr instruction, so minimising them significantly improves hash guest
exit performance. The slbmfev is only required if slbmfee found a valid
SLB entry.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20211123095231.1036501-47-npiggin@gmail.com
  • Loading branch information
Nicholas Piggin authored and Michael Ellerman committed Nov 24, 2021
1 parent b49c65c commit 241d1f1
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions arch/powerpc/kvm/book3s_hv_p9_entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,10 +487,22 @@ static void __accumulate_time(struct kvm_vcpu *vcpu, struct kvmhv_tb_accumulator
#define accumulate_time(vcpu, next) do {} while (0)
#endif

static inline void mfslb(unsigned int idx, u64 *slbee, u64 *slbev)
static inline u64 mfslbv(unsigned int idx)
{
asm volatile("slbmfev %0,%1" : "=r" (*slbev) : "r" (idx));
asm volatile("slbmfee %0,%1" : "=r" (*slbee) : "r" (idx));
u64 slbev;

asm volatile("slbmfev %0,%1" : "=r" (slbev) : "r" (idx));

return slbev;
}

static inline u64 mfslbe(unsigned int idx)
{
u64 slbee;

asm volatile("slbmfee %0,%1" : "=r" (slbee) : "r" (idx));

return slbee;
}

static inline void mtslb(u64 slbee, u64 slbev)
Expand Down Expand Up @@ -620,8 +632,10 @@ static void save_clear_guest_mmu(struct kvm *kvm, struct kvm_vcpu *vcpu)
*/
for (i = 0; i < vcpu->arch.slb_nr; i++) {
u64 slbee, slbev;
mfslb(i, &slbee, &slbev);

slbee = mfslbe(i);
if (slbee & SLB_ESID_V) {
slbev = mfslbv(i);
vcpu->arch.slb[nr].orige = slbee | i;
vcpu->arch.slb[nr].origv = slbev;
nr++;
Expand Down

0 comments on commit 241d1f1

Please sign in to comment.