Skip to content

Commit 20f1338

Browse files
KAGA-KOKOFrederic Weisbecker
authored andcommitted
posix-timers: Consolidate timer setup
hrtimer based and CPU timers have their own way to install the new interval and to reset overrun and signal handling related data. Create a helper function and do the same operation for all variants. This also makes the handling of the interval consistent. It's only stored when the timer is actually armed, i.e. timer->it_value != 0. Before that it was stored unconditionally for posix CPU timers and conditionally for the other posix timers. Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Frederic Weisbecker <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]>
1 parent 52dea0a commit 20f1338

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

kernel/time/posix-cpu-timers.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -714,21 +714,8 @@ static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags,
714714
}
715715

716716
unlock_task_sighand(p, &flags);
717-
/*
718-
* Install the new reload setting, and
719-
* set up the signal and overrun bookkeeping.
720-
*/
721-
timer->it_interval = timespec64_to_ktime(new->it_interval);
722717

723-
/*
724-
* This acts as a modification timestamp for the timer,
725-
* so any automatic reload attempt will punt on seeing
726-
* that we have reset the timer manually.
727-
*/
728-
timer->it_requeue_pending = (timer->it_requeue_pending + 2) &
729-
~REQUEUE_PENDING;
730-
timer->it_overrun_last = 0;
731-
timer->it_overrun = -1;
718+
posix_timer_set_common(timer, new);
732719

733720
/*
734721
* If the new expiry time was already in the past the timer was not

kernel/time/posix-timers.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,23 @@ static struct k_itimer *timer_wait_running(struct k_itimer *timer,
856856
return lock_timer(timer_id, flags);
857857
}
858858

859+
/*
860+
* Set up the new interval and reset the signal delivery data
861+
*/
862+
void posix_timer_set_common(struct k_itimer *timer, struct itimerspec64 *new_setting)
863+
{
864+
if (new_setting->it_value.tv_sec || new_setting->it_value.tv_nsec)
865+
timer->it_interval = timespec64_to_ktime(new_setting->it_interval);
866+
else
867+
timer->it_interval = 0;
868+
869+
/* Prevent reloading in case there is a signal pending */
870+
timer->it_requeue_pending = (timer->it_requeue_pending + 2) & ~REQUEUE_PENDING;
871+
/* Reset overrun accounting */
872+
timer->it_overrun_last = 0;
873+
timer->it_overrun = -1LL;
874+
}
875+
859876
/* Set a POSIX.1b interval timer. */
860877
int common_timer_set(struct k_itimer *timr, int flags,
861878
struct itimerspec64 *new_setting,
@@ -878,16 +895,12 @@ int common_timer_set(struct k_itimer *timr, int flags,
878895
return TIMER_RETRY;
879896

880897
timr->it_active = 0;
881-
timr->it_requeue_pending = (timr->it_requeue_pending + 2) &
882-
~REQUEUE_PENDING;
883-
timr->it_overrun_last = 0;
884-
timr->it_overrun = -1LL;
898+
posix_timer_set_common(timr, new_setting);
885899

886-
/* Switch off the timer when it_value is zero */
900+
/* Keep timer disarmed when it_value is zero */
887901
if (!new_setting->it_value.tv_sec && !new_setting->it_value.tv_nsec)
888902
return 0;
889903

890-
timr->it_interval = timespec64_to_ktime(new_setting->it_interval);
891904
expires = timespec64_to_ktime(new_setting->it_value);
892905
if (flags & TIMER_ABSTIME)
893906
expires = timens_ktime_to_host(timr->it_clock, expires);

kernel/time/posix-timers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,5 @@ void common_timer_get(struct k_itimer *timr, struct itimerspec64 *cur_setting);
4242
int common_timer_set(struct k_itimer *timr, int flags,
4343
struct itimerspec64 *new_setting,
4444
struct itimerspec64 *old_setting);
45+
void posix_timer_set_common(struct k_itimer *timer, struct itimerspec64 *new_setting);
4546
int common_timer_del(struct k_itimer *timer);

0 commit comments

Comments
 (0)