diff mbox series

[V6,3/3] powercap/drivers/idle_inject: Specify the idle state to inject

Message ID 20191030075141.1039-3-daniel.lezcano@linaro.org
State New
Headers show
Series [V6,1/3] cpuidle: play_idle: Make play_idle more flexible | expand

Commit Message

Daniel Lezcano Oct. 30, 2019, 7:51 a.m. UTC
Currently the idle injection framework only allows to inject the
deepest idle state available on the system.

Give the opportunity to specify which idle state we want to inject by
adding a new function helper to set the state and use it when calling
play_idle().

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

Acked-by: Mathieu Poirier <mathieu.poirier@linaro.org>

Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>

---
  V6:
   - Rename variable name 'state' -> 'state_idx':
     https://lkml.org/lkml/2019/10/28/874
---
 drivers/powercap/idle_inject.c | 14 +++++++++++++-
 include/linux/idle_inject.h    |  3 +++
 2 files changed, 16 insertions(+), 1 deletion(-)

-- 
2.17.1

Comments

Rafael J. Wysocki Nov. 8, 2019, 1:24 a.m. UTC | #1
On Wednesday, October 30, 2019 8:51:41 AM CET Daniel Lezcano wrote:
> Currently the idle injection framework only allows to inject the

> deepest idle state available on the system.

> 

> Give the opportunity to specify which idle state we want to inject by

> adding a new function helper to set the state and use it when calling

> play_idle().

> 

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

> Acked-by: Mathieu Poirier <mathieu.poirier@linaro.org>

> Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>

> ---

>   V6:

>    - Rename variable name 'state' -> 'state_idx':

>      https://lkml.org/lkml/2019/10/28/874

> ---

>  drivers/powercap/idle_inject.c | 14 +++++++++++++-

>  include/linux/idle_inject.h    |  3 +++

>  2 files changed, 16 insertions(+), 1 deletion(-)

> 

> diff --git a/drivers/powercap/idle_inject.c b/drivers/powercap/idle_inject.c

> index 233c878cbf46..2607d3e9afc5 100644

> --- a/drivers/powercap/idle_inject.c

> +++ b/drivers/powercap/idle_inject.c

> @@ -66,6 +66,7 @@ struct idle_inject_thread {

>   */

>  struct idle_inject_device {

>  	struct hrtimer timer;

> +	int state_idx;

>  	unsigned int idle_duration_us;

>  	unsigned int run_duration_us;

>  	unsigned long int cpumask[0];

> @@ -140,7 +141,7 @@ static void idle_inject_fn(unsigned int cpu)

>  	iit->should_run = 0;

>  

>  	play_idle(READ_ONCE(ii_dev->idle_duration_us),

> -		  cpuidle_find_deepest_state());

> +		  READ_ONCE(ii_dev->state_idx));

>  }

>  

>  /**

> @@ -171,6 +172,16 @@ void idle_inject_get_duration(struct idle_inject_device *ii_dev,

>  	*idle_duration_us = READ_ONCE(ii_dev->idle_duration_us);

>  }

>  

> +/**

> + * idle_inject_set_state - set the idle state to inject

> + * @state: an integer for the idle state to inject

> + */

> +void idle_inject_set_state(struct idle_inject_device *ii_dev, int index)

> +{

> +	if (index >= CPUIDLE_STATE_NOUSE && index < CPUIDLE_STATE_MAX)

> +		WRITE_ONCE(ii_dev->state_idx, index);

> +}


So whoever uses this interface, needs to know the idle states list as
provided by the cpuidle driver for the given CPU, but what really needs
to be specified here is the exit latency limit (which can be provided as
a number in us or ns without knowing the state index).
diff mbox series

Patch

diff --git a/drivers/powercap/idle_inject.c b/drivers/powercap/idle_inject.c
index 233c878cbf46..2607d3e9afc5 100644
--- a/drivers/powercap/idle_inject.c
+++ b/drivers/powercap/idle_inject.c
@@ -66,6 +66,7 @@  struct idle_inject_thread {
  */
 struct idle_inject_device {
 	struct hrtimer timer;
+	int state_idx;
 	unsigned int idle_duration_us;
 	unsigned int run_duration_us;
 	unsigned long int cpumask[0];
@@ -140,7 +141,7 @@  static void idle_inject_fn(unsigned int cpu)
 	iit->should_run = 0;
 
 	play_idle(READ_ONCE(ii_dev->idle_duration_us),
-		  cpuidle_find_deepest_state());
+		  READ_ONCE(ii_dev->state_idx));
 }
 
 /**
@@ -171,6 +172,16 @@  void idle_inject_get_duration(struct idle_inject_device *ii_dev,
 	*idle_duration_us = READ_ONCE(ii_dev->idle_duration_us);
 }
 
+/**
+ * idle_inject_set_state - set the idle state to inject
+ * @state: an integer for the idle state to inject
+ */
+void idle_inject_set_state(struct idle_inject_device *ii_dev, int index)
+{
+	if (index >= CPUIDLE_STATE_NOUSE && index < CPUIDLE_STATE_MAX)
+		WRITE_ONCE(ii_dev->state_idx, index);
+}
+
 /**
  * idle_inject_start - start idle injections
  * @ii_dev: idle injection control device structure
@@ -299,6 +310,7 @@  struct idle_inject_device *idle_inject_register(struct cpumask *cpumask)
 	cpumask_copy(to_cpumask(ii_dev->cpumask), cpumask);
 	hrtimer_init(&ii_dev->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
 	ii_dev->timer.function = idle_inject_timer_fn;
+	ii_dev->state_idx = 0;
 
 	for_each_cpu(cpu, to_cpumask(ii_dev->cpumask)) {
 
diff --git a/include/linux/idle_inject.h b/include/linux/idle_inject.h
index a445cd1a36c5..2efc60252d7b 100644
--- a/include/linux/idle_inject.h
+++ b/include/linux/idle_inject.h
@@ -26,4 +26,7 @@  void idle_inject_set_duration(struct idle_inject_device *ii_dev,
 void idle_inject_get_duration(struct idle_inject_device *ii_dev,
 				 unsigned int *run_duration_us,
 				 unsigned int *idle_duration_us);
+
+void idle_inject_set_state(struct idle_inject_device *ii_dev, int index);
+
 #endif /* __IDLE_INJECT_H__ */