linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] thermal/idle_inject: Support 100% idle injection
@ 2023-01-17 18:22 Srinivas Pandruvada
  2023-01-18  8:18 ` Daniel Lezcano
  2023-01-20 17:30 ` Rafael J. Wysocki
  0 siblings, 2 replies; 3+ messages in thread
From: Srinivas Pandruvada @ 2023-01-17 18:22 UTC (permalink / raw)
  To: rafael
  Cc: linux-pm, linux-kernel, daniel.lezcano, rui.zhang, 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.

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(). Also check for !(run_duration_us +
idle_duration_us) to return -EINVAL in the function idle_inject_start().

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
Change log:
Compared to RFC/RFT
- Add a pr_debug for 100% idle

 drivers/powercap/idle_inject.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/powercap/idle_inject.c b/drivers/powercap/idle_inject.c
index c57b40477246..3ac81086d71f 100644
--- a/drivers/powercap/idle_inject.c
+++ b/drivers/powercap/idle_inject.c
@@ -170,10 +170,12 @@ 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);
 	}
+	if (!run_duration_us)
+		pr_debug("CPU is forced to 100 percent idle\n");
 }
 EXPORT_SYMBOL_NS_GPL(idle_inject_set_duration, IDLE_INJECT);
 
@@ -219,7 +221,7 @@ int idle_inject_start(struct idle_inject_device *ii_dev)
 	unsigned int idle_duration_us = READ_ONCE(ii_dev->idle_duration_us);
 	unsigned int run_duration_us = READ_ONCE(ii_dev->run_duration_us);
 
-	if (!idle_duration_us || !run_duration_us)
+	if (!(idle_duration_us + run_duration_us))
 		return -EINVAL;
 
 	pr_debug("Starting injecting idle cycles on CPUs '%*pbl'\n",
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] thermal/idle_inject: Support 100% idle injection
  2023-01-17 18:22 [PATCH] thermal/idle_inject: Support 100% idle injection Srinivas Pandruvada
@ 2023-01-18  8:18 ` Daniel Lezcano
  2023-01-20 17:30 ` Rafael J. Wysocki
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Lezcano @ 2023-01-18  8:18 UTC (permalink / raw)
  To: Srinivas Pandruvada, rafael; +Cc: linux-pm, linux-kernel, rui.zhang

On 17/01/2023 19:22, Srinivas Pandruvada wrote:
> 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(). Also check for !(run_duration_us +
> idle_duration_us) to return -EINVAL in the function idle_inject_start().
> 
> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
> ---

Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>

-- 
<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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] thermal/idle_inject: Support 100% idle injection
  2023-01-17 18:22 [PATCH] thermal/idle_inject: Support 100% idle injection Srinivas Pandruvada
  2023-01-18  8:18 ` Daniel Lezcano
@ 2023-01-20 17:30 ` Rafael J. Wysocki
  1 sibling, 0 replies; 3+ messages in thread
From: Rafael J. Wysocki @ 2023-01-20 17:30 UTC (permalink / raw)
  To: Srinivas Pandruvada
  Cc: rafael, linux-pm, linux-kernel, daniel.lezcano, rui.zhang

It's powercap/idle_inject.

On Tue, Jan 17, 2023 at 7:23 PM Srinivas Pandruvada
<srinivas.pandruvada@linux.intel.com> wrote:
>
> 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(). Also check for !(run_duration_us +
> idle_duration_us) to return -EINVAL in the function idle_inject_start().

And I have edited the changelog somewhat.

> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
> ---
> Change log:
> Compared to RFC/RFT
> - Add a pr_debug for 100% idle
>
>  drivers/powercap/idle_inject.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/powercap/idle_inject.c b/drivers/powercap/idle_inject.c
> index c57b40477246..3ac81086d71f 100644
> --- a/drivers/powercap/idle_inject.c
> +++ b/drivers/powercap/idle_inject.c
> @@ -170,10 +170,12 @@ 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);
>         }
> +       if (!run_duration_us)
> +               pr_debug("CPU is forced to 100 percent idle\n");
>  }
>  EXPORT_SYMBOL_NS_GPL(idle_inject_set_duration, IDLE_INJECT);
>
> @@ -219,7 +221,7 @@ int idle_inject_start(struct idle_inject_device *ii_dev)
>         unsigned int idle_duration_us = READ_ONCE(ii_dev->idle_duration_us);
>         unsigned int run_duration_us = READ_ONCE(ii_dev->run_duration_us);
>
> -       if (!idle_duration_us || !run_duration_us)
> +       if (!(idle_duration_us + run_duration_us))
>                 return -EINVAL;
>
>         pr_debug("Starting injecting idle cycles on CPUs '%*pbl'\n",
> --

Applied as 6.3 material, thanks!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-01-20 17:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-17 18:22 [PATCH] thermal/idle_inject: Support 100% idle injection Srinivas Pandruvada
2023-01-18  8:18 ` Daniel Lezcano
2023-01-20 17:30 ` Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).