Skip to contentSkip to conversation

cpuidle: tegra: Correctly handle result of arm_cpuidle_simple_enter()

PATCH Superseded Dmitry Osipenko 2 participants 5 messages Jun 29, 2020 – Jul 1, 2020

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpuidle: tegra: Correctly handle result of arm_cpuidle_simple_enter()

The arm_cpuidle_simple_enter() returns the entered idle-index and not a error code. It happened that TEGRA_C1=index=err=0, and hence this typo was difficult to notice in the code since everything happened to work properly. This patch fixes the minor typo, it doesn't fix any problem.

---
 drivers/cpuidle/cpuidle-tegra.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cpuidle/cpuidle-tegra.c +2 -2
index 150045849d78..9e9a9cccd755 100644
@@ -236,14 +236,14 @@ static int tegra_cpuidle_enter(struct cpuidle_device *dev,
 			       int index)
 {
 	unsigned int cpu = cpu_logical_map(dev->cpu);
-	int err;
+	int err = 0;
 
 	index = tegra_cpuidle_adjust_state_index(index, cpu);
 	if (dev->states_usage[index].disable)
 		return -1;
 
 	if (index == TEGRA_C1)
-		err = arm_cpuidle_simple_enter(dev, drv, index);
+		index = arm_cpuidle_simple_enter(dev, drv, index);
 	else
 		err = tegra_cpuidle_state_enter(dev, index, cpu);
 
Signature · 1 line
2.26.0
maintainer
#1 lore raw
Quoted 4 lines · Dmitry Osipenko

The arm_cpuidle_simple_enter() returns the entered idle-index and not a error code. It happened that TEGRA_C1=index=err=0, and hence this typo was difficult to notice in the code since everything happened to work properly. This patch fixes the minor typo, it doesn't fix any problem.

I guess that is dependent on if CPUIDLE is enabled ...

#ifdef CONFIG_CPU_IDLE
extern int arm_cpuidle_simple_enter(struct cpuidle_device *dev,

                struct cpuidle_driver *drv, int index);
#else
static inline int arm_cpuidle_simple_enter(struct cpuidle_device *dev,
                 struct cpuidle_driver *drv, int index) { return -ENODEV; }

#endif

Looks like it could return an error.

Quoted 17 lines
---
 drivers/cpuidle/cpuidle-tegra.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cpuidle/cpuidle-tegra.c +1 -1
index 150045849d78..9e9a9cccd755 100644
@@ -236,14 +236,14 @@ static int tegra_cpuidle_enter(struct cpuidle_device *dev,
 			       int index)
 {
 	unsigned int cpu = cpu_logical_map(dev->cpu);
-	int err;
+	int err = 0;
 

drivers/cpuidle/cpuidle-tegra.c static int tegra_cpuidle_enter(struct cpuidle_device *dev, · line 249

Quoted 10 lines
drivers/cpuidle/cpuidle-tegra.c +1 -1
 	index = tegra_cpuidle_adjust_state_index(index, cpu);
 	if (dev->states_usage[index].disable)
 		return -1;
 
 	if (index == TEGRA_C1)
-		err = arm_cpuidle_simple_enter(dev, drv, index);
+		index = arm_cpuidle_simple_enter(dev, drv, index);
 	else
 		err = tegra_cpuidle_state_enter(dev, index, cpu);
 

However, I do think that there is something not right in the error handling here. Would also be nice to get rid of these -1.

Jon

Signature · 1 line
nvpublic
#2 lore raw

30.06.2020 12:02, Jon Hunter пишет:

Quoted 11 lines · Dmitry Osipenko
Quoted 4 lines

The arm_cpuidle_simple_enter() returns the entered idle-index and not a error code. It happened that TEGRA_C1=index=err=0, and hence this typo was difficult to notice in the code since everything happened to work properly. This patch fixes the minor typo, it doesn't fix any problem.

I guess that is dependent on if CPUIDLE is enabled ...

#ifdef CONFIG_CPU_IDLE
extern int arm_cpuidle_simple_enter(struct cpuidle_device *dev,

Quoted 7 lines
                struct cpuidle_driver *drv, int index);
#else
static inline int arm_cpuidle_simple_enter(struct cpuidle_device *dev,
                 struct cpuidle_driver *drv, int index) { return -ENODEV; }

#endif

Looks like it could return an error.

Hello Jon!

The cpuidle's enter() callback returns an index of the entered state on success, on negative value on failure.

The negative number *could be* a proper error code, but in the same time it also doesn't matter what's the exact negative value is for the cpuidle's core code. Please see more below!

Quoted 20 lines
Quoted 20 lines
---
 drivers/cpuidle/cpuidle-tegra.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cpuidle/cpuidle-tegra.c +1 -1
index 150045849d78..9e9a9cccd755 100644
@@ -236,14 +236,14 @@ static int tegra_cpuidle_enter(struct cpuidle_device *dev,
 			       int index)
 {
 	unsigned int cpu = cpu_logical_map(dev->cpu);
-	int err;
+	int err = 0;
 
 	index = tegra_cpuidle_adjust_state_index(index, cpu);
 	if (dev->states_usage[index].disable)
 		return -1;
 
Quoted 10 lines

drivers/cpuidle/cpuidle-tegra.c static int tegra_cpuidle_enter(struct cpuidle_device *dev, · line 249

Quoted 7 lines
drivers/cpuidle/cpuidle-tegra.c +1 -1
 	if (index == TEGRA_C1)
-		err = arm_cpuidle_simple_enter(dev, drv, index);
+		index = arm_cpuidle_simple_enter(dev, drv, index);
 	else
 		err = tegra_cpuidle_state_enter(dev, index, cpu);
 

However, I do think that there is something not right in the error handling here. Would also be nice to get rid of these -1.

IIRC, the -1 was borrowed from some other cpuidle driver, for example cpuidle-psci[1] and coupled.c[2] are returning -1 on a failure.

[1]
https://elixir.bootlin.com/linux/v5.8-rc3/source/drivers/cpuidle/cpuidle-psci.c#L63
[2]
https://elixir.bootlin.com/linux/v5.8-rc3/source/drivers/cpuidle/coupled.c#L473

Looking at the the cpuidle's call chain, all of the code checks only whether the returned value of the enter() is negative or not and in the end that value is ignored [3][4].

[3]
https://elixir.bootlin.com/linux/v5.8-rc3/source/kernel/sched/idle.c#L216
[4]
https://elixir.bootlin.com/linux/v5.8-rc3/source/drivers/cpuidle/cpuidle.c#L360

Indeed, it would be better to return something more meaningful, but what should we return for a disabled state if not -1?

maintainer
#3 lore raw
Quoted 18 lines · Dmitry Osipenko

30.06.2020 12:02, Jon Hunter пишет:

Quoted 17 lines · Dmitry Osipenko
Quoted 4 lines

The arm_cpuidle_simple_enter() returns the entered idle-index and not a error code. It happened that TEGRA_C1=index=err=0, and hence this typo was difficult to notice in the code since everything happened to work properly. This patch fixes the minor typo, it doesn't fix any problem.

I guess that is dependent on if CPUIDLE is enabled ...

#ifdef CONFIG_CPU_IDLE
extern int arm_cpuidle_simple_enter(struct cpuidle_device *dev,

                struct cpuidle_driver *drv, int index);
#else
static inline int arm_cpuidle_simple_enter(struct cpuidle_device *dev,
                 struct cpuidle_driver *drv, int index) { return -ENODEV; }

#endif

Quoted 6 lines
Quoted 1 line

Looks like it could return an error.

Hello Jon!

The cpuidle's enter() callback returns an index of the entered state on success, on negative value on failure.

Yes, however, when I read the first sentence of the changelog it seemed to suggested it would never return and error code. Perhaps you meant in the context of the Tegra CPUIdle driver because CPU_IDLE is always enabled?

Quoted 35 lines

The negative number *could be* a proper error code, but in the same time it also doesn't matter what's the exact negative value is for the cpuidle's core code. Please see more below!

Quoted 20 lines
Quoted 20 lines
---
 drivers/cpuidle/cpuidle-tegra.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cpuidle/cpuidle-tegra.c +1 -1
index 150045849d78..9e9a9cccd755 100644
@@ -236,14 +236,14 @@ static int tegra_cpuidle_enter(struct cpuidle_device *dev,
 			       int index)
 {
 	unsigned int cpu = cpu_logical_map(dev->cpu);
-	int err;
+	int err = 0;
 
 	index = tegra_cpuidle_adjust_state_index(index, cpu);
 	if (dev->states_usage[index].disable)
 		return -1;
 
Quoted 10 lines

drivers/cpuidle/cpuidle-tegra.c static int tegra_cpuidle_enter(struct cpuidle_device *dev, · line 249

Quoted 7 lines
drivers/cpuidle/cpuidle-tegra.c +1 -1
 	if (index == TEGRA_C1)
-		err = arm_cpuidle_simple_enter(dev, drv, index);
+		index = arm_cpuidle_simple_enter(dev, drv, index);
 	else
 		err = tegra_cpuidle_state_enter(dev, index, cpu);
 

However, I do think that there is something not right in the error handling here. Would also be nice to get rid of these -1.

Quoted 2 lines

IIRC, the -1 was borrowed from some other cpuidle driver, for example cpuidle-psci[1] and coupled.c[2] are returning -1 on a failure.

Indeed. Maybe we just let sleeping dogs lie in this case.

Jon

Signature · 1 line
nvpublic
#4 lore raw

01.07.2020 16:56, Jon Hunter пишет:

Quoted 22 lines · Dmitry Osipenko
Quoted 20 lines

30.06.2020 12:02, Jon Hunter пишет:

Quoted 18 lines · Dmitry Osipenko
Quoted 4 lines

The arm_cpuidle_simple_enter() returns the entered idle-index and not a error code. It happened that TEGRA_C1=index=err=0, and hence this typo was difficult to notice in the code since everything happened to work properly. This patch fixes the minor typo, it doesn't fix any problem.

I guess that is dependent on if CPUIDLE is enabled ...

#ifdef CONFIG_CPU_IDLE
extern int arm_cpuidle_simple_enter(struct cpuidle_device *dev,

                struct cpuidle_driver *drv, int index);
#else
static inline int arm_cpuidle_simple_enter(struct cpuidle_device *dev,
                 struct cpuidle_driver *drv, int index) { return -ENODEV; }

#endif

Looks like it could return an error.

Quoted 8 lines
Quoted 4 lines

Hello Jon!

The cpuidle's enter() callback returns an index of the entered state on success, on negative value on failure.

Yes, however, when I read the first sentence of the changelog it seemed to suggested it would never return and error code. Perhaps you meant in the context of the Tegra CPUIdle driver because CPU_IDLE is always enabled?

Yes, the commit message could be improved in regards to the error condition clarification. I'll update it in v2, thank you for the suggestion!

Quoted 35 lines
Quoted 35 lines

The negative number *could be* a proper error code, but in the same time it also doesn't matter what's the exact negative value is for the cpuidle's core code. Please see more below!

Quoted 30 lines
Quoted 17 lines
---
 drivers/cpuidle/cpuidle-tegra.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cpuidle/cpuidle-tegra.c +1 -1
index 150045849d78..9e9a9cccd755 100644
@@ -236,14 +236,14 @@ static int tegra_cpuidle_enter(struct cpuidle_device *dev,
 			       int index)
 {
 	unsigned int cpu = cpu_logical_map(dev->cpu);
-	int err;
+	int err = 0;
 

drivers/cpuidle/cpuidle-tegra.c static int tegra_cpuidle_enter(struct cpuidle_device *dev, · line 249

Quoted 10 lines
drivers/cpuidle/cpuidle-tegra.c +1 -1
 	index = tegra_cpuidle_adjust_state_index(index, cpu);
 	if (dev->states_usage[index].disable)
 		return -1;
 
 	if (index == TEGRA_C1)
-		err = arm_cpuidle_simple_enter(dev, drv, index);
+		index = arm_cpuidle_simple_enter(dev, drv, index);
 	else
 		err = tegra_cpuidle_state_enter(dev, index, cpu);
 

However, I do think that there is something not right in the error handling here. Would also be nice to get rid of these -1.

Quoted 4 lines
Quoted 2 lines

IIRC, the -1 was borrowed from some other cpuidle driver, for example cpuidle-psci[1] and coupled.c[2] are returning -1 on a failure.

Indeed. Maybe we just let sleeping dogs lie in this case.

+1

We could always return to this later on, once there will be a real need.