]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/vtime.h
Merge tag 'writeback-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/wfg...
[mirror_ubuntu-bionic-kernel.git] / include / linux / vtime.h
CommitLineData
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
10struct task_struct;
11
b0493406
FW
12/*
13 * vtime_accounting_enabled() definitions/declarations
14 */
15#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
16static inline bool vtime_accounting_enabled(void) { return true; }
17#endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
18
19#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
20static inline bool vtime_accounting_enabled(void)
21{
22 if (static_key_false(&context_tracking_enabled)) {
23 if (context_tracking_active())
24 return true;
25 }
26
27 return false;
28}
29#endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */
30
31#ifndef CONFIG_VIRT_CPU_ACCOUNTING
32static inline bool vtime_accounting_enabled(void) { return false; }
33#endif /* !CONFIG_VIRT_CPU_ACCOUNTING */
34
35
36/*
37 * Common vtime APIs
38 */
dcbf832e 39#ifdef CONFIG_VIRT_CPU_ACCOUNTING
b0493406
FW
40
41#ifdef __ARCH_HAS_VTIME_TASK_SWITCH
dcbf832e 42extern void vtime_task_switch(struct task_struct *prev);
b0493406
FW
43#else
44extern void vtime_common_task_switch(struct task_struct *prev);
45static inline void vtime_task_switch(struct task_struct *prev)
46{
47 if (vtime_accounting_enabled())
48 vtime_common_task_switch(prev);
49}
50#endif /* __ARCH_HAS_VTIME_TASK_SWITCH */
51
dcbf832e 52extern void vtime_account_system(struct task_struct *tsk);
fd25b4c2 53extern void vtime_account_idle(struct task_struct *tsk);
bcebdf84 54extern void vtime_account_user(struct task_struct *tsk);
3f4724ea 55
b0493406
FW
56#ifdef __ARCH_HAS_VTIME_ACCOUNT
57extern void vtime_account_irq_enter(struct task_struct *tsk);
58#else
59extern void vtime_common_account_irq_enter(struct task_struct *tsk);
60static inline void vtime_account_irq_enter(struct task_struct *tsk)
61{
62 if (vtime_accounting_enabled())
63 vtime_common_account_irq_enter(tsk);
64}
65#endif /* __ARCH_HAS_VTIME_ACCOUNT */
3f4724ea
FW
66
67#else /* !CONFIG_VIRT_CPU_ACCOUNTING */
6a61671b 68
dcbf832e 69static inline void vtime_task_switch(struct task_struct *prev) { }
11113334 70static inline void vtime_account_system(struct task_struct *tsk) { }
abf917cd 71static inline void vtime_account_user(struct task_struct *tsk) { }
6a61671b 72static inline void vtime_account_irq_enter(struct task_struct *tsk) { }
b0493406 73#endif /* !CONFIG_VIRT_CPU_ACCOUNTING */
abf917cd
FW
74
75#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
6a61671b 76extern void arch_vtime_task_switch(struct task_struct *tsk);
b0493406
FW
77extern void vtime_gen_account_irq_exit(struct task_struct *tsk);
78
79static inline void vtime_account_irq_exit(struct task_struct *tsk)
80{
81 if (vtime_accounting_enabled())
82 vtime_gen_account_irq_exit(tsk);
83}
84
6a61671b 85extern void vtime_user_enter(struct task_struct *tsk);
b0493406 86
abf917cd
FW
87static inline void vtime_user_exit(struct task_struct *tsk)
88{
89 vtime_account_user(tsk);
90}
6a61671b
FW
91extern void vtime_guest_enter(struct task_struct *tsk);
92extern void vtime_guest_exit(struct task_struct *tsk);
45eacc69 93extern void vtime_init_idle(struct task_struct *tsk, int cpu);
b0493406 94#else /* !CONFIG_VIRT_CPU_ACCOUNTING_GEN */
6a61671b
FW
95static inline void vtime_account_irq_exit(struct task_struct *tsk)
96{
97 /* On hard|softirq exit we always account to hard|softirq cputime */
98 vtime_account_system(tsk);
99}
abf917cd
FW
100static inline void vtime_user_enter(struct task_struct *tsk) { }
101static inline void vtime_user_exit(struct task_struct *tsk) { }
6a61671b
FW
102static inline void vtime_guest_enter(struct task_struct *tsk) { }
103static inline void vtime_guest_exit(struct task_struct *tsk) { }
45eacc69 104static inline void vtime_init_idle(struct task_struct *tsk, int cpu) { }
dcbf832e
FW
105#endif
106
3e1df4f5
FW
107#ifdef CONFIG_IRQ_TIME_ACCOUNTING
108extern void irqtime_account_irq(struct task_struct *tsk);
dcbf832e 109#else
3e1df4f5 110static inline void irqtime_account_irq(struct task_struct *tsk) { }
dcbf832e
FW
111#endif
112
6a61671b 113static inline void account_irq_enter_time(struct task_struct *tsk)
fa5058f3 114{
6a61671b 115 vtime_account_irq_enter(tsk);
3e1df4f5 116 irqtime_account_irq(tsk);
fa5058f3
FW
117}
118
6a61671b 119static inline void account_irq_exit_time(struct task_struct *tsk)
fa5058f3 120{
6a61671b 121 vtime_account_irq_exit(tsk);
3e1df4f5 122 irqtime_account_irq(tsk);
fa5058f3
FW
123}
124
dcbf832e 125#endif /* _LINUX_KERNEL_VTIME_H */