Commit | Line | Data |
---|---|---|
dcbf832e FW |
1 | #ifndef _LINUX_KERNEL_VTIME_H |
2 | #define _LINUX_KERNEL_VTIME_H | |
3 | ||
b0493406 | 4 | #include <linux/context_tracking_state.h> |
a5725ac2 FW |
5 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE |
6 | #include <asm/vtime.h> | |
7 | #endif | |
8 | ||
b0493406 | 9 | |
dcbf832e FW |
10 | struct task_struct; |
11 | ||
b0493406 | 12 | /* |
55dbdcfa | 13 | * vtime_accounting_cpu_enabled() definitions/declarations |
b0493406 FW |
14 | */ |
15 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE | |
55dbdcfa | 16 | static inline bool vtime_accounting_cpu_enabled(void) { return true; } |
b0493406 FW |
17 | #endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */ |
18 | ||
19 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN | |
e5925394 FW |
20 | /* |
21 | * Checks if vtime is enabled on some CPU. Cputime readers want to be careful | |
22 | * in that case and compute the tickless cputime. | |
23 | * For now vtime state is tied to context tracking. We might want to decouple | |
24 | * those later if necessary. | |
25 | */ | |
26 | static inline bool vtime_accounting_enabled(void) | |
27 | { | |
28 | return context_tracking_is_enabled(); | |
29 | } | |
30 | ||
55dbdcfa | 31 | static inline bool vtime_accounting_cpu_enabled(void) |
b0493406 | 32 | { |
e5925394 | 33 | if (vtime_accounting_enabled()) { |
d0df09eb | 34 | if (context_tracking_cpu_is_enabled()) |
b0493406 FW |
35 | return true; |
36 | } | |
37 | ||
38 | return false; | |
39 | } | |
40 | #endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */ | |
41 | ||
42 | #ifndef CONFIG_VIRT_CPU_ACCOUNTING | |
55dbdcfa | 43 | static inline bool vtime_accounting_cpu_enabled(void) { return false; } |
b0493406 FW |
44 | #endif /* !CONFIG_VIRT_CPU_ACCOUNTING */ |
45 | ||
46 | ||
47 | /* | |
48 | * Common vtime APIs | |
49 | */ | |
dcbf832e | 50 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING |
b0493406 FW |
51 | |
52 | #ifdef __ARCH_HAS_VTIME_TASK_SWITCH | |
dcbf832e | 53 | extern void vtime_task_switch(struct task_struct *prev); |
b0493406 FW |
54 | #else |
55 | extern void vtime_common_task_switch(struct task_struct *prev); | |
56 | static inline void vtime_task_switch(struct task_struct *prev) | |
57 | { | |
55dbdcfa | 58 | if (vtime_accounting_cpu_enabled()) |
b0493406 FW |
59 | vtime_common_task_switch(prev); |
60 | } | |
61 | #endif /* __ARCH_HAS_VTIME_TASK_SWITCH */ | |
62 | ||
dcbf832e | 63 | extern void vtime_account_system(struct task_struct *tsk); |
fd25b4c2 | 64 | extern void vtime_account_idle(struct task_struct *tsk); |
bcebdf84 | 65 | extern void vtime_account_user(struct task_struct *tsk); |
3f4724ea | 66 | |
b0493406 FW |
67 | #ifdef __ARCH_HAS_VTIME_ACCOUNT |
68 | extern void vtime_account_irq_enter(struct task_struct *tsk); | |
69 | #else | |
70 | extern void vtime_common_account_irq_enter(struct task_struct *tsk); | |
71 | static inline void vtime_account_irq_enter(struct task_struct *tsk) | |
72 | { | |
55dbdcfa | 73 | if (vtime_accounting_cpu_enabled()) |
b0493406 FW |
74 | vtime_common_account_irq_enter(tsk); |
75 | } | |
76 | #endif /* __ARCH_HAS_VTIME_ACCOUNT */ | |
3f4724ea FW |
77 | |
78 | #else /* !CONFIG_VIRT_CPU_ACCOUNTING */ | |
6a61671b | 79 | |
dcbf832e | 80 | static inline void vtime_task_switch(struct task_struct *prev) { } |
11113334 | 81 | static inline void vtime_account_system(struct task_struct *tsk) { } |
abf917cd | 82 | static inline void vtime_account_user(struct task_struct *tsk) { } |
6a61671b | 83 | static inline void vtime_account_irq_enter(struct task_struct *tsk) { } |
b0493406 | 84 | #endif /* !CONFIG_VIRT_CPU_ACCOUNTING */ |
abf917cd FW |
85 | |
86 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN | |
6a61671b | 87 | extern void arch_vtime_task_switch(struct task_struct *tsk); |
b0493406 FW |
88 | extern void vtime_gen_account_irq_exit(struct task_struct *tsk); |
89 | ||
90 | static inline void vtime_account_irq_exit(struct task_struct *tsk) | |
91 | { | |
55dbdcfa | 92 | if (vtime_accounting_cpu_enabled()) |
b0493406 FW |
93 | vtime_gen_account_irq_exit(tsk); |
94 | } | |
95 | ||
6a61671b | 96 | extern void vtime_user_enter(struct task_struct *tsk); |
b0493406 | 97 | |
abf917cd FW |
98 | static inline void vtime_user_exit(struct task_struct *tsk) |
99 | { | |
100 | vtime_account_user(tsk); | |
101 | } | |
6a61671b FW |
102 | extern void vtime_guest_enter(struct task_struct *tsk); |
103 | extern void vtime_guest_exit(struct task_struct *tsk); | |
45eacc69 | 104 | extern void vtime_init_idle(struct task_struct *tsk, int cpu); |
b0493406 | 105 | #else /* !CONFIG_VIRT_CPU_ACCOUNTING_GEN */ |
6a61671b FW |
106 | static inline void vtime_account_irq_exit(struct task_struct *tsk) |
107 | { | |
108 | /* On hard|softirq exit we always account to hard|softirq cputime */ | |
109 | vtime_account_system(tsk); | |
110 | } | |
abf917cd FW |
111 | static inline void vtime_user_enter(struct task_struct *tsk) { } |
112 | static inline void vtime_user_exit(struct task_struct *tsk) { } | |
6a61671b FW |
113 | static inline void vtime_guest_enter(struct task_struct *tsk) { } |
114 | static inline void vtime_guest_exit(struct task_struct *tsk) { } | |
45eacc69 | 115 | static inline void vtime_init_idle(struct task_struct *tsk, int cpu) { } |
dcbf832e FW |
116 | #endif |
117 | ||
3e1df4f5 FW |
118 | #ifdef CONFIG_IRQ_TIME_ACCOUNTING |
119 | extern void irqtime_account_irq(struct task_struct *tsk); | |
dcbf832e | 120 | #else |
3e1df4f5 | 121 | static inline void irqtime_account_irq(struct task_struct *tsk) { } |
dcbf832e FW |
122 | #endif |
123 | ||
6a61671b | 124 | static inline void account_irq_enter_time(struct task_struct *tsk) |
fa5058f3 | 125 | { |
6a61671b | 126 | vtime_account_irq_enter(tsk); |
3e1df4f5 | 127 | irqtime_account_irq(tsk); |
fa5058f3 FW |
128 | } |
129 | ||
6a61671b | 130 | static inline void account_irq_exit_time(struct task_struct *tsk) |
fa5058f3 | 131 | { |
6a61671b | 132 | vtime_account_irq_exit(tsk); |
3e1df4f5 | 133 | irqtime_account_irq(tsk); |
fa5058f3 FW |
134 | } |
135 | ||
dcbf832e | 136 | #endif /* _LINUX_KERNEL_VTIME_H */ |