aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/compiler.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/compiler.h')
-rw-r--r--include/linux/compiler.h61
1 files changed, 59 insertions, 2 deletions
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 98115d9d04da..935e30cfaf3c 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -59,8 +59,65 @@ extern void __chk_io_ptr(const volatile void __iomem *);
59 * specific implementations come from the above header files 59 * specific implementations come from the above header files
60 */ 60 */
61 61
62#define likely(x) __builtin_expect(!!(x), 1) 62#ifdef CONFIG_TRACE_UNLIKELY_PROFILE
63#define unlikely(x) __builtin_expect(!!(x), 0) 63struct ftrace_likely_data {
64 const char *func;
65 const char *file;
66 unsigned line;
67 unsigned long correct;
68 unsigned long incorrect;
69};
70void ftrace_likely_update(struct ftrace_likely_data *f, int val, int expect);
71
72#define likely_notrace(x) __builtin_expect(!!(x), 1)
73#define unlikely_notrace(x) __builtin_expect(!!(x), 0)
74
75#define likely_check(x) ({ \
76 int ______r; \
77 static struct ftrace_likely_data \
78 __attribute__((__aligned__(4))) \
79 __attribute__((section("_ftrace_likely"))) \
80 ______f = { \
81 .func = __func__, \
82 .file = __FILE__, \
83 .line = __LINE__, \
84 }; \
85 ______f.line = __LINE__; \
86 ______r = likely_notrace(x); \
87 ftrace_likely_update(&______f, ______r, 1); \
88 ______r; \
89 })
90#define unlikely_check(x) ({ \
91 int ______r; \
92 static struct ftrace_likely_data \
93 __attribute__((__aligned__(4))) \
94 __attribute__((section("_ftrace_unlikely"))) \
95 ______f = { \
96 .func = __func__, \
97 .file = __FILE__, \
98 .line = __LINE__, \
99 }; \
100 ______f.line = __LINE__; \
101 ______r = unlikely_notrace(x); \
102 ftrace_likely_update(&______f, ______r, 0); \
103 ______r; \
104 })
105
106/*
107 * Using __builtin_constant_p(x) to ignore cases where the return
108 * value is always the same. This idea is taken from a similar patch
109 * written by Daniel Walker.
110 */
111# ifndef likely
112# define likely(x) (__builtin_constant_p(x) ? !!(x) : likely_check(x))
113# endif
114# ifndef unlikely
115# define unlikely(x) (__builtin_constant_p(x) ? !!(x) : unlikely_check(x))
116# endif
117#else
118# define likely(x) __builtin_expect(!!(x), 1)
119# define unlikely(x) __builtin_expect(!!(x), 0)
120#endif
64 121
65/* Optimization barrier */ 122/* Optimization barrier */
66#ifndef barrier 123#ifndef barrier