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 | e44fcb4 | 2019-10-16 04:56:54 +0200 | [diff] [blame] | 14 | * vtime_accounting_enabled_this_cpu() 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 | 8d49547 | 2019-10-03 18:17:45 +0200 | [diff] [blame] | 17 | |
Frederic Weisbecker | e44fcb4 | 2019-10-16 04:56:54 +0200 | [diff] [blame] | 18 | static inline bool vtime_accounting_enabled_this_cpu(void) { return true; } |
Frederic Weisbecker | 8d49547 | 2019-10-03 18:17:45 +0200 | [diff] [blame] | 19 | extern void vtime_task_switch(struct task_struct *prev); |
| 20 | |
Frederic Weisbecker | 8612f17 | 2016-07-13 16:50:04 +0200 | [diff] [blame] | 21 | #elif defined(CONFIG_VIRT_CPU_ACCOUNTING_GEN) |
Frederic Weisbecker | 8d49547 | 2019-10-03 18:17:45 +0200 | [diff] [blame] | 22 | |
Frederic Weisbecker | e592539 | 2015-11-19 16:47:33 +0100 | [diff] [blame] | 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 | */ |
| 29 | static inline bool vtime_accounting_enabled(void) |
| 30 | { |
Frederic Weisbecker | 74c5787 | 2019-10-16 04:56:51 +0200 | [diff] [blame] | 31 | return context_tracking_enabled(); |
Frederic Weisbecker | e592539 | 2015-11-19 16:47:33 +0100 | [diff] [blame] | 32 | } |
| 33 | |
Frederic Weisbecker | 9adbb9d | 2019-10-16 04:56:55 +0200 | [diff] [blame] | 34 | static inline bool vtime_accounting_enabled_cpu(int cpu) |
| 35 | { |
Frederic Weisbecker | 023e9de | 2019-10-16 04:56:56 +0200 | [diff] [blame] | 36 | return context_tracking_enabled_cpu(cpu); |
Frederic Weisbecker | 9adbb9d | 2019-10-16 04:56:55 +0200 | [diff] [blame] | 37 | } |
| 38 | |
Frederic Weisbecker | e44fcb4 | 2019-10-16 04:56:54 +0200 | [diff] [blame] | 39 | static inline bool vtime_accounting_enabled_this_cpu(void) |
Frederic Weisbecker | b049340 | 2013-07-12 03:10:15 +0200 | [diff] [blame] | 40 | { |
Frederic Weisbecker | 023e9de | 2019-10-16 04:56:56 +0200 | [diff] [blame] | 41 | return context_tracking_enabled_this_cpu(); |
Frederic Weisbecker | b049340 | 2013-07-12 03:10:15 +0200 | [diff] [blame] | 42 | } |
Frederic Weisbecker | b049340 | 2013-07-12 03:10:15 +0200 | [diff] [blame] | 43 | |
Frederic Weisbecker | 8d49547 | 2019-10-03 18:17:45 +0200 | [diff] [blame] | 44 | extern void vtime_task_switch_generic(struct task_struct *prev); |
| 45 | |
| 46 | static inline void vtime_task_switch(struct task_struct *prev) |
| 47 | { |
Frederic Weisbecker | e44fcb4 | 2019-10-16 04:56:54 +0200 | [diff] [blame] | 48 | if (vtime_accounting_enabled_this_cpu()) |
Frederic Weisbecker | 8d49547 | 2019-10-03 18:17:45 +0200 | [diff] [blame] | 49 | vtime_task_switch_generic(prev); |
| 50 | } |
| 51 | |
| 52 | #else /* !CONFIG_VIRT_CPU_ACCOUNTING */ |
| 53 | |
Frederic Weisbecker | 9adbb9d | 2019-10-16 04:56:55 +0200 | [diff] [blame] | 54 | static inline bool vtime_accounting_enabled_cpu(int cpu) {return false; } |
Frederic Weisbecker | e44fcb4 | 2019-10-16 04:56:54 +0200 | [diff] [blame] | 55 | static inline bool vtime_accounting_enabled_this_cpu(void) { return false; } |
Frederic Weisbecker | 8d49547 | 2019-10-03 18:17:45 +0200 | [diff] [blame] | 56 | static inline void vtime_task_switch(struct task_struct *prev) { } |
| 57 | |
| 58 | #endif |
Frederic Weisbecker | b049340 | 2013-07-12 03:10:15 +0200 | [diff] [blame] | 59 | |
| 60 | /* |
| 61 | * Common vtime APIs |
| 62 | */ |
Frederic Weisbecker | dcbf832 | 2012-10-05 23:07:19 +0200 | [diff] [blame] | 63 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING |
Frederic Weisbecker | f83eeb1 | 2019-10-03 18:17:44 +0200 | [diff] [blame] | 64 | extern void vtime_account_kernel(struct task_struct *tsk); |
Frederic Weisbecker | fd25b4c | 2012-11-13 18:21:22 +0100 | [diff] [blame] | 65 | extern void vtime_account_idle(struct task_struct *tsk); |
Frederic Weisbecker | 3f4724e | 2012-07-16 18:00:34 +0200 | [diff] [blame] | 66 | #else /* !CONFIG_VIRT_CPU_ACCOUNTING */ |
Frederic Weisbecker | f83eeb1 | 2019-10-03 18:17:44 +0200 | [diff] [blame] | 67 | static inline void vtime_account_kernel(struct task_struct *tsk) { } |
Frederic Weisbecker | b049340 | 2013-07-12 03:10:15 +0200 | [diff] [blame] | 68 | #endif /* !CONFIG_VIRT_CPU_ACCOUNTING */ |
Frederic Weisbecker | dcbf832 | 2012-10-05 23:07:19 +0200 | [diff] [blame] | 69 | |
Frederic Weisbecker | abf917c | 2012-07-25 07:56:04 +0200 | [diff] [blame] | 70 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN |
Frederic Weisbecker | 6a61671 | 2012-12-16 20:00:34 +0100 | [diff] [blame] | 71 | extern void arch_vtime_task_switch(struct task_struct *tsk); |
Frederic Weisbecker | 6a61671 | 2012-12-16 20:00:34 +0100 | [diff] [blame] | 72 | extern void vtime_user_enter(struct task_struct *tsk); |
Frederic Weisbecker | 1c3eda0 | 2017-06-29 19:15:07 +0200 | [diff] [blame] | 73 | extern void vtime_user_exit(struct task_struct *tsk); |
Frederic Weisbecker | 6a61671 | 2012-12-16 20:00:34 +0100 | [diff] [blame] | 74 | extern void vtime_guest_enter(struct task_struct *tsk); |
| 75 | extern void vtime_guest_exit(struct task_struct *tsk); |
Frederic Weisbecker | 45eacc6 | 2013-05-15 22:16:32 +0200 | [diff] [blame] | 76 | extern void vtime_init_idle(struct task_struct *tsk, int cpu); |
Frederic Weisbecker | b049340 | 2013-07-12 03:10:15 +0200 | [diff] [blame] | 77 | #else /* !CONFIG_VIRT_CPU_ACCOUNTING_GEN */ |
Frederic Weisbecker | abf917c | 2012-07-25 07:56:04 +0200 | [diff] [blame] | 78 | static inline void vtime_user_enter(struct task_struct *tsk) { } |
| 79 | static inline void vtime_user_exit(struct task_struct *tsk) { } |
Frederic Weisbecker | 6a61671 | 2012-12-16 20:00:34 +0100 | [diff] [blame] | 80 | static inline void vtime_guest_enter(struct task_struct *tsk) { } |
| 81 | static inline void vtime_guest_exit(struct task_struct *tsk) { } |
Frederic Weisbecker | 45eacc6 | 2013-05-15 22:16:32 +0200 | [diff] [blame] | 82 | static inline void vtime_init_idle(struct task_struct *tsk, int cpu) { } |
Frederic Weisbecker | abf917c | 2012-07-25 07:56:04 +0200 | [diff] [blame] | 83 | #endif |
| 84 | |
Frederic Weisbecker | 8612f17 | 2016-07-13 16:50:04 +0200 | [diff] [blame] | 85 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE |
| 86 | extern void vtime_account_irq_enter(struct task_struct *tsk); |
| 87 | static inline void vtime_account_irq_exit(struct task_struct *tsk) |
| 88 | { |
| 89 | /* On hard|softirq exit we always account to hard|softirq cputime */ |
Frederic Weisbecker | f83eeb1 | 2019-10-03 18:17:44 +0200 | [diff] [blame] | 90 | vtime_account_kernel(tsk); |
Frederic Weisbecker | 8612f17 | 2016-07-13 16:50:04 +0200 | [diff] [blame] | 91 | } |
Frederic Weisbecker | c8d7dab | 2017-01-05 18:11:50 +0100 | [diff] [blame] | 92 | extern void vtime_flush(struct task_struct *tsk); |
Frederic Weisbecker | 8612f17 | 2016-07-13 16:50:04 +0200 | [diff] [blame] | 93 | #else /* !CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */ |
| 94 | static inline void vtime_account_irq_enter(struct task_struct *tsk) { } |
| 95 | static inline void vtime_account_irq_exit(struct task_struct *tsk) { } |
Frederic Weisbecker | c8d7dab | 2017-01-05 18:11:50 +0100 | [diff] [blame] | 96 | static inline void vtime_flush(struct task_struct *tsk) { } |
Frederic Weisbecker | 8612f17 | 2016-07-13 16:50:04 +0200 | [diff] [blame] | 97 | #endif |
| 98 | |
| 99 | |
Frederic Weisbecker | 3e1df4f5 | 2012-10-06 05:23:22 +0200 | [diff] [blame] | 100 | #ifdef CONFIG_IRQ_TIME_ACCOUNTING |
| 101 | extern void irqtime_account_irq(struct task_struct *tsk); |
Frederic Weisbecker | dcbf832 | 2012-10-05 23:07:19 +0200 | [diff] [blame] | 102 | #else |
Frederic Weisbecker | 3e1df4f5 | 2012-10-06 05:23:22 +0200 | [diff] [blame] | 103 | static inline void irqtime_account_irq(struct task_struct *tsk) { } |
Frederic Weisbecker | dcbf832 | 2012-10-05 23:07:19 +0200 | [diff] [blame] | 104 | #endif |
| 105 | |
Frederic Weisbecker | 6a61671 | 2012-12-16 20:00:34 +0100 | [diff] [blame] | 106 | static inline void account_irq_enter_time(struct task_struct *tsk) |
Frederic Weisbecker | fa5058f | 2012-10-06 04:07:19 +0200 | [diff] [blame] | 107 | { |
Frederic Weisbecker | 6a61671 | 2012-12-16 20:00:34 +0100 | [diff] [blame] | 108 | vtime_account_irq_enter(tsk); |
Frederic Weisbecker | 3e1df4f5 | 2012-10-06 05:23:22 +0200 | [diff] [blame] | 109 | irqtime_account_irq(tsk); |
Frederic Weisbecker | fa5058f | 2012-10-06 04:07:19 +0200 | [diff] [blame] | 110 | } |
| 111 | |
Frederic Weisbecker | 6a61671 | 2012-12-16 20:00:34 +0100 | [diff] [blame] | 112 | static inline void account_irq_exit_time(struct task_struct *tsk) |
Frederic Weisbecker | fa5058f | 2012-10-06 04:07:19 +0200 | [diff] [blame] | 113 | { |
Frederic Weisbecker | 6a61671 | 2012-12-16 20:00:34 +0100 | [diff] [blame] | 114 | vtime_account_irq_exit(tsk); |
Frederic Weisbecker | 3e1df4f5 | 2012-10-06 05:23:22 +0200 | [diff] [blame] | 115 | irqtime_account_irq(tsk); |
Frederic Weisbecker | fa5058f | 2012-10-06 04:07:19 +0200 | [diff] [blame] | 116 | } |
| 117 | |
Frederic Weisbecker | dcbf832 | 2012-10-05 23:07:19 +0200 | [diff] [blame] | 118 | #endif /* _LINUX_KERNEL_VTIME_H */ |