Commit | Line | Data |
---|---|---|
91d1aa43 FW |
1 | #ifndef _LINUX_CONTEXT_TRACKING_H |
2 | #define _LINUX_CONTEXT_TRACKING_H | |
3 | ||
91d1aa43 | 4 | #include <linux/sched.h> |
521921ba | 5 | #include <linux/vtime.h> |
e7358b3b | 6 | #include <linux/context_tracking_state.h> |
56dd9470 | 7 | #include <asm/ptrace.h> |
95a79fd4 | 8 | |
521921ba | 9 | |
6c1e0256 | 10 | #ifdef CONFIG_CONTEXT_TRACKING |
2e709338 FW |
11 | extern void context_tracking_cpu_set(int cpu); |
12 | ||
3aab4f50 RR |
13 | extern void context_tracking_enter(enum ctx_state state); |
14 | extern void context_tracking_exit(enum ctx_state state); | |
ad65782f FW |
15 | extern void context_tracking_user_enter(void); |
16 | extern void context_tracking_user_exit(void); | |
73d424f9 FW |
17 | extern void __context_tracking_task_switch(struct task_struct *prev, |
18 | struct task_struct *next); | |
ad65782f FW |
19 | |
20 | static inline void user_enter(void) | |
21 | { | |
58135f57 | 22 | if (context_tracking_is_enabled()) |
ad65782f FW |
23 | context_tracking_user_enter(); |
24 | ||
25 | } | |
26 | static inline void user_exit(void) | |
27 | { | |
58135f57 | 28 | if (context_tracking_is_enabled()) |
ad65782f FW |
29 | context_tracking_user_exit(); |
30 | } | |
56dd9470 | 31 | |
6c1e0256 | 32 | static inline enum ctx_state exception_enter(void) |
56dd9470 | 33 | { |
6c1e0256 FW |
34 | enum ctx_state prev_ctx; |
35 | ||
58135f57 | 36 | if (!context_tracking_is_enabled()) |
ad65782f FW |
37 | return 0; |
38 | ||
6c1e0256 | 39 | prev_ctx = this_cpu_read(context_tracking.state); |
3aab4f50 RR |
40 | if (prev_ctx != CONTEXT_KERNEL) |
41 | context_tracking_exit(prev_ctx); | |
6c1e0256 FW |
42 | |
43 | return prev_ctx; | |
56dd9470 FW |
44 | } |
45 | ||
6c1e0256 | 46 | static inline void exception_exit(enum ctx_state prev_ctx) |
56dd9470 | 47 | { |
58135f57 | 48 | if (context_tracking_is_enabled()) { |
3aab4f50 RR |
49 | if (prev_ctx != CONTEXT_KERNEL) |
50 | context_tracking_enter(prev_ctx); | |
ad65782f | 51 | } |
56dd9470 FW |
52 | } |
53 | ||
73d424f9 FW |
54 | static inline void context_tracking_task_switch(struct task_struct *prev, |
55 | struct task_struct *next) | |
56 | { | |
58135f57 | 57 | if (context_tracking_is_enabled()) |
73d424f9 FW |
58 | __context_tracking_task_switch(prev, next); |
59 | } | |
91d1aa43 FW |
60 | #else |
61 | static inline void user_enter(void) { } | |
62 | static inline void user_exit(void) { } | |
2d854e57 FW |
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 */ | |
521921ba | 68 | |
65f382fd FW |
69 | |
70 | #ifdef CONFIG_CONTEXT_TRACKING_FORCE | |
71 | extern void context_tracking_init(void); | |
72 | #else | |
73 | static inline void context_tracking_init(void) { } | |
74 | #endif /* CONFIG_CONTEXT_TRACKING_FORCE */ | |
75 | ||
76 | ||
2d854e57 | 77 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN |
48d6a816 FW |
78 | static inline void guest_enter(void) |
79 | { | |
b0493406 | 80 | if (vtime_accounting_enabled()) |
48d6a816 FW |
81 | vtime_guest_enter(current); |
82 | else | |
83 | current->flags |= PF_VCPU; | |
84 | } | |
85 | ||
86 | static inline void guest_exit(void) | |
87 | { | |
b0493406 | 88 | if (vtime_accounting_enabled()) |
48d6a816 FW |
89 | vtime_guest_exit(current); |
90 | else | |
91 | current->flags &= ~PF_VCPU; | |
92 | } | |
73d424f9 | 93 | |
2d854e57 | 94 | #else |
521921ba FW |
95 | static inline void guest_enter(void) |
96 | { | |
2d854e57 | 97 | /* |
5b206d48 FW |
98 | * This is running in ioctl context so its safe |
99 | * to assume that it's the stime pending cputime | |
100 | * to flush. | |
2d854e57 FW |
101 | */ |
102 | vtime_account_system(current); | |
103 | current->flags |= PF_VCPU; | |
521921ba FW |
104 | } |
105 | ||
106 | static inline void guest_exit(void) | |
107 | { | |
5b206d48 | 108 | /* Flush the guest cputime we spent on the guest */ |
2d854e57 FW |
109 | vtime_account_system(current); |
110 | current->flags &= ~PF_VCPU; | |
521921ba | 111 | } |
2d854e57 | 112 | #endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */ |
91d1aa43 FW |
113 | |
114 | #endif |