All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] cpuidle: menu: Two more refinements
@ 2018-10-15 11:50 Rafael J. Wysocki
  2018-10-15 11:51 ` [PATCH 1/2] cpuidle: menu: Drop redundant comparison Rafael J. Wysocki
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Rafael J. Wysocki @ 2018-10-15 11:50 UTC (permalink / raw)
  To: Linux PM; +Cc: LKML, Peter Zijlstra, Daniel Lezcano, Doug Smythies

Hi All,

The following patches are two more refinements of the menu governor (on top
of the recent changes in linux-next now).  The are not expected to change the
overall behavior of it.

Please refer to the patch changelogs for details.

Thanks,
Rafael


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

* [PATCH 1/2] cpuidle: menu: Drop redundant comparison
  2018-10-15 11:50 [PATCH 0/2] cpuidle: menu: Two more refinements Rafael J. Wysocki
@ 2018-10-15 11:51 ` Rafael J. Wysocki
  2018-10-15 11:53 ` [PATCH 2/2] cpuidle: menu: Avoid computations when result will be discarded Rafael J. Wysocki
  2018-10-17 10:36 ` [PATCH 0/2] cpuidle: menu: Two more refinements Rafael J. Wysocki
  2 siblings, 0 replies; 4+ messages in thread
From: Rafael J. Wysocki @ 2018-10-15 11:51 UTC (permalink / raw)
  To: Linux PM; +Cc: LKML, Peter Zijlstra, Daniel Lezcano, Doug Smythies

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Since the correction factor cannot be greater than RESOLUTION * DECAY,
the result of the predicted_us computation in menu_select() cannot be
greater than data->next_timer_us, so it is not necessary to compare
the "typical interval" value coming from get_typical_interval() with
data->next_timer_us separately.

It is sufficient to copmare predicted_us with the return value of
get_typical_interval() directly, so do that and drop the now
redundant expected_interval variable.

No intentional changes of behavior.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/cpuidle/governors/menu.c |    7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

