tick.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. #ifdef CONFIG_GENERIC_CLOCKEVENTS
  11. enum tick_device_mode {
  12. TICKDEV_MODE_PERIODIC,
  13. TICKDEV_MODE_ONESHOT,
  14. };
  15. struct tick_device {
  16. struct clock_event_device *evtdev;
  17. enum tick_device_mode mode;
  18. };
  19. enum tick_nohz_mode {
  20. NOHZ_MODE_INACTIVE,
  21. NOHZ_MODE_LOWRES,
  22. NOHZ_MODE_HIGHRES,
  23. };
  24. /**
  25. * struct tick_sched - sched tick emulation and no idle tick control/stats
  26. * @sched_timer: hrtimer to schedule the periodic tick in high
  27. * resolution mode
  28. * @idle_tick: Store the last idle tick expiry time when the tick
  29. * timer is modified for idle sleeps. This is necessary
  30. * to resume the tick timer operation in the timeline
  31. * when the CPU returns from idle
  32. * @tick_stopped: Indicator that the idle tick has been stopped
  33. * @idle_jiffies: jiffies at the entry to idle for idle time accounting
  34. * @idle_calls: Total number of idle calls
  35. * @idle_sleeps: Number of idle calls, where the sched tick was stopped
  36. * @idle_entrytime: Time when the idle call was entered
  37. * @idle_waketime: Time when the idle was interrupted
  38. * @idle_exittime: Time when the idle state was left
  39. * @idle_sleeptime: Sum of the time slept in idle with sched tick stopped
  40. * @iowait_sleeptime: Sum of the time slept in idle with sched tick stopped, with IO outstanding
  41. * @sleep_length: Duration of the current idle sleep
  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. ktime_t sleep_length;
  61. unsigned long last_jiffies;
  62. unsigned long next_jiffies;
  63. ktime_t idle_expires;
  64. int do_timer_last;
  65. };
  66. extern void __init tick_init(void);
  67. extern int tick_is_oneshot_available(void);
  68. extern struct tick_device *tick_get_device(int cpu);
  69. # ifdef CONFIG_HIGH_RES_TIMERS
  70. extern int tick_init_highres(void);
  71. extern int tick_program_event(ktime_t expires, int force);
  72. extern void tick_setup_sched_timer(void);
  73. # endif
  74. # if defined CONFIG_NO_HZ || defined CONFIG_HIGH_RES_TIMERS
  75. extern void tick_cancel_sched_timer(int cpu);
  76. # else
  77. static inline void tick_cancel_sched_timer(int cpu) { }
  78. # endif
  79. # ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
  80. extern struct tick_device *tick_get_broadcast_device(void);
  81. extern struct cpumask *tick_get_broadcast_mask(void);
  82. # ifdef CONFIG_TICK_ONESHOT
  83. extern struct cpumask *tick_get_broadcast_oneshot_mask(void);
  84. # endif
  85. # endif /* BROADCAST */
  86. # ifdef CONFIG_TICK_ONESHOT
  87. extern void tick_clock_notify(void);
  88. extern int tick_check_oneshot_change(int allow_nohz);
  89. extern struct tick_sched *tick_get_tick_sched(int cpu);
  90. extern void tick_check_idle(int cpu);
  91. extern int tick_oneshot_mode_active(void);
  92. # ifndef arch_needs_cpu
  93. # define arch_needs_cpu(cpu) (0)
  94. # endif
  95. # else
  96. static inline void tick_clock_notify(void) { }
  97. static inline int tick_check_oneshot_change(int allow_nohz) { return 0; }
  98. static inline void tick_check_idle(int cpu) { }
  99. static inline int tick_oneshot_mode_active(void) { return 0; }
  100. # endif
  101. #else /* CONFIG_GENERIC_CLOCKEVENTS */
  102. static inline void tick_init(void) { }
  103. static inline void tick_cancel_sched_timer(int cpu) { }
  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. #endif /* !CONFIG_GENERIC_CLOCKEVENTS */
  109. # ifdef CONFIG_NO_HZ
  110. extern void tick_nohz_idle_enter(void);
  111. extern void tick_nohz_idle_exit(void);
  112. extern void tick_nohz_irq_exit(void);
  113. extern ktime_t tick_nohz_get_sleep_length(void);
  114. extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time);
  115. extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time);
  116. # else
  117. static inline void tick_nohz_idle_enter(void) { }
  118. static inline void tick_nohz_idle_exit(void) { }
  119. static inline ktime_t tick_nohz_get_sleep_length(void)
  120. {
  121. ktime_t len = { .tv64 = NSEC_PER_SEC/HZ };
  122. return len;
  123. }
  124. static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; }
  125. static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; }
  126. # endif /* !NO_HZ */
  127. #endif