diff options
| author | Ingo Molnar <mingo@elte.hu> | 2008-12-29 09:42:58 +0100 | 
|---|---|---|
| committer | Ingo Molnar <mingo@elte.hu> | 2008-12-29 10:37:07 +0100 | 
| commit | 0ce74d9296c971b2355c26984ad0bc538e34dd6c (patch) | |
| tree | 566d03e2a4f6b42dab9628cd82c93cd61d587467 /include/linux/compiler.h | |
| parent | 1cc4fff0b360aeffeedb7d6db5089d88dd861700 (diff) | |
| parent | 3c92ec8ae91ecf59d88c798301833d7cf83f2179 (diff) | |
Merge branch 'linus' into timers/hrtimers
Conflicts:
	sound/drivers/pcsp/pcsp.c
Semantic conflict:
        sound/core/hrtimer.c
Diffstat (limited to 'include/linux/compiler.h')
| -rw-r--r-- | include/linux/compiler.h | 84 | 
1 files changed, 82 insertions, 2 deletions
diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 98115d9d04da..ea7c6be354b7 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -59,8 +59,88 @@ extern void __chk_io_ptr(const volatile void __iomem *);   * specific implementations come from the above header files   */ -#define likely(x)	__builtin_expect(!!(x), 1) -#define unlikely(x)	__builtin_expect(!!(x), 0) +struct ftrace_branch_data { +	const char *func; +	const char *file; +	unsigned line; +	union { +		struct { +			unsigned long correct; +			unsigned long incorrect; +		}; +		struct { +			unsigned long miss; +			unsigned long hit; +		}; +	}; +}; + +/* + * Note: DISABLE_BRANCH_PROFILING can be used by special lowlevel code + * to disable branch tracing on a per file basis. + */ +#if defined(CONFIG_TRACE_BRANCH_PROFILING) && !defined(DISABLE_BRANCH_PROFILING) +void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect); + +#define likely_notrace(x)	__builtin_expect(!!(x), 1) +#define unlikely_notrace(x)	__builtin_expect(!!(x), 0) + +#define __branch_check__(x, expect) ({					\ +			int ______r;					\ +			static struct ftrace_branch_data		\ +				__attribute__((__aligned__(4)))		\ +				__attribute__((section("_ftrace_annotated_branch"))) \ +				______f = {				\ +				.func = __func__,			\ +				.file = __FILE__,			\ +				.line = __LINE__,			\ +			};						\ +			______r = likely_notrace(x);			\ +			ftrace_likely_update(&______f, ______r, expect); \ +			______r;					\ +		}) + +/* + * Using __builtin_constant_p(x) to ignore cases where the return + * value is always the same.  This idea is taken from a similar patch + * written by Daniel Walker. + */ +# ifndef likely +#  define likely(x)	(__builtin_constant_p(x) ? !!(x) : __branch_check__(x, 1)) +# endif +# ifndef unlikely +#  define unlikely(x)	(__builtin_constant_p(x) ? !!(x) : __branch_check__(x, 0)) +# endif + +#ifdef CONFIG_PROFILE_ALL_BRANCHES +/* + * "Define 'is'", Bill Clinton + * "Define 'if'", Steven Rostedt + */ +#define if(cond) if (__builtin_constant_p((cond)) ? !!(cond) :		\ +	({								\ +		int ______r;						\ +		static struct ftrace_branch_data			\ +			__attribute__((__aligned__(4)))			\ +			__attribute__((section("_ftrace_branch")))	\ +			______f = {					\ +				.func = __func__,			\ +				.file = __FILE__,			\ +				.line = __LINE__,			\ +			};						\ +		______r = !!(cond);					\ +		if (______r)						\ +			______f.hit++;					\ +		else							\ +			______f.miss++;					\ +		______r;						\ +	})) +#endif /* CONFIG_PROFILE_ALL_BRANCHES */ + +#else +# define likely(x)	__builtin_expect(!!(x), 1) +# define unlikely(x)	__builtin_expect(!!(x), 0) +#endif  /* Optimization barrier */  #ifndef barrier  | 
