From mboxrd@z Thu Jan 1 00:00:00 1970 From: Xiao Guangrong Subject: Re: [PATCH 2/3] KVM: send IPI to vcpu only when it's in guest mode Date: Wed, 05 Jan 2011 18:05:35 +0800 Message-ID: <4D24426F.5090000@cn.fujitsu.com> References: <4D243B95.3070203@cn.fujitsu.com> <4D243C05.7060307@cn.fujitsu.com> <4D243E69.60603@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Cc: Marcelo Tosatti , LKML , KVM To: Avi Kivity Return-path: In-Reply-To: <4D243E69.60603@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org On 01/05/2011 05:48 PM, Avi Kivity wrote: >> srcu_read_unlock(&vcpu->kvm->srcu, idx); >> + atomic_set(&vcpu->guest_mode, 1); >> kvm_guest_enter(); > > I think it needs an smp_wmb() (technically x86 needs it too, but x86 is strongly ordered) ...... >> - if (cpus != NULL&& cpu != -1&& cpu != me) >> + if (cpus != NULL&& cpu != -1&& cpu != me&& >> + atomic_read(&vcpu->guest_mode)) >> cpumask_set_cpu(cpu, cpus); > > and smp_rmb() before the atomic_read(). Yeah, you're right, i'll fix these in the next version. > >> } >> if (unlikely(cpus == NULL)) > > Not sure if this is an optimization. On one hand it removes an expensive IPI for the fraction of time the cpu is out of guest mode. On the other hand it adds an unconditional cacheline bounce (and bounce back). > > Hm. I see that ->guest_mode and ->requests are in fact in the same cache line. So this is likely really an optimization. We should probably reorganize kvm_vcpu so that this is made explicit. > OK, will do it in the separate patch in the future, thanks!