[PATCH] cpuidle: menu: allow state 0 to be disabled

Subsystems: cpu idle time management framework, the rest

STALE3394d REVIEWED: 1 (0M)

1 review trailer.

3 messages, 2 authors, 2017-06-30 · open the first message on its own page

[PATCH] cpuidle: menu: allow state 0 to be disabled

From: Nicholas Piggin <npiggin@gmail.com>
Date: 2017-06-26 05:38:42

The menu driver does not allow state0 to be disabled completely.
If it is disabled but other enabled states don't meet latency
requirements, it is still used.

Fix this by starting with the first enabled idle state. Fall back
to state 0 if no idle states are enabled (arguably this should be
-EINVAL if it is attempted, but this is the minimal fix).

Acked-by: Gautham R. Shenoy <redacted>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---

Hi Rafael,

This patch is helpful when measuring power draw of polling,
latency cost of idle states, etc. Please consider merging if
you agree.

Thanks,
Nick


 drivers/cpuidle/governors/menu.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c
index b2330fd69e34..61b64c2b2cb8 100644
--- a/drivers/cpuidle/governors/menu.c
+++ b/drivers/cpuidle/governors/menu.c
@@ -286,6 +286,8 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev)
 	struct device *device = get_cpu_device(dev->cpu);
 	int latency_req = pm_qos_request(PM_QOS_CPU_DMA_LATENCY);
 	int i;
+	int first_idx;
+	int idx;
 	unsigned int interactivity_req;
 	unsigned int expected_interval;
 	unsigned long nr_iowaiters, cpu_load;
@@ -335,11 +337,11 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev)
 		if (data->next_timer_us > polling_threshold &&
 		    latency_req > s->exit_latency && !s->disabled &&
 		    !dev->states_usage[CPUIDLE_DRIVER_STATE_START].disable)
-			data->last_state_idx = CPUIDLE_DRIVER_STATE_START;
+			first_idx = CPUIDLE_DRIVER_STATE_START;
 		else
-			data->last_state_idx = CPUIDLE_DRIVER_STATE_START - 1;
+			first_idx = CPUIDLE_DRIVER_STATE_START - 1;
 	} else {
-		data->last_state_idx = CPUIDLE_DRIVER_STATE_START;
+		first_idx = 0;
 	}
 
 	/*
@@ -359,20 +361,28 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev)
 	 * Find the idle state with the lowest power while satisfying
 	 * our constraints.
 	 */
-	for (i = data->last_state_idx + 1; i < drv->state_count; i++) {
+	idx = -1;
+	for (i = first_idx; i < drv->state_count; i++) {
 		struct cpuidle_state *s = &drv->states[i];
 		struct cpuidle_state_usage *su = &dev->states_usage[i];
 
 		if (s->disabled || su->disable)
 			continue;
+		if (idx == -1)
+			idx = i; /* first enabled state */
 		if (s->target_residency > data->predicted_us)
 			break;
 		if (s->exit_latency > latency_req)
 			break;
 
-		data->last_state_idx = i;
+		idx = i;
 	}
 
+	if (idx == -1)
+		idx = 0; /* No states enabled. Must use 0. */
+
+	data->last_state_idx = idx;
+
 	return data->last_state_idx;
 }
 
-- 
2.11.0

Re: [PATCH] cpuidle: menu: allow state 0 to be disabled

From: "Rafael J. Wysocki" <rafael@kernel.org>
Date: 2017-06-29 20:57:36

On Mon, Jun 26, 2017 at 7:38 AM, Nicholas Piggin [off-list ref] wrote:
The menu driver does not allow state0 to be disabled completely.
If it is disabled but other enabled states don't meet latency
requirements, it is still used.

Fix this by starting with the first enabled idle state. Fall back
to state 0 if no idle states are enabled (arguably this should be
-EINVAL if it is attempted, but this is the minimal fix).

Acked-by: Gautham R. Shenoy <redacted>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---

Hi Rafael,
Hi Nick,
This patch is helpful when measuring power draw of polling,
latency cost of idle states, etc. Please consider merging if
you agree.
I have a slight concern about x86 where state0 is mapped to polling
and the way it is used in general stems from that.

Still, I guess we can try and see if this causes any problems to
happen in practice, so I'm going to apply it.

Thanks,
Rafael

Re: [PATCH] cpuidle: menu: allow state 0 to be disabled

From: Nicholas Piggin <npiggin@gmail.com>
Date: 2017-06-30 08:35:33

On Thu, 29 Jun 2017 22:57:33 +0200
"Rafael J. Wysocki" [off-list ref] wrote:
On Mon, Jun 26, 2017 at 7:38 AM, Nicholas Piggin [off-list ref] wrote:
quoted
The menu driver does not allow state0 to be disabled completely.
If it is disabled but other enabled states don't meet latency
requirements, it is still used.

Fix this by starting with the first enabled idle state. Fall back
to state 0 if no idle states are enabled (arguably this should be
-EINVAL if it is attempted, but this is the minimal fix).

Acked-by: Gautham R. Shenoy <redacted>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---

Hi Rafael,  
Hi Nick,
quoted
This patch is helpful when measuring power draw of polling,
latency cost of idle states, etc. Please consider merging if
you agree.  
I have a slight concern about x86 where state0 is mapped to polling
and the way it is used in general stems from that.

Still, I guess we can try and see if this causes any problems to
happen in practice, so I'm going to apply it.
Hi Rafael,

I tried to avoid changing the logic for x86, but let me know if you
spot anything or run into a problem, I will try to help fix it.

I still think it may be worth investigating whether x86 can be fixed
instead of with this special case then by adjusting its idle state
parameters (e.g., in the case of Atom). Anyway that's for another
time and doesn't affect powerpc.

Thanks,
Nick
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help