d9aef2a0ec8eb48eb38a891bf263b90cfd43d502
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 /* Called with interrupts disabled. */
14 extern void __context_tracking_enter(enum ctx_state state
);
15 extern void __context_tracking_exit(enum ctx_state state
);
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);
22 static inline void user_enter(void)
24 if (context_tracking_is_enabled())
25 context_tracking_enter(CONTEXT_USER
);
28 static inline void user_exit(void)
30 if (context_tracking_is_enabled())
31 context_tracking_exit(CONTEXT_USER
);
34 /* Called with interrupts disabled. */
35 static inline void user_enter_irqoff(void)
37 if (context_tracking_is_enabled())
38 __context_tracking_enter(CONTEXT_USER
);
41 static inline void user_exit_irqoff(void)
43 if (context_tracking_is_enabled())
44 __context_tracking_exit(CONTEXT_USER
);
47 static inline enum ctx_state
exception_enter(void)
49 enum ctx_state prev_ctx
;
51 if (!context_tracking_is_enabled())
54 prev_ctx
= this_cpu_read(context_tracking
.state
);
55 if (prev_ctx
!= CONTEXT_KERNEL
)
56 context_tracking_exit(prev_ctx
);
61 static inline void exception_exit(enum ctx_state prev_ctx
)
63 if (context_tracking_is_enabled()) {
64 if (prev_ctx
!= CONTEXT_KERNEL
)
65 context_tracking_enter(prev_ctx
);
71 * ct_state() - return the current context tracking state if known
73 * Returns the current cpu's context tracking state if context tracking
74 * is enabled. If context tracking is disabled, returns
75 * CONTEXT_DISABLED. This should be used primarily for debugging.
77 static inline enum ctx_state
ct_state(void)
79 return context_tracking_is_enabled() ?
80 this_cpu_read(context_tracking
.state
) : CONTEXT_DISABLED
;
83 static inline void user_enter(void) { }
84 static inline void user_exit(void) { }
85 static inline void user_enter_irqoff(void) { }
86 static inline void user_exit_irqoff(void) { }
87 static inline enum ctx_state
exception_enter(void) { return 0; }
88 static inline void exception_exit(enum ctx_state prev_ctx
) { }
89 static inline enum ctx_state
ct_state(void) { return CONTEXT_DISABLED
; }
90 #endif /* !CONFIG_CONTEXT_TRACKING */
92 #define CT_WARN_ON(cond) WARN_ON(context_tracking_is_enabled() && (cond))
94 #ifdef CONFIG_CONTEXT_TRACKING_FORCE
95 extern void context_tracking_init(void);
97 static inline void context_tracking_init(void) { }
98 #endif /* CONFIG_CONTEXT_TRACKING_FORCE */
101 #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
102 static inline void guest_enter(void)
104 if (vtime_accounting_cpu_enabled())
105 vtime_guest_enter(current
);
107 current
->flags
|= PF_VCPU
;
109 if (context_tracking_is_enabled())
110 __context_tracking_enter(CONTEXT_GUEST
);
113 static inline void guest_exit(void)
115 if (context_tracking_is_enabled())
116 __context_tracking_exit(CONTEXT_GUEST
);
118 if (vtime_accounting_cpu_enabled())
119 vtime_guest_exit(current
);
121 current
->flags
&= ~PF_VCPU
;
125 static inline void guest_enter(void)
128 * This is running in ioctl context so its safe
129 * to assume that it's the stime pending cputime
132 vtime_account_system(current
);
133 current
->flags
|= PF_VCPU
;
136 static inline void guest_exit(void)
138 /* Flush the guest cputime we spent on the guest */
139 vtime_account_system(current
);
140 current
->flags
&= ~PF_VCPU
;
142 #endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */
This page took 0.03672 seconds and 5 git commands to generate.