linux/include/linux/vtime.h
<<
>>
Prefs
   1#ifndef _LINUX_KERNEL_VTIME_H
   2#define _LINUX_KERNEL_VTIME_H
   3
   4#include <linux/context_tracking_state.h>
   5#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
   6#include <asm/vtime.h>
   7#endif
   8
   9
  10struct task_struct;
  11
  12/*
  13 * vtime_accounting_cpu_enabled() definitions/declarations
  14 */
  15#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
  16static inline bool vtime_accounting_cpu_enabled(void) { return true; }
  17#endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
  18
  19#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
  20/*
  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
  31static inline bool vtime_accounting_cpu_enabled(void)
  32{
  33        if (vtime_accounting_enabled()) {
  34                if (context_tracking_cpu_is_enabled())
  35                        return true;
  36        }
  37
  38        return false;
  39}
  40#endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */
  41
  42#ifndef CONFIG_VIRT_CPU_ACCOUNTING
  43static inline bool vtime_accounting_cpu_enabled(void) { return false; }
  44#endif /* !CONFIG_VIRT_CPU_ACCOUNTING */
  45
  46
  47/*
  48 * Common vtime APIs
  49 */
  50#ifdef CONFIG_VIRT_CPU_ACCOUNTING
  51
  52#ifdef __ARCH_HAS_VTIME_TASK_SWITCH
  53extern void vtime_task_switch(struct task_struct *prev);
  54#else
  55extern void vtime_common_task_switch(struct task_struct *prev);
  56static inline void vtime_task_switch(struct task_struct *prev)
  57{
  58        if (vtime_accounting_cpu_enabled())
  59                vtime_common_task_switch(prev);
  60}
  61#endif /* __ARCH_HAS_VTIME_TASK_SWITCH */
  62
  63extern void vtime_account_system(struct task_struct *tsk);
  64extern void vtime_account_idle(struct task_struct *tsk);
  65extern void vtime_account_user(struct task_struct *tsk);
  66
  67#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{
  73        if (vtime_accounting_cpu_enabled())
  74                vtime_common_account_irq_enter(tsk);
  75}
  76#endif /* __ARCH_HAS_VTIME_ACCOUNT */
  77
  78#else /* !CONFIG_VIRT_CPU_ACCOUNTING */
  79
  80static inline void vtime_task_switch(struct task_struct *prev) { }
  81static inline void vtime_account_system(struct task_struct *tsk) { }
  82static inline void vtime_account_user(struct task_struct *tsk) { }
  83static inline void vtime_account_irq_enter(struct task_struct *tsk) { }
  84#endif /* !CONFIG_VIRT_CPU_ACCOUNTING */
  85
  86#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
  87extern void arch_vtime_task_switch(struct task_struct *tsk);
  88extern void vtime_gen_account_irq_exit(struct task_struct *tsk);
  89
  90static inline void vtime_account_irq_exit(struct task_struct *tsk)
  91{
  92        if (vtime_accounting_cpu_enabled())
  93                vtime_gen_account_irq_exit(tsk);
  94}
  95
  96extern void vtime_user_enter(struct task_struct *tsk);
  97
  98static inline void vtime_user_exit(struct task_struct *tsk)
  99{
 100        vtime_account_user(tsk);
 101}
 102extern void vtime_guest_enter(struct task_struct *tsk);
 103extern void vtime_guest_exit(struct task_struct *tsk);
 104extern void vtime_init_idle(struct task_struct *tsk, int cpu);
 105#else /* !CONFIG_VIRT_CPU_ACCOUNTING_GEN  */
 106static 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}
 111static inline void vtime_user_enter(struct task_struct *tsk) { }
 112static inline void vtime_user_exit(struct task_struct *tsk) { }
 113static inline void vtime_guest_enter(struct task_struct *tsk) { }
 114static inline void vtime_guest_exit(struct task_struct *tsk) { }
 115static inline void vtime_init_idle(struct task_struct *tsk, int cpu) { }
 116#endif
 117
 118#ifdef CONFIG_IRQ_TIME_ACCOUNTING
 119extern void irqtime_account_irq(struct task_struct *tsk);
 120#else
 121static inline void irqtime_account_irq(struct task_struct *tsk) { }
 122#endif
 123
 124static inline void account_irq_enter_time(struct task_struct *tsk)
 125{
 126        vtime_account_irq_enter(tsk);
 127        irqtime_account_irq(tsk);
 128}
 129
 130static inline void account_irq_exit_time(struct task_struct *tsk)
 131{
 132        vtime_account_irq_exit(tsk);
 133        irqtime_account_irq(tsk);
 134}
 135
 136#endif /* _LINUX_KERNEL_VTIME_H */
 137