Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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
11extern void context_tracking_cpu_set(int cpu);
12
13extern void context_tracking_user_enter(void);
14extern void context_tracking_user_exit(void);
15extern void __context_tracking_task_switch(struct task_struct *prev,
16 struct task_struct *next);
17
18static inline void user_enter(void)
19{
20 if (context_tracking_is_enabled())
21 context_tracking_user_enter();
22
23}
24static inline void user_exit(void)
25{
26 if (context_tracking_is_enabled())
27 context_tracking_user_exit();
28}
29
30static inline enum ctx_state exception_enter(void)
31{
32 enum ctx_state prev_ctx;
33
34 if (!context_tracking_is_enabled())
35 return 0;
36
37 prev_ctx = this_cpu_read(context_tracking.state);
38 context_tracking_user_exit();
39
40 return prev_ctx;
41}
42
43static inline void exception_exit(enum ctx_state prev_ctx)
44{
45 if (context_tracking_is_enabled()) {
46 if (prev_ctx == IN_USER)
47 context_tracking_user_enter();
48 }
49}
50
51static inline void context_tracking_task_switch(struct task_struct *prev,
52 struct task_struct *next)
53{
54 if (context_tracking_is_enabled())
55 __context_tracking_task_switch(prev, next);
56}
57#else
58static inline void user_enter(void) { }
59static inline void user_exit(void) { }
60static inline enum ctx_state exception_enter(void) { return 0; }
61static inline void exception_exit(enum ctx_state prev_ctx) { }
62static inline void context_tracking_task_switch(struct task_struct *prev,
63 struct task_struct *next) { }
64#endif /* !CONFIG_CONTEXT_TRACKING */
65
66
67#ifdef CONFIG_CONTEXT_TRACKING_FORCE
68extern void context_tracking_init(void);
69#else
70static inline void context_tracking_init(void) { }
71#endif /* CONFIG_CONTEXT_TRACKING_FORCE */
72
73
74#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
75static inline void guest_enter(void)
76{
77 if (vtime_accounting_enabled())
78 vtime_guest_enter(current);
79 else
80 current->flags |= PF_VCPU;
81}
82
83static inline void guest_exit(void)
84{
85 if (vtime_accounting_enabled())
86 vtime_guest_exit(current);
87 else
88 current->flags &= ~PF_VCPU;
89}
90
91#else
92static inline void guest_enter(void)
93{
94 /*
95 * This is running in ioctl context so its safe
96 * to assume that it's the stime pending cputime
97 * to flush.
98 */
99 vtime_account_system(current);
100 current->flags |= PF_VCPU;
101}
102
103static inline void guest_exit(void)
104{
105 /* Flush the guest cputime we spent on the guest */
106 vtime_account_system(current);
107 current->flags &= ~PF_VCPU;
108}
109#endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */
110
111#endif