License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[linux-block.git] / kernel / time / tick-internal.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
f8381cba
TG
2/*
3 * tick internal variable and functions used by low/high res code
4 */
e2830b5c
TH
5#include <linux/hrtimer.h>
6#include <linux/tick.h>
6441402b 7
8b094cd0 8#include "timekeeping.h"
c1797baf 9#include "tick-sched.h"
8b094cd0 10
9f083b74 11#ifdef CONFIG_GENERIC_CLOCKEVENTS
6441402b 12
3ae7a939
IM
13# define TICK_DO_TIMER_NONE -1
14# define TICK_DO_TIMER_BOOT -2
6441402b 15
f8381cba 16DECLARE_PER_CPU(struct tick_device, tick_cpu_device);
f8381cba
TG
17extern ktime_t tick_next_period;
18extern ktime_t tick_period;
d3ed7824 19extern int tick_do_timer_cpu __read_mostly;
f8381cba
TG
20
21extern void tick_setup_periodic(struct clock_event_device *dev, int broadcast);
22extern void tick_handle_periodic(struct clock_event_device *dev);
7172a286 23extern void tick_check_new_device(struct clock_event_device *dev);
a49b116d 24extern void tick_shutdown(unsigned int cpu);
8c53daf6 25extern void tick_suspend(void);
f46481d0 26extern void tick_resume(void);
03e13cf5
TG
27extern bool tick_check_replacement(struct clock_event_device *curdev,
28 struct clock_event_device *newdev);
29extern void tick_install_replacement(struct clock_event_device *dev);
c1797baf 30extern int tick_is_oneshot_available(void);
7270d11c 31extern struct tick_device *tick_get_device(int cpu);
f8381cba 32
554ef387 33extern int clockevents_tick_resume(struct clock_event_device *dev);
b7475eb5
TG
34/* Check, if the device is functional or a dummy for broadcast */
35static inline int tick_device_is_functional(struct clock_event_device *dev)
36{
37 return !(dev->features & CLOCK_EVT_FEAT_DUMMY);
38}
2344abbc 39
d7eb231c
TG
40static inline enum clock_event_state clockevent_get_state(struct clock_event_device *dev)
41{
be3ef76e 42 return dev->state_use_accessors;
d7eb231c
TG
43}
44
45static inline void clockevent_set_state(struct clock_event_device *dev,
46 enum clock_event_state state)
47{
be3ef76e 48 dev->state_use_accessors = state;
d7eb231c
TG
49}
50
b7475eb5 51extern void clockevents_shutdown(struct clock_event_device *dev);
c1797baf
TG
52extern void clockevents_exchange_device(struct clock_event_device *old,
53 struct clock_event_device *new);
d7eb231c
TG
54extern void clockevents_switch_state(struct clock_event_device *dev,
55 enum clock_event_state state);
7270d11c
TG
56extern int clockevents_program_event(struct clock_event_device *dev,
57 ktime_t expires, bool force);
c1797baf 58extern void clockevents_handle_noop(struct clock_event_device *dev);
b7475eb5 59extern int __clockevents_update_freq(struct clock_event_device *dev, u32 freq);
891292a7 60extern ssize_t sysfs_get_uname(const char *buf, char *dst, size_t cnt);
79bf2bb3 61
b7475eb5 62/* Broadcasting support */
3ae7a939 63# ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
f8381cba 64extern int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu);
7172a286 65extern void tick_install_broadcast_device(struct clock_event_device *dev);
f8381cba 66extern int tick_is_broadcast_device(struct clock_event_device *dev);
a49b116d 67extern void tick_shutdown_broadcast(unsigned int cpu);
6321dd60 68extern void tick_suspend_broadcast(void);
f46481d0
TG
69extern void tick_resume_broadcast(void);
70extern bool tick_resume_check_broadcast(void);
b352bc1c 71extern void tick_broadcast_init(void);
b7475eb5
TG
72extern void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast);
73extern int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq);
c1797baf
TG
74extern struct tick_device *tick_get_broadcast_device(void);
75extern struct cpumask *tick_get_broadcast_mask(void);
3ae7a939 76# else /* !CONFIG_GENERIC_CLOCKEVENTS_BROADCAST: */
b7475eb5
TG
77static inline void tick_install_broadcast_device(struct clock_event_device *dev) { }
78static inline int tick_is_broadcast_device(struct clock_event_device *dev) { return 0; }
79static inline int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu) { return 0; }
f8381cba 80static inline void tick_do_periodic_broadcast(struct clock_event_device *d) { }
a49b116d 81static inline void tick_shutdown_broadcast(unsigned int cpu) { }
6321dd60 82static inline void tick_suspend_broadcast(void) { }
f46481d0
TG
83static inline void tick_resume_broadcast(void) { }
84static inline bool tick_resume_check_broadcast(void) { return false; }
b352bc1c 85static inline void tick_broadcast_init(void) { }
b7475eb5 86static inline int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq) { return -ENODEV; }
f8381cba 87
b7475eb5
TG
88/* Set the periodic handler in non broadcast mode */
89static inline void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast)
f8381cba
TG
90{
91 dev->event_handler = tick_handle_periodic;
92}
3ae7a939
IM
93# endif /* !CONFIG_GENERIC_CLOCKEVENTS_BROADCAST */
94
95#else /* !GENERIC_CLOCKEVENTS: */
96static inline void tick_suspend(void) { }
97static inline void tick_resume(void) { }
98#endif /* !GENERIC_CLOCKEVENTS */
99
100/* Oneshot related functions */
101#ifdef CONFIG_TICK_ONESHOT
102extern void tick_setup_oneshot(struct clock_event_device *newdev,
103 void (*handler)(struct clock_event_device *),
104 ktime_t nextevt);
105extern int tick_program_event(ktime_t expires, int force);
106extern void tick_oneshot_notify(void);
107extern int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *));
108extern void tick_resume_oneshot(void);
109static inline bool tick_oneshot_possible(void) { return true; }
110extern int tick_oneshot_mode_active(void);
111extern void tick_clock_notify(void);
112extern int tick_check_oneshot_change(int allow_nohz);
113extern int tick_init_highres(void);
114#else /* !CONFIG_TICK_ONESHOT: */
115static inline
116void tick_setup_oneshot(struct clock_event_device *newdev,
117 void (*handler)(struct clock_event_device *),
118 ktime_t nextevt) { BUG(); }
119static inline void tick_resume_oneshot(void) { BUG(); }
120static inline int tick_program_event(ktime_t expires, int force) { return 0; }
121static inline void tick_oneshot_notify(void) { }
122static inline bool tick_oneshot_possible(void) { return false; }
123static inline int tick_oneshot_mode_active(void) { return 0; }
124static inline void tick_clock_notify(void) { }
125static inline int tick_check_oneshot_change(int allow_nohz) { return 0; }
126#endif /* !CONFIG_TICK_ONESHOT */
f8381cba 127
b7475eb5
TG
128/* Functions related to oneshot broadcasting */
129#if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
b7475eb5 130extern void tick_broadcast_switch_to_oneshot(void);
a49b116d 131extern void tick_shutdown_broadcast_oneshot(unsigned int cpu);
b7475eb5
TG
132extern int tick_broadcast_oneshot_active(void);
133extern void tick_check_oneshot_broadcast_this_cpu(void);
134bool tick_broadcast_oneshot_available(void);
c1797baf 135extern struct cpumask *tick_get_broadcast_oneshot_mask(void);
3ae7a939 136#else /* !(BROADCAST && ONESHOT): */
b7475eb5 137static inline void tick_broadcast_switch_to_oneshot(void) { }
a49b116d 138static inline void tick_shutdown_broadcast_oneshot(unsigned int cpu) { }
b7475eb5
TG
139static inline int tick_broadcast_oneshot_active(void) { return 0; }
140static inline void tick_check_oneshot_broadcast_this_cpu(void) { }
141static inline bool tick_broadcast_oneshot_available(void) { return tick_oneshot_possible(); }
3ae7a939 142#endif /* !(BROADCAST && ONESHOT) */
7cf37e87 143
b7475eb5
TG
144/* NO_HZ_FULL internal */
145#ifdef CONFIG_NO_HZ_FULL
146extern void tick_nohz_init(void);
147# else
148static inline void tick_nohz_init(void) { }
149#endif
c1ad348b 150
bc7a34b8
TG
151#ifdef CONFIG_NO_HZ_COMMON
152extern unsigned long tick_nohz_active;
153#else
154#define tick_nohz_active (0)
155#endif
156
157#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
683be13a 158extern void timers_update_migration(bool update_nohz);
bc7a34b8 159#else
683be13a 160static inline void timers_update_migration(bool update_nohz) { }
bc7a34b8
TG
161#endif
162
163DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
164
c1ad348b 165extern u64 get_next_timer_interrupt(unsigned long basej, u64 basem);
a683f390 166void timer_clear_idle(void);