mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christian Loehle <christian.loehle@arm.com>
To: "Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Linux PM <linux-pm@vger.kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Daniel Lezcano <daniel.lezcano@linaro.org>,
	Artem Bityutskiy <artem.bityutskiy@linux.intel.com>,
	Aboorva Devarajan <aboorvad@linux.ibm.com>
Subject: Re: [RFT][PATCH v1 4/5] cpuidle: menu: Eliminate outliers on both ends of the sample set
Date: Mon, 17 Feb 2025 13:26:40 +0000	[thread overview]
Message-ID: <3bbd1ada-0d26-4c91-b1f3-a947caf5abd0@arm.com> (raw)
In-Reply-To: <2301940.iZASKD2KPV@rjwysocki.net>

On 2/6/25 14:26, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> Currently, get_typical_interval() attempts to eliminate outliers at the
> high end of the sample set only (probably in order to bias the prediction
> toward lower values), but this it problematic because if the outliers are
> present at the low end of the sample set, discarding the highest values
> will not help to reduce the variance.
> 
> Since the presence of outliers at the low end of the sample set is
> generally as likely as their presence at the high end of the sample
> set, modify get_typical_interval() to treat samples at the largest
> distances from the average (on both ends of the sample set) as outliers.
> 
> This should increase the likelihood of making a meaningful prediction
> in some cases.
> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
>  drivers/cpuidle/governors/menu.c |   32 ++++++++++++++++++++++----------
>  1 file changed, 22 insertions(+), 10 deletions(-)
> 
> --- a/drivers/cpuidle/governors/menu.c
> +++ b/drivers/cpuidle/governors/menu.c
> @@ -116,30 +116,37 @@
>   */
>  static unsigned int get_typical_interval(struct menu_device *data)
>  {
> -	unsigned int max, divisor, thresh = UINT_MAX;
> +	s64 value, min_thresh = -1, max_thresh = UINT_MAX;
> +	unsigned int max, min, divisor;
>  	u64 avg, variance, avg_sq;
>  	int i;
>  
>  again:
>  	/* Compute the average and variance of past intervals. */
>  	max = 0;
> +	min = UINT_MAX;
>  	avg = 0;
>  	variance = 0;
>  	divisor = 0;
>  	for (i = 0; i < INTERVALS; i++) {
> -		unsigned int value = data->intervals[i];
> -
> -		/* Discard data points above or at the threshold. */
> -		if (value >= thresh)
> +		value = data->intervals[i];
> +		/*
> +		 * Discard the samples outside the interval between the min and
> +		 * max thresholds.
> +		 */
> +		if (value <= min_thresh || value >= max_thresh)
>  			continue;
>  
>  		divisor++;
>  
>  		avg += value;
> -		variance += (u64)value * value;
> +		variance += value * value;
>  
>  		if (value > max)
>  			max = value;
> +
> +		if (value < min)
> +			min = value;
>  	}
>  
>  	if (!max)
> @@ -175,10 +182,10 @@
>  	}
>  
>  	/*
> -	 * If we have outliers to the upside in our distribution, discard
> -	 * those by setting the threshold to exclude these outliers, then
> +	 * If there are outliers, discard them by setting thresholds to exclude
> +	 * data points at a large enough distance from the average, then
>  	 * calculate the average and standard deviation again. Once we get
> -	 * down to the bottom 3/4 of our samples, stop excluding samples.
> +	 * down to the last 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.
> @@ -186,7 +193,12 @@
>  	if ((divisor * 4) <= INTERVALS * 3)
>  		return UINT_MAX;
>  
> -	thresh = max;
> +	/* Update the thresholds for the next round. */
> +	if (avg - min > max - avg)
> +		min_thresh = min;
> +	else
> +		max_thresh = max;
> +
>  	goto again;
>  }

Reviewed-by: Christian Loehle <christian.loehle@arm.com>


  reply	other threads:[~2025-02-17 13:26 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-06 14:21 [RFT][PATCH v1 0/5] cpuidle: menu: Avoid discarding useful information when processing recent idle intervals Rafael J. Wysocki
2025-02-06 14:22 ` [RFT][PATCH v1 1/5] cpuidle: menu: Drop a redundant local variable Rafael J. Wysocki
2025-02-06 14:55   ` Christian Loehle
2025-02-06 14:24 ` [RFT][PATCH v1 2/5] cpuidle: menu: Use one loop for average and variance computations Rafael J. Wysocki
2025-02-17 13:03   ` Christian Loehle
2025-02-06 14:25 ` [RFT][PATCH v1 3/5] cpuidle: menu: Tweak threshold use in get_typical_interval() Rafael J. Wysocki
2025-02-17 13:08   ` Christian Loehle
2025-02-06 14:26 ` [RFT][PATCH v1 4/5] cpuidle: menu: Eliminate outliers on both ends of the sample set Rafael J. Wysocki
2025-02-17 13:26   ` Christian Loehle [this message]
2025-02-06 14:29 ` [RFT][PATCH v1 5/5] cpuidle: menu: Avoid discarding useful information Rafael J. Wysocki
2025-02-17 13:39   ` Christian Loehle
2025-02-17 13:47     ` Rafael J. Wysocki
2025-08-04 16:54   ` Marc Zyngier
2025-08-05 13:23     ` Rafael J. Wysocki
2025-08-05 14:41       ` Christian Loehle
2025-08-05 16:00       ` Marc Zyngier
2025-08-05 18:50         ` Rafael J. Wysocki
2025-08-06  7:19           ` Marc Zyngier
2025-08-06 12:48           ` Christian Loehle
2025-02-07 14:48 ` [RFT][PATCH v1 0/5] cpuidle: menu: Avoid discarding useful information when processing recent idle intervals Artem Bityutskiy
2025-02-07 15:24   ` Christian Loehle
2025-02-07 15:35     ` Rafael J. Wysocki
2025-02-07 15:45   ` Rafael J. Wysocki
2025-03-12 21:38   ` Doug Smythies
2025-02-10 14:15 ` Christian Loehle
2025-02-10 14:43   ` Rafael J. Wysocki
2025-02-10 14:47     ` Christian Loehle
2025-02-18 21:17   ` Christian Loehle
2025-02-19 12:06     ` Rafael J. Wysocki
2025-02-14  4:30 ` Doug Smythies
2025-02-14 22:10   ` Rafael J. Wysocki
2025-02-16 16:16     ` Doug Smythies
2025-02-24  6:27 ` Aboorva Devarajan
2025-02-24  6:38   ` Aboorva Devarajan
2025-02-24 12:35   ` Rafael J. Wysocki
2025-02-26  4:49   ` Aboorva Devarajan
2025-02-26 10:54     ` Christian Loehle

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=3bbd1ada-0d26-4c91-b1f3-a947caf5abd0@arm.com \
    --to=christian.loehle@arm.com \
    --cc=aboorvad@linux.ibm.com \
    --cc=artem.bityutskiy@linux.intel.com \
    --cc=daniel.lezcano@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rjw@rjwysocki.net \
    /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

all inboxes | Powered by JetHome®