diff options
author | Viresh Kumar <viresh.kumar@linaro.org> | 2015-01-29 13:45:54 +0530 |
---|---|---|
committer | Santosh Shukla <sshukla@mvista.com> | 2015-04-15 09:38:40 +0000 |
commit | 56d3aa2f6f5759149005abdb8a6b59d781a11a15 (patch) | |
tree | 6224f663afdbd4c48fd09744c0486f52917c9cf2 | |
parent | 92e946b6394b7513a9c207523ef35af23bf99ab7 (diff) |
clockevents: Restart clockevent device before using it
Clockevent device might have been switched to ONESHOT_STOPPED mode to avoid
getting spurious interrupts on a tickless CPU. Before reprogramming next event,
we must reconfigure clockevent device to ONESHOT mode if required.
This patch switches mode to ONESHOT at three different places and
following is the reasoning behind them.
1.) NOHZ_MODE_LOWRES
Timers & hrtimers are dependent on tick for their working in this mode and the
only place from where clockevent device is programmed is the tick-code.
So, we need to switch clockevent device to ONESHOT mode before we starting using
it. Two routines can restart ticks here in LOWRES mode:
tick_nohz_stop_sched_tick() and tick_nohz_restart().
2.) NOHZ_MODE_HIGHRES
Tick & timers are dependent on hrtimers for their working in this mode and the
only place from where clockevent device is programmed is the hrtimer-code.
Only hrtimer_reprogram() is responsible for programming the clockevent device
for next event, if the clockevent device is stopped earlier. And updating that
alone is sufficient here.
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 mode.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
-rw-r--r-- | kernel/time/clockevents.c | 4 | ||||
-rw-r--r-- | kernel/time/hrtimer.c | 5 | ||||
-rw-r--r-- | kernel/time/tick-sched.c | 14 |
3 files changed, 22 insertions, 1 deletions
diff --git a/kernel/time/clockevents.c b/kernel/time/clockevents.c index 808ae090237..95dcdbc269b 100644 --- a/kernel/time/clockevents.c +++ b/kernel/time/clockevents.c @@ -318,6 +318,10 @@ int clockevents_program_event(struct clock_event_device *dev, ktime_t expires, if (dev->mode == CLOCK_EVT_MODE_SHUTDOWN) return 0; + /* We must be in ONESHOT mode here */ + WARN_ONCE(dev->mode != CLOCK_EVT_MODE_ONESHOT, "Current mode: %d\n", + dev->mode); + /* Shortcut for clockevent devices that can deal with ktime. */ if (dev->features & CLOCK_EVT_FEAT_KTIME) return dev->set_next_ktime(expires, dev); diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c index e7d7b3f2777..986db1bcd82 100644 --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -559,6 +559,7 @@ static int hrtimer_reprogram(struct hrtimer *timer, { struct hrtimer_cpu_base *cpu_base = this_cpu_ptr(&hrtimer_bases); ktime_t expires = ktime_sub(hrtimer_get_expires(timer), base->offset); + struct clock_event_device *dev = __this_cpu_read(tick_cpu_device.evtdev); int res; WARN_ON_ONCE(hrtimer_get_expires_tv64(timer) < 0); @@ -594,6 +595,10 @@ static int hrtimer_reprogram(struct hrtimer *timer, if (cpu_base->hang_detected) return 0; + /* Switchback to ONESHOT mode */ + if (unlikely(dev->mode == CLOCK_EVT_MODE_ONESHOT_STOPPED)) + clockevents_set_mode(dev, CLOCK_EVT_MODE_ONESHOT); + /* * Clockevents returns -ETIME, when the event was in the past. */ diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index 8c30ef7a2b7..6cbccb6ffc4 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -701,8 +701,14 @@ static ktime_t tick_nohz_stop_sched_tick(struct tick_sched *ts, /* Check, if the timer was already in the past */ if (hrtimer_active(&ts->sched_timer)) goto out; - } else if (!tick_program_event(expires, 0)) + } else { + /* Switchback to ONESHOT mode */ + if (unlikely(dev->mode == CLOCK_EVT_MODE_ONESHOT_STOPPED)) + clockevents_set_mode(dev, CLOCK_EVT_MODE_ONESHOT); + + if (!tick_program_event(expires, 0)) goto out; + } /* * We are past the event already. So we crossed a * jiffie boundary. Update jiffies and raise the @@ -880,6 +886,8 @@ ktime_t tick_nohz_get_sleep_length(void) static void tick_nohz_restart(struct tick_sched *ts, ktime_t now) { + struct clock_event_device *dev = __this_cpu_read(tick_cpu_device.evtdev); + hrtimer_cancel(&ts->sched_timer); hrtimer_set_expires(&ts->sched_timer, ts->last_tick); @@ -894,6 +902,10 @@ static void tick_nohz_restart(struct tick_sched *ts, ktime_t now) if (hrtimer_active(&ts->sched_timer)) break; } else { + /* Switchback to ONESHOT mode */ + if (likely(dev->mode == CLOCK_EVT_MODE_ONESHOT_STOPPED)) + clockevents_set_mode(dev, CLOCK_EVT_MODE_ONESHOT); + if (!tick_program_event( hrtimer_get_expires(&ts->sched_timer), 0)) break; |