diff options
author | Andi Kleen <ak@suse.de> | 2007-07-21 11:10:00 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-07-21 21:37:08 -0400 |
commit | a586df067afe0580bb02b7a6312ca2afe49bba03 (patch) | |
tree | 7806fef0876a2fd3da2f4c16919cfc551a65ff72 /include/linux/compiler-gcc4.h | |
parent | b520b85a963bf7b14b9614579aff14558d7ee264 (diff) |
x86: Support __attribute__((__cold__)) in gcc 4.3
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: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/compiler-gcc4.h')
-rw-r--r-- | include/linux/compiler-gcc4.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h index a03e9398a6c..14f7494280f 100644 --- a/include/linux/compiler-gcc4.h +++ b/include/linux/compiler-gcc4.h | |||
@@ -23,3 +23,21 @@ | |||
23 | * code | 23 | * code |
24 | */ | 24 | */ |
25 | #define uninitialized_var(x) x = x | 25 | #define uninitialized_var(x) x = x |
26 | |||
27 | #if !(__GNUC__ == 4 && __GNUC_MINOR__ < 3) | ||
28 | /* Mark functions as cold. gcc will assume any path leading to a call | ||
29 | to them will be unlikely. This means a lot of manual unlikely()s | ||
30 | are unnecessary now for any paths leading to the usual suspects | ||
31 | like BUG(), printk(), panic() etc. [but let's keep them for now for | ||
32 | older compilers] | ||
33 | |||
34 | Early snapshots of gcc 4.3 don't support this and we can't detect this | ||
35 | in the preprocessor, but we can live with this because they're unreleased. | ||
36 | Maketime probing would be overkill here. | ||
37 | |||
38 | gcc also has a __attribute__((__hot__)) to move hot functions into | ||
39 | a special section, but I don't see any sense in this right now in | ||
40 | the kernel context */ | ||
41 | #define __cold __attribute__((__cold__)) | ||
42 | |||
43 | #endif | ||