Index: linux-pm/drivers/cpuidle/governors/menu.c
===================================================================
--- linux-pm.orig/drivers/cpuidle/governors/menu.c
+++ linux-pm/drivers/cpuidle/governors/menu.c
@@ -287,7 +287,6 @@ static int menu_select(struct cpuidle_dr
 	int i;
 	int idx;
 	unsigned int interactivity_req;
-	unsigned int expected_interval;
 	unsigned int predicted_us;
 	unsigned long nr_iowaiters, cpu_load;
 	ktime_t delta_next;
@@ -323,14 +322,10 @@ static int menu_select(struct cpuidle_dr
 	predicted_us = DIV_ROUND_CLOSEST_ULL((uint64_t)data->next_timer_us *
 					 data->correction_factor[data->bucket],
 					 RESOLUTION * DECAY);
-
-	expected_interval = get_typical_interval(data);
-	expected_interval = min(expected_interval, data->next_timer_us);
-
 	/*
 	 * Use the lowest expected idle interval to pick the idle state.
 	 */
-	predicted_us = min(predicted_us, expected_interval);
+	predicted_us = min(predicted_us, get_typical_interval(data));
 
 	if (tick_nohz_tick_stopped()) {
 		/*


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

* [PATCH 2/2] cpuidle: menu: Avoid computations when result will be discarded
  2018-10-15 11:50 [PATCH 0/2] cpuidle: menu: Two more refinements Rafael J. Wysocki
  2018-10-15 11:51 ` [PATCH 1/2] cpuidle: menu: Drop redundant comparison Rafael J. Wysocki
@ 2018-10-15 11:53 ` Rafael J. Wysocki
  2018-10-17 10:36 ` [PATCH 0/2] cpuidle: menu: Two more refinements Rafael J. Wysocki
  2 siblings, 0 replies; 4+ messages in thread
From: Rafael J. Wysocki @ 2018-10-15 11:53 UTC (permalink / raw)
  To: Linux PM; +Cc: LKML, Peter Zijlstra, Daniel Lezcano, Doug Smythies

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

If the minimum interval taken into account in the average computation
loop in get_typical_interval() is less than the expected idle
duration determined so far, the resultant average cannot be greater
than that value as well and the entire return result of the function
is going to be discarded anyway going forward.

In that case, it is a waste of time to carry out the remaining
computations in get_typical_interval(), so avoid that by returning
early if the minimum interval is not below the expected idle duration.

No intentional changes of behavior.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/cpuidle/governors/menu.c |   19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

Index: linux-pm/drivers/cpuidle/governors/menu.c
===================================================================
--- linux-pm.orig/drivers/cpuidle/governors/menu.c
+++ linux-pm/drivers/cpuidle/governors/menu.c
@@ -196,10 +196,11 @@ static void menu_update(struct cpuidle_d
  * of points is below a threshold. If it is... then use the
  * average of these 8 points as the estimated value.
  */
-static unsigned int get_typical_interval(struct menu_device *data)
+static unsigned int get_typical_interval(struct menu_device *data,
+					 unsigned int predicted_us)
 {
 	int i, divisor;
-	unsigned int max, thresh, avg;
+	unsigned int min, max, thresh, avg;
 	uint64_t sum, variance;
 
 	thresh = UINT_MAX; /* Discard outliers above this value */
@@ -207,6 +208,7 @@ static unsigned int get_typical_interval
 again:
 
 	/* First calculate the average of past intervals */
+	min = UINT_MAX;
 	max = 0;
 	sum = 0;
 	divisor = 0;
@@ -217,8 +219,19 @@ again:
 			divisor++;
 			if (value > max)
 				max = value;
+
+			if (value < min)
+				min = value;
 		}
 	}
+
+	/*
+	 * If the result of the computation is going to be discarded anyway,
+	 * avoid the computation altogether.
+	 */
+	if (min >= predicted_us)
+		return UINT_MAX;
+
 	if (divisor == INTERVALS)
 		avg = sum >> INTERVAL_SHIFT;
 	else
@@ -325,7 +338,7 @@ static int menu_select(struct cpuidle_dr
 	/*
 	 * Use the lowest expected idle interval to pick the idle state.
 	 */
-	predicted_us = min(predicted_us, get_typical_interval(data));
+	predicted_us = min(predicted_us, get_typical_interval(data, predicted_us));
 
 	if (tick_nohz_tick_stopped()) {
 		/*


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

* Re: [PATCH 0/2] cpuidle: menu: Two more refinements
  2018-10-15 11:50 [PATCH 0/2] cpuidle: menu: Two more refinements Rafael J. Wysocki
  2018-10-15 11:51 ` [PATCH 1/2] cpuidle: menu: Drop redundant comparison Rafael J. Wysocki
  2018-10-15 11:53 ` [PATCH 2/2] cpuidle: menu: Avoid computations when result will be discarded Rafael J. Wysocki
@ 2018-10-17 10:36 ` Rafael J. Wysocki
  2 siblings, 0 replies; 4+ messages in thread
From: Rafael J. Wysocki @ 2018-10-17 10:36 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM, Linux Kernel Mailing List, Peter Zijlstra,
	Daniel Lezcano, Doug Smythies

On Mon, Oct 15, 2018 at 1:57 PM Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
>
> Hi All,
>
> The following patches are two more refinements of the menu governor (on top
> of the recent changes in linux-next now).  The are not expected to change the
> overall behavior of it.
>
> Please refer to the patch changelogs for details.

Any objections or concerns regarding the two patches?

If not, I will queue them up.

Thanks,
Rafael

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

end of thread, other threads:[~2018-10-17 10:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-15 11:50 [PATCH 0/2] cpuidle: menu: Two more refinements Rafael J. Wysocki
2018-10-15 11:51 ` [PATCH 1/2] cpuidle: menu: Drop redundant comparison Rafael J. Wysocki
2018-10-15 11:53 ` [PATCH 2/2] cpuidle: menu: Avoid computations when result will be discarded Rafael J. Wysocki
2018-10-17 10:36 ` [PATCH 0/2] cpuidle: menu: Two more refinements Rafael J. Wysocki

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.