xref: /linux-6.15/include/linux/vtime.h (revision a5725ac2)
1 #ifndef _LINUX_KERNEL_VTIME_H
2 #define _LINUX_KERNEL_VTIME_H
3 
4 #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
5 #include <asm/vtime.h>
6 #endif
7 
8 struct task_struct;
9 
10 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
11 extern void vtime_task_switch(struct task_struct *prev);
12 extern void vtime_account_system(struct task_struct *tsk);
13 extern void vtime_account_idle(struct task_struct *tsk);
14 extern void vtime_account_user(struct task_struct *tsk);
15 extern void vtime_account_irq_enter(struct task_struct *tsk);
16 
17 #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
18 static inline bool vtime_accounting_enabled(void) { return true; }
19 #endif
20 
21 #else /* !CONFIG_VIRT_CPU_ACCOUNTING */
22 
23 static inline void vtime_task_switch(struct task_struct *prev) { }
24 static inline void vtime_account_system(struct task_struct *tsk) { }
25 static inline void vtime_account_user(struct task_struct *tsk) { }
26 static inline void vtime_account_irq_enter(struct task_struct *tsk) { }
27 static inline bool vtime_accounting_enabled(void) { return false; }
28 #endif
29 
30 #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
31 extern void arch_vtime_task_switch(struct task_struct *tsk);
32 extern void vtime_account_irq_exit(struct task_struct *tsk);
33 extern bool vtime_accounting_enabled(void);
34 extern void vtime_user_enter(struct task_struct *tsk);
35 static inline void vtime_user_exit(struct task_struct *tsk)
36 {
37 	vtime_account_user(tsk);
38 }
39 extern void vtime_guest_enter(struct task_struct *tsk);
40 extern void vtime_guest_exit(struct task_struct *tsk);
41 extern void vtime_init_idle(struct task_struct *tsk, int cpu);
42 #else
43 static inline void vtime_account_irq_exit(struct task_struct *tsk)
44 {
45 	/* On hard|softirq exit we always account to hard|softirq cputime */
46 	vtime_account_system(tsk);
47 }
48 static inline void vtime_user_enter(struct task_struct *tsk) { }
49 static inline void vtime_user_exit(struct task_struct *tsk) { }
50 static inline void vtime_guest_enter(struct task_struct *tsk) { }
51 static inline void vtime_guest_exit(struct task_struct *tsk) { }
52 static inline void vtime_init_idle(struct task_struct *tsk, int cpu) { }
53 #endif
54 
55 #ifdef CONFIG_IRQ_TIME_ACCOUNTING
56 extern void irqtime_account_irq(struct task_struct *tsk);
57 #else
58 static inline void irqtime_account_irq(struct task_struct *tsk) { }
59 #endif
60 
61 static inline void account_irq_enter_time(struct task_struct *tsk)
62 {
63 	vtime_account_irq_enter(tsk);
64 	irqtime_account_irq(tsk);
65 }
66 
67 static inline void account_irq_exit_time(struct task_struct *tsk)
68 {
69 	vtime_account_irq_exit(tsk);
70 	irqtime_account_irq(tsk);
71 }
72 
73 #endif /* _LINUX_KERNEL_VTIME_H */
74