aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorTodd Poynor <toddpoynor@google.com>2013-05-15 17:38:11 -0400
committerJohn Stultz <john.stultz@linaro.org>2013-05-29 15:57:34 -0400
commit6cffe00f7d4e24679eae6b7aae4caaf915288256 (patch)
tree3613480b8eefec8b865ba9d3acbb8ecb7ffe4def /kernel
parent3565184ed0c1ea46bea5b792da5f72a83c43e49b (diff)
alarmtimer: Add functions for timerfd support
Add functions needed for hooking up alarmtimer to timerfd: * alarm_restart: Similar to hrtimer_restart, restart an alarmtimer after the expires time has already been updated (as with alarm_forward). * alarm_forward_now: Similar to hrtimer_forward_now, move the expires time forward to an interval from the current time of the associated clock. * alarm_start_relative: Start an alarmtimer with an expires time relative to the current time of the associated clock. * alarm_expires_remaining: Similar to hrtimer_expires_remaining, return the amount of time remaining until alarm expiry. Signed-off-by: Todd Poynor <toddpoynor@google.com> Signed-off-by: John Stultz <john.stultz@linaro.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/time/alarmtimer.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index f11d83b12949..3e5cba274475 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -199,6 +199,12 @@ static enum hrtimer_restart alarmtimer_fired(struct hrtimer *timer)
199 199
200} 200}
201 201
202ktime_t alarm_expires_remaining(const struct alarm *alarm)
203{
204 struct alarm_base *base = &alarm_bases[alarm->type];
205 return ktime_sub(alarm->node.expires, base->gettime());
206}
207
202#ifdef CONFIG_RTC_CLASS 208#ifdef CONFIG_RTC_CLASS
203/** 209/**
204 * alarmtimer_suspend - Suspend time callback 210 * alarmtimer_suspend - Suspend time callback
@@ -305,7 +311,7 @@ void alarm_init(struct alarm *alarm, enum alarmtimer_type type,
305} 311}
306 312
307/** 313/**
308 * alarm_start - Sets an alarm to fire 314 * alarm_start - Sets an absolute alarm to fire
309 * @alarm: ptr to alarm to set 315 * @alarm: ptr to alarm to set
310 * @start: time to run the alarm 316 * @start: time to run the alarm
311 */ 317 */
@@ -325,6 +331,31 @@ int alarm_start(struct alarm *alarm, ktime_t start)
325} 331}
326 332
327/** 333/**
334 * alarm_start_relative - Sets a relative alarm to fire
335 * @alarm: ptr to alarm to set
336 * @start: time relative to now to run the alarm
337 */
338int alarm_start_relative(struct alarm *alarm, ktime_t start)
339{
340 struct alarm_base *base = &alarm_bases[alarm->type];
341
342 start = ktime_add(start, base->gettime());
343 return alarm_start(alarm, start);
344}
345
346void alarm_restart(struct alarm *alarm)
347{
348 struct alarm_base *base = &alarm_bases[alarm->type];
349 unsigned long flags;
350
351 spin_lock_irqsave(&base->lock, flags);
352 hrtimer_set_expires(&alarm->timer, alarm->node.expires);
353 hrtimer_restart(&alarm->timer);
354 alarmtimer_enqueue(base, alarm);
355 spin_unlock_irqrestore(&base->lock, flags);
356}
357
358/**
328 * alarm_try_to_cancel - Tries to cancel an alarm timer 359 * alarm_try_to_cancel - Tries to cancel an alarm timer
329 * @alarm: ptr to alarm to be canceled 360 * @alarm: ptr to alarm to be canceled
330 * 361 *
@@ -394,6 +425,12 @@ u64 alarm_forward(struct alarm *alarm, ktime_t now, ktime_t interval)
394 return overrun; 425 return overrun;
395} 426}
396 427
428u64 alarm_forward_now(struct alarm *alarm, ktime_t interval)
429{
430 struct alarm_base *base = &alarm_bases[alarm->type];
431
432 return alarm_forward(alarm, base->gettime(), interval);
433}
397 434
398 435
399 436