Interesting technique used by the Linux kernel: likely() and unlikely()


I was looking at kernel/sched/core.c and these functions caught my attention: likely() and unlikely().

Let's go to Stack Overflow and see: How do the likely/unlikely macros in the Linux kernel work and what is their benefit?

So these functions are hints to the compiler regarding branch prediction to favor either the likely or unlikely side of the prediction.

Cool stuff.

submitted by /u/jones_supa
[link] [comments]

Leave a Reply

Your email address will not be published. Required fields are marked *