Frederic Weisbecker | 91d1aa43 | 2012-11-27 19:33:25 +0100 | [diff] [blame] | 1 | #ifndef _LINUX_CONTEXT_TRACKING_H |
| 2 | #define _LINUX_CONTEXT_TRACKING_H |
| 3 | |
| 4 | #ifdef CONFIG_CONTEXT_TRACKING |
| 5 | #include <linux/sched.h> |
Frederic Weisbecker | 95a79fd | 2013-01-07 18:12:14 +0100 | [diff] [blame] | 6 | #include <linux/percpu.h> |
| 7 | |
| 8 | struct context_tracking { |
| 9 | /* |
| 10 | * When active is false, probes are unset in order |
| 11 | * to minimize overhead: TIF flags are cleared |
| 12 | * and calls to user_enter/exit are ignored. This |
| 13 | * may be further optimized using static keys. |
| 14 | */ |
| 15 | bool active; |
| 16 | enum { |
| 17 | IN_KERNEL = 0, |
| 18 | IN_USER, |
| 19 | } state; |
| 20 | }; |
| 21 | |
| 22 | DECLARE_PER_CPU(struct context_tracking, context_tracking); |
| 23 | |
| 24 | static inline bool context_tracking_in_user(void) |
| 25 | { |
| 26 | return __this_cpu_read(context_tracking.state) == IN_USER; |
| 27 | } |
| 28 | |
| 29 | static inline bool context_tracking_active(void) |
| 30 | { |
| 31 | return __this_cpu_read(context_tracking.active); |
| 32 | } |
Frederic Weisbecker | 91d1aa43 | 2012-11-27 19:33:25 +0100 | [diff] [blame] | 33 | |
| 34 | extern void user_enter(void); |
| 35 | extern void user_exit(void); |
| 36 | extern void context_tracking_task_switch(struct task_struct *prev, |
| 37 | struct task_struct *next); |
| 38 | #else |
Frederic Weisbecker | 95a79fd | 2013-01-07 18:12:14 +0100 | [diff] [blame] | 39 | static inline bool context_tracking_in_user(void) { return false; } |
Frederic Weisbecker | 91d1aa43 | 2012-11-27 19:33:25 +0100 | [diff] [blame] | 40 | static inline void user_enter(void) { } |
| 41 | static inline void user_exit(void) { } |
| 42 | static inline void context_tracking_task_switch(struct task_struct *prev, |
| 43 | struct task_struct *next) { } |
| 44 | #endif /* !CONFIG_CONTEXT_TRACKING */ |
| 45 | |
| 46 | #endif |