All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
Cc: Marcelo Tosatti <mtosatti@redhat.com>,
	avi@redhat.com, kvm@vger.kernel.org
Subject: Re: [PATCH] KVM: x86: lapic: Fix the misuse of likely() in find_highest_vector()
Date: Thu, 30 Aug 2012 13:44:59 +0300	[thread overview]
Message-ID: <20120830104458.GA19997@redhat.com> (raw)
In-Reply-To: <20120830192439.3e088595.yoshikawa.takuya@oss.ntt.co.jp>

On Thu, Aug 30, 2012 at 07:24:39PM +0900, Takuya Yoshikawa wrote:
> On Thu, 30 Aug 2012 13:10:33 +0300
> "Michael S. Tsirkin" <mst@redhat.com> wrote:
> 
> > > OK, I'll do these on top of this patch.
> > 
> > Tweaking these 5 lines for readability across multiple
> > patches is just not worth it.
> > As long as we do random cleanups of this function it's probably easier
> > to just do them all in one patch.
> 
> OK.
> 
> > > > Something like the below pseudo code would do this I think?
> > > > 
> > > > #define APIC_VECTORS_PER_REG 32
> > > > 
> > > > 	int vec;
> > > > 	for (vec = MAX_APIC_VECTOR - APIC_VECTORS_PER_REG;
> > > > 	     vec -= APIC_VECTORS_PER_REG; vec >= 0) {
> > > > 		u32 *reg = bitmap + REG_POS(vec);
> > > 
> > > We want to introduce apic_read_register(bitmap, reg) instead.
> > > u32 reg = apic_read_register(bitmap, REG_POS(vec));
> > 
> > If Marcelo takes it, I don't mind :)
> > 
> > > > 		if (*reg)
> > > > 			return __fls(*reg) - 1 + vec;
> > > 
> > > Because it is not clear that this *reg is the same value
> > > tested before. 
> > 
> > Before - where? Looks like this is the only place where
> > *reg is used.
> 
>   if (*reg)   // BEFORE
>       return __fls(*reg) - 1 + vec;    // AFTER
> 
> Unless the value pointed to by a pointer cannot be updated
> concurrently, it seems a good practice to use a local variable
> explicitely in C level.

This last statement is very wrong.  If you are trying to address concurrent
access on smp, using a varible will never fix it. You need ACCESS_ONCE,
barriers and all that jazz.

If instead you are talking about readability, using a wrapper just to do
'+' looks like a bit of an overkill to me: you almost literally do
#define plus(a,b) (a+b).

> I know that this will not change anything actually, but many
> bitops functions do similar things.
> 
> Takuya

They do a bit more: they avoid duplication by calling
VEC_POS and REG_POS with the same paramater.
But let's not argue theoretically, send a patch and maintainers
will judge it.

> > > > 	}
> > > > 	return -1
> > > > 
> > > > count_vectors similar:
> > > > 
> > > >         for (vec = 0; vec < MAX_APIC_VECTOR; vec += APIC_VECTORS_PER_REG) {
> > > > 		u32 *reg = bitmap + REG_POS(vec);
> > > 
> > > Same here.
> > 
> > Same question :)

  reply	other threads:[~2012-08-30 11:21 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-24  9:15 [PATCH] KVM: x86: lapic: Fix the misuse of likely() in find_highest_vector() Takuya Yoshikawa
2012-08-27 20:25 ` Marcelo Tosatti
2012-08-28  9:57   ` Takuya Yoshikawa
2012-08-29 19:10     ` Marcelo Tosatti
2012-08-29 22:51       ` Michael S. Tsirkin
2012-08-30  1:09         ` Takuya Yoshikawa
2012-08-30  6:37           ` Michael S. Tsirkin
2012-08-30  9:50             ` Takuya Yoshikawa
2012-08-30 10:10               ` Michael S. Tsirkin
2012-08-30 10:24                 ` Takuya Yoshikawa
2012-08-30 10:44                   ` Michael S. Tsirkin [this message]
2012-08-30 12:30                     ` [PATCH -v3] KVM: x86: lapic: Clean up find_highest_vector() and count_vectors() Takuya Yoshikawa
2012-08-30 13:21                       ` Michael S. Tsirkin
2012-08-30 16:09                         ` Takuya Yoshikawa
2012-08-30 16:49                           ` Michael S. Tsirkin
2012-09-05  8:30                             ` Takuya Yoshikawa
2012-09-05  9:26                               ` Michael S. Tsirkin
2012-09-05  9:40                                 ` Takuya Yoshikawa
2012-09-05  9:51                                   ` Michael S. Tsirkin
2012-09-05 10:30                                     ` [PATCH -v4] " Takuya Yoshikawa
2012-09-05 10:58                                       ` Michael S. Tsirkin
2012-09-12 16:39                                       ` Marcelo Tosatti

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=20120830104458.GA19997@redhat.com \
    --to=mst@redhat.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    --cc=yoshikawa.takuya@oss.ntt.co.jp \
    /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 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.