Skip to content
  • Andi Kleen's avatar
    x86: Support __attribute__((__cold__)) in gcc 4.3 · a586df06
    Andi Kleen authored
    
    
    gcc 4.3 supports a new __attribute__((__cold__)) to mark functions cold. Any
    path directly leading to a call of this function will be unlikely. And gcc
    will try to generate smaller code for the function itself.
    
    Please use with care. The code generation advantage isn't large and in most
    cases it is not worth uglifying code with this.
    
    This patch marks some common error functions like panic(), printk()
    as cold.  This will longer term make many unlikely()s unnecessary, although
    we can keep them for now for older compilers.
    
    BUG is not marked cold because there is currently no way to tell
    gcc to mark a inline function told.
    
    Also all __init and __exit functions are marked cold. With a non -Os
    build this will tell the compiler to generate slightly smaller code
    for them. I think it currently only uses less alignments for labels,
    but that might change in the future.
    
    One disadvantage over *likely() is that they cannot be easily instrumented
    to verify them.
    
    Another drawback is that only the latest gcc 4.3 snapshots support this.
    Unfortunately we cannot detect this using the preprocessor. This means older
    snapshots will fail now. I don't think that's a problem because they are
    unreleased compilers that nobody should be using.
    
    gcc also has a __hot__ attribute, but I don't see any sense in using
    this in the kernel right now. But someday I hope gcc will be able
    to use more aggressive optimizing for hot functions even in -Os,
    if that happens it should be added.
    
    Includes compile fix from Thomas Gleixner.
    
    Cc: Jan Hubicka <jh@suse.cz>
    Signed-off-by: default avatarAndi Kleen <ak@suse.de>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    a586df06