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 return clockevents_program_event(dev, expires, force);
32}
33
34
35
36
37void tick_resume_oneshot(void)
38{
39 struct clock_event_device *dev = __this_cpu_read(tick_cpu_device.evtdev);
40
41 clockevents_set_mode(dev, CLOCK_EVT_MODE_ONESHOT);
42 clockevents_program_event(dev, ktime_get(), true);
43}
44
45
46
47
48void tick_setup_oneshot(struct clock_event_device *newdev,
49 void (*handler)(struct clock_event_device *),
50 ktime_t next_event)
51{
52 newdev->event_handler = handler;
53 clockevents_set_mode(newdev, CLOCK_EVT_MODE_ONESHOT);
54 clockevents_program_event(newdev, next_event, true);
55}
56
57
58
59
60int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *))
61{
62 struct tick_device *td = &__get_cpu_var(tick_cpu_device);
63 struct clock_event_device *dev = td->evtdev;
64
65 if (!dev || !(dev->features & CLOCK_EVT_FEAT_ONESHOT) ||
66 !tick_device_is_functional(dev)) {
67
68 printk(KERN_INFO "Clockevents: "
69 "could not switch to one-shot mode:");
70 if (!dev) {
71 printk(" no tick device\n");
72 } else {
73 if (!tick_device_is_functional(dev))
74 printk(" %s is not functional.\n", dev->name);
75 else
76 printk(" %s does not support one-shot mode.\n",
77 dev->name);
78 }
79 return -EINVAL;
80 }
81
82 td->mode = TICKDEV_MODE_ONESHOT;
83 dev->event_handler = handler;
84 clockevents_set_mode(dev, CLOCK_EVT_MODE_ONESHOT);
85 tick_broadcast_switch_to_oneshot();
86 return 0;
87}
88
89
90
91
92
93
94int tick_oneshot_mode_active(void)
95{
96 unsigned long flags;
97 int ret;
98
99 local_irq_save(flags);
100 ret = __this_cpu_read(tick_cpu_device.mode) == TICKDEV_MODE_ONESHOT;
101 local_irq_restore(flags);
102
103 return ret;
104}
105
106#ifdef CONFIG_HIGH_RES_TIMERS
107
108
109
110
111
112int tick_init_highres(void)
113{
114 return tick_switch_to_oneshot(hrtimer_interrupt);
115}
116#endif
117