From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: [RFC] KVM: optimize the kvm_vcpu_on_spin Date: Mon, 31 Jul 2017 15:20:11 +0200 Message-ID: <3572e95a-a5eb-748b-25c8-b7e128cbbe1b@redhat.com> References: <1501309377-195256-1-git-send-email-longpeng2@huawei.com> <597F1DAE.4020809@huawei.com> <0677ed6e-280a-d2f3-d873-1daf99b39551@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: rkrcmar@redhat.com, agraf@suse.com, borntraeger@de.ibm.com, cohuck@redhat.com, christoffer.dall@linaro.org, marc.zyngier@arm.com, james.hogan@imgtec.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, weidong.huang@huawei.com, arei.gonglei@huawei.com, wangxinxin.wang@huawei.com, longpeng.mike@gmail.com To: David Hildenbrand , "Longpeng (Mike)" Return-path: In-Reply-To: <0677ed6e-280a-d2f3-d873-1daf99b39551@redhat.com> Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org On 31/07/2017 14:27, David Hildenbrand wrote: >> I'm not sure whether the operation of get the vcpu's priority-level is >> expensive on all architectures, so I record it in kvm_sched_out() for >> minimal the extra cycles cost in kvm_vcpu_on_spin(). >> > as you only care for x86 right now either way, you can directly optimize > here for the good (here: x86) case (keeping changes and therefore > possible bugs minimal). I agree with Cornelia that this is inconsistent, so you shouldn't update me->in_kernmode in kvm_vcpu_on_spin. However, get_cpl requires vcpu_load on Intel x86, so Mike's patch is necessary (vmx_get_cpl -> vmx_read_guest_seg_ar -> vmcs_read32). Alternatively, we can add a new callback kvm_x86_ops->sched_out to x86 KVM, and call vmx_get_cpl from the Intel implementation (vmx_sched_out). This will cache the result until the next sched_in, so that kvm_vcpu_on_spin can use it. Paolo