• Anna-Maria Gleixner's avatar
    hrtimer: Unify hrtimer removal handling · 61bb4bcb
    Anna-Maria Gleixner authored
    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: default avatarAnna-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.deSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
    61bb4bcb
hrtimer.c 45.9 KB