public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>,
	linux-kernel@vger.kernel.org,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>,
	x86@kernel.org, Rusty Russell <rusty@rustcorp.com.au>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Uros Bizjak <ubizjak@gmail.com>
Subject: Re: [PATCH 1/2] x86/bitops: implement __test_bit
Date: Tue, 1 Sep 2015 11:24:22 +0200	[thread overview]
Message-ID: <20150901092422.GA8088@gmail.com> (raw)
In-Reply-To: <20150831111910.GA24574@redhat.com>


* Michael S. Tsirkin <mst@redhat.com> wrote:

> I applied this patch on top of mine:

Yeah, looks similar to the one I sent.

> -static inline int __variable_test_bit(long nr, const unsigned long *addr)
> -{
> -	int oldbit;
> -
> -	asm volatile("bt %2,%1\n\t"
> -		     "sbb %0,%0"
> -		     : "=r" (oldbit)
> -		     : "m" (*addr), "Ir" (nr));
> -
> -	return oldbit;
> -}

> And the code size went up:
> 
>    134836    2997    8372  146205   23b1d arch/x86/kvm/kvm-intel.ko  ->
>    134846    2997    8372  146215   23b27 arch/x86/kvm/kvm-intel.ko     
> 
>    342690   47640     441  390771   5f673 arch/x86/kvm/kvm.ko ->
>    342738   47640     441  390819   5f6a3 arch/x86/kvm/kvm.ko   
> 
> I tried removing  __always_inline, this had no effect.

But code size isn't the only factor.

Uros Bizjak pointed out that the reason GCC does not use the "BT reg,mem" 
instruction is that it's highly suboptimal even on recent microarchitectures, 
Sandy Bridge is listed as having a 10 cycles latency (!) for this instruction:

   http://www.agner.org/optimize/instruction_tables.pdf

this instruction had bad latency going back to Pentium 4 CPUs.

... so unless something changed in this area with Skylake I think using the 
__variable_test_bit() code of the kernel is a bad choice and looking at kernel 
size only is misleading.

It makes sense for atomics, but not for unlocked access.

Thanks,

	Ingo

  reply	other threads:[~2015-09-01  9:24 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-30  8:38 [PATCH 1/2] x86/bitops: implement __test_bit Michael S. Tsirkin
2015-08-30  8:38 ` [PATCH 2/2] kvm/x86: use __test_bit Michael S. Tsirkin
2015-08-31  6:05 ` [PATCH 1/2] x86/bitops: implement __test_bit Ingo Molnar
2015-08-31  6:13   ` H. Peter Anvin
2015-08-31  7:56     ` Michael S. Tsirkin
2015-08-31  7:59       ` Ingo Molnar
2015-08-31  8:15         ` yalin wang
2015-08-31  8:19           ` Ingo Molnar
2015-08-31  8:15         ` Ingo Molnar
2015-08-31 11:19         ` Michael S. Tsirkin
2015-09-01  9:24           ` Ingo Molnar [this message]
2015-09-01  9:40             ` Michael S. Tsirkin
2015-09-01 11:39               ` Ingo Molnar
2015-09-01 15:03                 ` Michael S. Tsirkin
2015-09-01 23:48                   ` H. Peter Anvin

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=20150901092422.GA8088@gmail.com \
    --to=mingo@kernel.org \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=mst@redhat.com \
    --cc=rusty@rustcorp.com.au \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=ubizjak@gmail.com \
    --cc=x86@kernel.org \
    /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