kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: x86: Optimize local variable in start_sw_tscdeadline()
@ 2024-08-14 20:33 Thorsten Blum
  2024-08-14 21:33 ` Sean Christopherson
  2024-08-23 23:47 ` Sean Christopherson
  0 siblings, 2 replies; 3+ messages in thread
From: Thorsten Blum @ 2024-08-14 20:33 UTC (permalink / raw)
  To: seanjc, pbonzini, tglx, mingo, bp, dave.hansen, x86, hpa
  Cc: kvm, linux-kernel, Thorsten Blum

Change the data type of the local variable this_tsc_khz to u32 because
virtual_tsc_khz is also declared as u32.

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@toblux.com>
---
 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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] KVM: x86: Optimize local variable in start_sw_tscdeadline()
  2024-08-14 20:33 [PATCH] KVM: x86: Optimize local variable in start_sw_tscdeadline() Thorsten Blum
@ 2024-08-14 21:33 ` Sean Christopherson
  2024-08-23 23:47 ` Sean Christopherson
  1 sibling, 0 replies; 3+ messages in thread
From: Sean Christopherson @ 2024-08-14 21:33 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: pbonzini, tglx, mingo, bp, dave.hansen, x86, hpa, kvm,
	linux-kernel

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@google.com

> 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@toblux.com>
> ---
>  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
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] KVM: x86: Optimize local variable in start_sw_tscdeadline()
  2024-08-14 20:33 [PATCH] KVM: x86: Optimize local variable in start_sw_tscdeadline() Thorsten Blum
  2024-08-14 21:33 ` Sean Christopherson
@ 2024-08-23 23:47 ` Sean Christopherson
  1 sibling, 0 replies; 3+ messages in thread
From: Sean Christopherson @ 2024-08-23 23:47 UTC (permalink / raw)
  To: Sean Christopherson, pbonzini, tglx, mingo, bp, dave.hansen, x86,
	hpa, Thorsten Blum
  Cc: kvm, linux-kernel

On Wed, 14 Aug 2024 22:33:46 +0200, 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.
> 
> 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:
> 
> [...]

Applied to kvm-x86 misc, thanks!

[1/1] KVM: x86: Optimize local variable in start_sw_tscdeadline()
      https://github.com/kvm-x86/linux/commit/1448d4a935ab

--
https://github.com/kvm-x86/linux/tree/next

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-08-23 23:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-14 20:33 [PATCH] KVM: x86: Optimize local variable in start_sw_tscdeadline() Thorsten Blum
2024-08-14 21:33 ` Sean Christopherson
2024-08-23 23:47 ` Sean Christopherson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).