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 | |
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>
-rw-r--r-- | include/linux/compiler-gcc4.h | 18 | ||||
-rw-r--r-- | include/linux/compiler.h | 9 | ||||
-rw-r--r-- | include/linux/init.h | 8 | ||||
-rw-r--r-- | include/linux/kernel.h | 8 |
4 files changed, 35 insertions, 8 deletions
diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h index a03e9398a6c2..14f7494280f0 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 | ||
diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 8287a72bb6a9..12a1291855e2 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h | |||
@@ -174,4 +174,13 @@ extern void __chk_io_ptr(const void __iomem *); | |||
174 | # define __attribute_const__ /* unimplemented */ | 174 | # define __attribute_const__ /* unimplemented */ |
175 | #endif | 175 | #endif |
176 | 176 | ||
177 | /* | ||
178 | * Tell gcc if a function is cold. The compiler will assume any path | ||
179 | * directly leading to the call is unlikely. | ||
180 | */ | ||
181 | |||
182 | #ifndef __cold | ||
183 | #define __cold | ||
184 | #endif | ||
185 | |||
177 | #endif /* __LINUX_COMPILER_H */ | 186 | #endif /* __LINUX_COMPILER_H */ |
diff --git a/include/linux/init.h b/include/linux/init.h index 5b5285316339..f0d0e3295a9b 100644 --- a/include/linux/init.h +++ b/include/linux/init.h | |||
@@ -40,10 +40,10 @@ | |||
40 | 40 | ||
41 | /* These are for everybody (although not all archs will actually | 41 | /* These are for everybody (although not all archs will actually |
42 | discard it in modules) */ | 42 | discard it in modules) */ |
43 | #define __init __attribute__ ((__section__ (".init.text"))) | 43 | #define __init __attribute__ ((__section__ (".init.text"))) __cold |
44 | #define __initdata __attribute__ ((__section__ (".init.data"))) | 44 | #define __initdata __attribute__ ((__section__ (".init.data"))) |
45 | #define __exitdata __attribute__ ((__section__(".exit.data"))) | 45 | #define __exitdata __attribute__ ((__section__(".exit.data"))) |
46 | #define __exit_call __attribute_used__ __attribute__ ((__section__ (".exitcall.exit"))) | 46 | #define __exit_call __attribute_used__ __attribute__ ((__section__ (".exitcall.exit"))) __cold |
47 | 47 | ||
48 | /* modpost check for section mismatches during the kernel build. | 48 | /* modpost check for section mismatches during the kernel build. |
49 | * A section mismatch happens when there are references from a | 49 | * A section mismatch happens when there are references from a |
@@ -59,9 +59,9 @@ | |||
59 | #define __initdata_refok __attribute__ ((__section__ (".data.init.refok"))) | 59 | #define __initdata_refok __attribute__ ((__section__ (".data.init.refok"))) |
60 | 60 | ||
61 | #ifdef MODULE | 61 | #ifdef MODULE |
62 | #define __exit __attribute__ ((__section__(".exit.text"))) | 62 | #define __exit __attribute__ ((__section__(".exit.text"))) __cold |
63 | #else | 63 | #else |
64 | #define __exit __attribute_used__ __attribute__ ((__section__(".exit.text"))) | 64 | #define __exit __attribute_used__ __attribute__ ((__section__(".exit.text"))) __cold |
65 | #endif | 65 | #endif |
66 | 66 | ||
67 | /* For assembly routines */ | 67 | /* For assembly routines */ |
diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 1eb9cde550c4..4300bb462d29 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h | |||
@@ -106,7 +106,7 @@ extern int cond_resched(void); | |||
106 | extern struct atomic_notifier_head panic_notifier_list; | 106 | extern struct atomic_notifier_head panic_notifier_list; |
107 | extern long (*panic_blink)(long time); | 107 | extern long (*panic_blink)(long time); |
108 | NORET_TYPE void panic(const char * fmt, ...) | 108 | NORET_TYPE void panic(const char * fmt, ...) |
109 | __attribute__ ((NORET_AND format (printf, 1, 2))); | 109 | __attribute__ ((NORET_AND format (printf, 1, 2))) __cold; |
110 | extern void oops_enter(void); | 110 | extern void oops_enter(void); |
111 | extern void oops_exit(void); | 111 | extern void oops_exit(void); |
112 | extern int oops_may_print(void); | 112 | extern int oops_may_print(void); |
@@ -155,14 +155,14 @@ extern void dump_thread(struct pt_regs *regs, struct user *dump); | |||
155 | asmlinkage int vprintk(const char *fmt, va_list args) | 155 | asmlinkage int vprintk(const char *fmt, va_list args) |
156 | __attribute__ ((format (printf, 1, 0))); | 156 | __attribute__ ((format (printf, 1, 0))); |
157 | asmlinkage int printk(const char * fmt, ...) | 157 | asmlinkage int printk(const char * fmt, ...) |
158 | __attribute__ ((format (printf, 1, 2))); | 158 | __attribute__ ((format (printf, 1, 2))) __cold; |
159 | #else | 159 | #else |
160 | static inline int vprintk(const char *s, va_list args) | 160 | static inline int vprintk(const char *s, va_list args) |
161 | __attribute__ ((format (printf, 1, 0))); | 161 | __attribute__ ((format (printf, 1, 0))); |
162 | static inline int vprintk(const char *s, va_list args) { return 0; } | 162 | static inline int vprintk(const char *s, va_list args) { return 0; } |
163 | static inline int printk(const char *s, ...) | 163 | static inline int printk(const char *s, ...) |
164 | __attribute__ ((format (printf, 1, 2))); | 164 | __attribute__ ((format (printf, 1, 2))); |
165 | static inline int printk(const char *s, ...) { return 0; } | 165 | static inline int __cold printk(const char *s, ...) { return 0; } |
166 | #endif | 166 | #endif |
167 | 167 | ||
168 | unsigned long int_sqrt(unsigned long); | 168 | unsigned long int_sqrt(unsigned long); |
@@ -212,7 +212,7 @@ extern enum system_states { | |||
212 | #define TAINT_USER (1<<6) | 212 | #define TAINT_USER (1<<6) |
213 | #define TAINT_DIE (1<<7) | 213 | #define TAINT_DIE (1<<7) |
214 | 214 | ||
215 | extern void dump_stack(void); | 215 | extern void dump_stack(void) __cold; |
216 | 216 | ||
217 | enum { | 217 | enum { |
218 | DUMP_PREFIX_NONE, | 218 | DUMP_PREFIX_NONE, |