tick: Simplify tick-internal.h
[cascardo/linux.git] / kernel / time / tick-internal.h
1 /*
2  * tick internal variable and functions used by low/high res code
3  */
4 #include <linux/hrtimer.h>
5 #include <linux/tick.h>
6
7 #include "timekeeping.h"
8
9 #ifdef CONFIG_GENERIC_CLOCKEVENTS
10
11 #define TICK_DO_TIMER_NONE      -1
12 #define TICK_DO_TIMER_BOOT      -2
13
14 DECLARE_PER_CPU(struct tick_device, tick_cpu_device);
15 extern ktime_t tick_next_period;
16 extern ktime_t tick_period;
17 extern int tick_do_timer_cpu __read_mostly;
18
19 extern void tick_setup_periodic(struct clock_event_device *dev, int broadcast);
20 extern void tick_handle_periodic(struct clock_event_device *dev);
21 extern void tick_check_new_device(struct clock_event_device *dev);
22 extern void tick_handover_do_timer(int *cpup);
23 extern void tick_shutdown(unsigned int *cpup);
24 extern void tick_suspend(void);
25 extern void tick_resume(void);
26 extern bool tick_check_replacement(struct clock_event_device *curdev,
27                                    struct clock_event_device *newdev);
28 extern void tick_install_replacement(struct clock_event_device *dev);
29
30 extern int clockevents_tick_resume(struct clock_event_device *dev);
31 /* Check, if the device is functional or a dummy for broadcast */
32 static inline int tick_device_is_functional(struct clock_event_device *dev)
33 {
34         return !(dev->features & CLOCK_EVT_FEAT_DUMMY);
35 }
36
37 extern void clockevents_shutdown(struct clock_event_device *dev);
38 extern int __clockevents_update_freq(struct clock_event_device *dev, u32 freq);
39 extern ssize_t sysfs_get_uname(const char *buf, char *dst, size_t cnt);
40 #endif /* GENERIC_CLOCKEVENTS */
41
42 /* Oneshot related functions */
43 #ifdef CONFIG_TICK_ONESHOT
44 extern void tick_setup_oneshot(struct clock_event_device *newdev,
45                                void (*handler)(struct clock_event_device *),
46                                ktime_t nextevt);
47 extern int tick_program_event(ktime_t expires, int force);
48 extern void tick_oneshot_notify(void);
49 extern int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *));
50 extern void tick_resume_oneshot(void);
51 static inline bool tick_oneshot_possible(void) { return true; }
52 #else /* !ONESHOT */
53 static inline
54 void tick_setup_oneshot(struct clock_event_device *newdev,
55                         void (*handler)(struct clock_event_device *),
56                         ktime_t nextevt) { BUG(); }
57 static inline void tick_resume_oneshot(void) { BUG(); }
58 static inline int tick_program_event(ktime_t expires, int force) { return 0; }
59 static inline void tick_oneshot_notify(void) { }
60 static inline bool tick_oneshot_possible(void) { return false; }
61 #endif /* !TICK_ONESHOT */
62
63 /* Broadcasting support */
64 #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
65 extern int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu);
66 extern void tick_install_broadcast_device(struct clock_event_device *dev);
67 extern int tick_is_broadcast_device(struct clock_event_device *dev);
68 extern void tick_broadcast_on_off(unsigned long reason, int *oncpu);
69 extern void tick_shutdown_broadcast(unsigned int *cpup);
70 extern void tick_suspend_broadcast(void);
71 extern int tick_resume_broadcast(void);
72 extern void tick_broadcast_init(void);
73 extern void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast);
74 extern int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq);
75 #else /* !BROADCAST */
76 static inline void tick_install_broadcast_device(struct clock_event_device *dev) { }
77 static inline int tick_is_broadcast_device(struct clock_event_device *dev) { return 0; }
78 static inline int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu) { return 0; }
79 static inline void tick_do_periodic_broadcast(struct clock_event_device *d) { }
80 static inline void tick_broadcast_on_off(unsigned long reason, int *oncpu) { }
81 static inline void tick_shutdown_broadcast(unsigned int *cpup) { }
82 static inline void tick_suspend_broadcast(void) { }
83 static inline int tick_resume_broadcast(void) { return 0; }
84 static inline void tick_broadcast_init(void) { }
85 static inline int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq) { return -ENODEV; }
86
87 /* Set the periodic handler in non broadcast mode */
88 static inline void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast)
89 {
90         dev->event_handler = tick_handle_periodic;
91 }
92 #endif /* !BROADCAST */
93
94 /* Functions related to oneshot broadcasting */
95 #if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
96 extern void tick_broadcast_setup_oneshot(struct clock_event_device *bc);
97 extern int tick_broadcast_oneshot_control(unsigned long reason);
98 extern void tick_broadcast_switch_to_oneshot(void);
99 extern void tick_shutdown_broadcast_oneshot(unsigned int *cpup);
100 extern int tick_resume_broadcast_oneshot(struct clock_event_device *bc);
101 extern int tick_broadcast_oneshot_active(void);
102 extern void tick_check_oneshot_broadcast_this_cpu(void);
103 bool tick_broadcast_oneshot_available(void);
104 #else /* BROADCAST && ONESHOT */
105 static inline void tick_broadcast_setup_oneshot(struct clock_event_device *bc) { BUG(); }
106 static inline int tick_broadcast_oneshot_control(unsigned long reason) { return 0; }
107 static inline void tick_broadcast_switch_to_oneshot(void) { }
108 static inline void tick_shutdown_broadcast_oneshot(unsigned int *cpup) { }
109 static inline int tick_resume_broadcast_oneshot(struct clock_event_device *bc) { return 0; }
110 static inline int tick_broadcast_oneshot_active(void) { return 0; }
111 static inline void tick_check_oneshot_broadcast_this_cpu(void) { }
112 static inline bool tick_broadcast_oneshot_available(void) { return tick_oneshot_possible(); }
113 #endif /* !BROADCAST && ONESHOT */
114
115 /* NO_HZ_FULL internal */
116 #ifdef CONFIG_NO_HZ_FULL
117 extern void tick_nohz_init(void);
118 # else
119 static inline void tick_nohz_init(void) { }
120 #endif