Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Frederic Weisbecker | dcbf832 | 2012-10-05 23:07:19 +0200 | [diff] [blame] | 2 | #ifndef _LINUX_KERNEL_VTIME_H |
| 3 | #define _LINUX_KERNEL_VTIME_H |
| 4 | |
Frederic Weisbecker | b049340 | 2013-07-12 03:10:15 +0200 | [diff] [blame] | 5 | #include <linux/context_tracking_state.h> |
Frederic Weisbecker | a5725ac | 2013-07-16 18:50:52 +0200 | [diff] [blame] | 6 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE |
| 7 | #include <asm/vtime.h> |
| 8 | #endif |
| 9 | |
Frederic Weisbecker | b049340 | 2013-07-12 03:10:15 +0200 | [diff] [blame] | 10 | |
Frederic Weisbecker | dcbf832 | 2012-10-05 23:07:19 +0200 | [diff] [blame] | 11 | struct task_struct; |
| 12 | |
Frederic Weisbecker | b049340 | 2013-07-12 03:10:15 +0200 | [diff] [blame] | 13 | /* |
Frederic Weisbecker | 55dbdcf | 2015-11-19 16:47:32 +0100 | [diff] [blame] | 14 | * vtime_accounting_cpu_enabled() definitions/declarations |
Frederic Weisbecker | b049340 | 2013-07-12 03:10:15 +0200 | [diff] [blame] | 15 | */ |
Frederic Weisbecker | 8612f17 | 2016-07-13 16:50:04 +0200 | [diff] [blame] | 16 | #if defined(CONFIG_VIRT_CPU_ACCOUNTING_NATIVE) |
Frederic Weisbecker | 55dbdcf | 2015-11-19 16:47:32 +0100 | [diff] [blame] | 17 | static inline bool vtime_accounting_cpu_enabled(void) { return true; } |
Frederic Weisbecker | 8612f17 | 2016-07-13 16:50:04 +0200 | [diff] [blame] | 18 | #elif defined(CONFIG_VIRT_CPU_ACCOUNTING_GEN) |
Frederic Weisbecker | e592539 | 2015-11-19 16:47:33 +0100 | [diff] [blame] | 19 | /* |
| 20 | * Checks if vtime is enabled on some CPU. Cputime readers want to be careful |
| 21 | * in that case and compute the tickless cputime. |
| 22 | * For now vtime state is tied to context tracking. We might want to decouple |
| 23 | * those later if necessary. |
| 24 | */ |
| 25 | static inline bool vtime_accounting_enabled(void) |
| 26 | { |
| 27 | return context_tracking_is_enabled(); |
| 28 | } |
| 29 | |
Frederic Weisbecker | 55dbdcf | 2015-11-19 16:47:32 +0100 | [diff] [blame] | 30 | static inline bool vtime_accounting_cpu_enabled(void) |
Frederic Weisbecker | b049340 | 2013-07-12 03:10:15 +0200 | [diff] [blame] | 31 | { |
Frederic Weisbecker | e592539 | 2015-11-19 16:47:33 +0100 | [diff] [blame] | 32 | if (vtime_accounting_enabled()) { |
Frederic Weisbecker | d0df09e | 2013-11-06 15:11:57 +0100 | [diff] [blame] | 33 | if (context_tracking_cpu_is_enabled()) |
Frederic Weisbecker | b049340 | 2013-07-12 03:10:15 +0200 | [diff] [blame] | 34 | return true; |
| 35 | } |
| 36 | |
| 37 | return false; |
| 38 | } |
Frederic Weisbecker | 8612f17 | 2016-07-13 16:50:04 +0200 | [diff] [blame] | 39 | #else /* !CONFIG_VIRT_CPU_ACCOUNTING */ |
Frederic Weisbecker | 55dbdcf | 2015-11-19 16:47:32 +0100 | [diff] [blame] | 40 | static inline bool vtime_accounting_cpu_enabled(void) { return false; } |
Frederic Weisbecker | 8612f17 | 2016-07-13 16:50:04 +0200 | [diff] [blame] | 41 | #endif |
Frederic Weisbecker | b049340 | 2013-07-12 03:10:15 +0200 | [diff] [blame] | 42 | |
| 43 | |
| 44 | /* |
| 45 | * Common vtime APIs |
| 46 | */ |
Frederic Weisbecker | dcbf832 | 2012-10-05 23:07:19 +0200 | [diff] [blame] | 47 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING |
Frederic Weisbecker | b049340 | 2013-07-12 03:10:15 +0200 | [diff] [blame] | 48 | |
| 49 | #ifdef __ARCH_HAS_VTIME_TASK_SWITCH |
Frederic Weisbecker | dcbf832 | 2012-10-05 23:07:19 +0200 | [diff] [blame] | 50 | extern void vtime_task_switch(struct task_struct *prev); |
Frederic Weisbecker | b049340 | 2013-07-12 03:10:15 +0200 | [diff] [blame] | 51 | #else |
| 52 | extern void vtime_common_task_switch(struct task_struct *prev); |
| 53 | static inline void vtime_task_switch(struct task_struct *prev) |
| 54 | { |
Frederic Weisbecker | 55dbdcf | 2015-11-19 16:47:32 +0100 | [diff] [blame] | 55 | if (vtime_accounting_cpu_enabled()) |
Frederic Weisbecker | b049340 | 2013-07-12 03:10:15 +0200 | [diff] [blame] | 56 | vtime_common_task_switch(prev); |
| 57 | } |
| 58 | #endif /* __ARCH_HAS_VTIME_TASK_SWITCH */ |
| 59 | |
Frederic Weisbecker | dcbf832 | 2012-10-05 23:07:19 +0200 | [diff] [blame] | 60 | extern void vtime_account_system(struct task_struct *tsk); |
Frederic Weisbecker | fd25b4c | 2012-11-13 18:21:22 +0100 | [diff] [blame] | 61 | extern void vtime_account_idle(struct task_struct *tsk); |
Frederic Weisbecker | 3f4724e | 2012-07-16 18:00:34 +0200 | [diff] [blame] | 62 | |
Frederic Weisbecker | 3f4724e | 2012-07-16 18:00:34 +0200 | [diff] [blame] | 63 | #else /* !CONFIG_VIRT_CPU_ACCOUNTING */ |
Frederic Weisbecker | 6a61671 | 2012-12-16 20:00:34 +0100 | [diff] [blame] | 64 | |
Frederic Weisbecker | dcbf832 | 2012-10-05 23:07:19 +0200 | [diff] [blame] | 65 | static inline void vtime_task_switch(struct task_struct *prev) { } |
Frederic Weisbecker | 1111333 | 2012-10-24 18:05:51 +0200 | [diff] [blame] | 66 | static inline void vtime_account_system(struct task_struct *tsk) { } |
Frederic Weisbecker | b049340 | 2013-07-12 03:10:15 +0200 | [diff] [blame] | 67 | #endif /* !CONFIG_VIRT_CPU_ACCOUNTING */ |
Frederic Weisbecker | dcbf832 | 2012-10-05 23:07:19 +0200 | [diff] [blame] | 68 | |
Frederic Weisbecker | abf917c | 2012-07-25 07:56:04 +0200 | [diff] [blame] | 69 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN |
Frederic Weisbecker | 6a61671 | 2012-12-16 20:00:34 +0100 | [diff] [blame] | 70 | extern void arch_vtime_task_switch(struct task_struct *tsk); |
Frederic Weisbecker | 6a61671 | 2012-12-16 20:00:34 +0100 | [diff] [blame] | 71 | extern void vtime_user_enter(struct task_struct *tsk); |
Frederic Weisbecker | 1c3eda0 | 2017-06-29 19:15:07 +0200 | [diff] [blame] | 72 | extern void vtime_user_exit(struct task_struct *tsk); |
Frederic Weisbecker | 6a61671 | 2012-12-16 20:00:34 +0100 | [diff] [blame] | 73 | extern void vtime_guest_enter(struct task_struct *tsk); |
| 74 | extern void vtime_guest_exit(struct task_struct *tsk); |
Frederic Weisbecker | 45eacc6 | 2013-05-15 22:16:32 +0200 | [diff] [blame] | 75 | extern void vtime_init_idle(struct task_struct *tsk, int cpu); |
Frederic Weisbecker | b049340 | 2013-07-12 03:10:15 +0200 | [diff] [blame] | 76 | #else /* !CONFIG_VIRT_CPU_ACCOUNTING_GEN */ |
Frederic Weisbecker | abf917c | 2012-07-25 07:56:04 +0200 | [diff] [blame] | 77 | static inline void vtime_user_enter(struct task_struct *tsk) { } |
| 78 | static inline void vtime_user_exit(struct task_struct *tsk) { } |
Frederic Weisbecker | 6a61671 | 2012-12-16 20:00:34 +0100 | [diff] [blame] | 79 | static inline void vtime_guest_enter(struct task_struct *tsk) { } |
| 80 | static inline void vtime_guest_exit(struct task_struct *tsk) { } |
Frederic Weisbecker | 45eacc6 | 2013-05-15 22:16:32 +0200 | [diff] [blame] | 81 | static inline void vtime_init_idle(struct task_struct *tsk, int cpu) { } |
Frederic Weisbecker | abf917c | 2012-07-25 07:56:04 +0200 | [diff] [blame] | 82 | #endif |
| 83 | |
Frederic Weisbecker | 8612f17 | 2016-07-13 16:50:04 +0200 | [diff] [blame] | 84 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE |
| 85 | extern void vtime_account_irq_enter(struct task_struct *tsk); |
| 86 | static inline void vtime_account_irq_exit(struct task_struct *tsk) |
| 87 | { |
| 88 | /* On hard|softirq exit we always account to hard|softirq cputime */ |
| 89 | vtime_account_system(tsk); |
| 90 | } |
Frederic Weisbecker | c8d7dab | 2017-01-05 18:11:50 +0100 | [diff] [blame] | 91 | extern void vtime_flush(struct task_struct *tsk); |
Frederic Weisbecker | 8612f17 | 2016-07-13 16:50:04 +0200 | [diff] [blame] | 92 | #else /* !CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */ |
| 93 | static inline void vtime_account_irq_enter(struct task_struct *tsk) { } |
| 94 | static inline void vtime_account_irq_exit(struct task_struct *tsk) { } |
Frederic Weisbecker | c8d7dab | 2017-01-05 18:11:50 +0100 | [diff] [blame] | 95 | static inline void vtime_flush(struct task_struct *tsk) { } |
Frederic Weisbecker | 8612f17 | 2016-07-13 16:50:04 +0200 | [diff] [blame] | 96 | #endif |
| 97 | |
| 98 | |
Frederic Weisbecker | 3e1df4f5 | 2012-10-06 05:23:22 +0200 | [diff] [blame] | 99 | #ifdef CONFIG_IRQ_TIME_ACCOUNTING |
| 100 | extern void irqtime_account_irq(struct task_struct *tsk); |
Frederic Weisbecker | dcbf832 | 2012-10-05 23:07:19 +0200 | [diff] [blame] | 101 | #else |
Frederic Weisbecker | 3e1df4f5 | 2012-10-06 05:23:22 +0200 | [diff] [blame] | 102 | static inline void irqtime_account_irq(struct task_struct *tsk) { } |
Frederic Weisbecker | dcbf832 | 2012-10-05 23:07:19 +0200 | [diff] [blame] | 103 | #endif |
| 104 | |
Frederic Weisbecker | 6a61671 | 2012-12-16 20:00:34 +0100 | [diff] [blame] | 105 | static inline void account_irq_enter_time(struct task_struct *tsk) |
Frederic Weisbecker | fa5058f | 2012-10-06 04:07:19 +0200 | [diff] [blame] | 106 | { |
Frederic Weisbecker | 6a61671 | 2012-12-16 20:00:34 +0100 | [diff] [blame] | 107 | vtime_account_irq_enter(tsk); |
Frederic Weisbecker | 3e1df4f5 | 2012-10-06 05:23:22 +0200 | [diff] [blame] | 108 | irqtime_account_irq(tsk); |
Frederic Weisbecker | fa5058f | 2012-10-06 04:07:19 +0200 | [diff] [blame] | 109 | } |
| 110 | |
Frederic Weisbecker | 6a61671 | 2012-12-16 20:00:34 +0100 | [diff] [blame] | 111 | static inline void account_irq_exit_time(struct task_struct *tsk) |
Frederic Weisbecker | fa5058f | 2012-10-06 04:07:19 +0200 | [diff] [blame] | 112 | { |
Frederic Weisbecker | 6a61671 | 2012-12-16 20:00:34 +0100 | [diff] [blame] | 113 | vtime_account_irq_exit(tsk); |
Frederic Weisbecker | 3e1df4f5 | 2012-10-06 05:23:22 +0200 | [diff] [blame] | 114 | irqtime_account_irq(tsk); |
Frederic Weisbecker | fa5058f | 2012-10-06 04:07:19 +0200 | [diff] [blame] | 115 | } |
| 116 | |
Frederic Weisbecker | dcbf832 | 2012-10-05 23:07:19 +0200 | [diff] [blame] | 117 | #endif /* _LINUX_KERNEL_VTIME_H */ |