public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* likely/unlikely
@ 2002-01-16  3:22 David Schwartz
  2002-01-16  5:14 ` likely/unlikely Jeff Garzik
  0 siblings, 1 reply; 8+ messages in thread
From: David Schwartz @ 2002-01-16  3:22 UTC (permalink / raw)
  To: linux-kernel


	By the way, has anybody actually benchmarked these macros to see if they 
make any difference. I did a few quick inexact benchmarks on test code and 
found that in most cases there was no difference and in some cases code was 
made worse.

-- 
David Schwartz
<davids@webmaster.com>



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

* Re: likely/unlikely
  2002-01-16  3:22 likely/unlikely David Schwartz
@ 2002-01-16  5:14 ` Jeff Garzik
  2002-01-16  6:00   ` likely/unlikely Anton Blanchard
  2002-01-16  6:32   ` likely/unlikely Craig Christophel
  0 siblings, 2 replies; 8+ messages in thread
From: Jeff Garzik @ 2002-01-16  5:14 UTC (permalink / raw)
  To: David Schwartz; +Cc: linux-kernel

David Schwartz wrote:
> 
>         By the way, has anybody actually benchmarked these macros to see if they
> make any difference. I did a few quick inexact benchmarks on test code and
> found that in most cases there was no difference and in some cases code was
> made worse.

likely/unlikely set the branch prediction values to 99% or 1%
respectively.  If this causes the code generated to perform less
optimally than without, I'm sure the gcc guys would be -very- interested
to hear that...

-- 
Jeff Garzik      | Alternate titles for LOTR:
Building 1024    | Fast Times at Uruk-Hai
MandrakeSoft     | The Took, the Elf, His Daughter and Her Lover
                 | Samwise Gamgee: International Hobbit of Mystery

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

* Re: likely/unlikely
  2002-01-16  5:14 ` likely/unlikely Jeff Garzik
@ 2002-01-16  6:00   ` Anton Blanchard
  2002-01-16  9:12     ` likely/unlikely Jeff Garzik
  2002-01-16  6:32   ` likely/unlikely Craig Christophel
  1 sibling, 1 reply; 8+ messages in thread
From: Anton Blanchard @ 2002-01-16  6:00 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: David Schwartz, linux-kernel

 
> likely/unlikely set the branch prediction values to 99% or 1%
> respectively.  If this causes the code generated to perform less
> optimally than without, I'm sure the gcc guys would be -very- interested
> to hear that...

On some ppc64 the branch prediction is quite good and static prediction
will override the dynamic prediction. I think we avoid predicting a
branch unless we are quite sure (95%/5%).

So if likely/unlikely is overused (on more marginal conditionals) then
it could be a performance loss.

Anton

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

* Re: likely/unlikely
  2002-01-16  5:14 ` likely/unlikely Jeff Garzik
  2002-01-16  6:00   ` likely/unlikely Anton Blanchard
@ 2002-01-16  6:32   ` Craig Christophel
  2002-01-16  7:38     ` likely/unlikely Adrian Bunk
  2002-01-16  9:14     ` likely/unlikely Jeff Garzik
  1 sibling, 2 replies; 8+ messages in thread
From: Craig Christophel @ 2002-01-16  6:32 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: linux-kernel


> likely/unlikely set the branch prediction values to 99% or 1%


	So all of the BUG() routines in the kernel would benifit greatly from this.



Craig.

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

* Re: likely/unlikely
  2002-01-16  6:32   ` likely/unlikely Craig Christophel
@ 2002-01-16  7:38     ` Adrian Bunk
  2002-01-16  9:14     ` likely/unlikely Jeff Garzik
  1 sibling, 0 replies; 8+ messages in thread
From: Adrian Bunk @ 2002-01-16  7:38 UTC (permalink / raw)
  To: Craig Christophel; +Cc: linux-kernel

On Wed, 16 Jan 2002, Craig Christophel wrote:

> > likely/unlikely set the branch prediction values to 99% or 1%
>
>
> 	So all of the BUG() routines in the kernel would benifit greatly from this.

In the 2.5 kernels this is done when you use the BUG_ON macro that is
defined as follows:

