public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH/RFC] KVM: do early exit in kvm_check_request
@ 2016-09-09 10:10 Christian Borntraeger
  2016-09-09 16:35 ` Paolo Bonzini
  0 siblings, 1 reply; 4+ messages in thread
From: Christian Borntraeger @ 2016-09-09 10:10 UTC (permalink / raw)
  To: Paolo Bonzini, Radim Krčmář; +Cc: KVM, Christian Borntraeger

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 <borntraeger@de.ibm.com>
---
 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);
 
-- 
2.5.5


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

* Re: [PATCH/RFC] KVM: do early exit in kvm_check_request
  2016-09-09 10:10 [PATCH/RFC] KVM: do early exit in kvm_check_request Christian Borntraeger
@ 2016-09-09 16:35 ` Paolo Bonzini
  2016-09-09 18:10   ` Christian Borntraeger
  2016-09-09 18:30   ` Nadav Amit
  0 siblings, 2 replies; 4+ messages in thread
From: Paolo Bonzini @ 2016-09-09 16:35 UTC (permalink / raw)
  To: Christian Borntraeger, Radim Krčmář; +Cc: KVM



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 <borntraeger@de.ibm.com>
> ---
>  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

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

* Re: [PATCH/RFC] KVM: do early exit in kvm_check_request
  2016-09-09 16:35 ` Paolo Bonzini
@ 2016-09-09 18:10   ` Christian Borntraeger
  2016-09-09 18:30   ` Nadav Amit
  1 sibling, 0 replies; 4+ messages in thread
From: Christian Borntraeger @ 2016-09-09 18:10 UTC (permalink / raw)
  To: Paolo Bonzini, Radim Krčmář; +Cc: KVM

On 09/09/2016 06:35 PM, Paolo Bonzini wrote:
> 
> 
> 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 <borntraeger@de.ibm.com>
>> ---
>>  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.

Not sure either, it seems to work like above (but does not work when I combine both ifs..)
So yes, maybe its just too unreliable and we keep things as is.


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

* Re: [PATCH/RFC] KVM: do early exit in kvm_check_request
  2016-09-09 16:35 ` Paolo Bonzini
  2016-09-09 18:10   ` Christian Borntraeger
@ 2016-09-09 18:30   ` Nadav Amit
  1 sibling, 0 replies; 4+ messages in thread
From: Nadav Amit @ 2016-09-09 18:30 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Christian Borntraeger, Radim Krčmář, KVM

Paolo Bonzini <pbonzini@redhat.com> wrote:

> 
> 
> 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 <borntraeger@de.ibm.com>
>> ---
>> 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.

Interesting. I don’t think that this test_bit usually goes through the asm
part (since usually req is constant). However, it seems that due to the
indirection to vcpu->requests, the compiler does not use a register to cache
vcpu->requests. It is shameful in places like vcpu_enter_guest. Perhaps
checking the bit directly in kvm_check_request is wiser?

Nadav



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

end of thread, other threads:[~2016-09-09 18:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-09 10:10 [PATCH/RFC] KVM: do early exit in kvm_check_request Christian Borntraeger
2016-09-09 16:35 ` Paolo Bonzini
2016-09-09 18:10   ` Christian Borntraeger
2016-09-09 18:30   ` Nadav Amit

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