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 */
151 * alarmtimer_enqueue - Adds an alarm timer to an alarm_base timerqueue
153 * @alarm: pointer to alarm being enqueued.
155 * Adds alarm to a alarm_base timerqueue
159 static void alarmtimer_enqueue(struct alarm_base *base, struct alarm *alarm) in alarmtimer_enqueue() argument
161 if (alarm->state & ALARMTIMER_STATE_ENQUEUED) in alarmtimer_enqueue()
162 timerqueue_del(&base->timerqueue, &alarm->node); in alarmtimer_enqueue()
164 timerqueue_add(&base->timerqueue, &alarm->node); in alarmtimer_enqueue()
165 alarm->state |= ALARMTIMER_STATE_ENQUEUED; in alarmtimer_enqueue()
169 * alarmtimer_dequeue - Removes an alarm timer from an alarm_base timerqueue
171 * @alarm: pointer to alarm being removed
173 * Removes alarm to a alarm_base timerqueue
177 static void alarmtimer_dequeue(struct alarm_base *base, struct alarm *alarm) in alarmtimer_dequeue() argument
179 if (!(alarm->state & ALARMTIMER_STATE_ENQUEUED)) in alarmtimer_dequeue()
182 timerqueue_del(&base->timerqueue, &alarm->node); in alarmtimer_dequeue()
183 alarm->state &= ~ALARMTIMER_STATE_ENQUEUED; in alarmtimer_dequeue()
188 * alarmtimer_fired - Handles alarm hrtimer being fired.
191 * When a alarm timer fires, this runs through the timerqueue to
192 * see which alarms expired, and runs those. If there are more alarm
194 * the next future alarm timer expires.
198 struct alarm *alarm = container_of(timer, struct alarm, timer); in alarmtimer_fired() local
199 struct alarm_base *base = &alarm_bases[alarm->type]; in alarmtimer_fired()
202 alarmtimer_dequeue(base, alarm); in alarmtimer_fired()
204 if (alarm->function) in alarmtimer_fired()
205 alarm->function(alarm, base->get_ktime()); in alarmtimer_fired()
207 trace_alarmtimer_fired(alarm, base->get_ktime()); in alarmtimer_fired()
211 ktime_t alarm_expires_remaining(const struct alarm *alarm) in alarm_expires_remaining() argument
213 struct alarm_base *base = &alarm_bases[alarm->type]; in alarm_expires_remaining()
214 return ktime_sub(alarm->node.expires, base->get_ktime()); in alarm_expires_remaining()
282 * If the RTC alarm timer only supports a limited time offset, set the in alarmtimer_suspend()
283 * alarm time to the maximum supported value. in alarmtimer_suspend()
293 /* Set alarm, if in the past reject suspend briefly to handle */ in alarmtimer_suspend()
323 __alarm_init(struct alarm *alarm, enum alarmtimer_type type, in __alarm_init() argument
324 void (*function)(struct alarm *, ktime_t)) in __alarm_init() argument
326 timerqueue_init(&alarm->node); in __alarm_init()
327 alarm->function = function; in __alarm_init()
328 alarm->type = type; in __alarm_init()
329 alarm->state = ALARMTIMER_STATE_INACTIVE; in __alarm_init()
333 * alarm_init - Initialize an alarm structure
334 * @alarm: ptr to alarm to be initialized
335 * @type: the type of the alarm
336 * @function: callback that is run when the alarm fires
338 void alarm_init(struct alarm *alarm, enum alarmtimer_type type, in alarm_init() argument
339 void (*function)(struct alarm *, ktime_t)) in alarm_init() argument
341 hrtimer_setup(&alarm->timer, alarmtimer_fired, alarm_bases[type].base_clockid, in alarm_init()
343 __alarm_init(alarm, type, function); in alarm_init()
348 * alarm_start - Sets an absolute alarm to fire
349 * @alarm: ptr to alarm to set
350 * @start: time to run the alarm
352 void alarm_start(struct alarm *alarm, ktime_t start) in alarm_start() argument
354 struct alarm_base *base = &alarm_bases[alarm->type]; in alarm_start()
358 alarm->node.expires = start; in alarm_start()
359 alarmtimer_enqueue(base, alarm); in alarm_start()
360 hrtimer_start(&alarm->timer, alarm->node.expires, HRTIMER_MODE_ABS); in alarm_start()
363 trace_alarmtimer_start(alarm, base->get_ktime()); in alarm_start()
368 * alarm_start_relative - Sets a relative alarm to fire
369 * @alarm: ptr to alarm to set
370 * @start: time relative to now to run the alarm
372 void alarm_start_relative(struct alarm *alarm, ktime_t start) in alarm_start_relative() argument
374 struct alarm_base *base = &alarm_bases[alarm->type]; in alarm_start_relative()
377 alarm_start(alarm, start); in alarm_start_relative()
381 void alarm_restart(struct alarm *alarm) in alarm_restart() argument
383 struct alarm_base *base = &alarm_bases[alarm->type]; in alarm_restart()
387 hrtimer_set_expires(&alarm->timer, alarm->node.expires); in alarm_restart()
388 hrtimer_restart(&alarm->timer); in alarm_restart()
389 alarmtimer_enqueue(base, alarm); in alarm_restart()
395 * alarm_try_to_cancel - Tries to cancel an alarm timer
396 * @alarm: ptr to alarm to be canceled
401 int alarm_try_to_cancel(struct alarm *alarm) in alarm_try_to_cancel() argument
403 struct alarm_base *base = &alarm_bases[alarm->type]; in alarm_try_to_cancel()
408 ret = hrtimer_try_to_cancel(&alarm->timer); in alarm_try_to_cancel()
410 alarmtimer_dequeue(base, alarm); in alarm_try_to_cancel()
413 trace_alarmtimer_cancel(alarm, base->get_ktime()); in alarm_try_to_cancel()
420 * alarm_cancel - Spins trying to cancel an alarm timer until it is done
421 * @alarm: ptr to alarm to be canceled
425 int alarm_cancel(struct alarm *alarm) in alarm_cancel() argument
428 int ret = alarm_try_to_cancel(alarm); in alarm_cancel()
431 hrtimer_cancel_wait_running(&alarm->timer); in alarm_cancel()
437 u64 alarm_forward(struct alarm *alarm, ktime_t now, ktime_t interval) in alarm_forward() argument
442 delta = ktime_sub(now, alarm->node.expires); in alarm_forward()
452 alarm->node.expires = ktime_add_ns(alarm->node.expires, in alarm_forward()
455 if (alarm->node.expires > now) in alarm_forward()
464 alarm->node.expires = ktime_add_safe(alarm->node.expires, interval); in alarm_forward()
469 u64 alarm_forward_now(struct alarm *alarm, ktime_t interval) in alarm_forward_now() argument
471 struct alarm_base *base = &alarm_bases[alarm->type]; in alarm_forward_now()
473 return alarm_forward(alarm, base->get_ktime(), interval); in alarm_forward_now()
495 WARN_ONCE(1, "Invalid alarm type: %d\n", type); in alarmtimer_freezerset()
525 * @alarm: alarm that fired
528 * Posix timer callback for expired alarm timers.
532 static void alarm_handle_timer(struct alarm *alarm, ktime_t now) in alarm_handle_timer() argument
534 struct k_itimer *ptr = container_of(alarm, struct k_itimer, it.alarm.alarmtimer); in alarm_handle_timer()
546 struct alarm *alarm = &timr->it.alarm.alarmtimer; in alarm_timer_rearm() local
548 timr->it_overrun += alarm_forward_now(alarm, timr->it_interval); in alarm_timer_rearm()
549 alarm_start(alarm, alarm->node.expires); in alarm_timer_rearm()
559 struct alarm *alarm = &timr->it.alarm.alarmtimer; in alarm_timer_forward() local
561 return alarm_forward(alarm, timr->it_interval, now); in alarm_timer_forward()
571 struct alarm *alarm = &timr->it.alarm.alarmtimer; in alarm_timer_remaining() local
573 return ktime_sub(alarm->node.expires, now); in alarm_timer_remaining()
582 return alarm_try_to_cancel(&timr->it.alarm.alarmtimer); in alarm_timer_try_to_cancel()
595 hrtimer_cancel_wait_running(&timr->it.alarm.alarmtimer.timer); in alarm_timer_wait_running()
608 struct alarm *alarm = &timr->it.alarm.alarmtimer; in alarm_timer_arm() local
609 struct alarm_base *base = &alarm_bases[alarm->type]; in alarm_timer_arm()
614 alarm->node.expires = expires; in alarm_timer_arm()
616 alarm_start(&timr->it.alarm.alarmtimer, expires); in alarm_timer_arm()
624 * Returns the granularity of underlying alarm base clock
641 * Provides the underlying alarm base time in a tasks time namespace.
659 * Provides the underlying alarm base time in the root namespace.
688 alarm_init(&new_timer->it.alarm.alarmtimer, type, alarm_handle_timer); in alarm_timer_create()
694 * @alarm: ptr to alarm that fired
699 static void alarmtimer_nsleep_wakeup(struct alarm *alarm, ktime_t now) in alarmtimer_nsleep_wakeup() argument
701 struct task_struct *task = alarm->data; in alarmtimer_nsleep_wakeup()
703 alarm->data = NULL; in alarmtimer_nsleep_wakeup()
710 * @alarm: ptr to alarmtimer
712 * @type: alarm type (BOOTTIME/REALTIME).
714 * Sets the alarm timer and sleeps until it is fired or interrupted.
716 static int alarmtimer_do_nsleep(struct alarm *alarm, ktime_t absexp, in alarmtimer_do_nsleep() argument
720 alarm->data = (void *)current; in alarmtimer_do_nsleep()
723 alarm_start(alarm, absexp); in alarmtimer_do_nsleep()
724 if (likely(alarm->data)) in alarmtimer_do_nsleep()
727 alarm_cancel(alarm); in alarmtimer_do_nsleep()
728 } while (alarm->data && !signal_pending(current)); in alarmtimer_do_nsleep()
732 destroy_hrtimer_on_stack(&alarm->timer); in alarmtimer_do_nsleep()
734 if (!alarm->data) in alarmtimer_do_nsleep()
756 alarm_init_on_stack(struct alarm *alarm, enum alarmtimer_type type, in alarm_init_on_stack() argument
757 void (*function)(struct alarm *, ktime_t)) in alarm_init_on_stack() argument
759 hrtimer_setup_on_stack(&alarm->timer, alarmtimer_fired, alarm_bases[type].base_clockid, in alarm_init_on_stack()
761 __alarm_init(alarm, type, function); in alarm_init_on_stack()
774 struct alarm alarm; in alarm_timer_nsleep_restart() local
776 alarm_init_on_stack(&alarm, type, alarmtimer_nsleep_wakeup); in alarm_timer_nsleep_restart()
778 return alarmtimer_do_nsleep(&alarm, exp, type); in alarm_timer_nsleep_restart()
794 struct alarm alarm; in alarm_timer_nsleep() local
807 alarm_init_on_stack(&alarm, type, alarmtimer_nsleep_wakeup); in alarm_timer_nsleep()
819 ret = alarmtimer_do_nsleep(&alarm, exp, type); in alarm_timer_nsleep()
872 * alarmtimer_init - Initialize alarm timer code
874 * This function initializes the alarm bases and registers
884 /* Initialize alarm bases */ in alarmtimer_init()