Skip to contentSkip to conversation

thermal/idle_inject: Support 100% idle injection

RFC PATCH In review Srinivas Pandruvada 2 participants 4 messages Dec 9, 2022 – Dec 21, 2022 Power management core

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 thermal/idle_inject: Support 100% idle injection

The users of idle injection framework allow 100% idle injection. For
example: thermal/cpuidle_cooling.c driver. When the ratio set to 100%, the runtime_duration becomes zero.

In the function idle_inject_set_duration() in idle injection framework run_duration_us == 0 is silently ignored, without any error (it is a void function). So, the caller will assume that everything is fine and 100% idle is effective. But in reality the idle inject will be whatever set before.

There are two options:
- The caller change their max state to 99% instead of 100% and document that 100% is not supported by idle inject framework
- Support 100% idle support in idle inject framework

Since there are other protections via RT throttling, this framework can allow 100% idle. The RT throttling will be activated at 95% idle by default. The caller disabling RT throttling and injecting 100% idle, should be aware that CPU can't be used at all.

The idle inject timer is started for (run_duration_us + idle_duration_us) duration. Hence replace (run_duration_us && idle_duration_us) with (run_duration_us + idle_duration_us) in the function idle_inject_set_duration().

---
 drivers/powercap/idle_inject.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/powercap/idle_inject.c +1 -1
