Skip to content

Commit

Permalink
cpuidle: Run tick_broadcast_exit() with disabled interrupts
Browse files Browse the repository at this point in the history
Commit 335f491 (sched/idle: Use explicit broadcast oneshot
control function) replaced clockevents_notify() invocations in
cpuidle_idle_call() with direct calls to tick_broadcast_enter()
and tick_broadcast_exit(), but it overlooked the fact that
interrupts were already enabled before calling the latter which
led to functional breakage on systems using idle states with the
CPUIDLE_FLAG_TIMER_STOP flag set.

Fix that by moving the invocations of tick_broadcast_enter()
and tick_broadcast_exit() down into cpuidle_enter_state() where
interrupts are still disabled when tick_broadcast_exit() is
called.  Also ensure that interrupts will be disabled before
running tick_broadcast_exit() even if they have been enabled by
the idle state's ->enter callback.  Trigger a WARN_ON_ONCE() in
that case, as we generally don't want that to happen for states
with CPUIDLE_FLAG_TIMER_STOP set.

Fixes: 335f491 (sched/idle: Use explicit broadcast oneshot control function)
Reported-and-tested-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Reported-and-tested-by: Sudeep Holla <sudeep.holla@arm.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  • Loading branch information
Rafael J. Wysocki committed Apr 29, 2015
1 parent b787f68 commit df8d9ee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
16 changes: 16 additions & 0 deletions drivers/cpuidle/cpuidle.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,18 @@ int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv,
int entered_state;

struct cpuidle_state *target_state = &drv->states[index];
bool broadcast = !!(target_state->flags & CPUIDLE_FLAG_TIMER_STOP);
ktime_t time_start, time_end;
s64 diff;

/*
* Tell the time framework to switch to a broadcast timer because our
* local timer will be shut down. If a local timer is used from another
* CPU as a broadcast timer, this call may fail if it is not available.
*/
if (broadcast && tick_broadcast_enter())
return -EBUSY;

trace_cpu_idle_rcuidle(index, dev->cpu);
time_start = ktime_get();

Expand All @@ -169,6 +178,13 @@ int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv,
time_end = ktime_get();
trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, dev->cpu);

if (broadcast) {
if (WARN_ON_ONCE(!irqs_disabled()))
local_irq_disable();

tick_broadcast_exit();
}

if (!cpuidle_state_is_coupled(dev, drv, entered_state))
local_irq_enable();

Expand Down
16 changes: 2 additions & 14 deletions kernel/sched/idle.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ static void cpuidle_idle_call(void)
struct cpuidle_device *dev = __this_cpu_read(cpuidle_devices);
struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
int next_state, entered_state;
unsigned int broadcast;
bool reflect;

/*
Expand Down Expand Up @@ -150,17 +149,6 @@ static void cpuidle_idle_call(void)
goto exit_idle;
}

broadcast = drv->states[next_state].flags & CPUIDLE_FLAG_TIMER_STOP;

/*
* Tell the time framework to switch to a broadcast timer
* because our local timer will be shutdown. If a local timer
* is used from another cpu as a broadcast timer, this call may
* fail if it is not available
*/
if (broadcast && tick_broadcast_enter())
goto use_default;

/* Take note of the planned idle state. */
idle_set_state(this_rq(), &drv->states[next_state]);

Expand All @@ -174,8 +162,8 @@ static void cpuidle_idle_call(void)
/* The cpu is no longer idle or about to enter idle. */
idle_set_state(this_rq(), NULL);

if (broadcast)
tick_broadcast_exit();
if (entered_state == -EBUSY)
goto use_default;

/*
* Give the governor an opportunity to reflect on the outcome
Expand Down

0 comments on commit df8d9ee

Please sign in to comment.