xref: /openbmc/linux/kernel/time/tick-internal.h (revision a49b116d)
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);
23a49b116dSThomas Gleixner extern void tick_shutdown(unsigned int cpu);
248c53daf6SThomas Gleixner extern void tick_suspend(void);
25f46481d0SThomas Gleixner extern void tick_resume(void);
2603e13cf5SThomas Gleixner extern bool tick_check_replacement(struct clock_event_device *curdev,
2703e13cf5SThomas Gleixner 				   struct clock_event_device *newdev);
2803e13cf5SThomas Gleixner extern void tick_install_replacement(struct clock_event_device *dev);
29c1797bafSThomas Gleixner extern int tick_is_oneshot_available(void);
307270d11cSThomas Gleixner extern struct tick_device *tick_get_device(int cpu);
31f8381cbaSThomas Gleixner 
32554ef387SViresh Kumar extern int clockevents_tick_resume(struct clock_event_device *dev);
33b7475eb5SThomas Gleixner /* Check, if the device is functional or a dummy for broadcast */
34b7475eb5SThomas Gleixner static inline int tick_device_is_functional(struct clock_event_device *dev)
35b7475eb5SThomas Gleixner {
36b7475eb5SThomas Gleixner 	return !(dev->features & CLOCK_EVT_FEAT_DUMMY);
37b7475eb5SThomas Gleixner }
382344abbcSThomas Gleixner 
39b7475eb5SThomas Gleixner extern void clockevents_shutdown(struct clock_event_device *dev);
40c1797bafSThomas Gleixner extern void clockevents_exchange_device(struct clock_event_device *old,
41c1797bafSThomas Gleixner 					struct clock_event_device *new);
427270d11cSThomas Gleixner extern void clockevents_set_state(struct clock_event_device *dev,
437270d11cSThomas Gleixner 				 enum clock_event_state state);
447270d11cSThomas Gleixner extern int clockevents_program_event(struct clock_event_device *dev,
457270d11cSThomas Gleixner 				     ktime_t expires, bool force);
46c1797bafSThomas Gleixner extern void clockevents_handle_noop(struct clock_event_device *dev);
47b7475eb5SThomas Gleixner extern int __clockevents_update_freq(struct clock_event_device *dev, u32 freq);
48891292a7SPatrick Palka extern ssize_t sysfs_get_uname(const char *buf, char *dst, size_t cnt);
4979bf2bb3SThomas Gleixner 
50b7475eb5SThomas Gleixner /* Broadcasting support */
51f8381cbaSThomas Gleixner # ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
52f8381cbaSThomas Gleixner extern int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu);
537172a286SThomas Gleixner extern void tick_install_broadcast_device(struct clock_event_device *dev);
54f8381cbaSThomas Gleixner extern int tick_is_broadcast_device(struct clock_event_device *dev);
55a49b116dSThomas Gleixner extern void tick_shutdown_broadcast(unsigned int cpu);
566321dd60SThomas Gleixner extern void tick_suspend_broadcast(void);
57f46481d0SThomas Gleixner extern void tick_resume_broadcast(void);
58f46481d0SThomas Gleixner extern bool tick_resume_check_broadcast(void);
59b352bc1cSThomas Gleixner extern void tick_broadcast_init(void);
60b7475eb5SThomas Gleixner extern void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast);
61b7475eb5SThomas Gleixner extern int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq);
62c1797bafSThomas Gleixner extern struct tick_device *tick_get_broadcast_device(void);
63c1797bafSThomas Gleixner extern struct cpumask *tick_get_broadcast_mask(void);
643ae7a939SIngo Molnar # else /* !CONFIG_GENERIC_CLOCKEVENTS_BROADCAST: */
65b7475eb5SThomas Gleixner static inline void tick_install_broadcast_device(struct clock_event_device *dev) { }
66b7475eb5SThomas Gleixner static inline int tick_is_broadcast_device(struct clock_event_device *dev) { return 0; }
67b7475eb5SThomas Gleixner static inline int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu) { return 0; }
68f8381cbaSThomas Gleixner static inline void tick_do_periodic_broadcast(struct clock_event_device *d) { }
69a49b116dSThomas Gleixner static inline void tick_shutdown_broadcast(unsigned int cpu) { }
706321dd60SThomas Gleixner static inline void tick_suspend_broadcast(void) { }
71f46481d0SThomas Gleixner static inline void tick_resume_broadcast(void) { }
72f46481d0SThomas Gleixner static inline bool tick_resume_check_broadcast(void) { return false; }
73b352bc1cSThomas Gleixner static inline void tick_broadcast_init(void) { }
74b7475eb5SThomas Gleixner static inline int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq) { return -ENODEV; }
75f8381cbaSThomas Gleixner 
76b7475eb5SThomas Gleixner /* Set the periodic handler in non broadcast mode */
77b7475eb5SThomas Gleixner static inline void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast)
78f8381cbaSThomas Gleixner {
79f8381cbaSThomas Gleixner 	dev->event_handler = tick_handle_periodic;
80f8381cbaSThomas Gleixner }
813ae7a939SIngo Molnar # endif /* !CONFIG_GENERIC_CLOCKEVENTS_BROADCAST */
823ae7a939SIngo Molnar 
833ae7a939SIngo Molnar #else /* !GENERIC_CLOCKEVENTS: */
843ae7a939SIngo Molnar static inline void tick_suspend(void) { }
853ae7a939SIngo Molnar static inline void tick_resume(void) { }
863ae7a939SIngo Molnar #endif /* !GENERIC_CLOCKEVENTS */
873ae7a939SIngo Molnar 
883ae7a939SIngo Molnar /* Oneshot related functions */
893ae7a939SIngo Molnar #ifdef CONFIG_TICK_ONESHOT
903ae7a939SIngo Molnar extern void tick_setup_oneshot(struct clock_event_device *newdev,
913ae7a939SIngo Molnar 			       void (*handler)(struct clock_event_device *),
923ae7a939SIngo Molnar 			       ktime_t nextevt);
933ae7a939SIngo Molnar extern int tick_program_event(ktime_t expires, int force);
943ae7a939SIngo Molnar extern void tick_oneshot_notify(void);
953ae7a939SIngo Molnar extern int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *));
963ae7a939SIngo Molnar extern void tick_resume_oneshot(void);
973ae7a939SIngo Molnar static inline bool tick_oneshot_possible(void) { return true; }
983ae7a939SIngo Molnar extern int tick_oneshot_mode_active(void);
993ae7a939SIngo Molnar extern void tick_clock_notify(void);
1003ae7a939SIngo Molnar extern int tick_check_oneshot_change(int allow_nohz);
1013ae7a939SIngo Molnar extern int tick_init_highres(void);
1023ae7a939SIngo Molnar #else /* !CONFIG_TICK_ONESHOT: */
1033ae7a939SIngo Molnar static inline
1043ae7a939SIngo Molnar void tick_setup_oneshot(struct clock_event_device *newdev,
1053ae7a939SIngo Molnar 			void (*handler)(struct clock_event_device *),
1063ae7a939SIngo Molnar 			ktime_t nextevt) { BUG(); }
1073ae7a939SIngo Molnar static inline void tick_resume_oneshot(void) { BUG(); }
1083ae7a939SIngo Molnar static inline int tick_program_event(ktime_t expires, int force) { return 0; }
1093ae7a939SIngo Molnar static inline void tick_oneshot_notify(void) { }
1103ae7a939SIngo Molnar static inline bool tick_oneshot_possible(void) { return false; }
1113ae7a939SIngo Molnar static inline int tick_oneshot_mode_active(void) { return 0; }
1123ae7a939SIngo Molnar static inline void tick_clock_notify(void) { }
1133ae7a939SIngo Molnar static inline int tick_check_oneshot_change(int allow_nohz) { return 0; }
1143ae7a939SIngo Molnar #endif /* !CONFIG_TICK_ONESHOT */
115f8381cbaSThomas Gleixner 
116b7475eb5SThomas Gleixner /* Functions related to oneshot broadcasting */
117b7475eb5SThomas Gleixner #if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
118b7475eb5SThomas Gleixner extern void tick_broadcast_setup_oneshot(struct clock_event_device *bc);
119b7475eb5SThomas Gleixner extern void tick_broadcast_switch_to_oneshot(void);
120a49b116dSThomas Gleixner extern void tick_shutdown_broadcast_oneshot(unsigned int cpu);
121b7475eb5SThomas Gleixner extern int tick_broadcast_oneshot_active(void);
122b7475eb5SThomas Gleixner extern void tick_check_oneshot_broadcast_this_cpu(void);
123b7475eb5SThomas Gleixner bool tick_broadcast_oneshot_available(void);
124c1797bafSThomas Gleixner extern struct cpumask *tick_get_broadcast_oneshot_mask(void);
1253ae7a939SIngo Molnar #else /* !(BROADCAST && ONESHOT): */
126b7475eb5SThomas Gleixner static inline void tick_broadcast_setup_oneshot(struct clock_event_device *bc) { BUG(); }
127b7475eb5SThomas Gleixner static inline void tick_broadcast_switch_to_oneshot(void) { }
128a49b116dSThomas Gleixner static inline void tick_shutdown_broadcast_oneshot(unsigned int cpu) { }
129b7475eb5SThomas Gleixner static inline int tick_broadcast_oneshot_active(void) { return 0; }
130b7475eb5SThomas Gleixner static inline void tick_check_oneshot_broadcast_this_cpu(void) { }
131b7475eb5SThomas Gleixner static inline bool tick_broadcast_oneshot_available(void) { return tick_oneshot_possible(); }
1323ae7a939SIngo Molnar #endif /* !(BROADCAST && ONESHOT) */
133e2830b5cSTorben Hohn 
134b7475eb5SThomas Gleixner /* NO_HZ_FULL internal */
135b7475eb5SThomas Gleixner #ifdef CONFIG_NO_HZ_FULL
136b7475eb5SThomas Gleixner extern void tick_nohz_init(void);
137b7475eb5SThomas Gleixner # else
138b7475eb5SThomas Gleixner static inline void tick_nohz_init(void) { }
139b7475eb5SThomas Gleixner #endif
140