Re: [PATCHv6 6/8] kvm: only sync when attention bits set

Michael S. Tsirkin
2012-06-14T08:04:05Z

On Wed, Jun 13, 2012 at 08:38:46PM -0300, Marcelo Tosatti wrote:
> On Thu, Jun 14, 2012 at 12:04:23AM +0300, Michael S. Tsirkin wrote:
> > On Wed, Jun 13, 2012 at 05:53:36PM -0300, Marcelo Tosatti wrote:
> > > On Wed, Jun 13, 2012 at 11:35:07AM +0300, Michael S. Tsirkin wrote:
> > > > On Wed, Jun 13, 2012 at 11:19:24AM +0300, Michael S. Tsirkin wrote:
> > > > > On Tue, Jun 12, 2012 at 07:27:48PM -0300, Marcelo Tosatti wrote:
> > > > > > On Sun, Jun 03, 2012 at 10:28:29AM +0300, Michael S. Tsirkin wrote:
> > > > > > > Commit eb0dc6d0368072236dcd086d7fdc17fd3c4574d4 introduced apic
> > > > > > > attention bitmask but kvm still syncs lapic unconditionally.
> > > > > > > As that commit suggested and in anticipation of adding more attention
> > > > > > > bits, only sync lapic if(apic_attention).
> > > > > > >
> > > > > > > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > > > > > > ---
> > > > > > > arch/x86/kvm/x86.c | 3 ++-
> > > > > > > 1 files changed, 2 insertions(+), 1 deletions(-)
> > > > > > >
> > > > > > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> > > > > > > index be6d549..2f70861 100644
> > > > > > > --- a/arch/x86/kvm/x86.c
> > > > > > > +++ b/arch/x86/kvm/x86.c
> > > > > > > @@ -5388,7 +5388,8 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
> > > > > > > if (unlikely(vcpu->arch.tsc_always_catchup))
> > > > > > > kvm_make_request(KVM_REQ_CLOCK_UPDATE, vcpu);
> > > > > > >
> > > > > > > - kvm_lapic_sync_from_vapic(vcpu);
> > > > > > > + if (unlikely(vcpu->arch.apic_attention))
> > > > > > > + kvm_lapic_sync_from_vapic(vcpu);
> > > > > >
> > > > > > void kvm_lapic_sync_from_vapic(struct kvm_vcpu *vcpu)
> > > > > > {
> > > > > > u32 data;
> > > > > > void *vapic;
> > > > > >
> > > > > > if (!test_bit(KVM_APIC_CHECK_VAPIC, &vcpu->arch.apic_attention))
> > > > > > return;
> > > > > >
> > > > > > Please use unlikely more carefully, when a gain is measureable:
> > > > > > http://lwn.net/Articles/420019/
> > > > >
> > > > > Do we have to measure every single thing?
> > > > > Sometimes it's obvious: vapic is slow path, isn't it?
> > > >
> > > > Just to clarify the question: I think it's obvious this condition is
> > > > false more often than true. By how much, depends on the workload.
> > > > Do you think this is enough to tag this unlikely?
> > >
> > > Depends whether your processor supports flexpriority or not. I don't
> > > want to argue in favour/against the particular instance
> > >
> > > GCC docs:
> > >
> > > "
> > > — Built-in Function: long __builtin_expect (long exp, long c)
> > >
> > > You may use __builtin_expect to provide the compiler with branch
> > > prediction information. In general, you should prefer to use actual
> > > profile feedback for this (-fprofile-arcs), as programmers are
> > > notoriously bad at predicting how their programs actually perform.
> > > However, there are applications in which this data is hard to collect.
> > > "
> > >
> > > Lately half of branches in your patches are annotated.
> >
> > So if I instrument and show that branch is almost never taken that is enough?
> > This citation does not require measuring the perf impact.
>
> Without flexpriority its always taken.

OK I will remove this one and keep around the unlikely
for the cases that my measurements show occur in
less than 1% of cases.