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