Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _LINUX_KERNEL_VTIME_H
3#define _LINUX_KERNEL_VTIME_H
4
5#include <linux/context_tracking_state.h>
6#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
7#include <asm/vtime.h>
8#endif
9
10
11struct task_struct;
12
13/*
14 * vtime_accounting_enabled_this_cpu() definitions/declarations
15 */
16#if defined(CONFIG_VIRT_CPU_ACCOUNTING_NATIVE)
17
18static inline bool vtime_accounting_enabled_this_cpu(void) { return true; }
19extern void vtime_task_switch(struct task_struct *prev);
20
21#elif defined(CONFIG_VIRT_CPU_ACCOUNTING_GEN)
22
23/*
24 * Checks if vtime is enabled on some CPU. Cputime readers want to be careful
25 * in that case and compute the tickless cputime.
26 * For now vtime state is tied to context tracking. We might want to decouple
27 * those later if necessary.
28 */
29static inline bool vtime_accounting_enabled(void)
30{
31 return context_tracking_enabled();
32}
33
34static inline bool vtime_accounting_enabled_cpu(int cpu)
35{
36 return context_tracking_enabled_cpu(cpu);
37}
38
39static inline bool vtime_accounting_enabled_this_cpu(void)
40{
41 return context_tracking_enabled_this_cpu();
42}
43
44extern void vtime_task_switch_generic(struct task_struct *prev);
45
46static inline void vtime_task_switch(struct task_struct *prev)
47{
48 if (vtime_accounting_enabled_this_cpu())
49 vtime_task_switch_generic(prev);
50}
51
52#else /* !CONFIG_VIRT_CPU_ACCOUNTING */
53
54static inline bool vtime_accounting_enabled_cpu(int cpu) {return false; }
55static inline bool vtime_accounting_enabled_this_cpu(void) { return false; }
56static inline void vtime_task_switch(struct task_struct *prev) { }
57
58#endif
59
60/*
61 * Common vtime APIs
62 */
63#ifdef CONFIG_VIRT_CPU_ACCOUNTING
64extern void vtime_account_kernel(struct task_struct *tsk);
65extern void vtime_account_idle(struct task_struct *tsk);
66#else /* !CONFIG_VIRT_CPU_ACCOUNTING */
67static inline void vtime_account_kernel(struct task_struct *tsk) { }
68#endif /* !CONFIG_VIRT_CPU_ACCOUNTING */
69
70#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
71extern void arch_vtime_task_switch(struct task_struct *tsk);
72extern void vtime_user_enter(struct task_struct *tsk);
73extern void vtime_user_exit(struct task_struct *tsk);
74extern void vtime_guest_enter(struct task_struct *tsk);
75extern void vtime_guest_exit(struct task_struct *tsk);
76extern void vtime_init_idle(struct task_struct *tsk, int cpu);
77#else /* !CONFIG_VIRT_CPU_ACCOUNTING_GEN */
78static inline void vtime_user_enter(struct task_struct *tsk) { }
79static inline void vtime_user_exit(struct task_struct *tsk) { }
80static inline void vtime_guest_enter(struct task_struct *tsk) { }
81static inline void vtime_guest_exit(struct task_struct *tsk) { }
82static inline void vtime_init_idle(struct task_struct *tsk, int cpu) { }
83#endif
84
85#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
86extern void vtime_account_irq(struct task_struct *tsk, unsigned int offset);
87extern void vtime_account_softirq(struct task_struct *tsk);
88extern void vtime_account_hardirq(struct task_struct *tsk);
89extern void vtime_flush(struct task_struct *tsk);
90#else /* !CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
91static inline void vtime_account_irq(struct task_struct *tsk, unsigned int offset) { }
92static inline void vtime_account_softirq(struct task_struct *tsk) { }
93static inline void vtime_account_hardirq(struct task_struct *tsk) { }
94static inline void vtime_flush(struct task_struct *tsk) { }
95#endif
96
97
98#ifdef CONFIG_IRQ_TIME_ACCOUNTING
99extern void irqtime_account_irq(struct task_struct *tsk, unsigned int offset);
100#else
101static inline void irqtime_account_irq(struct task_struct *tsk, unsigned int offset) { }
102#endif
103
104static inline void account_softirq_enter(struct task_struct *tsk)
105{
106 vtime_account_irq(tsk, SOFTIRQ_OFFSET);
107 irqtime_account_irq(tsk, SOFTIRQ_OFFSET);
108}
109
110static inline void account_softirq_exit(struct task_struct *tsk)
111{
112 vtime_account_softirq(tsk);
113 irqtime_account_irq(tsk, 0);
114}
115
116static inline void account_hardirq_enter(struct task_struct *tsk)
117{
118 vtime_account_irq(tsk, HARDIRQ_OFFSET);
119 irqtime_account_irq(tsk, HARDIRQ_OFFSET);
120}
121
122static inline void account_hardirq_exit(struct task_struct *tsk)
123{
124 vtime_account_hardirq(tsk);
125 irqtime_account_irq(tsk, 0);
126}
127
128#endif /* _LINUX_KERNEL_VTIME_H */