From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: [PATCH/RFC] KVM: do early exit in kvm_check_request Date: Fri, 9 Sep 2016 18:35:49 +0200 Message-ID: <94de9256-838c-73e6-d6de-2338a552d5df@redhat.com> References: <1473415834-98576-1-git-send-email-borntraeger@de.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: KVM To: Christian Borntraeger , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= Return-path: Received: from mx1.redhat.com ([209.132.183.28]:54492 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751121AbcIIQfw (ORCPT ); Fri, 9 Sep 2016 12:35:52 -0400 In-Reply-To: <1473415834-98576-1-git-send-email-borntraeger@de.ibm.com> Sender: kvm-owner@vger.kernel.org List-ID: On 09/09/2016 12:10, Christian Borntraeger wrote: > By checking vcpu->requests we can do an early exit and allow gcc > to optimize multiple kvm_check_request into one block for the > common case (no requests). > > Signed-off-by: Christian Borntraeger > --- > include/linux/kvm_host.h | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > index 1c9c973..b15b460 100644 > --- a/include/linux/kvm_host.h > +++ b/include/linux/kvm_host.h > @@ -1115,6 +1115,8 @@ static inline void kvm_make_request(int req, struct kvm_vcpu *vcpu) > > static inline bool kvm_check_request(int req, struct kvm_vcpu *vcpu) > { > + if (likely(!vcpu->requests)) > + return false; > if (test_bit(req, &vcpu->requests)) { > clear_bit(req, &vcpu->requests); I'm not sure -- due to asm in test_bit and to -fno-strict-aliasing, I'm afraid that each kvm_check_request will have its own zero check. kvm_check_request should be rare, but it does show up in microbenchmarks so perhaps it's best to keep those two lines of code duplicated across the architectures. Paolo