vtime.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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_enabled() definitions/declarations
  10. */
  11. #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
  12. static inline bool vtime_accounting_enabled(void) { return true; }
  13. #endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
  14. #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
  15. static inline bool vtime_accounting_enabled(void)
  16. {
  17. if (static_key_false(&context_tracking_enabled)) {
  18. if (context_tracking_active())
  19. return true;
  20. }
  21. return false;
  22. }
  23. #endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */
  24. #ifndef CONFIG_VIRT_CPU_ACCOUNTING
  25. static inline bool vtime_accounting_enabled(void) { return false; }
  26. #endif /* !CONFIG_VIRT_CPU_ACCOUNTING */
  27. /*
  28. * Common vtime APIs
  29. */
  30. #ifdef CONFIG_VIRT_CPU_ACCOUNTING
  31. #ifdef __ARCH_HAS_VTIME_TASK_SWITCH
  32. extern void vtime_task_switch(struct task_struct *prev);
  33. #else
  34. extern void vtime_common_task_switch(struct task_struct *prev);
  35. static inline void vtime_task_switch(struct task_struct *prev)
  36. {
  37. if (vtime_accounting_enabled())
  38. vtime_common_task_switch(prev);
  39. }
  40. #endif /* __ARCH_HAS_VTIME_TASK_SWITCH */
  41. extern void vtime_account_system(struct task_struct *tsk);
  42. extern void vtime_account_idle(struct task_struct *tsk);
  43. extern void vtime_account_user(struct task_struct *tsk);
  44. #ifdef __ARCH_HAS_VTIME_ACCOUNT
  45. extern void vtime_account_irq_enter(struct task_struct *tsk);
  46. #else
  47. extern void vtime_common_account_irq_enter(struct task_struct *tsk);
  48. static inline void vtime_account_irq_enter(struct task_struct *tsk)
  49. {
  50. if (vtime_accounting_enabled())
  51. vtime_common_account_irq_enter(tsk);
  52. }
  53. #endif /* __ARCH_HAS_VTIME_ACCOUNT */
  54. #else /* !CONFIG_VIRT_CPU_ACCOUNTING */
  55. static inline void vtime_task_switch(struct task_struct *prev) { }
  56. static inline void vtime_account_system(struct task_struct *tsk) { }
  57. static inline void vtime_account_user(struct task_struct *tsk) { }
  58. static inline void vtime_account_irq_enter(struct task_struct *tsk) { }
  59. #endif /* !CONFIG_VIRT_CPU_ACCOUNTING */
  60. #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
  61. extern void arch_vtime_task_switch(struct task_struct *tsk);
  62. extern void vtime_gen_account_irq_exit(struct task_struct *tsk);
  63. static inline void vtime_account_irq_exit(struct task_struct *tsk)
  64. {
  65. if (vtime_accounting_enabled())
  66. vtime_gen_account_irq_exit(tsk);
  67. }
  68. extern void vtime_user_enter(struct task_struct *tsk);
  69. static inline void vtime_user_exit(struct task_struct *tsk)
  70. {
  71. vtime_account_user(tsk);
  72. }
  73. extern void vtime_guest_enter(struct task_struct *tsk);
  74. extern void vtime_guest_exit(struct task_struct *tsk);
  75. extern void vtime_init_idle(struct task_struct *tsk, int cpu);
  76. #else /* !CONFIG_VIRT_CPU_ACCOUNTING_GEN */
  77. static inline void vtime_account_irq_exit(struct task_struct *tsk)
  78. {
  79. /* On hard|softirq exit we always account to hard|softirq cputime */
  80. vtime_account_system(tsk);
  81. }
  82. static inline void vtime_user_enter(struct task_struct *tsk) { }
  83. static inline void vtime_user_exit(struct task_struct *tsk) { }
  84. static inline void vtime_guest_enter(struct task_struct *tsk) { }
  85. static inline void vtime_guest_exit(struct task_struct *tsk) { }
  86. static inline void vtime_init_idle(struct task_struct *tsk, int cpu) { }
  87. #endif
  88. #ifdef CONFIG_IRQ_TIME_ACCOUNTING
  89. extern void irqtime_account_irq(struct task_struct *tsk);
  90. #else
  91. static inline void irqtime_account_irq(struct task_struct *tsk) { }
  92. #endif
  93. static inline void account_irq_enter_time(struct task_struct *tsk)
  94. {
  95. vtime_account_irq_enter(tsk);
  96. irqtime_account_irq(tsk);
  97. }
  98. static inline void account_irq_exit_time(struct task_struct *tsk)
  99. {
  100. vtime_account_irq_exit(tsk);
  101. irqtime_account_irq(tsk);
  102. }
  103. #endif /* _LINUX_KERNEL_VTIME_H */