blob: c5165fd256f9d25162d648e53e1e73d95a740caf [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/*
13 * vtime_accounting_enabled() definitions/declarations
14 */
15#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
16static inline bool vtime_accounting_enabled(void) { return true; }
17#endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
18
19#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
20static inline bool vtime_accounting_enabled(void)
21{
Frederic Weisbecker58135f52013-11-06 14:45:57 +010022 if (context_tracking_is_enabled()) {
Frederic Weisbeckerd0df09e2013-11-06 15:11:57 +010023 if (context_tracking_cpu_is_enabled())
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020024 return true;
25 }
26
27 return false;
28}
29#endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */
30
31#ifndef CONFIG_VIRT_CPU_ACCOUNTING
32static inline bool vtime_accounting_enabled(void) { return false; }
33#endif /* !CONFIG_VIRT_CPU_ACCOUNTING */
34
35
36/*
37 * Common vtime APIs
38 */
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +020039#ifdef CONFIG_VIRT_CPU_ACCOUNTING
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020040
41#ifdef __ARCH_HAS_VTIME_TASK_SWITCH
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +020042extern void vtime_task_switch(struct task_struct *prev);
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020043#else
44extern void vtime_common_task_switch(struct task_struct *prev);
45static 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 Weisbeckerdcbf8322012-10-05 23:07:19 +020052extern void vtime_account_system(struct task_struct *tsk);
Frederic Weisbeckerfd25b4c2012-11-13 18:21:22 +010053extern void vtime_account_idle(struct task_struct *tsk);
Frederic Weisbeckerbcebdf82012-11-13 23:51:06 +010054extern void vtime_account_user(struct task_struct *tsk);
Frederic Weisbecker3f4724e2012-07-16 18:00:34 +020055
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020056#ifdef __ARCH_HAS_VTIME_ACCOUNT
57extern void vtime_account_irq_enter(struct task_struct *tsk);
58#else
59extern void vtime_common_account_irq_enter(struct task_struct *tsk);
60static 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 Weisbecker3f4724e2012-07-16 18:00:34 +020066
67#else /* !CONFIG_VIRT_CPU_ACCOUNTING */
Frederic Weisbecker6a616712012-12-16 20:00:34 +010068
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +020069static inline void vtime_task_switch(struct task_struct *prev) { }
Frederic Weisbecker11113332012-10-24 18:05:51 +020070static inline void vtime_account_system(struct task_struct *tsk) { }
Frederic Weisbeckerabf917c2012-07-25 07:56:04 +020071static inline void vtime_account_user(struct task_struct *tsk) { }
Frederic Weisbecker6a616712012-12-16 20:00:34 +010072static inline void vtime_account_irq_enter(struct task_struct *tsk) { }
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020073#endif /* !CONFIG_VIRT_CPU_ACCOUNTING */
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +020074
Frederic Weisbeckerabf917c2012-07-25 07:56:04 +020075#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
Frederic Weisbecker6a616712012-12-16 20:00:34 +010076extern void arch_vtime_task_switch(struct task_struct *tsk);
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020077extern void vtime_gen_account_irq_exit(struct task_struct *tsk);
78
79static 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 Weisbecker6a616712012-12-16 20:00:34 +010085extern void vtime_user_enter(struct task_struct *tsk);
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020086
Frederic Weisbeckerabf917c2012-07-25 07:56:04 +020087static inline void vtime_user_exit(struct task_struct *tsk)
88{
89 vtime_account_user(tsk);
90}
Frederic Weisbecker6a616712012-12-16 20:00:34 +010091extern void vtime_guest_enter(struct task_struct *tsk);
92extern void vtime_guest_exit(struct task_struct *tsk);
Frederic Weisbecker45eacc62013-05-15 22:16:32 +020093extern void vtime_init_idle(struct task_struct *tsk, int cpu);
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020094#else /* !CONFIG_VIRT_CPU_ACCOUNTING_GEN */
Frederic Weisbecker6a616712012-12-16 20:00:34 +010095static 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 Weisbeckerabf917c2012-07-25 07:56:04 +0200100static inline void vtime_user_enter(struct task_struct *tsk) { }
101static inline void vtime_user_exit(struct task_struct *tsk) { }
Frederic Weisbecker6a616712012-12-16 20:00:34 +0100102static inline void vtime_guest_enter(struct task_struct *tsk) { }
103static inline void vtime_guest_exit(struct task_struct *tsk) { }
Frederic Weisbecker45eacc62013-05-15 22:16:32 +0200104static inline void vtime_init_idle(struct task_struct *tsk, int cpu) { }
Frederic Weisbeckerabf917c2012-07-25 07:56:04 +0200105#endif
106
Frederic Weisbecker3e1df4f52012-10-06 05:23:22 +0200107#ifdef CONFIG_IRQ_TIME_ACCOUNTING
108extern void irqtime_account_irq(struct task_struct *tsk);
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +0200109#else
Frederic Weisbecker3e1df4f52012-10-06 05:23:22 +0200110static inline void irqtime_account_irq(struct task_struct *tsk) { }
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +0200111#endif
112
Frederic Weisbecker6a616712012-12-16 20:00:34 +0100113static inline void account_irq_enter_time(struct task_struct *tsk)
Frederic Weisbeckerfa5058f2012-10-06 04:07:19 +0200114{
Frederic Weisbecker6a616712012-12-16 20:00:34 +0100115 vtime_account_irq_enter(tsk);
Frederic Weisbecker3e1df4f52012-10-06 05:23:22 +0200116 irqtime_account_irq(tsk);
Frederic Weisbeckerfa5058f2012-10-06 04:07:19 +0200117}
118
Frederic Weisbecker6a616712012-12-16 20:00:34 +0100119static inline void account_irq_exit_time(struct task_struct *tsk)
Frederic Weisbeckerfa5058f2012-10-06 04:07:19 +0200120{
Frederic Weisbecker6a616712012-12-16 20:00:34 +0100121 vtime_account_irq_exit(tsk);
Frederic Weisbecker3e1df4f52012-10-06 05:23:22 +0200122 irqtime_account_irq(tsk);
Frederic Weisbeckerfa5058f2012-10-06 04:07:19 +0200123}
124
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +0200125#endif /* _LINUX_KERNEL_VTIME_H */