blob: fa2196990f84b2db9d77883b0bb7d7f329d0cc8e [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 */
15#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
Frederic Weisbecker55dbdcf2015-11-19 16:47:32 +010016static inline bool vtime_accounting_cpu_enabled(void) { return true; }
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020017#endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
18
19#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
Frederic Weisbeckere5925392015-11-19 16:47:33 +010020/*
21 * Checks if vtime is enabled on some CPU. Cputime readers want to be careful
22 * in that case and compute the tickless cputime.
23 * For now vtime state is tied to context tracking. We might want to decouple
24 * those later if necessary.
25 */
26static inline bool vtime_accounting_enabled(void)
27{
28 return context_tracking_is_enabled();
29}
30
Frederic Weisbecker55dbdcf2015-11-19 16:47:32 +010031static inline bool vtime_accounting_cpu_enabled(void)
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020032{
Frederic Weisbeckere5925392015-11-19 16:47:33 +010033 if (vtime_accounting_enabled()) {
Frederic Weisbeckerd0df09e2013-11-06 15:11:57 +010034 if (context_tracking_cpu_is_enabled())
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020035 return true;
36 }
37
38 return false;
39}
40#endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */
41
42#ifndef CONFIG_VIRT_CPU_ACCOUNTING
Frederic Weisbecker55dbdcf2015-11-19 16:47:32 +010043static inline bool vtime_accounting_cpu_enabled(void) { return false; }
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020044#endif /* !CONFIG_VIRT_CPU_ACCOUNTING */
45
46
47/*
48 * Common vtime APIs
49 */
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +020050#ifdef CONFIG_VIRT_CPU_ACCOUNTING
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020051
52#ifdef __ARCH_HAS_VTIME_TASK_SWITCH
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +020053extern void vtime_task_switch(struct task_struct *prev);
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020054#else
55extern void vtime_common_task_switch(struct task_struct *prev);
56static inline void vtime_task_switch(struct task_struct *prev)
57{
Frederic Weisbecker55dbdcf2015-11-19 16:47:32 +010058 if (vtime_accounting_cpu_enabled())
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020059 vtime_common_task_switch(prev);
60}
61#endif /* __ARCH_HAS_VTIME_TASK_SWITCH */
62
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +020063extern void vtime_account_system(struct task_struct *tsk);
Frederic Weisbeckerfd25b4c2012-11-13 18:21:22 +010064extern void vtime_account_idle(struct task_struct *tsk);
Frederic Weisbeckerbcebdf82012-11-13 23:51:06 +010065extern void vtime_account_user(struct task_struct *tsk);
Frederic Weisbecker3f4724e2012-07-16 18:00:34 +020066
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020067#ifdef __ARCH_HAS_VTIME_ACCOUNT
68extern void vtime_account_irq_enter(struct task_struct *tsk);
69#else
70extern void vtime_common_account_irq_enter(struct task_struct *tsk);
71static inline void vtime_account_irq_enter(struct task_struct *tsk)
72{
Frederic Weisbecker55dbdcf2015-11-19 16:47:32 +010073 if (vtime_accounting_cpu_enabled())
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020074 vtime_common_account_irq_enter(tsk);
75}
76#endif /* __ARCH_HAS_VTIME_ACCOUNT */
Frederic Weisbecker3f4724e2012-07-16 18:00:34 +020077
78#else /* !CONFIG_VIRT_CPU_ACCOUNTING */
Frederic Weisbecker6a616712012-12-16 20:00:34 +010079
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +020080static inline void vtime_task_switch(struct task_struct *prev) { }
Frederic Weisbecker11113332012-10-24 18:05:51 +020081static inline void vtime_account_system(struct task_struct *tsk) { }
Frederic Weisbeckerabf917c2012-07-25 07:56:04 +020082static inline void vtime_account_user(struct task_struct *tsk) { }
Frederic Weisbecker6a616712012-12-16 20:00:34 +010083static inline void vtime_account_irq_enter(struct task_struct *tsk) { }
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020084#endif /* !CONFIG_VIRT_CPU_ACCOUNTING */
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +020085
Frederic Weisbeckerabf917c2012-07-25 07:56:04 +020086#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
Frederic Weisbecker6a616712012-12-16 20:00:34 +010087extern void arch_vtime_task_switch(struct task_struct *tsk);
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020088extern void vtime_gen_account_irq_exit(struct task_struct *tsk);
89
90static inline void vtime_account_irq_exit(struct task_struct *tsk)
91{
Frederic Weisbecker55dbdcf2015-11-19 16:47:32 +010092 if (vtime_accounting_cpu_enabled())
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020093 vtime_gen_account_irq_exit(tsk);
94}
95
Frederic Weisbecker6a616712012-12-16 20:00:34 +010096extern void vtime_user_enter(struct task_struct *tsk);
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020097
Frederic Weisbeckerabf917c2012-07-25 07:56:04 +020098static inline void vtime_user_exit(struct task_struct *tsk)
99{
100 vtime_account_user(tsk);
101}
Frederic Weisbecker6a616712012-12-16 20:00:34 +0100102extern void vtime_guest_enter(struct task_struct *tsk);
103extern void vtime_guest_exit(struct task_struct *tsk);
Frederic Weisbecker45eacc62013-05-15 22:16:32 +0200104extern void vtime_init_idle(struct task_struct *tsk, int cpu);
Frederic Weisbeckerb0493402013-07-12 03:10:15 +0200105#else /* !CONFIG_VIRT_CPU_ACCOUNTING_GEN */
Frederic Weisbecker6a616712012-12-16 20:00:34 +0100106static inline void vtime_account_irq_exit(struct task_struct *tsk)
107{
108 /* On hard|softirq exit we always account to hard|softirq cputime */
109 vtime_account_system(tsk);
110}
Frederic Weisbeckerabf917c2012-07-25 07:56:04 +0200111static inline void vtime_user_enter(struct task_struct *tsk) { }
112static inline void vtime_user_exit(struct task_struct *tsk) { }
Frederic Weisbecker6a616712012-12-16 20:00:34 +0100113static inline void vtime_guest_enter(struct task_struct *tsk) { }
114static inline void vtime_guest_exit(struct task_struct *tsk) { }
Frederic Weisbecker45eacc62013-05-15 22:16:32 +0200115static inline void vtime_init_idle(struct task_struct *tsk, int cpu) { }
Frederic Weisbeckerabf917c2012-07-25 07:56:04 +0200116#endif
117
Frederic Weisbecker3e1df4f52012-10-06 05:23:22 +0200118#ifdef CONFIG_IRQ_TIME_ACCOUNTING
119extern void irqtime_account_irq(struct task_struct *tsk);
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +0200120#else
Frederic Weisbecker3e1df4f52012-10-06 05:23:22 +0200121static inline void irqtime_account_irq(struct task_struct *tsk) { }
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +0200122#endif
123
Frederic Weisbecker6a616712012-12-16 20:00:34 +0100124static inline void account_irq_enter_time(struct task_struct *tsk)
Frederic Weisbeckerfa5058f2012-10-06 04:07:19 +0200125{
Frederic Weisbecker6a616712012-12-16 20:00:34 +0100126 vtime_account_irq_enter(tsk);
Frederic Weisbecker3e1df4f52012-10-06 05:23:22 +0200127 irqtime_account_irq(tsk);
Frederic Weisbeckerfa5058f2012-10-06 04:07:19 +0200128}
129
Frederic Weisbecker6a616712012-12-16 20:00:34 +0100130static inline void account_irq_exit_time(struct task_struct *tsk)
Frederic Weisbeckerfa5058f2012-10-06 04:07:19 +0200131{
Frederic Weisbecker6a616712012-12-16 20:00:34 +0100132 vtime_account_irq_exit(tsk);
Frederic Weisbecker3e1df4f52012-10-06 05:23:22 +0200133 irqtime_account_irq(tsk);
Frederic Weisbeckerfa5058f2012-10-06 04:07:19 +0200134}
135
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +0200136#endif /* _LINUX_KERNEL_VTIME_H */