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_enter(enum ctx_state state);
14 extern void context_tracking_exit(enum ctx_state state);
15 extern void context_tracking_user_enter(void);
16 extern void context_tracking_user_exit(void);
17 extern void __context_tracking_task_switch(struct task_struct *prev,
18 struct task_struct *next);
20 static inline void user_enter(void)
22 if (context_tracking_is_enabled())
23 context_tracking_user_enter();
26 static inline void user_exit(void)
28 if (context_tracking_is_enabled())
29 context_tracking_user_exit();
32 static inline enum ctx_state exception_enter(void)
34 enum ctx_state prev_ctx;
36 if (!context_tracking_is_enabled())
39 prev_ctx = this_cpu_read(context_tracking.state);
40 if (prev_ctx != CONTEXT_KERNEL)
41 context_tracking_exit(prev_ctx);
46 static inline void exception_exit(enum ctx_state prev_ctx)
48 if (context_tracking_is_enabled()) {
49 if (prev_ctx != CONTEXT_KERNEL)
50 context_tracking_enter(prev_ctx);
54 static inline void context_tracking_task_switch(struct task_struct *prev,
55 struct task_struct *next)
57 if (context_tracking_is_enabled())
58 __context_tracking_task_switch(prev, next);
61 static inline void user_enter(void) { }
62 static inline void user_exit(void) { }
63 static inline enum ctx_state exception_enter(void) { return 0; }
64 static inline void exception_exit(enum ctx_state prev_ctx) { }
65 static inline void context_tracking_task_switch(struct task_struct *prev,
66 struct task_struct *next) { }
67 #endif /* !CONFIG_CONTEXT_TRACKING */
70 #ifdef CONFIG_CONTEXT_TRACKING_FORCE
71 extern void context_tracking_init(void);
73 static inline void context_tracking_init(void) { }
74 #endif /* CONFIG_CONTEXT_TRACKING_FORCE */
77 #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
78 static inline void guest_enter(void)
80 if (vtime_accounting_enabled())
81 vtime_guest_enter(current);
83 current->flags |= PF_VCPU;
85 if (context_tracking_is_enabled())
86 context_tracking_enter(CONTEXT_GUEST);
89 static inline void guest_exit(void)
91 if (context_tracking_is_enabled())
92 context_tracking_exit(CONTEXT_GUEST);
94 if (vtime_accounting_enabled())
95 vtime_guest_exit(current);
97 current->flags &= ~PF_VCPU;
101 static inline void guest_enter(void)
104 * This is running in ioctl context so its safe
105 * to assume that it's the stime pending cputime
108 vtime_account_system(current);
109 current->flags |= PF_VCPU;
112 static inline void guest_exit(void)
114 /* Flush the guest cputime we spent on the guest */
115 vtime_account_system(current);
116 current->flags &= ~PF_VCPU;
118 #endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */