mirror of
https://github.com/torvalds/linux.git
synced 2026-07-28 01:55:51 +02:00
alarmtimer: Provide alarm_start_timer()
Alarm timers utilize hrtimers for normal operation and only switch to the RTC on suspend. In order to catch already expired timers early and without going through a timer interrupt cycle, provide a new start function which internally uses hrtimer_start_range_ns_user(). If hrtimer_start_range_ns_user() detects an already expired timer, it does not queue it. In that case remove the timer from the alarm base as well. Return the status queued or not back to the caller to handle the early expiry. Signed-off-by: Thomas Gleixner <tglx@kernel.org> Reviewed-by: Frederic Weisbecker <frederic@kernel.org> Acked-by: John Stultz <jstultz@google.com> Link: https://patch.msgid.link/20260408114952.332822525@kernel.org
This commit is contained in:
parent
acc071343d
commit
183d00b727
|
|
@ -42,8 +42,14 @@ struct alarm {
|
|||
void *data;
|
||||
};
|
||||
|
||||
static __always_inline ktime_t alarm_get_expires(struct alarm *alarm)
|
||||
{
|
||||
return alarm->node.expires;
|
||||
}
|
||||
|
||||
void alarm_init(struct alarm *alarm, enum alarmtimer_type type,
|
||||
void (*function)(struct alarm *, ktime_t));
|
||||
bool alarm_start_timer(struct alarm *alarm, ktime_t expires, bool relative);
|
||||
void alarm_start(struct alarm *alarm, ktime_t start);
|
||||
void alarm_start_relative(struct alarm *alarm, ktime_t start);
|
||||
void alarm_restart(struct alarm *alarm);
|
||||
|
|
|
|||
|
|
@ -369,6 +369,34 @@ void alarm_start_relative(struct alarm *alarm, ktime_t start)
|
|||
}
|
||||
EXPORT_SYMBOL_GPL(alarm_start_relative);
|
||||
|
||||
/**
|
||||
* alarm_start_timer - Sets an alarm to fire
|
||||
* @alarm: Pointer to alarm to set
|
||||
* @expires: Expiry time
|
||||
* @relative: True if @expires is relative
|
||||
*
|
||||
* Returns: True if the alarm was queued. False if it already expired
|
||||
*/
|
||||
bool alarm_start_timer(struct alarm *alarm, ktime_t expires, bool relative)
|
||||
{
|
||||
struct alarm_base *base = &alarm_bases[alarm->type];
|
||||
|
||||
if (relative)
|
||||
expires = ktime_add_safe(expires, base->get_ktime());
|
||||
|
||||
trace_alarmtimer_start(alarm, base->get_ktime());
|
||||
|
||||
guard(spinlock_irqsave)(&base->lock);
|
||||
alarm->node.expires = expires;
|
||||
alarmtimer_enqueue(base, alarm);
|
||||
if (!hrtimer_start_range_ns_user(&alarm->timer, expires, 0, HRTIMER_MODE_ABS)) {
|
||||
alarmtimer_dequeue(base, alarm);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(alarm_start_timer);
|
||||
|
||||
void alarm_restart(struct alarm *alarm)
|
||||
{
|
||||
struct alarm_base *base = &alarm_bases[alarm->type];
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user