Merge tag 'fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/arm...
[linux-2.6.git] / include / linux / context_tracking.h
blob158158704c30e75820913051283c6533ce669a4b
1 #ifndef _LINUX_CONTEXT_TRACKING_H
2 #define _LINUX_CONTEXT_TRACKING_H
4 #include <linux/sched.h>
5 #include <linux/vtime.h>
6 #include <linux/context_tracking_state.h>
7 #include <asm/ptrace.h>
10 #ifdef CONFIG_CONTEXT_TRACKING
11 extern void context_tracking_cpu_set(int cpu);
13 extern void context_tracking_user_enter(void);
14 extern void context_tracking_user_exit(void);
15 extern void __context_tracking_task_switch(struct task_struct *prev,
16 struct task_struct *next);
18 static inline void user_enter(void)
20 if (static_key_false(&context_tracking_enabled))
21 context_tracking_user_enter();
24 static inline void user_exit(void)
26 if (static_key_false(&context_tracking_enabled))
27 context_tracking_user_exit();
30 static inline enum ctx_state exception_enter(void)
32 enum ctx_state prev_ctx;
34 if (!static_key_false(&context_tracking_enabled))
35 return 0;
37 prev_ctx = this_cpu_read(context_tracking.state);
38 context_tracking_user_exit();
40 return prev_ctx;
43 static inline void exception_exit(enum ctx_state prev_ctx)
45 if (static_key_false(&context_tracking_enabled)) {
46 if (prev_ctx == IN_USER)
47 context_tracking_user_enter();
51 static inline void context_tracking_task_switch(struct task_struct *prev,
52 struct task_struct *next)
54 if (static_key_false(&context_tracking_enabled))
55 __context_tracking_task_switch(prev, next);
57 #else
58 static inline void user_enter(void) { }
59 static inline void user_exit(void) { }
60 static inline enum ctx_state exception_enter(void) { return 0; }
61 static inline void exception_exit(enum ctx_state prev_ctx) { }
62 static inline void context_tracking_task_switch(struct task_struct *prev,
63 struct task_struct *next) { }
64 #endif /* !CONFIG_CONTEXT_TRACKING */
67 #ifdef CONFIG_CONTEXT_TRACKING_FORCE
68 extern void context_tracking_init(void);
69 #else
70 static inline void context_tracking_init(void) { }
71 #endif /* CONFIG_CONTEXT_TRACKING_FORCE */
74 #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
75 static inline void guest_enter(void)
77 if (vtime_accounting_enabled())
78 vtime_guest_enter(current);
79 else
80 current->flags |= PF_VCPU;
83 static inline void guest_exit(void)
85 if (vtime_accounting_enabled())
86 vtime_guest_exit(current);
87 else
88 current->flags &= ~PF_VCPU;
91 #else
92 static inline void guest_enter(void)
95 * This is running in ioctl context so its safe
96 * to assume that it's the stime pending cputime
97 * to flush.
99 vtime_account_system(current);
100 current->flags |= PF_VCPU;
103 static inline void guest_exit(void)
105 /* Flush the guest cputime we spent on the guest */
106 vtime_account_system(current);
107 current->flags &= ~PF_VCPU;
109 #endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */
111 #endif