15 #include <linux/hrtimer.h>
17 #include <linux/module.h>
42 u64 clc = (
u64) latch << evt->shift;
67 enum clock_event_mode
mode)
69 if (dev->mode != mode) {
70 dev->set_mode(mode, dev);
77 if (mode == CLOCK_EVT_MODE_ONESHOT) {
96 #ifdef CONFIG_GENERIC_CLOCKEVENTS_MIN_ADJUST
99 #define MIN_DELTA_LIMIT (NSEC_PER_SEC / HZ)
107 static int clockevents_increase_min_delta(
struct clock_event_device *
dev)
110 if (dev->min_delta_ns >= MIN_DELTA_LIMIT) {
116 if (dev->min_delta_ns < 5000)
117 dev->min_delta_ns = 5000;
119 dev->min_delta_ns += dev->min_delta_ns >> 1;
121 if (dev->min_delta_ns > MIN_DELTA_LIMIT)
122 dev->min_delta_ns = MIN_DELTA_LIMIT;
125 dev->name ? dev->name :
"?",
126 (
unsigned long long) dev->min_delta_ns);
136 static int clockevents_program_min_delta(
struct clock_event_device *dev)
138 unsigned long long clc;
143 delta = dev->min_delta_ns;
146 if (dev->mode == CLOCK_EVT_MODE_SHUTDOWN)
150 clc = ((
unsigned long long) delta * dev->mult) >> dev->shift;
151 if (dev->set_next_event((
unsigned long) clc, dev) == 0)
160 if (clockevents_increase_min_delta(dev))
175 static int clockevents_program_min_delta(
struct clock_event_device *dev)
177 unsigned long long clc;
180 delta = dev->min_delta_ns;
183 if (dev->mode == CLOCK_EVT_MODE_SHUTDOWN)
187 clc = ((
unsigned long long) delta * dev->mult) >> dev->shift;
188 return dev->set_next_event((
unsigned long) clc, dev);
204 unsigned long long clc;
213 dev->next_event = expires;
215 if (dev->mode == CLOCK_EVT_MODE_SHUTDOWN)
219 if (dev->features & CLOCK_EVT_FEAT_KTIME)
220 return dev->set_next_ktime(expires, dev);
222 delta = ktime_to_ns(ktime_sub(expires,
ktime_get()));
224 return force ? clockevents_program_min_delta(dev) : -
ETIME;
226 delta =
min(delta, (int64_t) dev->max_delta_ns);
227 delta =
max(delta, (int64_t) dev->min_delta_ns);
229 clc = ((
unsigned long long) delta * dev->mult) >> dev->shift;
230 rc = dev->set_next_event((
unsigned long) clc, dev);
232 return (rc && force) ? clockevents_program_min_delta(dev) :
rc;
254 static void clockevents_do_notify(
unsigned long reason,
void *dev)
263 static void clockevents_notify_released(
void)
265 struct clock_event_device *
dev;
267 while (!list_empty(&clockevents_released)) {
269 struct clock_event_device,
list);
271 list_add(&dev->list, &clockevent_devices);
272 clockevents_do_notify(CLOCK_EVT_NOTIFY_ADD, dev);
284 BUG_ON(dev->mode != CLOCK_EVT_MODE_UNUSED);
292 list_add(&dev->list, &clockevent_devices);
293 clockevents_do_notify(CLOCK_EVT_NOTIFY_ADD, dev);
294 clockevents_notify_released();
304 if (!(dev->features & CLOCK_EVT_FEAT_ONESHOT))
312 sec = dev->max_delta_ticks;
316 else if (sec > 600 && dev->max_delta_ticks >
UINT_MAX)
319 clockevents_calc_mult_shift(dev, freq, sec);
334 u32 freq,
unsigned long min_delta,
335 unsigned long max_delta)
337 dev->min_delta_ticks = min_delta;
338 dev->max_delta_ticks = max_delta;
357 if (dev->mode != CLOCK_EVT_MODE_ONESHOT)
378 struct clock_event_device *
new)
390 list_add(&old->list, &clockevents_released);
394 BUG_ON(new->mode != CLOCK_EVT_MODE_UNUSED);
405 struct clock_event_device *
dev;
417 struct clock_event_device *
dev;
424 #ifdef CONFIG_GENERIC_CLOCKEVENTS
430 struct clock_event_device *
dev, *
tmp;
435 clockevents_do_notify(reason, arg);
438 case CLOCK_EVT_NOTIFY_CPU_DEAD:
451 cpumask_weight(dev->cpumask) == 1 &&
453 BUG_ON(dev->mode != CLOCK_EVT_MODE_UNUSED);