Lines Matching full:alarm
6 * but triggers a RTC alarm if the box is suspend.
8 * This interface is influenced by the Android RTC Alarm timer
37 * struct alarm_base - Alarm timer bases
61 /* rtc timer and device for setting alarm wakeups at suspend */
152 * alarmtimer_enqueue - Adds an alarm timer to an alarm_base timerqueue
154 * @alarm: pointer to alarm being enqueued.
156 * Adds alarm to a alarm_base timerqueue
160 static void alarmtimer_enqueue(struct alarm_base *base, struct alarm *alarm) in alarmtimer_enqueue() argument
162 if (alarm->state & ALARMTIMER_STATE_ENQUEUED) in alarmtimer_enqueue()
163 timerqueue_del(&base->timerqueue, &alarm->node); in alarmtimer_enqueue()
165 timerqueue_add(&base->timerqueue, &alarm->node); in alarmtimer_enqueue()
166 alarm->state |= ALARMTIMER_STATE_ENQUEUED; in alarmtimer_enqueue()
170 * alarmtimer_dequeue - Removes an alarm timer from an alarm_base timerqueue
172 * @alarm: pointer to alarm being removed
174 * Removes alarm to a alarm_base timerqueue
178 static void alarmtimer_dequeue(struct alarm_base *base, struct alarm *alarm) in alarmtimer_dequeue() argument
180 if (!(alarm->state & ALARMTIMER_STATE_ENQUEUED)) in alarmtimer_dequeue()
183 timerqueue_del(&base->timerqueue, &alarm->node); in alarmtimer_dequeue()
184 alarm->state &= ~ALARMTIMER_STATE_ENQUEUED; in alarmtimer_dequeue()
189 * alarmtimer_fired - Handles alarm hrtimer being fired.
192 * When a alarm timer fires, this runs through the timerqueue to
193 * see which alarms expired, and runs those. If there are more alarm
195 * the next future alarm timer expires.
199 struct alarm *alarm = container_of(timer, struct alarm, timer); in alarmtimer_fired() local
200 struct alarm_base *base = &alarm_bases[alarm->type]; in alarmtimer_fired()
206 alarmtimer_dequeue(base, alarm); in alarmtimer_fired()
209 if (alarm->function) in alarmtimer_fired()
210 restart = alarm->function(alarm, base->get_ktime()); in alarmtimer_fired()
214 hrtimer_set_expires(&alarm->timer, alarm->node.expires); in alarmtimer_fired()
215 alarmtimer_enqueue(base, alarm); in alarmtimer_fired()
220 trace_alarmtimer_fired(alarm, base->get_ktime()); in alarmtimer_fired()
225 ktime_t alarm_expires_remaining(const struct alarm *alarm) in alarm_expires_remaining() argument
227 struct alarm_base *base = &alarm_bases[alarm->type]; in alarm_expires_remaining()
228 return ktime_sub(alarm->node.expires, base->get_ktime()); in alarm_expires_remaining()
296 /* Set alarm, if in the past reject suspend briefly to handle */ in alarmtimer_suspend()
326 __alarm_init(struct alarm *alarm, enum alarmtimer_type type, in __alarm_init() argument
327 enum alarmtimer_restart (*function)(struct alarm *, ktime_t)) in __alarm_init() argument
329 timerqueue_init(&alarm->node); in __alarm_init()
330 alarm->timer.function = alarmtimer_fired; in __alarm_init()
331 alarm->function = function; in __alarm_init()
332 alarm->type = type; in __alarm_init()
333 alarm->state = ALARMTIMER_STATE_INACTIVE; in __alarm_init()
337 * alarm_init - Initialize an alarm structure
338 * @alarm: ptr to alarm to be initialized
339 * @type: the type of the alarm
340 * @function: callback that is run when the alarm fires
342 void alarm_init(struct alarm *alarm, enum alarmtimer_type type, in alarm_init() argument
343 enum alarmtimer_restart (*function)(struct alarm *, ktime_t)) in alarm_init() argument
345 hrtimer_init(&alarm->timer, alarm_bases[type].base_clockid, in alarm_init()
347 __alarm_init(alarm, type, function); in alarm_init()
352 * alarm_start - Sets an absolute alarm to fire
353 * @alarm: ptr to alarm to set
354 * @start: time to run the alarm
356 void alarm_start(struct alarm *alarm, ktime_t start) in alarm_start() argument
358 struct alarm_base *base = &alarm_bases[alarm->type]; in alarm_start()
362 alarm->node.expires = start; in alarm_start()
363 alarmtimer_enqueue(base, alarm); in alarm_start()
364 hrtimer_start(&alarm->timer, alarm->node.expires, HRTIMER_MODE_ABS); in alarm_start()
367 trace_alarmtimer_start(alarm, base->get_ktime()); in alarm_start()
372 * alarm_start_relative - Sets a relative alarm to fire
373 * @alarm: ptr to alarm to set
374 * @start: time relative to now to run the alarm
376 void alarm_start_relative(struct alarm *alarm, ktime_t start) in alarm_start_relative() argument
378 struct alarm_base *base = &alarm_bases[alarm->type]; in alarm_start_relative()
381 alarm_start(alarm, start); in alarm_start_relative()
385 void alarm_restart(struct alarm *alarm) in alarm_restart() argument
387 struct alarm_base *base = &alarm_bases[alarm->type]; in alarm_restart()
391 hrtimer_set_expires(&alarm->timer, alarm->node.expires); in alarm_restart()
392 hrtimer_restart(&alarm->timer); in alarm_restart()
393 alarmtimer_enqueue(base, alarm); in alarm_restart()
399 * alarm_try_to_cancel - Tries to cancel an alarm timer
400 * @alarm: ptr to alarm to be canceled
405 int alarm_try_to_cancel(struct alarm *alarm) in alarm_try_to_cancel() argument
407 struct alarm_base *base = &alarm_bases[alarm->type]; in alarm_try_to_cancel()
412 ret = hrtimer_try_to_cancel(&alarm->timer); in alarm_try_to_cancel()
414 alarmtimer_dequeue(base, alarm); in alarm_try_to_cancel()
417 trace_alarmtimer_cancel(alarm, base->get_ktime()); in alarm_try_to_cancel()
424 * alarm_cancel - Spins trying to cancel an alarm timer until it is done
425 * @alarm: ptr to alarm to be canceled
429 int alarm_cancel(struct alarm *alarm) in alarm_cancel() argument
432 int ret = alarm_try_to_cancel(alarm); in alarm_cancel()
435 hrtimer_cancel_wait_running(&alarm->timer); in alarm_cancel()
441 u64 alarm_forward(struct alarm *alarm, ktime_t now, ktime_t interval) in alarm_forward() argument
446 delta = ktime_sub(now, alarm->node.expires); in alarm_forward()
456 alarm->node.expires = ktime_add_ns(alarm->node.expires, in alarm_forward()
459 if (alarm->node.expires > now) in alarm_forward()
468 alarm->node.expires = ktime_add_safe(alarm->node.expires, interval); in alarm_forward()
473 u64 alarm_forward_now(struct alarm *alarm, ktime_t interval) in alarm_forward_now() argument
475 struct alarm_base *base = &alarm_bases[alarm->type]; in alarm_forward_now()
477 return alarm_forward(alarm, base->get_ktime(), interval); in alarm_forward_now()
499 WARN_ONCE(1, "Invalid alarm type: %d\n", type); in alarmtimer_freezerset()
529 * @alarm: alarm that fired
531 * Posix timer callback for expired alarm timers.
533 static enum alarmtimer_restart alarm_handle_timer(struct alarm *alarm, in alarm_handle_timer() argument
536 struct k_itimer *ptr = container_of(alarm, struct k_itimer, in alarm_handle_timer()
537 it.alarm.alarmtimer); in alarm_handle_timer()
553 ptr->it_overrun += alarm_forward_now(alarm, ptr->it_interval); in alarm_handle_timer()
569 struct alarm *alarm = &timr->it.alarm.alarmtimer; in alarm_timer_rearm() local
571 timr->it_overrun += alarm_forward_now(alarm, timr->it_interval); in alarm_timer_rearm()
572 alarm_start(alarm, alarm->node.expires); in alarm_timer_rearm()
582 struct alarm *alarm = &timr->it.alarm.alarmtimer; in alarm_timer_forward() local
584 return alarm_forward(alarm, timr->it_interval, now); in alarm_timer_forward()
594 struct alarm *alarm = &timr->it.alarm.alarmtimer; in alarm_timer_remaining() local
596 return ktime_sub(alarm->node.expires, now); in alarm_timer_remaining()
605 return alarm_try_to_cancel(&timr->it.alarm.alarmtimer); in alarm_timer_try_to_cancel()
618 hrtimer_cancel_wait_running(&timr->it.alarm.alarmtimer.timer); in alarm_timer_wait_running()
631 struct alarm *alarm = &timr->it.alarm.alarmtimer; in alarm_timer_arm() local
632 struct alarm_base *base = &alarm_bases[alarm->type]; in alarm_timer_arm()
637 alarm->node.expires = expires; in alarm_timer_arm()
639 alarm_start(&timr->it.alarm.alarmtimer, expires); in alarm_timer_arm()
647 * Returns the granularity of underlying alarm base clock
664 * Provides the underlying alarm base time in a tasks time namespace.
682 * Provides the underlying alarm base time in the root namespace.
711 alarm_init(&new_timer->it.alarm.alarmtimer, type, alarm_handle_timer); in alarm_timer_create()
717 * @alarm: ptr to alarm that fired
721 static enum alarmtimer_restart alarmtimer_nsleep_wakeup(struct alarm *alarm, in alarmtimer_nsleep_wakeup() argument
724 struct task_struct *task = (struct task_struct *)alarm->data; in alarmtimer_nsleep_wakeup()
726 alarm->data = NULL; in alarmtimer_nsleep_wakeup()
734 * @alarm: ptr to alarmtimer
737 * Sets the alarm timer and sleeps until it is fired or interrupted.
739 static int alarmtimer_do_nsleep(struct alarm *alarm, ktime_t absexp, in alarmtimer_do_nsleep() argument
743 alarm->data = (void *)current; in alarmtimer_do_nsleep()
746 alarm_start(alarm, absexp); in alarmtimer_do_nsleep()
747 if (likely(alarm->data)) in alarmtimer_do_nsleep()
750 alarm_cancel(alarm); in alarmtimer_do_nsleep()
751 } while (alarm->data && !signal_pending(current)); in alarmtimer_do_nsleep()
755 destroy_hrtimer_on_stack(&alarm->timer); in alarmtimer_do_nsleep()
757 if (!alarm->data) in alarmtimer_do_nsleep()
779 alarm_init_on_stack(struct alarm *alarm, enum alarmtimer_type type, in alarm_init_on_stack() argument
780 enum alarmtimer_restart (*function)(struct alarm *, ktime_t)) in alarm_init_on_stack() argument
782 hrtimer_init_on_stack(&alarm->timer, alarm_bases[type].base_clockid, in alarm_init_on_stack()
784 __alarm_init(alarm, type, function); in alarm_init_on_stack()
797 struct alarm alarm; in alarm_timer_nsleep_restart() local
799 alarm_init_on_stack(&alarm, type, alarmtimer_nsleep_wakeup); in alarm_timer_nsleep_restart()
801 return alarmtimer_do_nsleep(&alarm, exp, type); in alarm_timer_nsleep_restart()
818 struct alarm alarm; in alarm_timer_nsleep() local
831 alarm_init_on_stack(&alarm, type, alarmtimer_nsleep_wakeup); in alarm_timer_nsleep()
843 ret = alarmtimer_do_nsleep(&alarm, exp, type); in alarm_timer_nsleep()
896 * alarmtimer_init - Initialize alarm timer code
898 * This function initializes the alarm bases and registers
908 /* Initialize alarm bases */ in alarmtimer_init()