0001
0002
0003
0004
0005 #include <linux/hrtimer.h>
0006 #include <linux/tick.h>
0007
0008 #include "timekeeping.h"
0009 #include "tick-sched.h"
0010
0011 #ifdef CONFIG_GENERIC_CLOCKEVENTS
0012
0013 # define TICK_DO_TIMER_NONE -1
0014 # define TICK_DO_TIMER_BOOT -2
0015
0016 DECLARE_PER_CPU(struct tick_device, tick_cpu_device);
0017 extern ktime_t tick_next_period;
0018 extern int tick_do_timer_cpu __read_mostly;
0019
0020 extern void tick_setup_periodic(struct clock_event_device *dev, int broadcast);
0021 extern void tick_handle_periodic(struct clock_event_device *dev);
0022 extern void tick_check_new_device(struct clock_event_device *dev);
0023 extern void tick_shutdown(unsigned int cpu);
0024 extern void tick_suspend(void);
0025 extern void tick_resume(void);
0026 extern bool tick_check_replacement(struct clock_event_device *curdev,
0027 struct clock_event_device *newdev);
0028 extern void tick_install_replacement(struct clock_event_device *dev);
0029 extern int tick_is_oneshot_available(void);
0030 extern struct tick_device *tick_get_device(int cpu);
0031
0032 extern int clockevents_tick_resume(struct clock_event_device *dev);
0033
0034 static inline int tick_device_is_functional(struct clock_event_device *dev)
0035 {
0036 return !(dev->features & CLOCK_EVT_FEAT_DUMMY);
0037 }
0038
0039 static inline enum clock_event_state clockevent_get_state(struct clock_event_device *dev)
0040 {
0041 return dev->state_use_accessors;
0042 }
0043
0044 static inline void clockevent_set_state(struct clock_event_device *dev,
0045 enum clock_event_state state)
0046 {
0047 dev->state_use_accessors = state;
0048 }
0049
0050 extern void clockevents_shutdown(struct clock_event_device *dev);
0051 extern void clockevents_exchange_device(struct clock_event_device *old,
0052 struct clock_event_device *new);
0053 extern void clockevents_switch_state(struct clock_event_device *dev,
0054 enum clock_event_state state);
0055 extern int clockevents_program_event(struct clock_event_device *dev,
0056 ktime_t expires, bool force);
0057 extern void clockevents_handle_noop(struct clock_event_device *dev);
0058 extern int __clockevents_update_freq(struct clock_event_device *dev, u32 freq);
0059 extern ssize_t sysfs_get_uname(const char *buf, char *dst, size_t cnt);
0060
0061
0062 # ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
0063 extern int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu);
0064 extern void tick_install_broadcast_device(struct clock_event_device *dev, int cpu);
0065 extern int tick_is_broadcast_device(struct clock_event_device *dev);
0066 extern void tick_suspend_broadcast(void);
0067 extern void tick_resume_broadcast(void);
0068 extern bool tick_resume_check_broadcast(void);
0069 extern void tick_broadcast_init(void);
0070 extern void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast);
0071 extern int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq);
0072 extern struct tick_device *tick_get_broadcast_device(void);
0073 extern struct cpumask *tick_get_broadcast_mask(void);
0074 extern const struct clock_event_device *tick_get_wakeup_device(int cpu);
0075 # else
0076 static inline void tick_install_broadcast_device(struct clock_event_device *dev, int cpu) { }
0077 static inline int tick_is_broadcast_device(struct clock_event_device *dev) { return 0; }
0078 static inline int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu) { return 0; }
0079 static inline void tick_do_periodic_broadcast(struct clock_event_device *d) { }
0080 static inline void tick_suspend_broadcast(void) { }
0081 static inline void tick_resume_broadcast(void) { }
0082 static inline bool tick_resume_check_broadcast(void) { return false; }
0083 static inline void tick_broadcast_init(void) { }
0084 static inline int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq) { return -ENODEV; }
0085
0086
0087 static inline void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast)
0088 {
0089 dev->event_handler = tick_handle_periodic;
0090 }
0091 # endif
0092
0093 #else
0094 static inline void tick_suspend(void) { }
0095 static inline void tick_resume(void) { }
0096 #endif
0097
0098
0099 #ifdef CONFIG_TICK_ONESHOT
0100 extern void tick_setup_oneshot(struct clock_event_device *newdev,
0101 void (*handler)(struct clock_event_device *),
0102 ktime_t nextevt);
0103 extern int tick_program_event(ktime_t expires, int force);
0104 extern void tick_oneshot_notify(void);
0105 extern int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *));
0106 extern void tick_resume_oneshot(void);
0107 static inline bool tick_oneshot_possible(void) { return true; }
0108 extern int tick_oneshot_mode_active(void);
0109 extern void tick_clock_notify(void);
0110 extern int tick_check_oneshot_change(int allow_nohz);
0111 extern int tick_init_highres(void);
0112 #else
0113 static inline
0114 void tick_setup_oneshot(struct clock_event_device *newdev,
0115 void (*handler)(struct clock_event_device *),
0116 ktime_t nextevt) { BUG(); }
0117 static inline void tick_resume_oneshot(void) { BUG(); }
0118 static inline int tick_program_event(ktime_t expires, int force) { return 0; }
0119 static inline void tick_oneshot_notify(void) { }
0120 static inline bool tick_oneshot_possible(void) { return false; }
0121 static inline int tick_oneshot_mode_active(void) { return 0; }
0122 static inline void tick_clock_notify(void) { }
0123 static inline int tick_check_oneshot_change(int allow_nohz) { return 0; }
0124 #endif
0125
0126
0127 #if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
0128 extern void tick_broadcast_switch_to_oneshot(void);
0129 extern int tick_broadcast_oneshot_active(void);
0130 extern void tick_check_oneshot_broadcast_this_cpu(void);
0131 bool tick_broadcast_oneshot_available(void);
0132 extern struct cpumask *tick_get_broadcast_oneshot_mask(void);
0133 #else
0134 static inline void tick_broadcast_switch_to_oneshot(void) { }
0135 static inline int tick_broadcast_oneshot_active(void) { return 0; }
0136 static inline void tick_check_oneshot_broadcast_this_cpu(void) { }
0137 static inline bool tick_broadcast_oneshot_available(void) { return tick_oneshot_possible(); }
0138 #endif
0139
0140 #if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_HOTPLUG_CPU)
0141 extern void tick_broadcast_offline(unsigned int cpu);
0142 #else
0143 static inline void tick_broadcast_offline(unsigned int cpu) { }
0144 #endif
0145
0146
0147 #ifdef CONFIG_NO_HZ_FULL
0148 extern void tick_nohz_init(void);
0149 # else
0150 static inline void tick_nohz_init(void) { }
0151 #endif
0152
0153 #ifdef CONFIG_NO_HZ_COMMON
0154 extern unsigned long tick_nohz_active;
0155 extern void timers_update_nohz(void);
0156 # ifdef CONFIG_SMP
0157 extern struct static_key_false timers_migration_enabled;
0158 # endif
0159 #else
0160 static inline void timers_update_nohz(void) { }
0161 #define tick_nohz_active (0)
0162 #endif
0163
0164 DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
0165
0166 extern u64 get_next_timer_interrupt(unsigned long basej, u64 basem);
0167 void timer_clear_idle(void);
0168
0169 #define CLOCK_SET_WALL \
0170 (BIT(HRTIMER_BASE_REALTIME) | BIT(HRTIMER_BASE_REALTIME_SOFT) | \
0171 BIT(HRTIMER_BASE_TAI) | BIT(HRTIMER_BASE_TAI_SOFT))
0172
0173 #define CLOCK_SET_BOOT \
0174 (BIT(HRTIMER_BASE_BOOTTIME) | BIT(HRTIMER_BASE_BOOTTIME_SOFT))
0175
0176 void clock_was_set(unsigned int bases);
0177 void clock_was_set_delayed(void);
0178
0179 void hrtimers_resume_local(void);
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193 #if HZ < 34
0194 #define JIFFIES_SHIFT 6
0195 #elif HZ < 67
0196 #define JIFFIES_SHIFT 7
0197 #else
0198 #define JIFFIES_SHIFT 8
0199 #endif