Linux 4.6-rc6
[cris-mirror.git] / include / linux / context_tracking_state.h
blob1d34fe68f48ad3bea0c98e2eadbabae0aeb152d9
1 #ifndef _LINUX_CONTEXT_TRACKING_STATE_H
2 #define _LINUX_CONTEXT_TRACKING_STATE_H
4 #include <linux/percpu.h>
5 #include <linux/static_key.h>
7 struct context_tracking {
8 /*
9 * When active is false, probes are unset in order
10 * to minimize overhead: TIF flags are cleared
11 * and calls to user_enter/exit are ignored. This
12 * may be further optimized using static keys.
14 bool active;
15 int recursion;
16 enum ctx_state {
17 CONTEXT_DISABLED = -1, /* returned by ct_state() if unknown */
18 CONTEXT_KERNEL = 0,
19 CONTEXT_USER,
20 CONTEXT_GUEST,
21 } state;
24 #ifdef CONFIG_CONTEXT_TRACKING
25 extern struct static_key_false context_tracking_enabled;
26 DECLARE_PER_CPU(struct context_tracking, context_tracking);
28 static inline bool context_tracking_is_enabled(void)
30 return static_branch_unlikely(&context_tracking_enabled);
33 static inline bool context_tracking_cpu_is_enabled(void)
35 return __this_cpu_read(context_tracking.active);
38 static inline bool context_tracking_in_user(void)
40 return __this_cpu_read(context_tracking.state) == CONTEXT_USER;
42 #else
43 static inline bool context_tracking_in_user(void) { return false; }
44 static inline bool context_tracking_active(void) { return false; }
45 static inline bool context_tracking_is_enabled(void) { return false; }
46 static inline bool context_tracking_cpu_is_enabled(void) { return false; }
47 #endif /* CONFIG_CONTEXT_TRACKING */
49 #endif