blob: 5368af9bdf0622391845958686f0c67db1686609 [file] [log] [blame]
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +02001#ifndef _LINUX_KERNEL_VTIME_H
2#define _LINUX_KERNEL_VTIME_H
3
4struct task_struct;
5
6#ifdef CONFIG_VIRT_CPU_ACCOUNTING
7extern void vtime_task_switch(struct task_struct *prev);
8extern void vtime_account_system(struct task_struct *tsk);
Frederic Weisbeckerfd25b4c2012-11-13 18:21:22 +01009extern void vtime_account_system_irqsafe(struct task_struct *tsk);
10extern void vtime_account_idle(struct task_struct *tsk);
Frederic Weisbeckerbcebdf82012-11-13 23:51:06 +010011extern void vtime_account_user(struct task_struct *tsk);
Frederic Weisbecker3e1df4f52012-10-06 05:23:22 +020012extern void vtime_account(struct task_struct *tsk);
Frederic Weisbecker3f4724e2012-07-16 18:00:34 +020013
14#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
15extern bool vtime_accounting_enabled(void);
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +020016#else
Frederic Weisbecker3f4724e2012-07-16 18:00:34 +020017static inline bool vtime_accounting_enabled(void) { return true; }
18#endif
19
20#else /* !CONFIG_VIRT_CPU_ACCOUNTING */
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +020021static inline void vtime_task_switch(struct task_struct *prev) { }
Frederic Weisbecker11113332012-10-24 18:05:51 +020022static inline void vtime_account_system(struct task_struct *tsk) { }
Frederic Weisbeckerfd25b4c2012-11-13 18:21:22 +010023static inline void vtime_account_system_irqsafe(struct task_struct *tsk) { }
Frederic Weisbeckerabf917c2012-07-25 07:56:04 +020024static inline void vtime_account_user(struct task_struct *tsk) { }
Frederic Weisbecker3e1df4f52012-10-06 05:23:22 +020025static inline void vtime_account(struct task_struct *tsk) { }
Frederic Weisbecker3f4724e2012-07-16 18:00:34 +020026static inline bool vtime_accounting_enabled(void) { return false; }
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +020027#endif
28
Frederic Weisbeckerabf917c2012-07-25 07:56:04 +020029#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
30static inline void arch_vtime_task_switch(struct task_struct *tsk) { }
31static inline void vtime_user_enter(struct task_struct *tsk)
32{
33 vtime_account_system(tsk);
34}
35static inline void vtime_user_exit(struct task_struct *tsk)
36{
37 vtime_account_user(tsk);
38}
39#else
40static inline void vtime_user_enter(struct task_struct *tsk) { }
41static inline void vtime_user_exit(struct task_struct *tsk) { }
42#endif
43
Frederic Weisbecker3e1df4f52012-10-06 05:23:22 +020044#ifdef CONFIG_IRQ_TIME_ACCOUNTING
45extern void irqtime_account_irq(struct task_struct *tsk);
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +020046#else
Frederic Weisbecker3e1df4f52012-10-06 05:23:22 +020047static inline void irqtime_account_irq(struct task_struct *tsk) { }
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +020048#endif
49
Frederic Weisbeckerfa5058f2012-10-06 04:07:19 +020050static inline void vtime_account_irq_enter(struct task_struct *tsk)
51{
52 /*
53 * Hardirq can interrupt idle task anytime. So we need vtime_account()
54 * that performs the idle check in CONFIG_VIRT_CPU_ACCOUNTING.
55 * Softirq can also interrupt idle task directly if it calls
56 * local_bh_enable(). Such case probably don't exist but we never know.
57 * Ksoftirqd is not concerned because idle time is flushed on context
58 * switch. Softirqs in the end of hardirqs are also not a problem because
59 * the idle time is flushed on hardirq time already.
60 */
61 vtime_account(tsk);
Frederic Weisbecker3e1df4f52012-10-06 05:23:22 +020062 irqtime_account_irq(tsk);
Frederic Weisbeckerfa5058f2012-10-06 04:07:19 +020063}
64
65static inline void vtime_account_irq_exit(struct task_struct *tsk)
66{
Frederic Weisbeckerfa5058f2012-10-06 04:07:19 +020067 /* On hard|softirq exit we always account to hard|softirq cputime */
Frederic Weisbeckerfd25b4c2012-11-13 18:21:22 +010068 vtime_account_system(tsk);
Frederic Weisbecker3e1df4f52012-10-06 05:23:22 +020069 irqtime_account_irq(tsk);
Frederic Weisbeckerfa5058f2012-10-06 04:07:19 +020070}
71
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +020072#endif /* _LINUX_KERNEL_VTIME_H */