tick.h 4.3 KB

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