Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / include / linux / context_tracking_state.h
1 #ifndef _LINUX_CONTEXT_TRACKING_STATE_H
2 #define _LINUX_CONTEXT_TRACKING_STATE_H
3
4 #include <linux/percpu.h>
5 #include <linux/static_key.h>
6
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.
13          */
14         bool active;
15         enum ctx_state {
16                 CONTEXT_KERNEL = 0,
17                 CONTEXT_USER,
18                 CONTEXT_GUEST,
19         } state;
20 };
21
22 #ifdef CONFIG_CONTEXT_TRACKING
23 extern struct static_key context_tracking_enabled;
24 DECLARE_PER_CPU(struct context_tracking, context_tracking);
25
26 static inline bool context_tracking_is_enabled(void)
27 {
28         return static_key_false(&context_tracking_enabled);
29 }
30
31 static inline bool context_tracking_cpu_is_enabled(void)
32 {
33         return __this_cpu_read(context_tracking.active);
34 }
35
36 static inline bool context_tracking_in_user(void)
37 {
38         return __this_cpu_read(context_tracking.state) == CONTEXT_USER;
39 }
40 #else
41 static inline bool context_tracking_in_user(void) { return false; }
42 static inline bool context_tracking_active(void) { return false; }
43 static inline bool context_tracking_is_enabled(void) { return false; }
44 static inline bool context_tracking_cpu_is_enabled(void) { return false; }
45 #endif /* CONFIG_CONTEXT_TRACKING */
46
47 #endif