Skip to content

cpuidle / sleep: fix timer stopping regression (was: drivers: cpuidle: minor suspend-to-idle fixes)

Rafael J. Wysocki linux-pm lkml 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest0 of 2 patches 0 repliesNew

Patches in v1 No applies recorded yet

None of the 2 patches the cover letter announces are in this archive.

Reviews trailers per patch

PatchLorenzo Pieralisi
SeriesT-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 0/2] cpuidle / sleep: fix timer stopping regression (was: drivers: cpuidle: minor suspend-to-idle fixes)
Quoted 66 lines · Rafael J. Wysocki
Quoted 2 lines · Lorenzo Pieralisi
Quoted 1 line · Rafael J. Wysocki

On Saturday, February 28, 2015 11:54:23 AM Lorenzo Pieralisi wrote:

[cut]

Quoted 43 lines
Quoted 43 lines

Index: linux-pm/drivers/cpuidle/cpuidle.c
===================================================================

drivers/cpuidle/cpuidle.c +26 -5
@@ -230,15 +230,39 @@ int cpuidle_select(struct cpuidle_driver
  * @dev:   the cpuidle device
  * @index: the index in the idle state table
  *
- * Returns the index in the idle state, < 0 in case of error.
- * The error code depends on the backend driver
+ * Returns the index in the idle state, < 0 in case of error.  -EBUSY is
+ * returned to indicate that the target state was temporarily inaccessible.
+ * The other error codes depend on the backend driver.
  */
 int cpuidle_enter(struct cpuidle_driver *drv, struct cpuidle_device *dev,
 		  int index)
 {
-	if (cpuidle_state_is_coupled(dev, drv, index))
-		return cpuidle_enter_state_coupled(dev, drv, index);
-	return cpuidle_enter_state(dev, drv, index);
+	unsigned int broadcast;
+	int ret;
+
+	broadcast = drv->states[index].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) {
+		ret = clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER,
+					 &dev->cpu);
+		if (ret)
+			return ret;
+	}
+
+	ret = cpuidle_state_is_coupled(dev, drv, index) ?
+		cpuidle_enter_state_coupled(dev, drv, index) :
+		cpuidle_enter_state(dev, drv, index);
+
+	if (broadcast)
Quoted 8 lines

drivers/cpuidle/cpuidle.c int cpuidle_select(struct cpuidle_driver · line 265

Quoted 3 lines
drivers/cpuidle/cpuidle.c +3 -0
+		clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu);
+
+	return ret;

You have to check this return value in cpuidle_enter_freeze() too otherwise we return to the idle thread on -EBUSY without even executing arch_cpu_idle() and with IRQ disabled, code hits the WARN_ON_ONCE line 180.

Right.

Quoted 5 lines

There are multiple ways of fixing the issue, either you check the cpuidle_enter_freeze() return value (you add one) to cpuidle_idle_call() to make code consistent with the cpuidle_idle_call "normal" idle behaviour or you add the return value check in cpuidle_enter_freeze(), I am fine both ways.

Quoted 5 lines

Well, in both cases we'd end up with a function enabling interrupts on exit in some cases and not doing that in some other ones. Not nice.

Below is an alternative to that (on top of the previous patches). Can you test it please?

Actually, this one is still slightly incorrect, because we only should call cpuidle_reflect() if we've called cpuidle_select() before. Also it's better to pass cpuidle_driver and cpuidle_device to all functions called by cpuidle_idle_call().

Two patches will follow. [1/2] is a cleanup re-arranging the code in cpuidle_idle_call() to move the fallback path to the end of the function. [2/2] is a replacement for the patch sent previously.

Please test.

Rafael