tick.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /* linux/include/linux/tick.h
  2. *
  3. * This file contains the structure definitions for tick related functions
  4. *
  5. */
  6. #ifndef _LINUX_TICK_H
  7. #define _LINUX_TICK_H
  8. #include <linux/clockchips.h>
  9. #include <linux/irqflags.h>
  10. #include <linux/hrtimer.h>
  11. #ifdef CONFIG_GENERIC_CLOCKEVENTS
  12. enum tick_device_mode {
  13. TICKDEV_MODE_PERIODIC,
  14. TICKDEV_MODE_ONESHOT,
  15. };
  16. struct tick_device {
  17. struct clock_event_device *evtdev;
  18. enum tick_device_mode mode;
  19. };
  20. enum tick_nohz_mode {
  21. NOHZ_MODE_INACTIVE,
  22. NOHZ_MODE_LOWRES,
  23. NOHZ_MODE_HIGHRES,
  24. };
  25. /**
  26. * struct tick_sched - sched tick emulation and no idle tick control/stats
  27. * @sched_timer: hrtimer to schedule the periodic tick in high
  28. * resolution mode
  29. * @idle_tick: Store the last idle tick expiry time when the tick
  30. * timer is modified for idle sleeps. This is necessary
  31. * to resume the tick timer operation in the timeline
  32. * when the CPU returns from idle
  33. * @tick_stopped: Indicator that the idle tick has been stopped
  34. * @idle_jiffies: jiffies at the entry to idle for idle time accounting
  35. * @idle_calls: Total number of idle calls
  36. * @idle_sleeps: Number of idle calls, where the sched tick was stopped
  37. * @idle_entrytime: Time when the idle call was entered
  38. * @idle_waketime: Time when the idle was interrupted
  39. * @idle_exittime: Time when the idle state was left
  40. * @idle_sleeptime: Sum of the time slept in idle with sched tick stopped
  41. * @iowait_sleeptime: Sum of the time slept in idle with sched tick stopped, with IO outstanding
  42. * @do_timer_lst: CPU was the last one doing do_timer before going idle
  43. */
  44. struct tick_sched {
  45. struct hrtimer sched_timer;
  46. unsigned long check_clocks;
  47. enum tick_nohz_mode nohz_mode;
  48. ktime_t idle_tick;
  49. int inidle;
  50. int tick_stopped;
  51. unsigned long idle_jiffies;
  52. unsigned long idle_calls;
  53. unsigned long idle_sleeps;
  54. int idle_active;
  55. ktime_t idle_entrytime;
  56. ktime_t idle_waketime;
  57. ktime_t idle_exittime;
  58. ktime_t idle_sleeptime;
  59. ktime_t iowait_sleeptime;
  60. unsigned long last_jiffies;
  61. unsigned long next_jiffies;
  62. ktime_t idle_expires;
  63. int do_timer_last;
  64. };
  65. extern void __init tick_init(void);
  66. extern int tick_is_oneshot_available(void);
  67. extern struct tick_device *tick_get_device(int cpu);
  68. # ifdef CONFIG_HIGH_RES_TIMERS
  69. extern int tick_init_highres(void);
  70. extern int tick_program_event(ktime_t expires, int force);
  71. extern void tick_setup_sched_timer(void);
  72. # endif
  73. # if defined CONFIG_NO_HZ || defined CONFIG_HIGH_RES_TIMERS
  74. extern void tick_cancel_sched_timer(int cpu);
  75. # else
  76. static inline void tick_cancel_sched_timer(int cpu) { }
  77. # endif
  78. # ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
  79. extern struct tick_device *tick_get_broadcast_device(void);
  80. extern struct cpumask *tick_get_broadcast_mask(void);
  81. # ifdef CONFIG_TICK_ONESHOT
  82. extern struct cpumask *tick_get_broadcast_oneshot_mask(void);
  83. # endif
  84. #else
  85. static inline struct tick_device *tick_get_broadcast_device(void)
  86. {
  87. return NULL;
  88. }
  89. static inline struct cpumask *tick_get_broadcast_mask(void)
  90. {
  91. return NULL;
  92. }
  93. # endif /* BROADCAST */
  94. # ifdef CONFIG_TICK_ONESHOT
  95. extern void tick_clock_notify(void);
  96. extern int tick_check_oneshot_change(int allow_nohz);
  97. extern struct tick_sched *tick_get_tick_sched(int cpu);
  98. extern void tick_check_idle(int cpu);
  99. extern int tick_oneshot_mode_active(void);
  100. # ifndef arch_needs_cpu
  101. # define arch_needs_cpu(cpu) (0)
  102. # endif
  103. # else
  104. static inline void tick_clock_notify(void) { }
  105. static inline int tick_check_oneshot_change(int allow_nohz) { return 0; }
  106. static inline void tick_check_idle(int cpu) { }
  107. static inline int tick_oneshot_mode_active(void) { return 0; }
  108. static inline struct cpumask *tick_get_broadcast_oneshot_mask(void)
  109. {
  110. return NULL;
  111. }
  112. # endif
  113. #else /* CONFIG_GENERIC_CLOCKEVENTS */
  114. static inline void tick_init(void) { }
  115. static inline void tick_cancel_sched_timer(int cpu) { }
  116. static inline void tick_clock_notify(void) { }
  117. static inline int tick_check_oneshot_change(int allow_nohz) { return 0; }
  118. static inline void tick_check_idle(int cpu) { }
  119. static inline int tick_oneshot_mode_active(void) { return 0; }
  120. #endif /* !CONFIG_GENERIC_CLOCKEVENTS */
  121. # ifdef CONFIG_NO_HZ
  122. extern void tick_nohz_idle_enter(void);
  123. extern void tick_nohz_idle_exit(void);
  124. extern void tick_nohz_irq_exit(void);
  125. extern ktime_t tick_nohz_get_sleep_length(void);
  126. extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time);
  127. extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time);
  128. # else
  129. static inline void tick_nohz_idle_enter(void) { }
  130. static inline void tick_nohz_idle_exit(void) { }
  131. static inline ktime_t tick_nohz_get_sleep_length(void)
  132. {
  133. ktime_t len = { .tv64 = NSEC_PER_SEC/HZ };
  134. return len;
  135. }
  136. static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; }
  137. static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; }
  138. # endif /* !NO_HZ */
  139. #endif