Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: PPC: Use exported tb_to_ns() function in decrementer emulation

This changes the KVM code that emulates the decrementer function to do
the conversion of decrementer values to time intervals in nanoseconds
by calling the tb_to_ns() function exported by the powerpc timer code,
in preference to open-coded arithmetic using values from the
decrementer_clockevent struct. Similarly, the HV-KVM code that did
the same conversion using arithmetic on tb_ticks_per_sec also now
uses tb_to_ns().

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>

authored by

Paul Mackerras and committed by
Michael Ellerman
c43befca 772b039f

+4 -6
+1 -2
arch/powerpc/kvm/book3s_hv.c
··· 2160 2160 kvmppc_core_prepare_to_enter(vcpu); 2161 2161 return; 2162 2162 } 2163 - dec_nsec = (vcpu->arch.dec_expires - now) * NSEC_PER_SEC 2164 - / tb_ticks_per_sec; 2163 + dec_nsec = tb_to_ns(vcpu->arch.dec_expires - now); 2165 2164 hrtimer_start(&vcpu->arch.dec_timer, dec_nsec, HRTIMER_MODE_REL); 2166 2165 vcpu->arch.timer_running = 1; 2167 2166 }
+3 -4
arch/powerpc/kvm/emulate.c
··· 61 61 62 62 dec_time = vcpu->arch.dec; 63 63 /* 64 - * Guest timebase ticks at the same frequency as host decrementer. 65 - * So use the host decrementer calculations for decrementer emulation. 64 + * Guest timebase ticks at the same frequency as host timebase. 65 + * So use the host timebase calculations for decrementer emulation. 66 66 */ 67 - dec_time = dec_time << decrementer_clockevent.shift; 68 - do_div(dec_time, decrementer_clockevent.mult); 67 + dec_time = tb_to_ns(dec_time); 69 68 dec_nsec = do_div(dec_time, NSEC_PER_SEC); 70 69 hrtimer_start(&vcpu->arch.dec_timer, 71 70 ktime_set(dec_time, dec_nsec), HRTIMER_MODE_REL);