1
2
3
4
5
6
7
8
9
10
11
12
13
14#include <linux/cpu.h>
15#include <linux/err.h>
16#include <linux/hrtimer.h>
17#include <linux/interrupt.h>
18#include <linux/percpu.h>
19#include <linux/profile.h>
20#include <linux/sched.h>
21
22#include "tick-internal.h"
23
24
25
26
27int tick_program_event(ktime_t expires, int force)
28{
29 struct clock_event_device *dev = __this_cpu_read(tick_cpu_device.evtdev);
30
31 if (unlikely(expires == KTIME_MAX)) {
32
33
34
35 clockevents_switch_state(dev, CLOCK_EVT_STATE_ONESHOT_STOPPED);
36 dev->next_event = KTIME_MAX;
37 return 0;
38 }
39
40 if (unlikely(clockevent_state_oneshot_stopped(dev))) {
41
42
43
44
45 clockevents_switch_state(dev, CLOCK_EVT_STATE_ONESHOT);
46 }
47
48 return clockevents_program_event(dev, expires, force);
49}
50
51
52
53
54void tick_resume_oneshot(void)
55{
56 struct clock_event_device *dev = __this_cpu_read(tick_cpu_device.evtdev);
57
58 clockevents_switch_state(dev, CLOCK_EVT_STATE_ONESHOT);
59 clockevents_program_event(dev, ktime_get(), true);
60}
61
62
63
64
65void tick_setup_oneshot(struct clock_event_device *newdev,
66 void (*handler)(struct clock_event_device *),
67 ktime_t next_event)
68{
69 newdev->event_handler = handler;
70 clockevents_switch_state(newdev, CLOCK_EVT_STATE_ONESHOT);
71 clockevents_program_event(newdev, next_event, true);
72}
73
74
75
76
77int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *))
78{
79 struct tick_device *td = this_cpu_ptr(&tick_cpu_device);
80 struct clock_event_device *dev = td->evtdev;
81
82 if (!dev || !(dev->features & CLOCK_EVT_FEAT_ONESHOT) ||
83 !tick_device_is_functional(dev)) {
84
85 pr_info("Clockevents: could not switch to one-shot mode:");
86 if (!dev) {
87 pr_cont(" no tick device\n");
88 } else {
89 if (!tick_device_is_functional(dev))
90 pr_cont(" %s is not functional.\n", dev->name);
91 else
92 pr_cont(" %s does not support one-shot mode.\n",
93 dev->name);
94 }
95 return -EINVAL;
96 }
97
98 td->mode = TICKDEV_MODE_ONESHOT;
99 dev->event_handler = handler;
100 clockevents_switch_state(dev, CLOCK_EVT_STATE_ONESHOT);
101 tick_broadcast_switch_to_oneshot();
102 return 0;
103}
104
105
106
107
108
109
110int tick_oneshot_mode_active(void)
111{
112 unsigned long flags;
113 int ret;
114
115 local_irq_save(flags);
116 ret = __this_cpu_read(tick_cpu_device.mode) == TICKDEV_MODE_ONESHOT;
117 local_irq_restore(flags);
118
119 return ret;
120}
121
122#ifdef CONFIG_HIGH_RES_TIMERS
123
124
125
126
127
128int tick_init_highres(void)
129{
130 return tick_switch_to_oneshot(hrtimer_interrupt);
131}
132#endif
133