Merge tag 'renesas-dt-fixes2-for-v4.5' of git://git.kernel.org/pub/scm/linux/kernel...
[deliverable/linux.git] / include / linux / context_tracking.h
1 #ifndef _LINUX_CONTEXT_TRACKING_H
2 #define _LINUX_CONTEXT_TRACKING_H
3
4 #include <linux/sched.h>
5 #include <linux/vtime.h>
6 #include <linux/context_tracking_state.h>
7 #include <asm/ptrace.h>
8
9
10 #ifdef CONFIG_CONTEXT_TRACKING
11 extern void context_tracking_cpu_set(int cpu);
12
13 /* Called with interrupts disabled. */
14 extern void __context_tracking_enter(enum ctx_state state);
15 extern void __context_tracking_exit(enum ctx_state state);
16
17 extern void context_tracking_enter(enum ctx_state state);
18 extern void context_tracking_exit(enum ctx_state state);
19 extern void context_tracking_user_enter(void);
20 extern void context_tracking_user_exit(void);
21
22 static inline void user_enter(void)
23 {
24 if (context_tracking_is_enabled())
25 context_tracking_enter(CONTEXT_USER);
26
27 }
28 static inline void user_exit(void)
29 {
30 if (context_tracking_is_enabled())
31 context_tracking_exit(CONTEXT_USER);
32 }
33
34 static inline enum ctx_state exception_enter(void)
35 {
36 enum ctx_state prev_ctx;
37
38 if (!context_tracking_is_enabled())
39 return 0;
40
41 prev_ctx = this_cpu_read(context_tracking.state);
42 if (prev_ctx != CONTEXT_KERNEL)
43 context_tracking_exit(prev_ctx);
44
45 return prev_ctx;
46 }
47
48 static inline void exception_exit(enum ctx_state prev_ctx)
49 {
50 if (context_tracking_is_enabled()) {
51 if (prev_ctx != CONTEXT_KERNEL)
52 context_tracking_enter(prev_ctx);
53 }
54 }
55
56
57 /**
58 * ct_state() - return the current context tracking state if known
59 *
60 * Returns the current cpu's context tracking state if context tracking
61 * is enabled. If context tracking is disabled, returns
62 * CONTEXT_DISABLED. This should be used primarily for debugging.
63 */
64 static inline enum ctx_state ct_state(void)
65 {
66 return context_tracking_is_enabled() ?
67 this_cpu_read(context_tracking.state) : CONTEXT_DISABLED;
68 }
69 #else
70 static inline void user_enter(void) { }
71 static inline void user_exit(void) { }
72 static inline enum ctx_state exception_enter(void) { return 0; }
73 static inline void exception_exit(enum ctx_state prev_ctx) { }
74 static inline enum ctx_state ct_state(void) { return CONTEXT_DISABLED; }
75 #endif /* !CONFIG_CONTEXT_TRACKING */
76
77 #define CT_WARN_ON(cond) WARN_ON(context_tracking_is_enabled() && (cond))
78
79 #ifdef CONFIG_CONTEXT_TRACKING_FORCE
80 extern void context_tracking_init(void);
81 #else
82 static inline void context_tracking_init(void) { }
83 #endif /* CONFIG_CONTEXT_TRACKING_FORCE */
84
85
86 #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
87 static inline void guest_enter(void)
88 {
89 if (vtime_accounting_cpu_enabled())
90 vtime_guest_enter(current);
91 else
92 current->flags |= PF_VCPU;
93
94 if (context_tracking_is_enabled())
95 __context_tracking_enter(CONTEXT_GUEST);
96 }
97
98 static inline void guest_exit(void)
99 {
100 if (context_tracking_is_enabled())
101 __context_tracking_exit(CONTEXT_GUEST);
102
103 if (vtime_accounting_cpu_enabled())
104 vtime_guest_exit(current);
105 else
106 current->flags &= ~PF_VCPU;
107 }
108
109 #else
110 static inline void guest_enter(void)
111 {
112 /*
113 * This is running in ioctl context so its safe
114 * to assume that it's the stime pending cputime
115 * to flush.
116 */
117 vtime_account_system(current);
118 current->flags |= PF_VCPU;
119 }
120
121 static inline void guest_exit(void)
122 {
123 /* Flush the guest cputime we spent on the guest */
124 vtime_account_system(current);
125 current->flags &= ~PF_VCPU;
126 }
127 #endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */
128
129 #endif
This page took 0.034752 seconds and 6 git commands to generate.