Commit 34bf08a2 authored by Nicholas Piggin's avatar Nicholas Piggin Committed by Michael Ellerman

KVM: PPC: Book3S HV P9: Reduce mftb per guest entry/exit

mftb is serialising (dispatch next-to-complete) so it is heavy weight
for a mfspr. Avoid reading it multiple times in the entry or exit paths.
A small number of cycles delay to timers is tolerable.
Signed-off-by: default avatarNicholas Piggin <npiggin@gmail.com>
Reviewed-by: default avatarFabiano Rosas <farosas@linux.ibm.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20211123095231.1036501-7-npiggin@gmail.com
parent 9581991a
...@@ -3940,7 +3940,7 @@ static int kvmhv_p9_guest_entry(struct kvm_vcpu *vcpu, u64 time_limit, ...@@ -3940,7 +3940,7 @@ static int kvmhv_p9_guest_entry(struct kvm_vcpu *vcpu, u64 time_limit,
* *
* XXX: Another day's problem. * XXX: Another day's problem.
*/ */
mtspr(SPRN_DEC, vcpu->arch.dec_expires - mftb()); mtspr(SPRN_DEC, vcpu->arch.dec_expires - tb);
if (kvmhv_on_pseries()) { if (kvmhv_on_pseries()) {
/* /*
...@@ -4063,7 +4063,7 @@ static int kvmhv_p9_guest_entry(struct kvm_vcpu *vcpu, u64 time_limit, ...@@ -4063,7 +4063,7 @@ static int kvmhv_p9_guest_entry(struct kvm_vcpu *vcpu, u64 time_limit,
vc->in_guest = 0; vc->in_guest = 0;
next_timer = timer_get_next_tb(); next_timer = timer_get_next_tb();
set_dec(next_timer - mftb()); set_dec(next_timer - tb);
/* We may have raced with new irq work */ /* We may have raced with new irq work */
if (test_irq_work_pending()) if (test_irq_work_pending())
set_dec(1); set_dec(1);
......
...@@ -203,7 +203,8 @@ int kvmhv_vcpu_entry_p9(struct kvm_vcpu *vcpu, u64 time_limit, unsigned long lpc ...@@ -203,7 +203,8 @@ int kvmhv_vcpu_entry_p9(struct kvm_vcpu *vcpu, u64 time_limit, unsigned long lpc
unsigned long host_dawr1; unsigned long host_dawr1;
unsigned long host_dawrx1; unsigned long host_dawrx1;
hdec = time_limit - mftb(); tb = mftb();
hdec = time_limit - tb;
if (hdec < 0) if (hdec < 0)
return BOOK3S_INTERRUPT_HV_DECREMENTER; return BOOK3S_INTERRUPT_HV_DECREMENTER;
...@@ -215,7 +216,7 @@ int kvmhv_vcpu_entry_p9(struct kvm_vcpu *vcpu, u64 time_limit, unsigned long lpc ...@@ -215,7 +216,7 @@ int kvmhv_vcpu_entry_p9(struct kvm_vcpu *vcpu, u64 time_limit, unsigned long lpc
vcpu->arch.ceded = 0; vcpu->arch.ceded = 0;
if (vc->tb_offset) { if (vc->tb_offset) {
u64 new_tb = mftb() + vc->tb_offset; u64 new_tb = tb + vc->tb_offset;
mtspr(SPRN_TBU40, new_tb); mtspr(SPRN_TBU40, new_tb);
tb = mftb(); tb = mftb();
if ((tb & 0xffffff) < (new_tb & 0xffffff)) if ((tb & 0xffffff) < (new_tb & 0xffffff))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment