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