All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: Eliminate extra function calls in kvm_get_dirty_log_protect()
@ 2015-03-17  7:19 Takuya Yoshikawa
  2015-03-17  8:58 ` Paolo Bonzini
  0 siblings, 1 reply; 3+ messages in thread
From: Takuya Yoshikawa @ 2015-03-17  7:19 UTC (permalink / raw)
  To: pbonzini; +Cc: kvm, linux-kernel

When all bits in mask are not set,
kvm_arch_mmu_enable_log_dirty_pt_masked() has nothing to do.  But since
it needs to be called from the generic code, it cannot be inlined, and
a few function calls, two when PML is enabled, are wasted.

Since it is common to see many pages remain clean, e.g. framebuffers can
stay calm for a long time, it is worth eliminating this overhead.

Signed-off-by: Takuya Yoshikawa <yoshikawa_takuya_b1@lab.ntt.co.jp>
---
 virt/kvm/kvm_main.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index a109370..420d8cf 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1061,9 +1061,11 @@ int kvm_get_dirty_log_protect(struct kvm *kvm,
 		mask = xchg(&dirty_bitmap[i], 0);
 		dirty_bitmap_buffer[i] = mask;
 
-		offset = i * BITS_PER_LONG;
-		kvm_arch_mmu_enable_log_dirty_pt_masked(kvm, memslot, offset,
-								mask);
+		if (mask) {
+			offset = i * BITS_PER_LONG;
+			kvm_arch_mmu_enable_log_dirty_pt_masked(kvm, memslot,
+								offset, mask);
+		}
 	}
 
 	spin_unlock(&kvm->mmu_lock);
-- 
2.1.0


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

* Re: [PATCH] KVM: Eliminate extra function calls in kvm_get_dirty_log_protect()
  2015-03-17  7:19 [PATCH] KVM: Eliminate extra function calls in kvm_get_dirty_log_protect() Takuya Yoshikawa
@ 2015-03-17  8:58 ` Paolo Bonzini
  2015-03-19  1:23   ` Marcelo Tosatti
  0 siblings, 1 reply; 3+ messages in thread
From: Paolo Bonzini @ 2015-03-17  8:58 UTC (permalink / raw)
  To: Takuya Yoshikawa; +Cc: kvm, linux-kernel



On 17/03/2015 08:19, Takuya Yoshikawa wrote:
> When all bits in mask are not set,
> kvm_arch_mmu_enable_log_dirty_pt_masked() has nothing to do.  But since
> it needs to be called from the generic code, it cannot be inlined, and
> a few function calls, two when PML is enabled, are wasted.
> 
> Since it is common to see many pages remain clean, e.g. framebuffers can
> stay calm for a long time, it is worth eliminating this overhead.
> 
> Signed-off-by: Takuya Yoshikawa <yoshikawa_takuya_b1@lab.ntt.co.jp>
> ---
>  virt/kvm/kvm_main.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index a109370..420d8cf 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -1061,9 +1061,11 @@ int kvm_get_dirty_log_protect(struct kvm *kvm,
>  		mask = xchg(&dirty_bitmap[i], 0);
>  		dirty_bitmap_buffer[i] = mask;
>  
> -		offset = i * BITS_PER_LONG;
> -		kvm_arch_mmu_enable_log_dirty_pt_masked(kvm, memslot, offset,
> -								mask);
> +		if (mask) {
> +			offset = i * BITS_PER_LONG;
> +			kvm_arch_mmu_enable_log_dirty_pt_masked(kvm, memslot,
> +								offset, mask);
> +		}
>  	}
>  
>  	spin_unlock(&kvm->mmu_lock);
> 

Good catch!

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

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

* Re: [PATCH] KVM: Eliminate extra function calls in kvm_get_dirty_log_protect()
  2015-03-17  8:58 ` Paolo Bonzini
@ 2015-03-19  1:23   ` Marcelo Tosatti
  0 siblings, 0 replies; 3+ messages in thread
From: Marcelo Tosatti @ 2015-03-19  1:23 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Takuya Yoshikawa, kvm, linux-kernel

On Tue, Mar 17, 2015 at 09:58:21AM +0100, Paolo Bonzini wrote:
> 
> 
> On 17/03/2015 08:19, Takuya Yoshikawa wrote:
> > When all bits in mask are not set,
> > kvm_arch_mmu_enable_log_dirty_pt_masked() has nothing to do.  But since
> > it needs to be called from the generic code, it cannot be inlined, and
> > a few function calls, two when PML is enabled, are wasted.
> > 
> > Since it is common to see many pages remain clean, e.g. framebuffers can
> > stay calm for a long time, it is worth eliminating this overhead.
> > 
> > Signed-off-by: Takuya Yoshikawa <yoshikawa_takuya_b1@lab.ntt.co.jp>
> > ---
> >  virt/kvm/kvm_main.c | 8 +++++---
> >  1 file changed, 5 insertions(+), 3 deletions(-)
> > 
> > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> > index a109370..420d8cf 100644
> > --- a/virt/kvm/kvm_main.c
> > +++ b/virt/kvm/kvm_main.c
> > @@ -1061,9 +1061,11 @@ int kvm_get_dirty_log_protect(struct kvm *kvm,
> >  		mask = xchg(&dirty_bitmap[i], 0);
> >  		dirty_bitmap_buffer[i] = mask;
> >  
> > -		offset = i * BITS_PER_LONG;
> > -		kvm_arch_mmu_enable_log_dirty_pt_masked(kvm, memslot, offset,
> > -								mask);
> > +		if (mask) {
> > +			offset = i * BITS_PER_LONG;
> > +			kvm_arch_mmu_enable_log_dirty_pt_masked(kvm, memslot,
> > +								offset, mask);
> > +		}
> >  	}
> >  
> >  	spin_unlock(&kvm->mmu_lock);
> > 
> 
> Good catch!
> 
> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

Applied, thanks.


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

end of thread, other threads:[~2015-03-19  1:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-17  7:19 [PATCH] KVM: Eliminate extra function calls in kvm_get_dirty_log_protect() Takuya Yoshikawa
2015-03-17  8:58 ` Paolo Bonzini
2015-03-19  1:23   ` Marcelo Tosatti

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.