index f48e71501429..4a4fe60d2563 100644
@@ -184,7 +184,7 @@ void idle_inject_set_duration(struct idle_inject_device *ii_dev,
 			      unsigned int run_duration_us,
 			      unsigned int idle_duration_us)
 {
-	if (run_duration_us && idle_duration_us) {
+	if (run_duration_us + idle_duration_us) {
 		WRITE_ONCE(ii_dev->run_duration_us, run_duration_us);
 		WRITE_ONCE(ii_dev->idle_duration_us, idle_duration_us);
 	}
Signature · 1 line
2.37.2
#1 lore raw

Hi Srinivas,

Quoted 9 lines · Srinivas Pandruvada

The users of idle injection framework allow 100% idle injection. For
example: thermal/cpuidle_cooling.c driver. When the ratio set to 100%, the runtime_duration becomes zero.

In the function idle_inject_set_duration() in idle injection framework run_duration_us == 0 is silently ignored, without any error (it is a void function). So, the caller will assume that everything is fine and 100% idle is effective. But in reality the idle inject will be whatever set before.

Good catch

Quoted 4 lines

There are two options:
- The caller change their max state to 99% instead of 100% and document that 100% is not supported by idle inject framework
- Support 100% idle support in idle inject framework

Yes, from my POV a CPU being impossible to cool down for any reason should end up by staying off.

Quoted 4 lines

Since there are other protections via RT throttling, this framework can allow 100% idle. The RT throttling will be activated at 95% idle by default. The caller disabling RT throttling and injecting 100% idle, should be aware that CPU can't be used at all.

Would it make sense to write a trace in this case ?

Quoted 4 lines

The idle inject timer is started for (run_duration_us + idle_duration_us) duration. Hence replace (run_duration_us && idle_duration_us) with (run_duration_us + idle_duration_us) in the function idle_inject_set_duration().

Sounds good to me

Quoted 18 lines
---
  drivers/powercap/idle_inject.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/powercap/idle_inject.c +1 -1
index f48e71501429..4a4fe60d2563 100644
@@ -184,7 +184,7 @@ void idle_inject_set_duration(struct idle_inject_device *ii_dev,
  			      unsigned int run_duration_us,
  			      unsigned int idle_duration_us)
  {
-	if (run_duration_us && idle_duration_us) {
+	if (run_duration_us + idle_duration_us) {
  		WRITE_ONCE(ii_dev->run_duration_us, run_duration_us);
  		WRITE_ONCE(ii_dev->idle_duration_us, idle_duration_us);
  	}
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#2 lore raw
Quoted 31 lines · Daniel Lezcano

Hi Srinivas,

Quoted 6 lines · Srinivas Pandruvada

The users of idle injection framework allow 100% idle injection. For
example: thermal/cpuidle_cooling.c driver. When the ratio set to 100%,
the runtime_duration becomes zero.

Quoted 9 lines

In the function idle_inject_set_duration() in idle injection framework
run_duration_us == 0 is silently ignored, without any error (it is a
void function). So, the caller will assume that everything is fine and
100% idle is effective. But in reality the idle inject will be whatever
set before.

Good catch

Quoted 4 lines

There are two options:
- The caller change their max state to 99% instead of 100% and document that 100% is not supported by idle inject framework
- Support 100% idle support in idle inject framework

Yes, from my POV a CPU being impossible to cool down for any reason should end up by staying off.

Quoted 8 lines
Quoted 6 lines

Since there are other protections via RT throttling, this framework can
allow 100% idle. The RT throttling will be activated at 95% idle by default. The caller disabling RT throttling and injecting 100% idle,
should be aware that CPU can't be used at all.

Would it make sense to write a trace in this case ?

There is one printk already:
printk_deferred_once("sched: RT throttling activated\n")

You mean we should add

trace_sched_* for this?

Quoted 9 lines
Quoted 6 lines

The idle inject timer is started for (run_duration_us + idle_duration_us)
duration. Hence replace (run_duration_us && idle_duration_us) with (run_duration_us + idle_duration_us) in the function idle_inject_set_duration().

Sounds good to me

I will submit a patch for this.

Thanks,
Srinivas

Quoted 24 lines
Quoted 23 lines

Signed-off-by: Srinivas Pandruvada
<[email protected]>
---
  drivers/powercap/idle_inject.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/powercap/idle_inject.c +1 -1
index f48e71501429..4a4fe60d2563 100644
@@ -184,7 +184,7 @@ void idle_inject_set_duration(struct
 idle_inject_device *ii_dev,
                               unsigned int run_duration_us,
                               unsigned int idle_duration_us)
   {
-       if (run_duration_us && idle_duration_us) {
+       if (run_duration_us + idle_duration_us) {
                 WRITE_ONCE(ii_dev->run_duration_us,
 run_duration_us);

                WRITE_ONCE(ii_dev->idle_duration_us, idle_duration_us);
        }

#3 lore raw
Quoted 39 lines · srinivas pandruvada
Quoted 38 lines · Daniel Lezcano

Hi Srinivas,

Quoted 6 lines · Srinivas Pandruvada

The users of idle injection framework allow 100% idle injection. For
example: thermal/cpuidle_cooling.c driver. When the ratio set to 100%,
the runtime_duration becomes zero.

Quoted 9 lines

In the function idle_inject_set_duration() in idle injection framework
run_duration_us == 0 is silently ignored, without any error (it is a
void function). So, the caller will assume that everything is fine and
100% idle is effective. But in reality the idle inject will be whatever
set before.

Good catch

Quoted 4 lines

There are two options:
- The caller change their max state to 99% instead of 100% and document that 100% is not supported by idle inject framework
- Support 100% idle support in idle inject framework

Yes, from my POV a CPU being impossible to cool down for any reason should end up by staying off.

Quoted 6 lines

Since there are other protections via RT throttling, this framework can
allow 100% idle. The RT throttling will be activated at 95% idle by default. The caller disabling RT throttling and injecting 100% idle,
should be aware that CPU can't be used at all.

Quoted 7 lines
Quoted 1 line

Would it make sense to write a trace in this case ?

There is one printk already:
printk_deferred_once("sched: RT throttling activated\n") You mean we should add

trace_sched_* for this?

I meant the CPU is going 100% idle

Quoted 38 lines
Quoted 8 lines
Quoted 5 lines

The idle inject timer is started for (run_duration_us + idle_duration_us)
duration. Hence replace (run_duration_us && idle_duration_us) with (run_duration_us + idle_duration_us) in the function idle_inject_set_duration().

Sounds good to me

I will submit a patch for this.

Thanks,
Srinivas

Quoted 24 lines
Quoted 23 lines

Signed-off-by: Srinivas Pandruvada
<[email protected]>

---
   drivers/powercap/idle_inject.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
drivers/powercap/idle_inject.c +1 -1
index f48e71501429..4a4fe60d2563 100644
@@ -184,7 +184,7 @@ void idle_inject_set_duration(struct
 idle_inject_device *ii_dev,
                               unsigned int run_duration_us,
                               unsigned int idle_duration_us)
   {
-       if (run_duration_us && idle_duration_us) {
+       if (run_duration_us + idle_duration_us) {
                 WRITE_ONCE(ii_dev->run_duration_us,
 run_duration_us);

                WRITE_ONCE(ii_dev->idle_duration_us,
idle_duration_us);
        }

Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog