Skip to content

Commit bffe424

Browse files
rlarocque2gregkh
authored andcommitted
alarmtimer: Return relative times in timer_gettime
commit e86fea7 upstream. Returns the time remaining for an alarm timer, rather than the time at which it is scheduled to expire. If the timer has already expired or it is not currently scheduled, the it_value's members are set to zero. This new behavior matches that of the other posix-timers and the POSIX specifications. This is a change in user-visible behavior, and may break existing applications. Hopefully, few users rely on the old incorrect behavior. Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@kernel.org> Cc: Richard Cochran <richardcochran@gmail.com> Cc: Prarit Bhargava <prarit@redhat.com> Cc: Sharvil Nanavati <sharvil@google.com> Signed-off-by: Richard Larocque <rlarocque@google.com> [jstultz: minor style tweak] Signed-off-by: John Stultz <john.stultz@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 79b9b72 commit bffe424

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

‎kernel/time/alarmtimer.c‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -541,18 +541,22 @@ static int alarm_timer_create(struct k_itimer *new_timer)
541541
* @new_timer: k_itimer pointer
542542
* @cur_setting: itimerspec data to fill
543543
*
544-
* Copies the itimerspec data out from the k_itimer
544+
* Copies out the current itimerspec data
545545
*/
546546
static void alarm_timer_get(struct k_itimer *timr,
547547
struct itimerspec *cur_setting)
548548
{
549-
memset(cur_setting, 0, sizeof(struct itimerspec));
549+
ktime_t relative_expiry_time =
550+
alarm_expires_remaining(&(timr->it.alarm.alarmtimer));
550551

551-
cur_setting->it_interval =
552-
ktime_to_timespec(timr->it.alarm.interval);
553-
cur_setting->it_value =
554-
ktime_to_timespec(timr->it.alarm.alarmtimer.node.expires);
555-
return;
552+
if (ktime_to_ns(relative_expiry_time) > 0) {
553+
cur_setting->it_value = ktime_to_timespec(relative_expiry_time);
554+
} else {
555+
cur_setting->it_value.tv_sec = 0;
556+
cur_setting->it_value.tv_nsec = 0;
557+
}
558+
559+
cur_setting->it_interval = ktime_to_timespec(timr->it.alarm.interval);
556560
}
557561

558562
/**

0 commit comments

Comments
 (0)