Commit d2540875 authored by Viresh Kumar's avatar Viresh Kumar Committed by Thomas Gleixner

clockevents: Stop unused clockevent devices

To avoid getting spurious interrupts on a tickless CPU, clockevent
device can now be stopped by switching to ONESHOT_STOPPED state.

The natural place for handling this transition is tick_program_event().

On 'expires == KTIME_MAX', we skip programming the event and so we need
to fix such call sites as well, to always call tick_program_event()
irrespective of the expires value.

Once the clockevent device is required again, check if it was earlier
put into ONESHOT_STOPPED state. If yes, switch its state to ONESHOT
before programming its event.

To make sure we haven't missed any corner case, add a WARN() for the
case where we try to reprogram clockevent device while we aren't
configured in ONESHOT_STOPPED state.
Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
Cc: linaro-kernel@lists.linaro.org
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Kevin Hilman <khilman@linaro.org>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Preeti U Murthy <preeti@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/5146b07be7f0bc497e0ebae036590ec2fa73e540.1428031396.git.viresh.kumar@linaro.orgSigned-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent 8fff52fd
...@@ -331,6 +331,10 @@ int clockevents_program_event(struct clock_event_device *dev, ktime_t expires, ...@@ -331,6 +331,10 @@ int clockevents_program_event(struct clock_event_device *dev, ktime_t expires,
if (dev->state == CLOCK_EVT_STATE_SHUTDOWN) if (dev->state == CLOCK_EVT_STATE_SHUTDOWN)
return 0; return 0;
/* We must be in ONESHOT state here */
WARN_ONCE(dev->state != CLOCK_EVT_STATE_ONESHOT, "Current state: %d\n",
dev->state);
/* Shortcut for clockevent devices that can deal with ktime. */ /* Shortcut for clockevent devices that can deal with ktime. */
if (dev->features & CLOCK_EVT_FEAT_KTIME) if (dev->features & CLOCK_EVT_FEAT_KTIME)
return dev->set_next_ktime(expires, dev); return dev->set_next_ktime(expires, dev);
......
...@@ -550,7 +550,6 @@ hrtimer_force_reprogram(struct hrtimer_cpu_base *cpu_base, int skip_equal) ...@@ -550,7 +550,6 @@ hrtimer_force_reprogram(struct hrtimer_cpu_base *cpu_base, int skip_equal)
if (cpu_base->hang_detected) if (cpu_base->hang_detected)
return; return;
if (cpu_base->expires_next.tv64 != KTIME_MAX)
tick_program_event(cpu_base->expires_next, 1); tick_program_event(cpu_base->expires_next, 1);
} }
...@@ -1237,8 +1236,7 @@ void hrtimer_interrupt(struct clock_event_device *dev) ...@@ -1237,8 +1236,7 @@ void hrtimer_interrupt(struct clock_event_device *dev)
raw_spin_unlock(&cpu_base->lock); raw_spin_unlock(&cpu_base->lock);
/* Reprogramming necessary ? */ /* Reprogramming necessary ? */
if (expires_next.tv64 == KTIME_MAX || if (!tick_program_event(expires_next, 0)) {
!tick_program_event(expires_next, 0)) {
cpu_base->hang_detected = 0; cpu_base->hang_detected = 0;
return; return;
} }
......
...@@ -28,6 +28,22 @@ int tick_program_event(ktime_t expires, int force) ...@@ -28,6 +28,22 @@ int tick_program_event(ktime_t expires, int force)
{ {
struct clock_event_device *dev = __this_cpu_read(tick_cpu_device.evtdev); struct clock_event_device *dev = __this_cpu_read(tick_cpu_device.evtdev);
if (unlikely(expires.tv64 == KTIME_MAX)) {
/*
* We don't need the clock event device any more, stop it.
*/
clockevents_set_state(dev, CLOCK_EVT_STATE_ONESHOT_STOPPED);
return 0;
}
if (unlikely(dev->state == CLOCK_EVT_STATE_ONESHOT_STOPPED)) {
/*
* We need the clock event again, configure it in ONESHOT mode
* before using it.
*/
clockevents_set_state(dev, CLOCK_EVT_STATE_ONESHOT);
}
return clockevents_program_event(dev, expires, force); return clockevents_program_event(dev, expires, force);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment