Skip to content

Commit 80105cd

Browse files
committed
posix-timers: Move interval out of the union
Preparatory patch to unify the alarm timer and hrtimer based posix interval timer handling. The interval is used as a criteria for rearming decisions so moving it out of the clock specific data structures allows later unification. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: John Stultz <john.stultz@linaro.org> Link: http://lkml.kernel.org/r/20170530211656.563922908@linutronix.de
1 parent af888d6 commit 80105cd

3 files changed

Lines changed: 18 additions & 19 deletions

File tree

‎include/linux/posix-timers.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ struct cpu_timer_list {
6363
* @it_requeue_pending: Indicator that timer waits for being requeued on
6464
* signal delivery
6565
* @it_sigev_notify: The notify word of sigevent struct for signal delivery
66+
* @it_interval: The interval for periodic timers
6667
* @it_signal: Pointer to the creators signal struct
6768
* @it_pid: The pid of the process/task targeted by the signal
6869
* @it_process: The task to wakeup on clock_nanosleep (CPU timers)
@@ -80,6 +81,7 @@ struct k_itimer {
8081
int it_overrun_last;
8182
int it_requeue_pending;
8283
int it_sigev_notify;
84+
ktime_t it_interval;
8385
struct signal_struct *it_signal;
8486
union {
8587
struct pid *it_pid;
@@ -89,12 +91,10 @@ struct k_itimer {
8991
union {
9092
struct {
9193
struct hrtimer timer;
92-
ktime_t interval;
9394
} real;
9495
struct cpu_timer_list cpu;
9596
struct {
9697
struct alarm alarmtimer;
97-
ktime_t interval;
9898
} alarm;
9999
struct rcu_head rcu;
100100
} it;

‎kernel/time/alarmtimer.c‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -527,9 +527,8 @@ static enum alarmtimer_restart alarm_handle_timer(struct alarm *alarm,
527527
}
528528

529529
/* Re-add periodic timers */
530-
if (ptr->it.alarm.interval) {
531-
ptr->it_overrun += alarm_forward(alarm, now,
532-
ptr->it.alarm.interval);
530+
if (ptr->it_interval) {
531+
ptr->it_overrun += alarm_forward(alarm, now, ptr->it_interval);
533532
result = ALARMTIMER_RESTART;
534533
}
535534
spin_unlock_irqrestore(&ptr->it_lock, flags);
@@ -613,7 +612,7 @@ static void alarm_timer_get(struct k_itimer *timr,
613612
cur_setting->it_value.tv_nsec = 0;
614613
}
615614

616-
cur_setting->it_interval = ktime_to_timespec64(timr->it.alarm.interval);
615+
cur_setting->it_interval = ktime_to_timespec64(timr->it_interval);
617616
}
618617

619618
/**
@@ -662,14 +661,14 @@ static int alarm_timer_set(struct k_itimer *timr, int flags,
662661
return TIMER_RETRY;
663662

664663
/* start the timer */
665-
timr->it.alarm.interval = timespec64_to_ktime(new_setting->it_interval);
664+
timr->it_interval = timespec64_to_ktime(new_setting->it_interval);
666665

667666
/*
668667
* Rate limit to the tick as a hot fix to prevent DOS. Will be
669668
* mopped up later.
670669
*/
671-
if (timr->it.alarm.interval < TICK_NSEC)
672-
timr->it.alarm.interval = TICK_NSEC;
670+
if (timr->it_interval < TICK_NSEC)
671+
timr->it_interval = TICK_NSEC;
673672

674673
exp = timespec64_to_ktime(new_setting->it_value);
675674
/* Convert (if necessary) to absolute time */

‎kernel/time/posix-timers.c‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -285,12 +285,12 @@ static void schedule_next_timer(struct k_itimer *timr)
285285
{
286286
struct hrtimer *timer = &timr->it.real.timer;
287287

288-
if (timr->it.real.interval == 0)
288+
if (!timr->it_interval)
289289
return;
290290

291291
timr->it_overrun += (unsigned int) hrtimer_forward(timer,
292292
timer->base->get_time(),
293-
timr->it.real.interval);
293+
timr->it_interval);
294294
hrtimer_restart(timer);
295295
}
296296

@@ -375,7 +375,7 @@ static enum hrtimer_restart posix_timer_fn(struct hrtimer *timer)
375375
timr = container_of(timer, struct k_itimer, it.real.timer);
376376
spin_lock_irqsave(&timr->it_lock, flags);
377377

378-
if (timr->it.real.interval != 0)
378+
if (timr->it_interval != 0)
379379
si_private = ++timr->it_requeue_pending;
380380

381381
if (posix_timer_event(timr, si_private)) {
@@ -384,7 +384,7 @@ static enum hrtimer_restart posix_timer_fn(struct hrtimer *timer)
384384
* we will not get a call back to restart it AND
385385
* it should be restarted.
386386
*/
387-
if (timr->it.real.interval != 0) {
387+
if (timr->it_interval != 0) {
388388
ktime_t now = hrtimer_cb_get_time(timer);
389389

390390
/*
@@ -413,13 +413,13 @@ static enum hrtimer_restart posix_timer_fn(struct hrtimer *timer)
413413
{
414414
ktime_t kj = NSEC_PER_SEC / HZ;
415415

416-
if (timr->it.real.interval < kj)
416+
if (timr->it_interval < kj)
417417
now = ktime_add(now, kj);
418418
}
419419
#endif
420420
timr->it_overrun += (unsigned int)
421421
hrtimer_forward(timer, now,
422-
timr->it.real.interval);
422+
timr->it_interval);
423423
ret = HRTIMER_RESTART;
424424
++timr->it_requeue_pending;
425425
}
@@ -631,7 +631,7 @@ common_timer_get(struct k_itimer *timr, struct itimerspec64 *cur_setting)
631631

632632
memset(cur_setting, 0, sizeof(*cur_setting));
633633

634-
iv = timr->it.real.interval;
634+
iv = timr->it_interval;
635635

636636
/* interval timer ? */
637637
if (iv)
@@ -732,7 +732,7 @@ common_timer_set(struct k_itimer *timr, int flags,
732732
common_timer_get(timr, old_setting);
733733

734734
/* disable the timer */
735-
timr->it.real.interval = 0;
735+
timr->it_interval = 0;
736736
/*
737737
* careful here. If smp we could be in the "fire" routine which will
738738
* be spinning as we hold the lock. But this is ONLY an SMP issue.
@@ -755,7 +755,7 @@ common_timer_set(struct k_itimer *timr, int flags,
755755
hrtimer_set_expires(timer, timespec64_to_ktime(new_setting->it_value));
756756

757757
/* Convert interval */
758-
timr->it.real.interval = timespec64_to_ktime(new_setting->it_interval);
758+
timr->it_interval = timespec64_to_ktime(new_setting->it_interval);
759759

760760
/* SIGEV_NONE timers are not queued ! See common_timer_get */
761761
if (((timr->it_sigev_notify & ~SIGEV_THREAD_ID) == SIGEV_NONE)) {
@@ -820,7 +820,7 @@ SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
820820

821821
static int common_timer_del(struct k_itimer *timer)
822822
{
823-
timer->it.real.interval = 0;
823+
timer->it_interval = 0;
824824

825825
if (hrtimer_try_to_cancel(&timer->it.real.timer) < 0)
826826
return TIMER_RETRY;

0 commit comments

Comments
 (0)