diff options
-rw-r--r-- | include/linux/context_tracking.h | 28 | ||||
-rw-r--r-- | kernel/context_tracking.c | 16 |
2 files changed, 29 insertions, 15 deletions
diff --git a/include/linux/context_tracking.h b/include/linux/context_tracking.h index e24339ccb7f0..b28d161c1091 100644 --- a/include/linux/context_tracking.h +++ b/include/linux/context_tracking.h | |||
@@ -3,12 +3,40 @@ | |||
3 | 3 | ||
4 | #ifdef CONFIG_CONTEXT_TRACKING | 4 | #ifdef CONFIG_CONTEXT_TRACKING |
5 | #include <linux/sched.h> | 5 | #include <linux/sched.h> |
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 | } | ||
6 | 33 | ||
7 | extern void user_enter(void); | 34 | extern void user_enter(void); |
8 | extern void user_exit(void); | 35 | extern void user_exit(void); |
9 | extern void context_tracking_task_switch(struct task_struct *prev, | 36 | extern void context_tracking_task_switch(struct task_struct *prev, |
10 | struct task_struct *next); | 37 | struct task_struct *next); |
11 | #else | 38 | #else |
39 | static inline bool context_tracking_in_user(void) { return false; } | ||
12 | static inline void user_enter(void) { } | 40 | static inline void user_enter(void) { } |
13 | static inline void user_exit(void) { } | 41 | static inline void user_exit(void) { } |
14 | static inline void context_tracking_task_switch(struct task_struct *prev, | 42 | static inline void context_tracking_task_switch(struct task_struct *prev, |
diff --git a/kernel/context_tracking.c b/kernel/context_tracking.c index e0e07fd55508..54f471e536dc 100644 --- a/kernel/context_tracking.c +++ b/kernel/context_tracking.c | |||
@@ -1,24 +1,10 @@ | |||
1 | #include <linux/context_tracking.h> | 1 | #include <linux/context_tracking.h> |
2 | #include <linux/rcupdate.h> | 2 | #include <linux/rcupdate.h> |
3 | #include <linux/sched.h> | 3 | #include <linux/sched.h> |
4 | #include <linux/percpu.h> | ||
5 | #include <linux/hardirq.h> | 4 | #include <linux/hardirq.h> |
6 | 5 | ||
7 | struct context_tracking { | ||
8 | /* | ||
9 | * When active is false, hooks are not set to | ||
10 | * 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 { | ||
16 | IN_KERNEL = 0, | ||
17 | IN_USER, | ||
18 | } state; | ||
19 | }; | ||
20 | 6 | ||
21 | static DEFINE_PER_CPU(struct context_tracking, context_tracking) = { | 7 | DEFINE_PER_CPU(struct context_tracking, context_tracking) = { |
22 | #ifdef CONFIG_CONTEXT_TRACKING_FORCE | 8 | #ifdef CONFIG_CONTEXT_TRACKING_FORCE |
23 | .active = true, | 9 | .active = true, |
24 | #endif | 10 | #endif |