Frederic Weisbecker | dcbf832 | 2012-10-05 23:07:19 +0200 | [diff] [blame] | 1 | #ifndef _LINUX_KERNEL_VTIME_H |
| 2 | #define _LINUX_KERNEL_VTIME_H |
| 3 | |
Frederic Weisbecker | b049340 | 2013-07-12 03:10:15 +0200 | [diff] [blame] | 4 | #include <linux/context_tracking_state.h> |
Frederic Weisbecker | a5725ac | 2013-07-16 18:50:52 +0200 | [diff] [blame] | 5 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE |
| 6 | #include <asm/vtime.h> |
| 7 | #endif |
| 8 | |
Frederic Weisbecker | b049340 | 2013-07-12 03:10:15 +0200 | [diff] [blame] | 9 | |
Frederic Weisbecker | dcbf832 | 2012-10-05 23:07:19 +0200 | [diff] [blame] | 10 | struct task_struct; |
| 11 | |
Frederic Weisbecker | b049340 | 2013-07-12 03:10:15 +0200 | [diff] [blame] | 12 | /* |
| 13 | * vtime_accounting_enabled() definitions/declarations |
| 14 | */ |
| 15 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE |
| 16 | static inline bool vtime_accounting_enabled(void) { return true; } |
| 17 | #endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */ |
| 18 | |
| 19 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN |
| 20 | static inline bool vtime_accounting_enabled(void) |
| 21 | { |
Frederic Weisbecker | 58135f5 | 2013-11-06 14:45:57 +0100 | [diff] [blame] | 22 | if (context_tracking_is_enabled()) { |
Frederic Weisbecker | d0df09e | 2013-11-06 15:11:57 +0100 | [diff] [blame] | 23 | if (context_tracking_cpu_is_enabled()) |
Frederic Weisbecker | b049340 | 2013-07-12 03:10:15 +0200 | [diff] [blame] | 24 | return true; |
| 25 | } |
| 26 | |
| 27 | return false; |
| 28 | } |
| 29 | #endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */ |
| 30 | |
| 31 | #ifndef CONFIG_VIRT_CPU_ACCOUNTING |
| 32 | static inline bool vtime_accounting_enabled(void) { return false; } |
| 33 | #endif /* !CONFIG_VIRT_CPU_ACCOUNTING */ |
| 34 | |
| 35 | |
| 36 | /* |
| 37 | * Common vtime APIs |
| 38 | */ |
Frederic Weisbecker | dcbf832 | 2012-10-05 23:07:19 +0200 | [diff] [blame] | 39 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING |
Frederic Weisbecker | b049340 | 2013-07-12 03:10:15 +0200 | [diff] [blame] | 40 | |
| 41 | #ifdef __ARCH_HAS_VTIME_TASK_SWITCH |
Frederic Weisbecker | dcbf832 | 2012-10-05 23:07:19 +0200 | [diff] [blame] | 42 | extern void vtime_task_switch(struct task_struct *prev); |
Frederic Weisbecker | b049340 | 2013-07-12 03:10:15 +0200 | [diff] [blame] | 43 | #else |
| 44 | extern void vtime_common_task_switch(struct task_struct *prev); |
| 45 | static 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 | |
Frederic Weisbecker | dcbf832 | 2012-10-05 23:07:19 +0200 | [diff] [blame] | 52 | extern void vtime_account_system(struct task_struct *tsk); |
Frederic Weisbecker | fd25b4c | 2012-11-13 18:21:22 +0100 | [diff] [blame] | 53 | extern void vtime_account_idle(struct task_struct *tsk); |
Frederic Weisbecker | bcebdf8 | 2012-11-13 23:51:06 +0100 | [diff] [blame] | 54 | extern void vtime_account_user(struct task_struct *tsk); |
Frederic Weisbecker | 3f4724e | 2012-07-16 18:00:34 +0200 | [diff] [blame] | 55 | |
Frederic Weisbecker | b049340 | 2013-07-12 03:10:15 +0200 | [diff] [blame] | 56 | #ifdef __ARCH_HAS_VTIME_ACCOUNT |
| 57 | extern void vtime_account_irq_enter(struct task_struct *tsk); |
| 58 | #else |
| 59 | extern void vtime_common_account_irq_enter(struct task_struct *tsk); |
| 60 | static 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 */ |
Frederic Weisbecker | 3f4724e | 2012-07-16 18:00:34 +0200 | [diff] [blame] | 66 | |
| 67 | #else /* !CONFIG_VIRT_CPU_ACCOUNTING */ |
Frederic Weisbecker | 6a61671 | 2012-12-16 20:00:34 +0100 | [diff] [blame] | 68 | |
Frederic Weisbecker | dcbf832 | 2012-10-05 23:07:19 +0200 | [diff] [blame] | 69 | static inline void vtime_task_switch(struct task_struct *prev) { } |
Frederic Weisbecker | 1111333 | 2012-10-24 18:05:51 +0200 | [diff] [blame] | 70 | static inline void vtime_account_system(struct task_struct *tsk) { } |
Frederic Weisbecker | abf917c | 2012-07-25 07:56:04 +0200 | [diff] [blame] | 71 | static inline void vtime_account_user(struct task_struct *tsk) { } |
Frederic Weisbecker | 6a61671 | 2012-12-16 20:00:34 +0100 | [diff] [blame] | 72 | static inline void vtime_account_irq_enter(struct task_struct *tsk) { } |
Frederic Weisbecker | b049340 | 2013-07-12 03:10:15 +0200 | [diff] [blame] | 73 | #endif /* !CONFIG_VIRT_CPU_ACCOUNTING */ |
Frederic Weisbecker | dcbf832 | 2012-10-05 23:07:19 +0200 | [diff] [blame] | 74 | |
Frederic Weisbecker | abf917c | 2012-07-25 07:56:04 +0200 | [diff] [blame] | 75 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN |
Frederic Weisbecker | 6a61671 | 2012-12-16 20:00:34 +0100 | [diff] [blame] | 76 | extern void arch_vtime_task_switch(struct task_struct *tsk); |
Frederic Weisbecker | b049340 | 2013-07-12 03:10:15 +0200 | [diff] [blame] | 77 | extern void vtime_gen_account_irq_exit(struct task_struct *tsk); |
| 78 | |
| 79 | static 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 | |
Frederic Weisbecker | 6a61671 | 2012-12-16 20:00:34 +0100 | [diff] [blame] | 85 | extern void vtime_user_enter(struct task_struct *tsk); |
Frederic Weisbecker | b049340 | 2013-07-12 03:10:15 +0200 | [diff] [blame] | 86 | |
Frederic Weisbecker | abf917c | 2012-07-25 07:56:04 +0200 | [diff] [blame] | 87 | static inline void vtime_user_exit(struct task_struct *tsk) |
| 88 | { |
| 89 | vtime_account_user(tsk); |
| 90 | } |
Frederic Weisbecker | 6a61671 | 2012-12-16 20:00:34 +0100 | [diff] [blame] | 91 | extern void vtime_guest_enter(struct task_struct *tsk); |
| 92 | extern void vtime_guest_exit(struct task_struct *tsk); |
Frederic Weisbecker | 45eacc6 | 2013-05-15 22:16:32 +0200 | [diff] [blame] | 93 | extern void vtime_init_idle(struct task_struct *tsk, int cpu); |
Frederic Weisbecker | b049340 | 2013-07-12 03:10:15 +0200 | [diff] [blame] | 94 | #else /* !CONFIG_VIRT_CPU_ACCOUNTING_GEN */ |
Frederic Weisbecker | 6a61671 | 2012-12-16 20:00:34 +0100 | [diff] [blame] | 95 | static 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 | } |
Frederic Weisbecker | abf917c | 2012-07-25 07:56:04 +0200 | [diff] [blame] | 100 | static inline void vtime_user_enter(struct task_struct *tsk) { } |
| 101 | static inline void vtime_user_exit(struct task_struct *tsk) { } |
Frederic Weisbecker | 6a61671 | 2012-12-16 20:00:34 +0100 | [diff] [blame] | 102 | static inline void vtime_guest_enter(struct task_struct *tsk) { } |
| 103 | static inline void vtime_guest_exit(struct task_struct *tsk) { } |
Frederic Weisbecker | 45eacc6 | 2013-05-15 22:16:32 +0200 | [diff] [blame] | 104 | static inline void vtime_init_idle(struct task_struct *tsk, int cpu) { } |
Frederic Weisbecker | abf917c | 2012-07-25 07:56:04 +0200 | [diff] [blame] | 105 | #endif |
| 106 | |
Frederic Weisbecker | 3e1df4f5 | 2012-10-06 05:23:22 +0200 | [diff] [blame] | 107 | #ifdef CONFIG_IRQ_TIME_ACCOUNTING |
| 108 | extern void irqtime_account_irq(struct task_struct *tsk); |
Frederic Weisbecker | dcbf832 | 2012-10-05 23:07:19 +0200 | [diff] [blame] | 109 | #else |
Frederic Weisbecker | 3e1df4f5 | 2012-10-06 05:23:22 +0200 | [diff] [blame] | 110 | static inline void irqtime_account_irq(struct task_struct *tsk) { } |
Frederic Weisbecker | dcbf832 | 2012-10-05 23:07:19 +0200 | [diff] [blame] | 111 | #endif |
| 112 | |
Frederic Weisbecker | 6a61671 | 2012-12-16 20:00:34 +0100 | [diff] [blame] | 113 | static inline void account_irq_enter_time(struct task_struct *tsk) |
Frederic Weisbecker | fa5058f | 2012-10-06 04:07:19 +0200 | [diff] [blame] | 114 | { |
Frederic Weisbecker | 6a61671 | 2012-12-16 20:00:34 +0100 | [diff] [blame] | 115 | vtime_account_irq_enter(tsk); |
Frederic Weisbecker | 3e1df4f5 | 2012-10-06 05:23:22 +0200 | [diff] [blame] | 116 | irqtime_account_irq(tsk); |
Frederic Weisbecker | fa5058f | 2012-10-06 04:07:19 +0200 | [diff] [blame] | 117 | } |
| 118 | |
Frederic Weisbecker | 6a61671 | 2012-12-16 20:00:34 +0100 | [diff] [blame] | 119 | static inline void account_irq_exit_time(struct task_struct *tsk) |
Frederic Weisbecker | fa5058f | 2012-10-06 04:07:19 +0200 | [diff] [blame] | 120 | { |
Frederic Weisbecker | 6a61671 | 2012-12-16 20:00:34 +0100 | [diff] [blame] | 121 | vtime_account_irq_exit(tsk); |
Frederic Weisbecker | 3e1df4f5 | 2012-10-06 05:23:22 +0200 | [diff] [blame] | 122 | irqtime_account_irq(tsk); |
Frederic Weisbecker | fa5058f | 2012-10-06 04:07:19 +0200 | [diff] [blame] | 123 | } |
| 124 | |
Frederic Weisbecker | dcbf832 | 2012-10-05 23:07:19 +0200 | [diff] [blame] | 125 | #endif /* _LINUX_KERNEL_VTIME_H */ |