blob: bb50c3ca0d797d243073487bdea8bd0e420fdf25 [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_idle(struct task_struct *tsk);
Frederic Weisbeckerbcebdf82012-11-13 23:51:06 +010010extern void vtime_account_user(struct task_struct *tsk);
Frederic Weisbecker3e1df4f52012-10-06 05:23:22 +020011extern void vtime_account(struct task_struct *tsk);
Frederic Weisbecker3f4724e2012-07-16 18:00:34 +020012
13#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
14extern bool vtime_accounting_enabled(void);
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +020015#else
Frederic Weisbecker3f4724e2012-07-16 18:00:34 +020016static inline bool vtime_accounting_enabled(void) { return true; }
17#endif
18
19#else /* !CONFIG_VIRT_CPU_ACCOUNTING */
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +020020static inline void vtime_task_switch(struct task_struct *prev) { }
Frederic Weisbecker11113332012-10-24 18:05:51 +020021static inline void vtime_account_system(struct task_struct *tsk) { }
Frederic Weisbeckerabf917c2012-07-25 07:56:04 +020022static inline void vtime_account_user(struct task_struct *tsk) { }
Frederic Weisbecker3e1df4f52012-10-06 05:23:22 +020023static inline void vtime_account(struct task_struct *tsk) { }
Frederic Weisbecker3f4724e2012-07-16 18:00:34 +020024static inline bool vtime_accounting_enabled(void) { return false; }
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +020025#endif
26
Frederic Weisbeckerabf917c2012-07-25 07:56:04 +020027#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
28static inline void arch_vtime_task_switch(struct task_struct *tsk) { }
29static inline void vtime_user_enter(struct task_struct *tsk)
30{
31 vtime_account_system(tsk);
32}
33static inline void vtime_user_exit(struct task_struct *tsk)
34{
35 vtime_account_user(tsk);
36}
37#else
38static inline void vtime_user_enter(struct task_struct *tsk) { }
39static inline void vtime_user_exit(struct task_struct *tsk) { }
40#endif
41
Frederic Weisbecker3e1df4f52012-10-06 05:23:22 +020042#ifdef CONFIG_IRQ_TIME_ACCOUNTING
43extern void irqtime_account_irq(struct task_struct *tsk);
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +020044#else
Frederic Weisbecker3e1df4f52012-10-06 05:23:22 +020045static inline void irqtime_account_irq(struct task_struct *tsk) { }
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +020046#endif
47
Frederic Weisbeckerfa5058f2012-10-06 04:07:19 +020048static inline void vtime_account_irq_enter(struct task_struct *tsk)
49{
50 /*
51 * Hardirq can interrupt idle task anytime. So we need vtime_account()
52 * that performs the idle check in CONFIG_VIRT_CPU_ACCOUNTING.
53 * Softirq can also interrupt idle task directly if it calls
54 * local_bh_enable(). Such case probably don't exist but we never know.
55 * Ksoftirqd is not concerned because idle time is flushed on context
56 * switch. Softirqs in the end of hardirqs are also not a problem because
57 * the idle time is flushed on hardirq time already.
58 */
59 vtime_account(tsk);
Frederic Weisbecker3e1df4f52012-10-06 05:23:22 +020060 irqtime_account_irq(tsk);
Frederic Weisbeckerfa5058f2012-10-06 04:07:19 +020061}
62
63static inline void vtime_account_irq_exit(struct task_struct *tsk)
64{
Frederic Weisbeckerfa5058f2012-10-06 04:07:19 +020065 /* On hard|softirq exit we always account to hard|softirq cputime */
Frederic Weisbeckerfd25b4c2012-11-13 18:21:22 +010066 vtime_account_system(tsk);
Frederic Weisbecker3e1df4f52012-10-06 05:23:22 +020067 irqtime_account_irq(tsk);
Frederic Weisbeckerfa5058f2012-10-06 04:07:19 +020068}
69
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +020070#endif /* _LINUX_KERNEL_VTIME_H */