public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: "Radim Krčmář" <rkrcmar@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
	Nadav Amit <namit@cs.technion.ac.il>,
	Gleb Natapov <gleb@kernel.org>
Subject: Re: [PATCH 8/8] KVM: x86: simplify kvm_apic_map
Date: Fri, 30 Jan 2015 16:14:42 +0100	[thread overview]
Message-ID: <20150130151442.GC27414@potion.redhat.com> (raw)
In-Reply-To: <54CB4C5C.6090706@redhat.com>

2015-01-30 10:18+0100, Paolo Bonzini:
> On 29/01/2015 22:48, Radim Krčmář wrote:
> > +static inline bool
> > +apic_logical_id(struct kvm_apic_map *map, u32 ldr, u16 *cid, u16 *lid)
> >  {
> > +	switch (map->mode) {
> > +	case KVM_APIC_MODE_XAPIC_FLAT:
> > +		*cid = 0;
> > +		*lid = ldr & 0xff;
> > +		return true;
> > +	case KVM_APIC_MODE_XAPIC_CLUSTER:
> > +		*cid = (ldr >> 4) & 0xf;
> > +		*lid = ldr & 0xf;
> > +		return true;
> > +	case KVM_APIC_MODE_X2APIC:
> > +		*cid = ldr >> 16;
> > +		*lid = ldr & 0xffff;
> > +		return true;
> > +	}
> 
> We need some optimization here.  You can make the defines equal to the
> size of the lid: CLUSTER = 1 << 3, FLAT = 1 << 2, X2APIC = 1 << 4:
> 
> 	BUILD_BUG_ON(...FLAT != 4);
> 	BUILD_BUG_ON(...CLUSTER != 8);

(Swapped.)

> 	BUILD_BUG_ON(...X2APIC != 16);

(Check the mode and return false here.)

> 	lid_bits = mode;
> 	cid_bits = mode & (16 | 4);
> 	lid_mask = (1 << lid_bits) - 1;
> 	cid_mask = (1 << cid_bits) - 1;
> 
> 	*cid = (ldr >> lid_bits) & cid_mask;
> 	*lid = ldr & lid_mask;

Would jump predictor fail on the switch?  Or is size of the code that
important?  This code is shorter, but is going to execute far more
operations, so I think it would be slower ... (And harder to read.)

> Please move this to lapic.c since you are at it.

Ok.

  reply	other threads:[~2015-01-30 15:14 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-29 21:48 [PATCH 0/8] KVM: minor APIC fixes and cleanups Radim Krčmář
2015-01-29 21:48 ` [PATCH 1/8] KVM: x86: return bool from kvm_apic_match*() Radim Krčmář
2015-01-29 22:10   ` Joe Perches
2015-01-30  8:50     ` Paolo Bonzini
2015-01-29 21:48 ` [PATCH 2/8] KVM: x86: cleanup kvm_apic_match_*() Radim Krčmář
2015-01-30  8:52   ` Paolo Bonzini
2015-01-30 13:06     ` Radim Krčmář
2015-02-02 14:26     ` Radim Krčmář
2015-02-02 14:28       ` Paolo Bonzini
2015-02-02 14:30         ` Radim Krčmář
2015-02-02 14:29       ` Radim Krčmář
2015-01-29 21:48 ` [PATCH 3/8] KVM: x86: replace 0 with APIC_DEST_PHYSICAL Radim Krčmář
2015-01-29 21:48 ` [PATCH 4/8] KVM: x86: fix x2apic logical address matching Radim Krčmář
2015-01-29 21:48 ` [PATCH 5/8] KVM: x86: use MDA for interrupt matching Radim Krčmář
2015-01-30  9:03   ` Paolo Bonzini
2015-01-30 13:09     ` Radim Krčmář
2015-01-29 21:48 ` [PATCH 6/8] KVM: x86: allow mixed APIC mode broadcast Radim Krčmář
2015-01-29 21:48 ` [PATCH 7/8] KVM: x86: avoid logical_map when it is invalid Radim Krčmář
2015-01-30  9:19   ` Paolo Bonzini
2015-01-30 14:21     ` Radim Krčmář
2015-01-30 14:21       ` Paolo Bonzini
2015-01-30  9:38   ` Paolo Bonzini
2015-01-30 14:56     ` Radim Krčmář
2015-01-30 15:10       ` Paolo Bonzini
2015-01-30 17:09         ` Radim Krčmář
2015-01-29 21:48 ` [PATCH 8/8] KVM: x86: simplify kvm_apic_map Radim Krčmář
2015-01-30  9:18   ` Paolo Bonzini
2015-01-30 15:14     ` Radim Krčmář [this message]
2015-01-30 15:23       ` Paolo Bonzini
2015-01-30 16:57         ` Radim Krčmář
2015-01-30 21:15           ` Paolo Bonzini
2015-01-30  9:22 ` [PATCH 0/8] KVM: minor APIC fixes and cleanups Paolo Bonzini
2015-01-30 15:20   ` Radim Krčmář
2015-01-30 15:24     ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150130151442.GC27414@potion.redhat.com \
    --to=rkrcmar@redhat.com \
    --cc=gleb@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=namit@cs.technion.ac.il \
    --cc=pbonzini@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox