]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - include/linux/context_tracking.h
vtime: Describe overriden functions in dedicated arch headers
[mirror_ubuntu-zesty-kernel.git] / include / linux / context_tracking.h
CommitLineData
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
11extern void context_tracking_cpu_set(int cpu);
12
ad65782f
FW
13extern void context_tracking_user_enter(void);
14extern void context_tracking_user_exit(void);
73d424f9
FW
15extern void __context_tracking_task_switch(struct task_struct *prev,
16 struct task_struct *next);
ad65782f
FW
17
18static inline void user_enter(void)
19{
20 if (static_key_false(&context_tracking_enabled))
21 context_tracking_user_enter();
22
23}
24static inline void user_exit(void)
25{
26 if (static_key_false(&context_tracking_enabled))
27 context_tracking_user_exit();
28}
56dd9470 29
6c1e0256 30static inline enum ctx_state exception_enter(void)
56dd9470 31{
6c1e0256
FW
32 enum ctx_state prev_ctx;
33
ad65782f
FW
34 if (!static_key_false(&context_tracking_enabled))
35 return 0;
36
6c1e0256 37 prev_ctx = this_cpu_read(context_tracking.state);
ad65782f 38 context_tracking_user_exit();
6c1e0256
FW
39
40 return prev_ctx;
56dd9470
FW
41}
42
6c1e0256 43static inline void exception_exit(enum ctx_state prev_ctx)
56dd9470 44{
ad65782f
FW
45 if (static_key_false(&context_tracking_enabled)) {
46 if (prev_ctx == IN_USER)
47 context_tracking_user_enter();
48 }
56dd9470
FW
49}
50
73d424f9
FW
51static inline void context_tracking_task_switch(struct task_struct *prev,
52 struct task_struct *next)
53{
54 if (static_key_false(&context_tracking_enabled))
55 __context_tracking_task_switch(prev, next);
56}
91d1aa43
FW
57#else
58static inline void user_enter(void) { }
59static inline void user_exit(void) { }
2d854e57
FW
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 */
521921ba 65
65f382fd
FW
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
2d854e57 74#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
48d6a816
FW
75static inline void guest_enter(void)
76{
77 if (static_key_false(&context_tracking_enabled) &&
78 vtime_accounting_enabled())
79 vtime_guest_enter(current);
80 else
81 current->flags |= PF_VCPU;
82}
83
84static inline void guest_exit(void)
85{
86 if (static_key_false(&context_tracking_enabled) &&
87 vtime_accounting_enabled())
88 vtime_guest_exit(current);
89 else
90 current->flags &= ~PF_VCPU;
91}
73d424f9 92
2d854e57 93#else
521921ba
FW
94static inline void guest_enter(void)
95{
2d854e57 96 /*
5b206d48
FW
97 * This is running in ioctl context so its safe
98 * to assume that it's the stime pending cputime
99 * to flush.
2d854e57
FW
100 */
101 vtime_account_system(current);
102 current->flags |= PF_VCPU;
521921ba
FW
103}
104
105static inline void guest_exit(void)
106{
5b206d48 107 /* Flush the guest cputime we spent on the guest */
2d854e57
FW
108 vtime_account_system(current);
109 current->flags &= ~PF_VCPU;
521921ba 110}
2d854e57 111#endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */
91d1aa43
FW
112
113#endif