]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/vtime.h
mm/hotplug: invalid PFNs from pfn_to_online_page()
[mirror_ubuntu-bionic-kernel.git] / include / linux / vtime.h
CommitLineData
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>
a5725ac2
FW
6#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
7#include <asm/vtime.h>
8#endif
9
b0493406 10
dcbf832e
FW
11struct task_struct;
12
b0493406 13/*
55dbdcfa 14 * vtime_accounting_cpu_enabled() definitions/declarations
b0493406 15 */
8612f17a 16#if defined(CONFIG_VIRT_CPU_ACCOUNTING_NATIVE)
55dbdcfa 17static inline bool vtime_accounting_cpu_enabled(void) { return true; }
8612f17a 18#elif defined(CONFIG_VIRT_CPU_ACCOUNTING_GEN)
e5925394
FW
19/*
20 * Checks if vtime is enabled on some CPU. Cputime readers want to be careful
21 * in that case and compute the tickless cputime.
22 * For now vtime state is tied to context tracking. We might want to decouple
23 * those later if necessary.
24 */
25static inline bool vtime_accounting_enabled(void)
26{
27 return context_tracking_is_enabled();
28}
29
55dbdcfa 30static inline bool vtime_accounting_cpu_enabled(void)
b0493406 31{
e5925394 32 if (vtime_accounting_enabled()) {
d0df09eb 33 if (context_tracking_cpu_is_enabled())
b0493406
FW
34 return true;
35 }
36
37 return false;
38}
8612f17a 39#else /* !CONFIG_VIRT_CPU_ACCOUNTING */
55dbdcfa 40static inline bool vtime_accounting_cpu_enabled(void) { return false; }
8612f17a 41#endif
b0493406
FW
42
43
44/*
45 * Common vtime APIs
46 */
dcbf832e 47#ifdef CONFIG_VIRT_CPU_ACCOUNTING
b0493406
FW
48
49#ifdef __ARCH_HAS_VTIME_TASK_SWITCH
dcbf832e 50extern void vtime_task_switch(struct task_struct *prev);
b0493406
FW
51#else
52extern void vtime_common_task_switch(struct task_struct *prev);
53static inline void vtime_task_switch(struct task_struct *prev)
54{
55dbdcfa 55 if (vtime_accounting_cpu_enabled())
b0493406
FW
56 vtime_common_task_switch(prev);
57}
58#endif /* __ARCH_HAS_VTIME_TASK_SWITCH */
59
dcbf832e 60extern void vtime_account_system(struct task_struct *tsk);
fd25b4c2 61extern void vtime_account_idle(struct task_struct *tsk);
3f4724ea 62
3f4724ea 63#else /* !CONFIG_VIRT_CPU_ACCOUNTING */
6a61671b 64
dcbf832e 65static inline void vtime_task_switch(struct task_struct *prev) { }
11113334 66static inline void vtime_account_system(struct task_struct *tsk) { }
b0493406 67#endif /* !CONFIG_VIRT_CPU_ACCOUNTING */
abf917cd
FW
68
69#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
6a61671b 70extern void arch_vtime_task_switch(struct task_struct *tsk);
6a61671b 71extern void vtime_user_enter(struct task_struct *tsk);
1c3eda01 72extern void vtime_user_exit(struct task_struct *tsk);
6a61671b
FW
73extern void vtime_guest_enter(struct task_struct *tsk);
74extern void vtime_guest_exit(struct task_struct *tsk);
45eacc69 75extern void vtime_init_idle(struct task_struct *tsk, int cpu);
b0493406 76#else /* !CONFIG_VIRT_CPU_ACCOUNTING_GEN */
abf917cd
FW
77static inline void vtime_user_enter(struct task_struct *tsk) { }
78static inline void vtime_user_exit(struct task_struct *tsk) { }
6a61671b
FW
79static inline void vtime_guest_enter(struct task_struct *tsk) { }
80static inline void vtime_guest_exit(struct task_struct *tsk) { }
45eacc69 81static inline void vtime_init_idle(struct task_struct *tsk, int cpu) { }
dcbf832e
FW
82#endif
83
8612f17a
FW
84#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
85extern void vtime_account_irq_enter(struct task_struct *tsk);
86static inline void vtime_account_irq_exit(struct task_struct *tsk)
87{
88 /* On hard|softirq exit we always account to hard|softirq cputime */
89 vtime_account_system(tsk);
90}
c8d7dabf 91extern void vtime_flush(struct task_struct *tsk);
8612f17a
FW
92#else /* !CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
93static inline void vtime_account_irq_enter(struct task_struct *tsk) { }
94static inline void vtime_account_irq_exit(struct task_struct *tsk) { }
c8d7dabf 95static inline void vtime_flush(struct task_struct *tsk) { }
8612f17a
FW
96#endif
97
98
3e1df4f5
FW
99#ifdef CONFIG_IRQ_TIME_ACCOUNTING
100extern void irqtime_account_irq(struct task_struct *tsk);
dcbf832e 101#else
3e1df4f5 102static inline void irqtime_account_irq(struct task_struct *tsk) { }
dcbf832e
FW
103#endif
104
6a61671b 105static inline void account_irq_enter_time(struct task_struct *tsk)
fa5058f3 106{
6a61671b 107 vtime_account_irq_enter(tsk);
3e1df4f5 108 irqtime_account_irq(tsk);
fa5058f3
FW
109}
110
6a61671b 111static inline void account_irq_exit_time(struct task_struct *tsk)
fa5058f3 112{
6a61671b 113 vtime_account_irq_exit(tsk);
3e1df4f5 114 irqtime_account_irq(tsk);
fa5058f3
FW
115}
116
dcbf832e 117#endif /* _LINUX_KERNEL_VTIME_H */