Using probable / unlikely return argument in linux kernel

Just look at this construct in the linux kernel, and I can't figure out what that means.

110 return unlikely(sl->sequence != start); 

I know that likely / unlikely are executed using the __builtin_expect function described here: http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html

You can use __builtin_expect to provide branch prediction information to the compiler.

But what branch prediction clues are possible for an unconditional branch?

+7
source share
2 answers

Just guess here, but imagine that the function is built in by the compiler, and you have this in the calling code:

 if (functionUsingUnlikelyForReturn()) { // Do something } else { // Do something different } 

it is reasonable for branch prediction to take into account the hint.

+11
source

"Unlikely" does not give the probability of returning from the function, but rather the expected value for the return value. I assume the function is inline, so this is a hint for optimizing the caller function.

+4
source

All Articles