Re: [PATCH] KVM: x86: Optimize local variable in start_sw_tscdeadline()
From: Sean Christopherson
Date: Wed Aug 14 2024 - 17:34:02 EST
On Wed, Aug 14, 2024, Thorsten Blum wrote:
> Change the data type of the local variable this_tsc_khz to u32 because
> virtual_tsc_khz is also declared as u32.
Heh, thought this looked familiar[*]. I'll plan on applying this for 6.12.
[*] https://lore.kernel.org/all/ZT_WBanoip8zhxis@xxxxxxxxxx
> Since do_div() casts the divisor to u32 anyway, changing the data type
> of this_tsc_khz to u32 also removes the following Coccinelle/coccicheck
> warning reported by do_div.cocci:
>
> WARNING: do_div() does a 64-by-32 division, please consider using div64_ul instead
>
> Compile-tested only.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@xxxxxxxxxx>
> ---
> arch/x86/kvm/lapic.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
> index a7172ba59ad2..40ff955c1859 100644
> --- a/arch/x86/kvm/lapic.c
> +++ b/arch/x86/kvm/lapic.c
> @@ -1946,7 +1946,7 @@ static void start_sw_tscdeadline(struct kvm_lapic *apic)
> u64 ns = 0;
> ktime_t expire;
> struct kvm_vcpu *vcpu = apic->vcpu;
> - unsigned long this_tsc_khz = vcpu->arch.virtual_tsc_khz;
> + u32 this_tsc_khz = vcpu->arch.virtual_tsc_khz;
> unsigned long flags;
> ktime_t now;
>
> --
> 2.45.2
>