shinny@j02.itscom.net wrote: >Hi, > >How may I ask for your help? >Now I'm studying the linux scheduler(sched.c). >And I'm wondering what likey()/unlikely macros mean. >I could find they're defined in linux/compiler.h as follows. > >/* > * Generic compiler-dependent macros required for kernel > * build go below this comment. Actual compiler/compiler version > * specific implementations come from the above header files > */ > >#define likely(x) __builtin_expect(!!(x), 1) >#define unlikely(x) __builtin_expect(!!(x), 0) > >And I could find __builtin_expect()'s definition only in linux/compiler-gcc2.h as a follow. >I don't know what's going if __GNUC_MINOR__ is over 96, though... > >#if __GNUC_MINOR__ < 96 ># define __builtin_expect(x, expected_value) (x) >#endif > >As a result, although it seems likely() and unlikely() do nothing, is my expectation correct? >If there are other references about this, please let me know. > > Hello. As I've understand gcc after 96 introduced new feature which helps programmer suggest to compiler wishful execution branch of code. Compiler use this build in for optimizing. Gcc docs: long *__builtin_expect*/ /(/long /exp/, long /c)/ / Built-in Function You may use |__builtin_expect| to provide the compiler with branch prediction information. In general, you should prefer to use actual profile feedback for this (|-fprofile-arcs|), as programmers are notoriously bad at predicting how their programs actually perform. However, there are applications in which this data is hard to collect. The return value is the value of exp, which should be an integral expression. The value of c must be a compile-time constant. The semantics of the built-in are that it is expected that exp == c. For example: if (__builtin_expect (x, 0)) foo (); would indicate that we do not expect to call |foo|, since we expect |x| to be zero. Since you are limited to integral expressions for exp, you should use constructions such as if (__builtin_expect (ptr != NULL, 1)) error (); when testing pointer or floating-point values. Good luck. Ruslan. PS: Don't send html letters in future. -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/