Erik Mouw wrote:
> On Sat, Mar 29, 2008 at 04:03:18AM -0400, Robert P. J. Day wrote:
>> is there somewhere an actual quantification (is that a word?) to the
>> benefits of likely() and unlikely() in the kernel code? i've always
>> been curious about what difference those constructs made. thanks.
>
> They are macros around __builtin_expect(), which can be used to provide
> the compiler with branch prediction information. In the kernel, you see
> likely()/unlikely() usually used in error handling: most of the times
> you don't get an error, so tell the compiler to lay out the code in
> such a way that the error handling block becomes a branch and the
> normal code flows just straight. Something like:
>
>
> if(unlikely(ptr == NULL)) {
I leared that gcc will take (ptr == NULL) as unlikely, so actually you
don't need this unlikely() here.
> printk(KERN_EMERG "AARGH\n");
> panic();
> }
>
> foo(ptr);
>
>
> Erik
>
--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to [EMAIL PROTECTED]
Please read the FAQ at http://kernelnewbies.org/FAQ