KVM: PPC: Use exported tb_to_ns() function in decrementer emulation
Subsystems (3)
PATCH 1/1 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().
--- arch/powerpc/kvm/book3s_hv.c | 3 +-- arch/powerpc/kvm/emulate.c | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-)
arch/powerpc/kvm/book3s_hv.c +1 -2
@@ -2337,8 +2337,7 @@ static void kvmppc_set_timer(struct kvm_vcpu *vcpu)kvmppc_core_prepare_to_enter (vcpu);return ; } - dec_nsec = (vcpu->arch.dec_expires - now) *NSEC_PER_SEC - / tb_ticks_per_sec; + dec_nsec =tb_to_ns (vcpu->arch.dec_expires - now);hrtimer_start (&vcpu->arch.dec_timer, dec_nsec,HRTIMER_MODE_REL ); vcpu->arch.timer_running =1 ; }
arch/powerpc/kvm/emulate.c +2 -4
@@ -62,11 +62,9 @@ void kvmppc_emulate_dec(struct kvm_vcpu *vcpu) dec_time = vcpu->arch.dec;/* * Guest timebase ticks at the same frequency as host decrementer. -* So use the host decrementer calculations for decrementer emulation. +* So use the host timebase calculations for decrementer emulation. */ - dec_time = dec_time << decrementer_clockevent.shift; -do_div (dec_time, decrementer_clockevent.mult); - dec_nsec =do_div (dec_time,NSEC_PER_SEC ); + dec_nsec =tb_to_ns (dec_time);hrtimer_start (&vcpu->arch.dec_timer,ktime_set (dec_time, dec_nsec),HRTIMER_MODE_REL ); vcpu->arch.dec_jiffies =get_tb ();
Signature · 1 line
2.7.4
PATCH v2 1/1 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().
---
v2: don't delete the second do_div in kvmppc_emulate_dec(), we need it.
arch/powerpc/kvm/book3s_hv.c | 3 +-- arch/powerpc/kvm/emulate.c | 7 +++---- 2 files changed, 4 insertions(+), 6 deletions(-)
arch/powerpc/kvm/book3s_hv.c +1 -2
@@ -2337,8 +2337,7 @@ static void kvmppc_set_timer(struct kvm_vcpu *vcpu)kvmppc_core_prepare_to_enter (vcpu);return ; } - dec_nsec = (vcpu->arch.dec_expires - now) *NSEC_PER_SEC - / tb_ticks_per_sec; + dec_nsec =tb_to_ns (vcpu->arch.dec_expires - now);hrtimer_start (&vcpu->arch.dec_timer, dec_nsec,HRTIMER_MODE_REL ); vcpu->arch.timer_running =1 ; }
arch/powerpc/kvm/emulate.c +3 -4
@@ -61,11 +61,10 @@ void kvmppc_emulate_dec(struct kvm_vcpu *vcpu) dec_time = vcpu->arch.dec;/* -* Guest timebase ticks at the same frequency as host decrementer. -* So use the host decrementer calculations for decrementer emulation. +* Guest timebase ticks at the same frequency as host timebase. +* So use the host timebase calculations for decrementer emulation. */ - dec_time = dec_time << decrementer_clockevent.shift; -do_div (dec_time, decrementer_clockevent.mult); + dec_time =tb_to_ns (dec_time); dec_nsec =do_div (dec_time,NSEC_PER_SEC );hrtimer_start (&vcpu->arch.dec_timer,ktime_set (dec_time, dec_nsec),HRTIMER_MODE_REL );
Signature · 1 line
2.7.4
Michael Ellerman
AppliedQuoted 9 lines · Paul Mackerras
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 thedecrementer_clockeventstruct. Similarly, the HV-KVM code that did the same conversion using arithmetic ontb_ticks_per_secalso now usestb_to_ns().Signed-off-by Paul Mackerras <[email protected]>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/c43befca86ae35cc82bd889484bd17
cheers