1f8381cbaSThomas Gleixner /* 2f8381cbaSThomas Gleixner * tick internal variable and functions used by low/high res code 3f8381cbaSThomas Gleixner */ 4e2830b5cSTorben Hohn #include <linux/hrtimer.h> 5e2830b5cSTorben Hohn #include <linux/tick.h> 66441402bSThomas Gleixner 78b094cd0SThomas Gleixner #include "timekeeping.h" 8c1797bafSThomas Gleixner #include "tick-sched.h" 98b094cd0SThomas Gleixner 109f083b74SThomas Gleixner #ifdef CONFIG_GENERIC_CLOCKEVENTS 116441402bSThomas Gleixner 126441402bSThomas Gleixner #define TICK_DO_TIMER_NONE -1 136441402bSThomas Gleixner #define TICK_DO_TIMER_BOOT -2 146441402bSThomas Gleixner 15f8381cbaSThomas Gleixner DECLARE_PER_CPU(struct tick_device, tick_cpu_device); 16f8381cbaSThomas Gleixner extern ktime_t tick_next_period; 17f8381cbaSThomas Gleixner extern ktime_t tick_period; 18d3ed7824SThomas Gleixner extern int tick_do_timer_cpu __read_mostly; 19f8381cbaSThomas Gleixner 20f8381cbaSThomas Gleixner extern void tick_setup_periodic(struct clock_event_device *dev, int broadcast); 21f8381cbaSThomas Gleixner extern void tick_handle_periodic(struct clock_event_device *dev); 227172a286SThomas Gleixner extern void tick_check_new_device(struct clock_event_device *dev); 238c53daf6SThomas Gleixner extern void tick_handover_do_timer(int *cpup); 248c53daf6SThomas Gleixner extern void tick_shutdown(unsigned int *cpup); 258c53daf6SThomas Gleixner extern void tick_suspend(void); 26f46481d0SThomas Gleixner extern void tick_resume(void); 2703e13cf5SThomas Gleixner extern bool tick_check_replacement(struct clock_event_device *curdev, 2803e13cf5SThomas Gleixner struct clock_event_device *newdev); 2903e13cf5SThomas Gleixner extern void tick_install_replacement(struct clock_event_device *dev); 30c1797bafSThomas Gleixner extern int tick_is_oneshot_available(void); 317270d11cSThomas Gleixner extern struct tick_device *tick_get_device(int cpu); 32f8381cbaSThomas Gleixner 33554ef387SViresh Kumar extern int clockevents_tick_resume(struct clock_event_device *dev); 34b7475eb5SThomas Gleixner /* Check, if the device is functional or a dummy for broadcast */ 35b7475eb5SThomas Gleixner static inline int tick_device_is_functional(struct clock_event_device *dev) 36b7475eb5SThomas Gleixner { 37b7475eb5SThomas Gleixner return !(dev->features & CLOCK_EVT_FEAT_DUMMY); 38b7475eb5SThomas Gleixner } 392344abbcSThomas Gleixner 40b7475eb5SThomas Gleixner extern void clockevents_shutdown(struct clock_event_device *dev); 41c1797bafSThomas Gleixner extern void clockevents_exchange_device(struct clock_event_device *old, 42c1797bafSThomas Gleixner struct clock_event_device *new); 437270d11cSThomas Gleixner extern void clockevents_set_state(struct clock_event_device *dev, 447270d11cSThomas Gleixner enum clock_event_state state); 457270d11cSThomas Gleixner extern int clockevents_program_event(struct clock_event_device *dev, 467270d11cSThomas Gleixner ktime_t expires, bool force); 47c1797bafSThomas Gleixner extern void clockevents_handle_noop(struct clock_event_device *dev); 48b7475eb5SThomas Gleixner extern int __clockevents_update_freq(struct clock_event_device *dev, u32 freq); 49891292a7SPatrick Palka extern ssize_t sysfs_get_uname(const char *buf, char *dst, size_t cnt); 504ffee521SThomas Gleixner #else 514ffee521SThomas Gleixner static inline void tick_suspend(void) { } 52f46481d0SThomas Gleixner static inline void tick_resume(void) { } 53b7475eb5SThomas Gleixner #endif /* GENERIC_CLOCKEVENTS */ 5403e13cf5SThomas Gleixner 55b7475eb5SThomas Gleixner /* Oneshot related functions */ 5679bf2bb3SThomas Gleixner #ifdef CONFIG_TICK_ONESHOT 5779bf2bb3SThomas Gleixner extern void tick_setup_oneshot(struct clock_event_device *newdev, 5879bf2bb3SThomas Gleixner void (*handler)(struct clock_event_device *), 5979bf2bb3SThomas Gleixner ktime_t nextevt); 6079bf2bb3SThomas Gleixner extern int tick_program_event(ktime_t expires, int force); 6179bf2bb3SThomas Gleixner extern void tick_oneshot_notify(void); 6279bf2bb3SThomas Gleixner extern int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *)); 63cd05a1f8SThomas Gleixner extern void tick_resume_oneshot(void); 64b7475eb5SThomas Gleixner static inline bool tick_oneshot_possible(void) { return true; } 65c1797bafSThomas Gleixner extern int tick_oneshot_mode_active(void); 66c1797bafSThomas Gleixner extern void tick_clock_notify(void); 67c1797bafSThomas Gleixner extern int tick_check_oneshot_change(int allow_nohz); 68c1797bafSThomas Gleixner extern int tick_init_highres(void); 6979bf2bb3SThomas Gleixner #else /* !ONESHOT */ 7079bf2bb3SThomas Gleixner static inline 7179bf2bb3SThomas Gleixner void tick_setup_oneshot(struct clock_event_device *newdev, 7279bf2bb3SThomas Gleixner void (*handler)(struct clock_event_device *), 73b7475eb5SThomas Gleixner ktime_t nextevt) { BUG(); } 74b7475eb5SThomas Gleixner static inline void tick_resume_oneshot(void) { BUG(); } 75b7475eb5SThomas Gleixner static inline int tick_program_event(ktime_t expires, int force) { return 0; } 7679bf2bb3SThomas Gleixner static inline void tick_oneshot_notify(void) { } 77b7475eb5SThomas Gleixner static inline bool tick_oneshot_possible(void) { return false; } 78c1797bafSThomas Gleixner static inline int tick_oneshot_mode_active(void) { return 0; } 79c1797bafSThomas Gleixner static inline void tick_clock_notify(void) { } 80c1797bafSThomas Gleixner static inline int tick_check_oneshot_change(int allow_nohz) { return 0; } 8179bf2bb3SThomas Gleixner #endif /* !TICK_ONESHOT */ 8279bf2bb3SThomas Gleixner 83b7475eb5SThomas Gleixner /* Broadcasting support */ 84f8381cbaSThomas Gleixner #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST 85f8381cbaSThomas Gleixner extern int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu); 867172a286SThomas Gleixner extern void tick_install_broadcast_device(struct clock_event_device *dev); 87f8381cbaSThomas Gleixner extern int tick_is_broadcast_device(struct clock_event_device *dev); 88f8381cbaSThomas Gleixner extern void tick_broadcast_on_off(unsigned long reason, int *oncpu); 89f8381cbaSThomas Gleixner extern void tick_shutdown_broadcast(unsigned int *cpup); 906321dd60SThomas Gleixner extern void tick_suspend_broadcast(void); 91f46481d0SThomas Gleixner extern void tick_resume_broadcast(void); 92f46481d0SThomas Gleixner extern bool tick_resume_check_broadcast(void); 93b352bc1cSThomas Gleixner extern void tick_broadcast_init(void); 94b7475eb5SThomas Gleixner extern void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast); 95b7475eb5SThomas Gleixner extern int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq); 96c1797bafSThomas Gleixner extern struct tick_device *tick_get_broadcast_device(void); 97c1797bafSThomas Gleixner extern struct cpumask *tick_get_broadcast_mask(void); 98f8381cbaSThomas Gleixner #else /* !BROADCAST */ 99b7475eb5SThomas Gleixner static inline void tick_install_broadcast_device(struct clock_event_device *dev) { } 100b7475eb5SThomas Gleixner static inline int tick_is_broadcast_device(struct clock_event_device *dev) { return 0; } 101b7475eb5SThomas Gleixner static inline int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu) { return 0; } 102f8381cbaSThomas Gleixner static inline void tick_do_periodic_broadcast(struct clock_event_device *d) { } 103f8381cbaSThomas Gleixner static inline void tick_broadcast_on_off(unsigned long reason, int *oncpu) { } 104f8381cbaSThomas Gleixner static inline void tick_shutdown_broadcast(unsigned int *cpup) { } 1056321dd60SThomas Gleixner static inline void tick_suspend_broadcast(void) { } 106f46481d0SThomas Gleixner static inline void tick_resume_broadcast(void) { } 107f46481d0SThomas Gleixner static inline bool tick_resume_check_broadcast(void) { return false; } 108b352bc1cSThomas Gleixner static inline void tick_broadcast_init(void) { } 109b7475eb5SThomas Gleixner static inline int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq) { return -ENODEV; } 110f8381cbaSThomas Gleixner 111b7475eb5SThomas Gleixner /* Set the periodic handler in non broadcast mode */ 112b7475eb5SThomas Gleixner static inline void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast) 113f8381cbaSThomas Gleixner { 114f8381cbaSThomas Gleixner dev->event_handler = tick_handle_periodic; 115f8381cbaSThomas Gleixner } 116f8381cbaSThomas Gleixner #endif /* !BROADCAST */ 117f8381cbaSThomas Gleixner 118b7475eb5SThomas Gleixner /* Functions related to oneshot broadcasting */ 119b7475eb5SThomas Gleixner #if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT) 120b7475eb5SThomas Gleixner extern void tick_broadcast_setup_oneshot(struct clock_event_device *bc); 121b7475eb5SThomas Gleixner extern int tick_broadcast_oneshot_control(unsigned long reason); 122b7475eb5SThomas Gleixner extern void tick_broadcast_switch_to_oneshot(void); 123b7475eb5SThomas Gleixner extern void tick_shutdown_broadcast_oneshot(unsigned int *cpup); 124b7475eb5SThomas Gleixner extern int tick_broadcast_oneshot_active(void); 125b7475eb5SThomas Gleixner extern void tick_check_oneshot_broadcast_this_cpu(void); 126b7475eb5SThomas Gleixner bool tick_broadcast_oneshot_available(void); 127c1797bafSThomas Gleixner extern struct cpumask *tick_get_broadcast_oneshot_mask(void); 128b7475eb5SThomas Gleixner #else /* BROADCAST && ONESHOT */ 129b7475eb5SThomas Gleixner static inline void tick_broadcast_setup_oneshot(struct clock_event_device *bc) { BUG(); } 130b7475eb5SThomas Gleixner static inline int tick_broadcast_oneshot_control(unsigned long reason) { return 0; } 131b7475eb5SThomas Gleixner static inline void tick_broadcast_switch_to_oneshot(void) { } 132b7475eb5SThomas Gleixner static inline void tick_shutdown_broadcast_oneshot(unsigned int *cpup) { } 133b7475eb5SThomas Gleixner static inline int tick_broadcast_oneshot_active(void) { return 0; } 134b7475eb5SThomas Gleixner static inline void tick_check_oneshot_broadcast_this_cpu(void) { } 135b7475eb5SThomas Gleixner static inline bool tick_broadcast_oneshot_available(void) { return tick_oneshot_possible(); } 136b7475eb5SThomas Gleixner #endif /* !BROADCAST && ONESHOT */ 137e2830b5cSTorben Hohn 138b7475eb5SThomas Gleixner /* NO_HZ_FULL internal */ 139b7475eb5SThomas Gleixner #ifdef CONFIG_NO_HZ_FULL 140b7475eb5SThomas Gleixner extern void tick_nohz_init(void); 141b7475eb5SThomas Gleixner # else 142b7475eb5SThomas Gleixner static inline void tick_nohz_init(void) { } 143b7475eb5SThomas Gleixner #endif 144