blob: 0681fe25abeb423124f5561421aef56864cc8d69 [file] [log] [blame]
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +02001#ifndef _LINUX_KERNEL_VTIME_H
2#define _LINUX_KERNEL_VTIME_H
3
Frederic Weisbeckerb0493402013-07-12 03:10:15 +02004#include <linux/context_tracking_state.h>
Frederic Weisbeckera5725ac2013-07-16 18:50:52 +02005#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
6#include <asm/vtime.h>
7#endif
8
Frederic Weisbeckerb0493402013-07-12 03:10:15 +02009
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +020010struct task_struct;
11
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020012/*
Frederic Weisbecker55dbdcf2015-11-19 16:47:32 +010013 * vtime_accounting_cpu_enabled() definitions/declarations
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020014 */
Frederic Weisbecker8612f172016-07-13 16:50:04 +020015#if defined(CONFIG_VIRT_CPU_ACCOUNTING_NATIVE)
Frederic Weisbecker55dbdcf2015-11-19 16:47:32 +010016static inline bool vtime_accounting_cpu_enabled(void) { return true; }
Frederic Weisbecker8612f172016-07-13 16:50:04 +020017#elif defined(CONFIG_VIRT_CPU_ACCOUNTING_GEN)
Frederic Weisbeckere5925392015-11-19 16:47:33 +010018/*
19 * Checks if vtime is enabled on some CPU. Cputime readers want to be careful
20 * in that case and compute the tickless cputime.
21 * For now vtime state is tied to context tracking. We might want to decouple
22 * those later if necessary.
23 */
24static inline bool vtime_accounting_enabled(void)
25{
26 return context_tracking_is_enabled();
27}
28
Frederic Weisbecker55dbdcf2015-11-19 16:47:32 +010029static inline bool vtime_accounting_cpu_enabled(void)
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020030{
Frederic Weisbeckere5925392015-11-19 16:47:33 +010031 if (vtime_accounting_enabled()) {
Frederic Weisbeckerd0df09e2013-11-06 15:11:57 +010032 if (context_tracking_cpu_is_enabled())
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020033 return true;
34 }
35
36 return false;
37}
Frederic Weisbecker8612f172016-07-13 16:50:04 +020038#else /* !CONFIG_VIRT_CPU_ACCOUNTING */
Frederic Weisbecker55dbdcf2015-11-19 16:47:32 +010039static inline bool vtime_accounting_cpu_enabled(void) { return false; }
Frederic Weisbecker8612f172016-07-13 16:50:04 +020040#endif
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020041
42
43/*
44 * Common vtime APIs
45 */
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +020046#ifdef CONFIG_VIRT_CPU_ACCOUNTING
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020047
48#ifdef __ARCH_HAS_VTIME_TASK_SWITCH
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +020049extern void vtime_task_switch(struct task_struct *prev);
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020050#else
51extern void vtime_common_task_switch(struct task_struct *prev);
52static inline void vtime_task_switch(struct task_struct *prev)
53{
Frederic Weisbecker55dbdcf2015-11-19 16:47:32 +010054 if (vtime_accounting_cpu_enabled())
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020055 vtime_common_task_switch(prev);
56}
57#endif /* __ARCH_HAS_VTIME_TASK_SWITCH */
58
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +020059extern void vtime_account_system(struct task_struct *tsk);
Frederic Weisbeckerfd25b4c2012-11-13 18:21:22 +010060extern void vtime_account_idle(struct task_struct *tsk);
Frederic Weisbecker3f4724e2012-07-16 18:00:34 +020061
Frederic Weisbecker3f4724e2012-07-16 18:00:34 +020062#else /* !CONFIG_VIRT_CPU_ACCOUNTING */
Frederic Weisbecker6a616712012-12-16 20:00:34 +010063
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +020064static inline void vtime_task_switch(struct task_struct *prev) { }
Frederic Weisbecker11113332012-10-24 18:05:51 +020065static inline void vtime_account_system(struct task_struct *tsk) { }
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020066#endif /* !CONFIG_VIRT_CPU_ACCOUNTING */
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +020067
Frederic Weisbeckerabf917c2012-07-25 07:56:04 +020068#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
Frederic Weisbecker6a616712012-12-16 20:00:34 +010069extern void arch_vtime_task_switch(struct task_struct *tsk);
Frederic Weisbeckerc8d7dab2017-01-05 18:11:50 +010070extern void vtime_account_user(struct task_struct *tsk);
Frederic Weisbecker6a616712012-12-16 20:00:34 +010071extern void vtime_user_enter(struct task_struct *tsk);
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020072
Frederic Weisbeckerabf917c2012-07-25 07:56:04 +020073static inline void vtime_user_exit(struct task_struct *tsk)
74{
75 vtime_account_user(tsk);
76}
Frederic Weisbeckerc8d7dab2017-01-05 18:11:50 +010077
Frederic Weisbecker6a616712012-12-16 20:00:34 +010078extern void vtime_guest_enter(struct task_struct *tsk);
79extern void vtime_guest_exit(struct task_struct *tsk);
Frederic Weisbecker45eacc62013-05-15 22:16:32 +020080extern void vtime_init_idle(struct task_struct *tsk, int cpu);
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020081#else /* !CONFIG_VIRT_CPU_ACCOUNTING_GEN */
Frederic Weisbeckerc8d7dab2017-01-05 18:11:50 +010082static inline void vtime_account_user(struct task_struct *tsk) { }
Frederic Weisbeckerabf917c2012-07-25 07:56:04 +020083static inline void vtime_user_enter(struct task_struct *tsk) { }
84static inline void vtime_user_exit(struct task_struct *tsk) { }
Frederic Weisbecker6a616712012-12-16 20:00:34 +010085static inline void vtime_guest_enter(struct task_struct *tsk) { }
86static inline void vtime_guest_exit(struct task_struct *tsk) { }
Frederic Weisbecker45eacc62013-05-15 22:16:32 +020087static inline void vtime_init_idle(struct task_struct *tsk, int cpu) { }
Frederic Weisbeckerabf917c2012-07-25 07:56:04 +020088#endif
89
Frederic Weisbecker8612f172016-07-13 16:50:04 +020090#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
91extern void vtime_account_irq_enter(struct task_struct *tsk);
92static inline void vtime_account_irq_exit(struct task_struct *tsk)
93{
94 /* On hard|softirq exit we always account to hard|softirq cputime */
95 vtime_account_system(tsk);
96}
Frederic Weisbeckerc8d7dab2017-01-05 18:11:50 +010097extern void vtime_flush(struct task_struct *tsk);
Frederic Weisbecker8612f172016-07-13 16:50:04 +020098#else /* !CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
99static inline void vtime_account_irq_enter(struct task_struct *tsk) { }
100static inline void vtime_account_irq_exit(struct task_struct *tsk) { }
Frederic Weisbeckerc8d7dab2017-01-05 18:11:50 +0100101static inline void vtime_flush(struct task_struct *tsk) { }
Frederic Weisbecker8612f172016-07-13 16:50:04 +0200102#endif
103
104
Frederic Weisbecker3e1df4f52012-10-06 05:23:22 +0200105#ifdef CONFIG_IRQ_TIME_ACCOUNTING
106extern void irqtime_account_irq(struct task_struct *tsk);
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +0200107#else
Frederic Weisbecker3e1df4f52012-10-06 05:23:22 +0200108static inline void irqtime_account_irq(struct task_struct *tsk) { }
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +0200109#endif
110
Frederic Weisbecker6a616712012-12-16 20:00:34 +0100111static inline void account_irq_enter_time(struct task_struct *tsk)
Frederic Weisbeckerfa5058f2012-10-06 04:07:19 +0200112{
Frederic Weisbecker6a616712012-12-16 20:00:34 +0100113 vtime_account_irq_enter(tsk);
Frederic Weisbecker3e1df4f52012-10-06 05:23:22 +0200114 irqtime_account_irq(tsk);
Frederic Weisbeckerfa5058f2012-10-06 04:07:19 +0200115}
116
Frederic Weisbecker6a616712012-12-16 20:00:34 +0100117static inline void account_irq_exit_time(struct task_struct *tsk)
Frederic Weisbeckerfa5058f2012-10-06 04:07:19 +0200118{
Frederic Weisbecker6a616712012-12-16 20:00:34 +0100119 vtime_account_irq_exit(tsk);
Frederic Weisbecker3e1df4f52012-10-06 05:23:22 +0200120 irqtime_account_irq(tsk);
Frederic Weisbeckerfa5058f2012-10-06 04:07:19 +0200121}
122
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +0200123#endif /* _LINUX_KERNEL_VTIME_H */