|
3 | 3 | #define _LINUX_KERNEL_VTIME_H
|
4 | 4 |
|
5 | 5 | #include <linux/context_tracking_state.h>
|
| 6 | +#include <linux/sched.h> |
| 7 | + |
6 | 8 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
|
7 | 9 | #include <asm/vtime.h>
|
8 | 10 | #endif
|
9 | 11 |
|
10 |
| - |
11 |
| -struct task_struct; |
12 |
| - |
13 | 12 | /*
|
14 | 13 | * Common vtime APIs
|
15 | 14 | */
|
16 | 15 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING
|
17 | 16 | extern void vtime_account_kernel(struct task_struct *tsk);
|
18 | 17 | extern void vtime_account_idle(struct task_struct *tsk);
|
19 |
| -#else /* !CONFIG_VIRT_CPU_ACCOUNTING */ |
20 |
| -static inline void vtime_account_kernel(struct task_struct *tsk) { } |
21 | 18 | #endif /* !CONFIG_VIRT_CPU_ACCOUNTING */
|
22 | 19 |
|
23 | 20 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
|
@@ -55,6 +52,18 @@ static inline void vtime_flush(struct task_struct *tsk) { }
|
55 | 52 | static inline bool vtime_accounting_enabled_this_cpu(void) { return true; }
|
56 | 53 | extern void vtime_task_switch(struct task_struct *prev);
|
57 | 54 |
|
| 55 | +static __always_inline void vtime_account_guest_enter(void) |
| 56 | +{ |
| 57 | + vtime_account_kernel(current); |
| 58 | + current->flags |= PF_VCPU; |
| 59 | +} |
| 60 | + |
| 61 | +static __always_inline void vtime_account_guest_exit(void) |
| 62 | +{ |
| 63 | + vtime_account_kernel(current); |
| 64 | + current->flags &= ~PF_VCPU; |
| 65 | +} |
| 66 | + |
58 | 67 | #elif defined(CONFIG_VIRT_CPU_ACCOUNTING_GEN)
|
59 | 68 |
|
60 | 69 | /*
|
@@ -86,12 +95,37 @@ static inline void vtime_task_switch(struct task_struct *prev)
|
86 | 95 | vtime_task_switch_generic(prev);
|
87 | 96 | }
|
88 | 97 |
|
| 98 | +static __always_inline void vtime_account_guest_enter(void) |
| 99 | +{ |
| 100 | + if (vtime_accounting_enabled_this_cpu()) |
| 101 | + vtime_guest_enter(current); |
| 102 | + else |
| 103 | + current->flags |= PF_VCPU; |
| 104 | +} |
| 105 | + |
| 106 | +static __always_inline void vtime_account_guest_exit(void) |
| 107 | +{ |
| 108 | + if (vtime_accounting_enabled_this_cpu()) |
| 109 | + vtime_guest_exit(current); |
| 110 | + else |
| 111 | + current->flags &= ~PF_VCPU; |
| 112 | +} |
| 113 | + |
89 | 114 | #else /* !CONFIG_VIRT_CPU_ACCOUNTING */
|
90 | 115 |
|
91 |
| -static inline bool vtime_accounting_enabled_cpu(int cpu) {return false; } |
92 | 116 | static inline bool vtime_accounting_enabled_this_cpu(void) { return false; }
|
93 | 117 | static inline void vtime_task_switch(struct task_struct *prev) { }
|
94 | 118 |
|
| 119 | +static __always_inline void vtime_account_guest_enter(void) |
| 120 | +{ |
| 121 | + current->flags |= PF_VCPU; |
| 122 | +} |
| 123 | + |
| 124 | +static __always_inline void vtime_account_guest_exit(void) |
| 125 | +{ |
| 126 | + current->flags &= ~PF_VCPU; |
| 127 | +} |
| 128 | + |
95 | 129 | #endif
|
96 | 130 |
|
97 | 131 |
|
|
0 commit comments