vtime.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #ifndef _LINUX_KERNEL_VTIME_H
  2. #define _LINUX_KERNEL_VTIME_H
  3. #include <linux/context_tracking_state.h>
  4. #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
  5. #include <asm/vtime.h>
  6. #endif
  7. struct task_struct;
  8. /*
  9. * vtime_accounting_cpu_enabled() definitions/declarations
  10. */
  11. #if defined(CONFIG_VIRT_CPU_ACCOUNTING_NATIVE)
  12. static inline bool vtime_accounting_cpu_enabled(void) { return true; }
  13. #elif defined(CONFIG_VIRT_CPU_ACCOUNTING_GEN)
  14. /*
  15. * Checks if vtime is enabled on some CPU. Cputime readers want to be careful
  16. * in that case and compute the tickless cputime.
  17. * For now vtime state is tied to context tracking. We might want to decouple
  18. * those later if necessary.
  19. */
  20. static inline bool vtime_accounting_enabled(void)
  21. {
  22. return context_tracking_is_enabled();
  23. }
  24. static inline bool vtime_accounting_cpu_enabled(void)
  25. {
  26. if (vtime_accounting_enabled()) {
  27. if (context_tracking_cpu_is_enabled())
  28. return true;
  29. }
  30. return false;
  31. }
  32. #else /* !CONFIG_VIRT_CPU_ACCOUNTING */
  33. static inline bool vtime_accounting_cpu_enabled(void) { return false; }
  34. #endif
  35. /*
  36. * Common vtime APIs
  37. */
  38. #ifdef CONFIG_VIRT_CPU_ACCOUNTING
  39. #ifdef __ARCH_HAS_VTIME_TASK_SWITCH
  40. extern void vtime_task_switch(struct task_struct *prev);
  41. #else
  42. extern void vtime_common_task_switch(struct task_struct *prev);
  43. static inline void vtime_task_switch(struct task_struct *prev)
  44. {
  45. if (vtime_accounting_cpu_enabled())
  46. vtime_common_task_switch(prev);
  47. }
  48. #endif /* __ARCH_HAS_VTIME_TASK_SWITCH */
  49. extern void vtime_account_system(struct task_struct *tsk);
  50. extern void vtime_account_idle(struct task_struct *tsk);
  51. extern void vtime_account_user(struct task_struct *tsk);
  52. #else /* !CONFIG_VIRT_CPU_ACCOUNTING */
  53. static inline void vtime_task_switch(struct task_struct *prev) { }
  54. static inline void vtime_account_system(struct task_struct *tsk) { }
  55. static inline void vtime_account_user(struct task_struct *tsk) { }
  56. #endif /* !CONFIG_VIRT_CPU_ACCOUNTING */
  57. #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
  58. extern void arch_vtime_task_switch(struct task_struct *tsk);
  59. extern void vtime_user_enter(struct task_struct *tsk);
  60. static inline void vtime_user_exit(struct task_struct *tsk)
  61. {
  62. vtime_account_user(tsk);
  63. }
  64. extern void vtime_guest_enter(struct task_struct *tsk);
  65. extern void vtime_guest_exit(struct task_struct *tsk);
  66. extern void vtime_init_idle(struct task_struct *tsk, int cpu);
  67. #else /* !CONFIG_VIRT_CPU_ACCOUNTING_GEN */
  68. static inline void vtime_user_enter(struct task_struct *tsk) { }
  69. static inline void vtime_user_exit(struct task_struct *tsk) { }
  70. static inline void vtime_guest_enter(struct task_struct *tsk) { }
  71. static inline void vtime_guest_exit(struct task_struct *tsk) { }
  72. static inline void vtime_init_idle(struct task_struct *tsk, int cpu) { }
  73. #endif
  74. #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
  75. extern void vtime_account_irq_enter(struct task_struct *tsk);
  76. static inline void vtime_account_irq_exit(struct task_struct *tsk)
  77. {
  78. /* On hard|softirq exit we always account to hard|softirq cputime */
  79. vtime_account_system(tsk);
  80. }
  81. #else /* !CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
  82. static inline void vtime_account_irq_enter(struct task_struct *tsk) { }
  83. static inline void vtime_account_irq_exit(struct task_struct *tsk) { }
  84. #endif
  85. #ifdef CONFIG_IRQ_TIME_ACCOUNTING
  86. extern void irqtime_account_irq(struct task_struct *tsk);
  87. #else
  88. static inline void irqtime_account_irq(struct task_struct *tsk) { }
  89. #endif
  90. static inline void account_irq_enter_time(struct task_struct *tsk)
  91. {
  92. vtime_account_irq_enter(tsk);
  93. irqtime_account_irq(tsk);
  94. }
  95. static inline void account_irq_exit_time(struct task_struct *tsk)
  96. {
  97. vtime_account_irq_exit(tsk);
  98. irqtime_account_irq(tsk);
  99. }
  100. #endif /* _LINUX_KERNEL_VTIME_H */