public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/2] KVM: x86: Avoid issuing wbinvd twice
@ 2010-11-01 13:01 Jan Kiszka
  2010-11-01 17:57 ` Marcelo Tosatti
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Kiszka @ 2010-11-01 13:01 UTC (permalink / raw)
  To: Avi Kivity, Marcelo Tosatti; +Cc: kvm, Sheng Yang

From: Jan Kiszka <jan.kiszka@siemens.com>

Micro optimization to avoid calling wbinvd twice on the CPU that has to
emulate it. As we might be preempted between smp_call_function_many and
the local wbinvd, the cache might be filled again so that real work
could be done uselessly.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---

I can fold the first patch into this one if it's preferred.

 arch/x86/kvm/x86.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 0ed6dad..58e8232 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -4012,13 +4012,15 @@ int kvm_emulate_wbinvd(struct kvm_vcpu *vcpu)
 		return X86EMUL_CONTINUE;
 
 	if (kvm_x86_ops->has_wbinvd_exit()) {
-		preempt_disable();
+		int cpu = get_cpu();
+
+		cpumask_set_cpu(cpu, vcpu->arch.wbinvd_dirty_mask);
 		smp_call_function_many(vcpu->arch.wbinvd_dirty_mask,
 				wbinvd_ipi, NULL, 1);
-		preempt_enable();
+		put_cpu();
 		cpumask_clear(vcpu->arch.wbinvd_dirty_mask);
-	}
-	wbinvd();
+	} else
+		wbinvd();
 	return X86EMUL_CONTINUE;
 }
 EXPORT_SYMBOL_GPL(kvm_emulate_wbinvd);

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

* Re: [PATCH 2/2] KVM: x86: Avoid issuing wbinvd twice
  2010-11-01 13:01 [PATCH 2/2] KVM: x86: Avoid issuing wbinvd twice Jan Kiszka
@ 2010-11-01 17:57 ` Marcelo Tosatti
  0 siblings, 0 replies; 2+ messages in thread
From: Marcelo Tosatti @ 2010-11-01 17:57 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: Avi Kivity, kvm, Sheng Yang

On Mon, Nov 01, 2010 at 02:01:29PM +0100, Jan Kiszka wrote:
> From: Jan Kiszka <jan.kiszka@siemens.com>
> 
> Micro optimization to avoid calling wbinvd twice on the CPU that has to
> emulate it. As we might be preempted between smp_call_function_many and
> the local wbinvd, the cache might be filled again so that real work
> could be done uselessly.
> 
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>

Applied both, thanks.


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

end of thread, other threads:[~2010-11-01 18:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-01 13:01 [PATCH 2/2] KVM: x86: Avoid issuing wbinvd twice Jan Kiszka
2010-11-01 17:57 ` Marcelo Tosatti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox