Skip to contentSkip to conversation

cpuidle: Do not return from cpuidle_play_dead() on callback failures

PATCH In review Rafael J. Wysocki 4 participants 7 messages Nov 15, 2024 – Nov 19, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover cpuidle: Do not return from cpuidle_play_dead() on callback failures

Hi Everyone,

This series of 2 patches supersedes

https://lore.kernel.org/linux-pm/[email protected]/

in order to address review feedback.

Patch [1/2] modifies cpuidle_play_dead() as per the subject and patch [2/2] changes the :enter_dead() cpuidle state callback return type to void.

Thanks!

#1 lore raw

PATCH v2 1/2 cpuidle: Do not return from cpuidle_play_dead() on callback failures

From: Rafael J. Wysocki <[email protected]>

If the :enter_dead() idle state callback fails for a certain state, there may be still a shallower state for which it will work.

Because the only caller of cpuidle_play_dead(), native_play_dead(), falls back to hlt_play_dead() if it returns an error, it should better try all of the idle states for which :enter_dead() is present before failing, so change it accordingly.

Also notice that the :enter_dead() state callback is not expected to return on success (the CPU should be "dead" then), so make cpuidle_play_dead() ignore its return value.

---

v1 -> v2:
* Make cpuidle_play_dead() never return 0.
* Add tags from Mario (I have added them because the change of the patch should not make a practical difference, but if you want them to be dropped, please let me know).

---
 drivers/cpuidle/cpuidle.c |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/cpuidle/cpuidle.c +7 -3
Index: linux-pm/drivers/cpuidle/cpuidle.c
===================================================================
@@ -69,11 +69,15 @@ int cpuidle_play_dead(void)
 	if (!drv)
 		return -ENODEV;
 
-	/* Find lowest-power state that supports long-term idle */
-	for (i = drv->state_count - 1; i >= 0; i--)
+	for (i = drv->state_count - 1; i >= 0; i--) {
 		if (drv->states[i].enter_dead)
-			return drv->states[i].enter_dead(dev, i);
+			drv->states[i].enter_dead(dev, i);
+	}
 
+	/*
+	 * If :enter_dead() is successful, it will never return, so reaching
+	 * here means that all of them failed above or were not present.
+	 */
 	return -ENODEV;
 }
 
Reviewed-by on v2 1/2
#2 lore raw

Hello Rafael,

Quoted 10 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

If the :enter_dead() idle state callback fails for a certain state, there may be still a shallower state for which it will work.

Because the only caller of cpuidle_play_dead(), native_play_dead(), falls back to hlt_play_dead() if it returns an error, it should better try all of the idle states for which :enter_dead() is present before failing, so change it accordingly.

Quoted 7 lines

Also notice that the :enter_dead() state callback is not expected to return on success (the CPU should be "dead" then), so make cpuidle_play_dead() ignore its return value.

Thanks for fixing this.

--
Thanks and Regards
gautham.

Quoted 38 lines

---

v1 -> v2:
* Make cpuidle_play_dead() never return 0.
* Add tags from Mario (I have added them because the change of the patch should not make a practical difference, but if you want them to be dropped, please let me know).

---
 drivers/cpuidle/cpuidle.c |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

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

drivers/cpuidle/cpuidle.c +7 -3
@@ -69,11 +69,15 @@ int cpuidle_play_dead(void)
 	if (!drv)
 		return -ENODEV;
 
-	/* Find lowest-power state that supports long-term idle */
-	for (i = drv->state_count - 1; i >= 0; i--)
+	for (i = drv->state_count - 1; i >= 0; i--) {
 		if (drv->states[i].enter_dead)
-			return drv->states[i].enter_dead(dev, i);
+			drv->states[i].enter_dead(dev, i);
+	}
 
+	/*
+	 * If :enter_dead() is successful, it will never return, so reaching
+	 * here means that all of them failed above or were not present.
+	 */
 	return -ENODEV;
 }
 
#3 lore raw

PATCH v2 2/2 cpuidle: Change :enter_dead() driver callback return type to void

In reply to Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

After a previous change, cpuidle_play_dead(), which is the only caller of idle state :enter_dead() callbacks, ignores their return values, so they may as well be void.

---

v1 -> v2: New patch

Interestingly enough, the only user of :enter_dead() idle state callbacks in the current mainline turns out to be ACPI idle.

---
 drivers/acpi/processor_idle.c |    7 ++-----
 include/linux/cpuidle.h       |    2 +-
 2 files changed, 3 insertions(+), 6 deletions(-)
include/linux/cpuidle.h +1 -1
Index: linux-pm/include/linux/cpuidle.h
===================================================================
@@ -61,7 +61,7 @@ struct cpuidle_state {
 			struct cpuidle_driver *drv,
 			int index);
 
-	int (*enter_dead) (struct cpuidle_device *dev, int index);
+	void (*enter_dead) (struct cpuidle_device *dev, int index);
 
 	/*
 	 * CPUs execute ->enter_s2idle with the local tick or entire timekeeping
drivers/acpi/processor_idle.c +2 -5
Index: linux-pm/drivers/acpi/processor_idle.c
===================================================================
@@ -578,7 +578,7 @@ static void __cpuidle acpi_idle_do_entry
  * @dev: the target CPU
  * @index: the index of suggested state
  */
-static int acpi_idle_play_dead(struct cpuidle_device *dev, int index)
+static void acpi_idle_play_dead(struct cpuidle_device *dev, int index)
 {
 	struct acpi_processor_cx *cx = per_cpu(acpi_cstate[index], dev->cpu);
 
@@ -591,11 +591,8 @@ static int acpi_idle_play_dead(struct cp
 		else if (cx->entry_method == ACPI_CSTATE_SYSTEMIO) {
 			io_idle(cx->address);
 		} else
-			return -ENODEV;
+			return;
 	}
-
-	/* Never reached */
-	return 0;
 }
 
 static __always_inline bool acpi_idle_fallback_to_c1(struct acpi_processor *pr)
Reviewed-by on v2 2/2
#4 lore raw

Re: [PATCH v2 2/2] cpuidle: Change :enter_dead() driver callback return type to void

Hello Rafael,

Quoted 9 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

After a previous change, cpuidle_play_dead(), which is the only caller of idle state :enter_dead() callbacks, ignores their return values, so they may as well be void.

Quoted 6 lines

---

v1 -> v2: New patch

Interestingly enough, the only user of :enter_dead() idle state callbacks in the current mainline turns out to be ACPI idle.

For that matter, the only user of cpuidle_play_dead() is the native_play_dead(). Was that always the case?

Some of the other architectures select the deepest available idle state at boot time, and enter that state when a CPU is offlined.

In any case I am ok with this.

--
Thanks and Regards
gautham.

Quoted 48 lines
---
 drivers/acpi/processor_idle.c |    7 ++-----
 include/linux/cpuidle.h       |    2 +-
 2 files changed, 3 insertions(+), 6 deletions(-)

Index: linux-pm/include/linux/cpuidle.h
===================================================================

include/linux/cpuidle.h +1 -1
@@ -61,7 +61,7 @@ struct cpuidle_state {
 			struct cpuidle_driver *drv,
 			int index);
 
-	int (*enter_dead) (struct cpuidle_device *dev, int index);
+	void (*enter_dead) (struct cpuidle_device *dev, int index);
 
 	/*
 	 * CPUs execute ->enter_s2idle with the local tick or entire timekeeping

Index: linux-pm/drivers/acpi/processor_idle.c
===================================================================

drivers/acpi/processor_idle.c +2 -5
@@ -578,7 +578,7 @@ static void __cpuidle acpi_idle_do_entry
  * @dev: the target CPU
  * @index: the index of suggested state
  */
-static int acpi_idle_play_dead(struct cpuidle_device *dev, int index)
+static void acpi_idle_play_dead(struct cpuidle_device *dev, int index)
 {
 	struct acpi_processor_cx *cx = per_cpu(acpi_cstate[index], dev->cpu);
 
@@ -591,11 +591,8 @@ static int acpi_idle_play_dead(struct cp
 		else if (cx->entry_method == ACPI_CSTATE_SYSTEMIO) {
 			io_idle(cx->address);
 		} else
-			return -ENODEV;
+			return;
 	}
-
-	/* Never reached */
-	return 0;
 }
 
 static __always_inline bool acpi_idle_fallback_to_c1(struct acpi_processor *pr)
Reviewed-by
#5 lore raw

Re: [PATCH v2 2/2] cpuidle: Change :enter_dead() driver callback return type to void

Quoted 22 lines · Gautham R. Shenoy

Hello Rafael,

Quoted 9 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

After a previous change, cpuidle_play_dead(), which is the only caller of idle state :enter_dead() callbacks, ignores their return values, so they may as well be void.

Quoted 6 lines

---

v1 -> v2: New patch

Interestingly enough, the only user of :enter_dead() idle state callbacks in the current mainline turns out to be ACPI idle.

For that matter, the only user of cpuidle_play_dead() is the native_play_dead(). Was that always the case?

Quoted 6 lines

Some of the other architectures select the deepest available idle state at boot time, and enter that state when a CPU is offlined.

In any case I am ok with this.

Quoted 51 lines

--
Thanks and Regards
gautham.

Quoted 48 lines
---
  drivers/acpi/processor_idle.c |    7 ++-----
  include/linux/cpuidle.h       |    2 +-
  2 files changed, 3 insertions(+), 6 deletions(-)

Index: linux-pm/include/linux/cpuidle.h
===================================================================

include/linux/cpuidle.h +1 -1
@@ -61,7 +61,7 @@ struct cpuidle_state {
  			struct cpuidle_driver *drv,
  			int index);
 
-	int (*enter_dead) (struct cpuidle_device *dev, int index);
+	void (*enter_dead) (struct cpuidle_device *dev, int index);
 
  	/*
  	 * CPUs execute ->enter_s2idle with the local tick or entire timekeeping

Index: linux-pm/drivers/acpi/processor_idle.c
===================================================================

drivers/acpi/processor_idle.c +2 -5
@@ -578,7 +578,7 @@ static void __cpuidle acpi_idle_do_entry
   * @dev: the target CPU
   * @index: the index of suggested state
   */
-static int acpi_idle_play_dead(struct cpuidle_device *dev, int index)
+static void acpi_idle_play_dead(struct cpuidle_device *dev, int index)
  {
  	struct acpi_processor_cx *cx = per_cpu(acpi_cstate[index], dev->cpu);
 
@@ -591,11 +591,8 @@ static int acpi_idle_play_dead(struct cp
  		else if (cx->entry_method == ACPI_CSTATE_SYSTEMIO) {
  			io_idle(cx->address);
  		} else
-			return -ENODEV;
+			return;
  	}
-
-	/* Never reached */
-	return 0;
  }
 
  static __always_inline bool acpi_idle_fallback_to_c1(struct acpi_processor *pr)
#6 lore raw

Re: [PATCH v2 2/2] cpuidle: Change :enter_dead() driver callback return type to void

In reply to Gautham R. Shenoy

Hi Gautham,

Quoted 15 lines · Gautham R. Shenoy

Hello Rafael,

Quoted 11 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

After a previous change, cpuidle_play_dead(), which is the only caller of idle state :enter_dead() callbacks, ignores their return values, so they may as well be void.

---

Quoted 7 lines
Quoted 4 lines

v1 -> v2: New patch

Interestingly enough, the only user of :enter_dead() idle state callbacks in the current mainline turns out to be ACPI idle.

For that matter, the only user of cpuidle_play_dead() is the native_play_dead(). Was that always the case?

At least as long ago as of 4.20.

Quoted 2 lines

Some of the other architectures select the deepest available idle state at boot time, and enter that state when a CPU is offlined.

That's fine as long as the state to use is already known at that time.

Quoted 55 lines

In any case I am ok with this.

--
Thanks and Regards
gautham.

Quoted 48 lines
---
 drivers/acpi/processor_idle.c |    7 ++-----
 include/linux/cpuidle.h       |    2 +-
 2 files changed, 3 insertions(+), 6 deletions(-)

Index: linux-pm/include/linux/cpuidle.h
===================================================================

include/linux/cpuidle.h +1 -1
@@ -61,7 +61,7 @@ struct cpuidle_state {
                      struct cpuidle_driver *drv,
                      int index);
 
-     int (*enter_dead) (struct cpuidle_device *dev, int index);
+     void (*enter_dead) (struct cpuidle_device *dev, int index);
 
      /*
       * CPUs execute ->enter_s2idle with the local tick or entire timekeeping

Index: linux-pm/drivers/acpi/processor_idle.c
===================================================================

drivers/acpi/processor_idle.c +2 -5
@@ -578,7 +578,7 @@ static void __cpuidle acpi_idle_do_entry
  * @dev: the target CPU
  * @index: the index of suggested state
  */
-static int acpi_idle_play_dead(struct cpuidle_device *dev, int index)
+static void acpi_idle_play_dead(struct cpuidle_device *dev, int index)
 {
      struct acpi_processor_cx *cx = per_cpu(acpi_cstate[index], dev->cpu);
 
@@ -591,11 +591,8 @@ static int acpi_idle_play_dead(struct cp
              else if (cx->entry_method == ACPI_CSTATE_SYSTEMIO) {
                      io_idle(cx->address);
              } else
-                     return -ENODEV;
+                     return;
      }
-
-     /* Never reached */
-     return 0;
 }
 
 static __always_inline bool acpi_idle_fallback_to_c1(struct acpi_processor *pr)