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