vtime.h 3.6 KB

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