likely/unlikely
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.
Signature · 2 lines
David Schwartz <[email protected]>
Quoted 5 lines · David Schwartz
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...
Signature · 4 lines
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 MysteryQuoted 5 lines
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
Quoted 7 lines · Anton Blanchard
Quoted 6 lines
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...
Quoted 6 lines
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
Signature · 4 lines
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 MysteryQuoted 2 lines
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.
Quoted 4 lines · Craig Christophel
Quoted 1 line
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.
Quoted 1 line
Craig.
cu
Adrian
Quoted 4 lines · Craig Christophel
Quoted 2 lines
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
Signature · 4 lines
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 MysteryQuoted 9 lines · Jeff Garzik
Quoted 4 lines · Craig Christophel
Quoted 2 lines
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 ofBUG_ON, rather rather touching all the code that callsBUG(), though.
BUG_ON has had unlikely since the very beginning :-)
Signature · 1 line
Jens Axboe