1
2
3
4
5
6
7#include <linux/cpu.h>
8#include <linux/err.h>
9#include <linux/hrtimer.h>
10#include <linux/interrupt.h>
11#include <linux/percpu.h>
12#include <linux/profile.h>
13#include <linux/clockchips.h>
14#include <linux/sched.h>
15#include <linux/smp.h>
16#include <linux/module.h>
17
18#include "tick-internal.h"
19
20static struct hrtimer bctimer;
21
22static int bc_shutdown(struct clock_event_device *evt)
23{
24
25
26
27
28
29
30
31
32
33
34
35
36
37 hrtimer_try_to_cancel(&bctimer);
38 return 0;
39}
40
41
42
43
44
45static int bc_set_next(ktime_t expires, struct clock_event_device *bc)
46{
47 int bc_moved;
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64 RCU_NONIDLE({
65 bc_moved = hrtimer_try_to_cancel(&bctimer) >= 0;
66 if (bc_moved)
67 hrtimer_start(&bctimer, expires,
68 HRTIMER_MODE_ABS_PINNED);});
69 if (bc_moved) {
70
71 bc->bound_on = smp_processor_id();
72 } else if (bc->bound_on == smp_processor_id()) {
73 hrtimer_set_expires(&bctimer, expires);
74 }
75 return 0;
76}
77
78static struct clock_event_device ce_broadcast_hrtimer = {
79 .name = "bc_hrtimer",
80 .set_state_shutdown = bc_shutdown,
81 .set_next_ktime = bc_set_next,
82 .features = CLOCK_EVT_FEAT_ONESHOT |
83 CLOCK_EVT_FEAT_KTIME |
84 CLOCK_EVT_FEAT_HRTIMER,
85 .rating = 0,
86 .bound_on = -1,
87 .min_delta_ns = 1,
88 .max_delta_ns = KTIME_MAX,
89 .min_delta_ticks = 1,
90 .max_delta_ticks = ULONG_MAX,
91 .mult = 1,
92 .shift = 0,
93 .cpumask = cpu_all_mask,
94};
95
96static enum hrtimer_restart bc_handler(struct hrtimer *t)
97{
98 ce_broadcast_hrtimer.event_handler(&ce_broadcast_hrtimer);
99
100 if (clockevent_state_oneshot(&ce_broadcast_hrtimer))
101 if (ce_broadcast_hrtimer.next_event != KTIME_MAX)
102 return HRTIMER_RESTART;
103
104 return HRTIMER_NORESTART;
105}
106
107void tick_setup_hrtimer_broadcast(void)
108{
109 hrtimer_init(&bctimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
110 bctimer.function = bc_handler;
111 clockevents_register_device(&ce_broadcast_hrtimer);
112}
113