#define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)


BTW: Note that likely/unlikely doesn't has any effect for most of us
     because __builtin_expect is only available in gcc >= 2.96.


> Craig.

cu
Adrian



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

* Re: likely/unlikely
  2002-01-16  6:00   ` likely/unlikely Anton Blanchard
@ 2002-01-16  9:12     ` Jeff Garzik
  0 siblings, 0 replies; 8+ messages in thread
From: Jeff Garzik @ 2002-01-16  9:12 UTC (permalink / raw)
  To: Anton Blanchard; +Cc: David Schwartz, linux-kernel

Anton Blanchard wrote:
> 
> 
> > likely/unlikely set the branch prediction values to 99% or 1%
> > respectively.  If this causes the code generated to perform less
> > optimally than without, I'm sure the gcc guys would be -very- interested
> > to hear that...
> 
> On some ppc64 the branch prediction is quite good and static prediction
> will override the dynamic prediction. I think we avoid predicting a
> branch unless we are quite sure (95%/5%).
> 
> So if likely/unlikely is overused (on more marginal conditionals) then
> it could be a performance loss.

oh agreed... but marginal conditionals should not be getting
likely()/unlikely() as you are then lying to the compiler about the true
branch predictability...

	Jeff


-- 
Jeff Garzik      | Alternate titles for LOTR:
Building 1024    | Fast Times at Uruk-Hai
MandrakeSoft     | The Took, the Elf, His Daughter and Her Lover
                 | Samwise Gamgee: International Hobbit of Mystery

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

* Re: likely/unlikely
  2002-01-16  6:32   ` likely/unlikely Craig Christophel
  2002-01-16  7:38     ` likely/unlikely Adrian Bunk
@ 2002-01-16  9:14     ` Jeff Garzik
  2002-01-16  9:29       ` likely/unlikely Jens Axboe
  1 sibling, 1 reply; 8+ messages in thread
From: Jeff Garzik @ 2002-01-16  9:14 UTC (permalink / raw)
  To: Craig Christophel; +Cc: linux-kernel

Craig Christophel wrote:
> 
> > likely/unlikely set the branch prediction values to 99% or 1%
> 
>         So all of the BUG() routines in the kernel would benifit greatly from this.


It's likely :)  I would put one unlikely() in the definition of BUG_ON,
rather rather touching all the code that calls BUG(), though.

	Jeff



-- 
Jeff Garzik      | Alternate titles for LOTR:
Building 1024    | Fast Times at Uruk-Hai
MandrakeSoft     | The Took, the Elf, His Daughter and Her Lover
                 | Samwise Gamgee: International Hobbit of Mystery

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

* Re: likely/unlikely
  2002-01-16  9:14     ` likely/unlikely Jeff Garzik
@ 2002-01-16  9:29       ` Jens Axboe
  0 siblings, 0 replies; 8+ messages in thread
From: Jens Axboe @ 2002-01-16  9:29 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: Craig Christophel, linux-kernel

On Wed, Jan 16 2002, Jeff Garzik wrote:
> Craig Christophel wrote:
> > 
> > > likely/unlikely set the branch prediction values to 99% or 1%
> > 
> >         So all of the BUG() routines in the kernel would benifit greatly from this.
> 
> 
> It's likely :)  I would put one unlikely() in the definition of BUG_ON,
> rather rather touching all the code that calls BUG(), though.

BUG_ON has had unlikely since the very beginning :-)

-- 
Jens Axboe


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

end of thread, other threads:[~2002-01-16  9:30 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-01-16  3:22 likely/unlikely David Schwartz
2002-01-16  5:14 ` likely/unlikely Jeff Garzik
2002-01-16  6:00   ` likely/unlikely Anton Blanchard
2002-01-16  9:12     ` likely/unlikely Jeff Garzik
2002-01-16  6:32   ` likely/unlikely Craig Christophel
2002-01-16  7:38     ` likely/unlikely Adrian Bunk
2002-01-16  9:14     ` likely/unlikely Jeff Garzik
2002-01-16  9:29       ` likely/unlikely Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox