mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Aubrey Li <aubrey.li@intel.com>
To: tglx@linutronix.de, peterz@infradead.org, len.brown@intel.com,
	rjw@rjwysocki.net, ak@linux.intel.com,
	tim.c.chen@linux.intel.com, arjan@linux.intel.com,
	paulmck@linux.vnet.ibm.com, yang.zhang.wz@gmail.com
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
	Aubrey Li <aubrey.li@linux.intel.com>
Subject: [RFC PATCH v1 08/11] cpuidle: menu: remove reduplicative implementation
Date: Mon, 10 Jul 2017 09:38:38 +0800	[thread overview]
Message-ID: <1499650721-5928-9-git-send-email-aubrey.li@intel.com> (raw)
In-Reply-To: <1499650721-5928-1-git-send-email-aubrey.li@intel.com>

From: Aubrey Li <aubrey.li@linux.intel.com>

For what cpuidle governor already does, we remove them from menu governor
---
 drivers/cpuidle/governors/menu.c | 163 ---------------------------------------
 1 file changed, 163 deletions(-)

diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c
index b2330fd..f90c1a8 100644
--- a/drivers/cpuidle/governors/menu.c
+++ b/drivers/cpuidle/governors/menu.c
@@ -122,7 +122,6 @@
 
 struct menu_device {
 	int		last_state_idx;
-	int             needs_update;
 
 	unsigned int	next_timer_us;
 	unsigned int	predicted_us;
@@ -190,91 +189,6 @@ static inline int performance_multiplier(unsigned long nr_iowaiters, unsigned lo
 
 static DEFINE_PER_CPU(struct menu_device, menu_devices);
 
-static void menu_update(struct cpuidle_driver *drv, struct cpuidle_device *dev);
-
-/*
- * Try detecting repeating patterns by keeping track of the last 8
- * intervals, and checking if the standard deviation of that set
- * 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)
-{
-	int i, divisor;
-	unsigned int max, thresh, avg;
-	uint64_t sum, variance;
-
-	thresh = UINT_MAX; /* Discard outliers above this value */
-
-again:
-
-	/* First calculate the average of past intervals */
-	max = 0;
-	sum = 0;
-	divisor = 0;
-	for (i = 0; i < INTERVALS; i++) {
-		unsigned int value = data->intervals[i];
-		if (value <= thresh) {
-			sum += value;
-			divisor++;
-			if (value > max)
-				max = value;
-		}
-	}
-	if (divisor == INTERVALS)
-		avg = sum >> INTERVAL_SHIFT;
-	else
-		avg = div_u64(sum, divisor);
-
-	/* Then try to determine variance */
-	variance = 0;
-	for (i = 0; i < INTERVALS; i++) {
-		unsigned int value = data->intervals[i];
-		if (value <= thresh) {
-			int64_t diff = (int64_t)value - avg;
-			variance += diff * diff;
-		}
-	}
-	if (divisor == INTERVALS)
-		variance >>= INTERVAL_SHIFT;
-	else
-		do_div(variance, divisor);
-
-	/*
-	 * The typical interval is obtained when standard deviation is
-	 * small (stddev <= 20 us, variance <= 400 us^2) or standard
-	 * deviation is small compared to the average interval (avg >
-	 * 6*stddev, avg^2 > 36*variance). The average is smaller than
-	 * UINT_MAX aka U32_MAX, so computing its square does not
-	 * overflow a u64. We simply reject this candidate average if
-	 * the standard deviation is greater than 715 s (which is
-	 * rather unlikely).
-	 *
-	 * Use this result only if there is no timer to wake us up sooner.
-	 */
-	if (likely(variance <= U64_MAX/36)) {
-		if ((((u64)avg*avg > variance*36) && (divisor * 4 >= INTERVALS * 3))
-							|| variance <= 400) {
-			return avg;
-		}
-	}
-
-	/*
-	 * If we have outliers to the upside in our distribution, discard
-	 * those by setting the threshold to exclude these outliers, then
-	 * calculate the average and standard deviation again. Once we get
-	 * down to the bottom 3/4 of our samples, stop excluding samples.
-	 *
-	 * This can deal with workloads that have long pauses interspersed
-	 * with sporadic activity with a bunch of short pauses.
-	 */
-	if ((divisor * 4) <= INTERVALS * 3)
-		return UINT_MAX;
-
-	thresh = max - 1;
-	goto again;
-}
-
 /**
  * menu_select - selects the next idle state to enter
  * @drv: cpuidle driver containing state data
@@ -291,11 +205,6 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev)
 	unsigned long nr_iowaiters, cpu_load;
 	int resume_latency = dev_pm_qos_raw_read_value(device);
 
-	if (data->needs_update) {
-		menu_update(drv, dev);
-		data->needs_update = 0;
-	}
-
 	/* resume_latency is 0 means no restriction */
 	if (resume_latency && resume_latency < latency_req)
 		latency_req = resume_latency;
@@ -389,78 +298,6 @@ static void menu_reflect(struct cpuidle_device *dev, int index)
 	struct menu_device *data = this_cpu_ptr(&menu_devices);
 
 	data->last_state_idx = index;
-	data->needs_update = 1;
-}
-
-/**
- * menu_update - attempts to guess what happened after entry
- * @drv: cpuidle driver containing state data
- * @dev: the CPU
- */
-static void menu_update(struct cpuidle_driver *drv, struct cpuidle_device *dev)
-{
-	struct menu_device *data = this_cpu_ptr(&menu_devices);
-	int last_idx = data->last_state_idx;
-	struct cpuidle_state *target = &drv->states[last_idx];
-	unsigned int measured_us;
-	unsigned int new_factor;
-
-	/*
-	 * Try to figure out how much time passed between entry to low
-	 * power state and occurrence of the wakeup event.
-	 *
-	 * If the entered idle state didn't support residency measurements,
-	 * we use them anyway if they are short, and if long,
-	 * truncate to the whole expected time.
-	 *
-	 * Any measured amount of time will include the exit latency.
-	 * Since we are interested in when the wakeup begun, not when it
-	 * was completed, we must subtract the exit latency. However, if
-	 * the measured amount of time is less than the exit latency,
-	 * assume the state was never reached and the exit latency is 0.
-	 */
-
-	/* measured value */
-	measured_us = cpuidle_get_last_residency(dev);
-
-	/* Deduct exit latency */
-	if (measured_us > 2 * target->exit_latency)
-		measured_us -= target->exit_latency;
-	else
-		measured_us /= 2;
-
-	/* Make sure our coefficients do not exceed unity */
-	if (measured_us > data->next_timer_us)
-		measured_us = data->next_timer_us;
-
-	/* Update our correction ratio */
-	new_factor = data->correction_factor[data->bucket];
-	new_factor -= new_factor / DECAY;
-
-	if (data->next_timer_us > 0 && measured_us < MAX_INTERESTING)
-		new_factor += RESOLUTION * measured_us / data->next_timer_us;
-	else
-		/*
-		 * we were idle so long that we count it as a perfect
-		 * prediction
-		 */
-		new_factor += RESOLUTION;
-
-	/*
-	 * We don't want 0 as factor; we always want at least
-	 * a tiny bit of estimated time. Fortunately, due to rounding,
-	 * new_factor will stay nonzero regardless of measured_us values
-	 * and the compiler can eliminate this test as long as DECAY > 1.
-	 */
-	if (DECAY == 1 && unlikely(new_factor == 0))
-		new_factor = 1;
-
-	data->correction_factor[data->bucket] = new_factor;
-
-	/* update the repeating-pattern data */
-	data->intervals[data->interval_ptr++] = measured_us;
-	if (data->interval_ptr >= INTERVALS)
-		data->interval_ptr = 0;
 }
 
 /**
-- 
2.7.4

  parent reply	other threads:[~2017-07-10  1:50 UTC|newest]

Thread overview: 114+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-10  1:38 [RFC PATCH v1 00/11] Create fast idle path for short idle periods Aubrey Li
2017-07-10  1:38 ` [RFC PATCH v1 01/11] sched/idle: create a fast " Aubrey Li
2017-07-10  1:38 ` [RFC PATCH v1 02/11] cpuidle: attach cpuidle governor statistics to the per-CPU device Aubrey Li
2017-07-10  1:38 ` [RFC PATCH v1 03/11] cpuidle: introduce cpuidle governor for idle prediction Aubrey Li
2017-07-12 12:16   ` Peter Zijlstra
2017-07-10  1:38 ` [RFC PATCH v1 04/11] sched/idle: make the fast idle path for short idle periods Aubrey Li
2017-07-11 12:58   ` Paul E. McKenney
2017-07-11 16:33     ` Frederic Weisbecker
2017-07-11 18:11       ` Paul E. McKenney
2017-07-12  3:19         ` Li, Aubrey
2017-07-12  5:03           ` Paul E. McKenney
2017-07-12  5:22             ` Li, Aubrey
2017-07-12 12:19       ` Peter Zijlstra
2017-07-10  1:38 ` [RFC PATCH v1 05/11] cpuidle: update idle statistics before cpuidle governor Aubrey Li
2017-07-10  1:38 ` [RFC PATCH v1 06/11] timers: keep sleep length updated as needed Aubrey Li
2017-07-10  1:38 ` [RFC PATCH v1 07/11] cpuidle: make idle residency update more generic Aubrey Li
2017-07-10  1:38 ` Aubrey Li [this message]
2017-07-10  1:38 ` [RFC PATCH v1 09/11] cpuidle: menu: feed cpuidle prediction to menu governor Aubrey Li
2017-07-10  1:38 ` [RFC PATCH v1 10/11] cpuidle: update cpuidle governor when needed Aubrey Li
2017-07-10  1:38 ` [RFC PATCH v1 11/11] sched/idle: Add a tuning knob to allow changing fast idle threshold Aubrey Li
2017-07-10  8:46 ` [RFC PATCH v1 00/11] Create fast idle path for short idle periods Peter Zijlstra
2017-07-10  9:29   ` Wanpeng Li
2017-07-10 13:59   ` Li, Aubrey
2017-07-10 14:46   ` Andi Kleen
2017-07-10 16:42     ` Peter Zijlstra
2017-07-10 17:27       ` Andi Kleen
2017-07-11  4:40         ` Li, Aubrey
2017-07-11  9:41           ` Peter Zijlstra
2017-07-11 16:09             ` Frederic Weisbecker
2017-07-11 16:34               ` Peter Zijlstra
2017-07-11 18:09                 ` Paul E. McKenney
2017-07-12 11:54                   ` Peter Zijlstra
2017-07-12 15:56                     ` Paul E. McKenney
2017-07-12 17:46                       ` Peter Zijlstra
2017-07-12 18:53                         ` Paul E. McKenney
2017-07-12 19:00                           ` Paul E. McKenney
2017-07-19 13:43                       ` Frederic Weisbecker
2017-07-19 14:51                         ` Paul E. McKenney
2017-07-12 12:22                   ` Peter Zijlstra
2017-07-12 15:54                     ` Paul E. McKenney
2017-07-12 17:17                       ` Peter Zijlstra
2017-07-12 17:57                         ` Peter Zijlstra
2017-07-12 18:50                           ` Paul E. McKenney
2017-07-12 18:46                         ` Paul E. McKenney
2017-07-13  8:34                           ` Peter Zijlstra
2017-07-12  4:15                 ` Li, Aubrey
2017-07-12  8:34                   ` Peter Zijlstra
2017-07-12 21:32                     ` Andi Kleen
2017-07-13  8:36                       ` Peter Zijlstra
2017-07-13 14:48                         ` Li, Aubrey
2017-07-13 14:53                           ` Peter Zijlstra
2017-07-13 15:13                             ` Li, Aubrey
2017-07-13 18:28                               ` Peter Zijlstra
2017-07-14  3:56                                 ` Li, Aubrey
2017-07-14 15:38                                   ` Peter Zijlstra
2017-07-14 15:52                                     ` Arjan van de Ven
2017-07-14 15:58                                       ` Peter Zijlstra
2017-07-14 16:03                                         ` Andi Kleen
2017-07-17  9:21                                           ` Peter Zijlstra
2017-07-17 13:41                                             ` Li, Aubrey
2017-07-14 15:53                                     ` Andi Kleen
2017-07-14 16:06                                       ` Peter Zijlstra
2017-07-14 16:26                                         ` Andi Kleen
2017-07-17 19:23                                           ` Peter Zijlstra
2017-07-17 19:27                                             ` Arjan van de Ven
2017-07-17 19:46                                               ` Thomas Gleixner
2017-07-17 19:51                                                 ` Arjan van de Ven
2017-07-17 19:59                                                   ` Thomas Gleixner
2017-07-17 19:48                                             ` Arjan van de Ven
2017-07-17 19:53                                               ` Thomas Gleixner
2017-07-17 19:55                                                 ` Arjan van de Ven
2017-07-18  3:23                                               ` Li, Aubrey
2017-07-18 18:55                                               ` Peter Zijlstra
2017-07-18  3:14                                             ` Li, Aubrey
2017-07-18  4:45                                               ` Andi Kleen
2017-07-18  6:43                                                 ` Thomas Gleixner
2017-07-18  6:56                                                   ` Li, Aubrey
2017-07-18 15:20                                                     ` Paul E. McKenney
2017-07-18 15:29                                                       ` Arjan van de Ven
2017-07-18 16:36                                                         ` Peter Zijlstra
2017-07-18 16:37                                                           ` Arjan van de Ven
2017-07-18 17:05                                                             ` Peter Zijlstra
2017-07-19  5:44                                                       ` Li, Aubrey
2017-07-19 14:48                                                         ` Paul E. McKenney
2017-07-19 15:03                                                           ` Christopher Lameter
2017-07-19 16:54                                                             ` Paul E. McKenney
2017-07-20  1:40                                                           ` Li, Aubrey
2017-07-20 12:50                                                             ` Paul E. McKenney
2017-07-20 13:45                                                               ` Arjan van de Ven
2017-07-20 14:19                                                               ` Peter Zijlstra
2017-07-20 16:02                                                                 ` Paul E. McKenney
2017-07-18 16:45                                                     ` Peter Zijlstra
2017-07-18  6:59                                                   ` Andi Kleen
2017-07-18  7:19                                                     ` Thomas Gleixner
2017-07-19  6:12                                                       ` Li, Aubrey
2017-07-19  7:55                                                         ` Thomas Gleixner
2017-07-20  1:56                                                           ` Li, Aubrey
2017-07-20  8:11                                                             ` Thomas Gleixner
2017-07-20 13:48                                                               ` Arjan van de Ven
2017-07-18  7:24                                                     ` Thomas Gleixner
2017-07-18 13:23                                               ` Peter Zijlstra
2017-07-19 13:43                                               ` Peter Zijlstra
2017-07-13 15:20                             ` Paul E. McKenney
2017-07-14  3:47                               ` Li, Aubrey
2017-07-14  4:05                                 ` Paul E. McKenney
2017-07-17 13:24                                   ` Li, Aubrey
2017-07-17 13:58                                     ` Peter Zijlstra
2017-07-17 14:02                                       ` Li, Aubrey
2017-07-12 12:14                   ` Peter Zijlstra
2017-07-11 17:58               ` Christoph Lameter
2017-07-12  2:07                 ` Li, Aubrey
2017-07-12  2:35               ` Li, Aubrey
2017-07-12 18:10               ` Peter Zijlstra
2017-07-11  9:02         ` Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1499650721-5928-9-git-send-email-aubrey.li@intel.com \
    --to=aubrey.li@intel.com \
    --cc=ak@linux.intel.com \
    --cc=arjan@linux.intel.com \
    --cc=aubrey.li@linux.intel.com \
    --cc=len.brown@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=rjw@rjwysocki.net \
    --cc=tglx@linutronix.de \
    --cc=tim.c.chen@linux.intel.com \
    --cc=x86@kernel.org \
    --cc=yang.zhang.wz@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome