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