Skip to content

Commit 61bb4bc

Browse files
anna-marialxingomolnar
authored andcommitted
hrtimer: Unify hrtimer removal handling
When the first hrtimer on the current CPU is removed, hrtimer_force_reprogram() is invoked but only when CONFIG_HIGH_RES_TIMERS=y and hrtimer_cpu_base.hres_active is set. hrtimer_force_reprogram() updates hrtimer_cpu_base.expires_next and reprograms the clock event device. When CONFIG_HIGH_RES_TIMERS=y and hrtimer_cpu_base.hres_active is set, a pointless hrtimer interrupt can be prevented. hrtimer_check_target() makes the 'can remote enqueue' decision. As soon as hrtimer_check_target() is unconditionally available and hrtimer_cpu_base.expires_next is updated by hrtimer_reprogram(), hrtimer_force_reprogram() needs to be available unconditionally as well to prevent the following scenario with CONFIG_HIGH_RES_TIMERS=n: - the first hrtimer on this CPU is removed and hrtimer_force_reprogram() is not executed - CPU goes idle (next timer is calculated and hrtimers are taken into account) - a hrtimer is enqueued remote on the idle CPU: hrtimer_check_target() compares expiry value and hrtimer_cpu_base.expires_next. The expiry value is after expires_next, so the hrtimer is enqueued. This timer will fire late, if it expires before the effective first hrtimer on this CPU and the comparison was with an outdated expires_next value. To prevent this scenario, make hrtimer_force_reprogram() unconditional except the effective reprogramming part, which gets eliminated by the compiler in the CONFIG_HIGH_RES_TIMERS=n case. Signed-off-by: Anna-Maria Gleixner <anna-maria@linutronix.de> Cc: Christoph Hellwig <hch@lst.de> Cc: John Stultz <john.stultz@linaro.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: keescook@chromium.org Link: http://lkml.kernel.org/r/20171221104205.7269-20-anna-maria@linutronix.de Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent ebba2c7 commit 61bb4bc

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

‎kernel/time/hrtimer.c‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -521,9 +521,6 @@ hrtimer_force_reprogram(struct hrtimer_cpu_base *cpu_base, int skip_equal)
521521
{
522522
ktime_t expires_next;
523523

524-
if (!__hrtimer_hres_active(cpu_base))
525-
return;
526-
527524
expires_next = __hrtimer_get_next_event(cpu_base);
528525

529526
if (skip_equal && expires_next == cpu_base->expires_next)
@@ -532,6 +529,9 @@ hrtimer_force_reprogram(struct hrtimer_cpu_base *cpu_base, int skip_equal)
532529
cpu_base->expires_next = expires_next;
533530

534531
/*
532+
* If hres is not active, hardware does not have to be
533+
* reprogrammed yet.
534+
*
535535
* If a hang was detected in the last timer interrupt then we
536536
* leave the hang delay active in the hardware. We want the
537537
* system to make progress. That also prevents the following
@@ -545,7 +545,7 @@ hrtimer_force_reprogram(struct hrtimer_cpu_base *cpu_base, int skip_equal)
545545
* set. So we'd effectivly block all timers until the T2 event
546546
* fires.
547547
*/
548-
if (cpu_base->hang_detected)
548+
if (!__hrtimer_hres_active(cpu_base) || cpu_base->hang_detected)
549549
return;
550550

551551
tick_program_event(cpu_base->expires_next, 1);
@@ -844,7 +844,6 @@ static void __remove_hrtimer(struct hrtimer *timer,
844844
if (!timerqueue_del(&base->active, &timer->node))
845845
cpu_base->active_bases &= ~(1 << base->index);
846846

847-
#ifdef CONFIG_HIGH_RES_TIMERS
848847
/*
849848
* Note: If reprogram is false we do not update
850849
* cpu_base->next_timer. This happens when we remove the first
@@ -855,7 +854,6 @@ static void __remove_hrtimer(struct hrtimer *timer,
855854
*/
856855
if (reprogram && timer == cpu_base->next_timer)
857856
hrtimer_force_reprogram(cpu_base, 1);
858-
#endif
859857
}
860858

861859
/*

0 commit comments

Comments
 (0)