Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
dcbf832e FW |
2 | #ifndef _LINUX_KERNEL_VTIME_H |
3 | #define _LINUX_KERNEL_VTIME_H | |
4 | ||
b0493406 | 5 | #include <linux/context_tracking_state.h> |
6f922b89 SC |
6 | #include <linux/sched.h> |
7 | ||
b41c723b SC |
8 | /* |
9 | * Common vtime APIs | |
10 | */ | |
11 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING | |
12 | extern void vtime_account_kernel(struct task_struct *tsk); | |
13 | extern void vtime_account_idle(struct task_struct *tsk); | |
b41c723b SC |
14 | #endif /* !CONFIG_VIRT_CPU_ACCOUNTING */ |
15 | ||
16 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN | |
b41c723b SC |
17 | extern void vtime_user_enter(struct task_struct *tsk); |
18 | extern void vtime_user_exit(struct task_struct *tsk); | |
19 | extern void vtime_guest_enter(struct task_struct *tsk); | |
20 | extern void vtime_guest_exit(struct task_struct *tsk); | |
21 | extern void vtime_init_idle(struct task_struct *tsk, int cpu); | |
22 | #else /* !CONFIG_VIRT_CPU_ACCOUNTING_GEN */ | |
23 | static inline void vtime_user_enter(struct task_struct *tsk) { } | |
24 | static inline void vtime_user_exit(struct task_struct *tsk) { } | |
25 | static inline void vtime_guest_enter(struct task_struct *tsk) { } | |
26 | static inline void vtime_guest_exit(struct task_struct *tsk) { } | |
27 | static inline void vtime_init_idle(struct task_struct *tsk, int cpu) { } | |
28 | #endif | |
29 | ||
30 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE | |
31 | extern void vtime_account_irq(struct task_struct *tsk, unsigned int offset); | |
32 | extern void vtime_account_softirq(struct task_struct *tsk); | |
33 | extern void vtime_account_hardirq(struct task_struct *tsk); | |
34 | extern void vtime_flush(struct task_struct *tsk); | |
35 | #else /* !CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */ | |
36 | static inline void vtime_account_irq(struct task_struct *tsk, unsigned int offset) { } | |
37 | static inline void vtime_account_softirq(struct task_struct *tsk) { } | |
38 | static inline void vtime_account_hardirq(struct task_struct *tsk) { } | |
39 | static inline void vtime_flush(struct task_struct *tsk) { } | |
40 | #endif | |
41 | ||
b0493406 | 42 | /* |
e44fcb4b | 43 | * vtime_accounting_enabled_this_cpu() definitions/declarations |
b0493406 | 44 | */ |
8612f17a | 45 | #if defined(CONFIG_VIRT_CPU_ACCOUNTING_NATIVE) |
8d495477 | 46 | |
e44fcb4b | 47 | static inline bool vtime_accounting_enabled_this_cpu(void) { return true; } |
8d495477 FW |
48 | extern void vtime_task_switch(struct task_struct *prev); |
49 | ||
6f922b89 SC |
50 | static __always_inline void vtime_account_guest_enter(void) |
51 | { | |
52 | vtime_account_kernel(current); | |
53 | current->flags |= PF_VCPU; | |
54 | } | |
55 | ||
56 | static __always_inline void vtime_account_guest_exit(void) | |
57 | { | |
58 | vtime_account_kernel(current); | |
59 | current->flags &= ~PF_VCPU; | |
60 | } | |
61 | ||
8612f17a | 62 | #elif defined(CONFIG_VIRT_CPU_ACCOUNTING_GEN) |
8d495477 | 63 | |
e5925394 FW |
64 | /* |
65 | * Checks if vtime is enabled on some CPU. Cputime readers want to be careful | |
66 | * in that case and compute the tickless cputime. | |
67 | * For now vtime state is tied to context tracking. We might want to decouple | |
68 | * those later if necessary. | |
69 | */ | |
70 | static inline bool vtime_accounting_enabled(void) | |
71 | { | |
74c57875 | 72 | return context_tracking_enabled(); |
e5925394 FW |
73 | } |
74 | ||
9adbb9dd | 75 | static inline bool vtime_accounting_enabled_cpu(int cpu) |
b0493406 | 76 | { |
023e9deb | 77 | return context_tracking_enabled_cpu(cpu); |
9adbb9dd | 78 | } |
b0493406 | 79 | |
9adbb9dd FW |
80 | static inline bool vtime_accounting_enabled_this_cpu(void) |
81 | { | |
023e9deb | 82 | return context_tracking_enabled_this_cpu(); |
b0493406 | 83 | } |
8d495477 FW |
84 | |
85 | extern void vtime_task_switch_generic(struct task_struct *prev); | |
86 | ||
87 | static inline void vtime_task_switch(struct task_struct *prev) | |
88 | { | |
e44fcb4b | 89 | if (vtime_accounting_enabled_this_cpu()) |
8d495477 FW |
90 | vtime_task_switch_generic(prev); |
91 | } | |
92 | ||
6f922b89 SC |
93 | static __always_inline void vtime_account_guest_enter(void) |
94 | { | |
95 | if (vtime_accounting_enabled_this_cpu()) | |
96 | vtime_guest_enter(current); | |
97 | else | |
98 | current->flags |= PF_VCPU; | |
99 | } | |
100 | ||
101 | static __always_inline void vtime_account_guest_exit(void) | |
102 | { | |
103 | if (vtime_accounting_enabled_this_cpu()) | |
104 | vtime_guest_exit(current); | |
105 | else | |
106 | current->flags &= ~PF_VCPU; | |
107 | } | |
108 | ||
8612f17a | 109 | #else /* !CONFIG_VIRT_CPU_ACCOUNTING */ |
8d495477 | 110 | |
e44fcb4b | 111 | static inline bool vtime_accounting_enabled_this_cpu(void) { return false; } |
8d495477 | 112 | static inline void vtime_task_switch(struct task_struct *prev) { } |
b0493406 | 113 | |
6f922b89 SC |
114 | static __always_inline void vtime_account_guest_enter(void) |
115 | { | |
116 | current->flags |= PF_VCPU; | |
117 | } | |
118 | ||
119 | static __always_inline void vtime_account_guest_exit(void) | |
120 | { | |
121 | current->flags &= ~PF_VCPU; | |
122 | } | |
123 | ||
8d495477 | 124 | #endif |
b0493406 | 125 | |
8612f17a | 126 | |
3e1df4f5 | 127 | #ifdef CONFIG_IRQ_TIME_ACCOUNTING |
d3759e71 | 128 | extern void irqtime_account_irq(struct task_struct *tsk, unsigned int offset); |
dcbf832e | 129 | #else |
d3759e71 | 130 | static inline void irqtime_account_irq(struct task_struct *tsk, unsigned int offset) { } |
dcbf832e FW |
131 | #endif |
132 | ||
d3759e71 | 133 | static inline void account_softirq_enter(struct task_struct *tsk) |
fa5058f3 | 134 | { |
d3759e71 FW |
135 | vtime_account_irq(tsk, SOFTIRQ_OFFSET); |
136 | irqtime_account_irq(tsk, SOFTIRQ_OFFSET); | |
fa5058f3 FW |
137 | } |
138 | ||
d3759e71 | 139 | static inline void account_softirq_exit(struct task_struct *tsk) |
fa5058f3 | 140 | { |
d3759e71 FW |
141 | vtime_account_softirq(tsk); |
142 | irqtime_account_irq(tsk, 0); | |
143 | } | |
144 | ||
145 | static inline void account_hardirq_enter(struct task_struct *tsk) | |
146 | { | |
147 | vtime_account_irq(tsk, HARDIRQ_OFFSET); | |
148 | irqtime_account_irq(tsk, HARDIRQ_OFFSET); | |
149 | } | |
150 | ||
151 | static inline void account_hardirq_exit(struct task_struct *tsk) | |
152 | { | |
153 | vtime_account_hardirq(tsk); | |
154 | irqtime_account_irq(tsk, 0); | |
fa5058f3 FW |
155 | } |
156 | ||
dcbf832e | 157 | #endif /* _LINUX_KERNEL_VTIME_H */ |