From: Christian Loehle <christian.loehle@arm.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Linux PM <linux-pm@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
Reka Norman <rekanorman@chromium.org>
Subject: Re: [PATCH v1 4/4] cpuidle: governors: teo: Decay metrics below DECAY_SHIFT threshold
Date: Wed, 12 Nov 2025 18:00:01 +0000 [thread overview]
Message-ID: <8baa1d22-c3ad-4c62-a70e-fc64bfbfdf0e@arm.com> (raw)
In-Reply-To: <CAJZ5v0jcGsFh1ATM-Aw1oxZy-zazm+GaMUC4gwEaCskn9V-amg@mail.gmail.com>
On 11/12/25 17:51, Rafael J. Wysocki wrote:
> On Wed, Nov 12, 2025 at 6:29 PM Christian Loehle
> <christian.loehle@arm.com> wrote:
>>
>> On 11/12/25 16:25, Rafael J. Wysocki wrote:
>>> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>>>
>>> If a given governor metric falls below a certain value (8 for
>>> DECAY_SHIFT equal to 3), it will not decay any more due to the
>>> simplistic decay implementation. This may in some cases lead to
>>> subtle inconsistencies in the governor behavior, so change the
>>> decay implementation to take it into account and set the metric
>>> at hand to 0 in that case.
>>>
>>> Suggested-by: Christian Loehle <christian.loehle@arm.com>
>>> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>>> ---
>>> drivers/cpuidle/governors/teo.c | 20 +++++++++++++++-----
>>> 1 file changed, 15 insertions(+), 5 deletions(-)
>>>
>>> --- a/drivers/cpuidle/governors/teo.c
>>> +++ b/drivers/cpuidle/governors/teo.c
>>> @@ -148,6 +148,16 @@ struct teo_cpu {
>>>
>>> static DEFINE_PER_CPU(struct teo_cpu, teo_cpus);
>>>
>>> +static void teo_decay(unsigned int *metric)
>>> +{
>>> + unsigned int delta = *metric >> DECAY_SHIFT;
>>> +
>>> + if (delta)
>>> + *metric -= delta;
>>> + else
>>> + *metric = 0;
>>> +}
>>> +
>>> /**
>>> * teo_update - Update CPU metrics after wakeup.
>>> * @drv: cpuidle driver containing state data.
>>> @@ -159,7 +169,7 @@ static void teo_update(struct cpuidle_dr
>>> int i, idx_timer = 0, idx_duration = 0;
>>> s64 target_residency_ns, measured_ns;
>>>
>>> - cpu_data->short_idles -= cpu_data->short_idles >> DECAY_SHIFT;
>>> + teo_decay(&cpu_data->short_idles);
>>>
>>> if (cpu_data->artificial_wakeup) {
>>> /*
>>> @@ -195,8 +205,8 @@ static void teo_update(struct cpuidle_dr
>>> for (i = 0; i < drv->state_count; i++) {
>>> struct teo_bin *bin = &cpu_data->state_bins[i];
>>>
>>> - bin->hits -= bin->hits >> DECAY_SHIFT;
>>> - bin->intercepts -= bin->intercepts >> DECAY_SHIFT;
>>> + teo_decay(&bin->hits);
>>> + teo_decay(&bin->intercepts);
>>>
>>> target_residency_ns = drv->states[i].target_residency_ns;
>>>
>>> @@ -207,7 +217,7 @@ static void teo_update(struct cpuidle_dr
>>> }
>>> }
>>>
>>> - cpu_data->tick_intercepts -= cpu_data->tick_intercepts >> DECAY_SHIFT;
>>> + teo_decay(&cpu_data->tick_intercepts);
>>> /*
>>> * If the measured idle duration falls into the same bin as the sleep
>>> * length, this is a "hit", so update the "hits" metric for that bin.
>>> @@ -222,7 +232,7 @@ static void teo_update(struct cpuidle_dr
>>> cpu_data->tick_intercepts += PULSE;
>>> }
>>>
>>> - cpu_data->total -= cpu_data->total >> DECAY_SHIFT;
>>> + teo_decay(&cpu_data->total);
>>> cpu_data->total += PULSE;
>>
>> This will result in total no longer being a strict sum of the bins.
>
> Ah, good point.
>
>> Any reason not to do something like:
>
> Well, it would be more straightforward to just compute "total" from
> scratch instead of using total_decay (it would be the same amount of
> computation minus the teo_decay() changes AFAICS).
Duh, of course...
>
> I'll send an update of this patch.
Thanks!
next prev parent reply other threads:[~2025-11-12 18:00 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-12 16:21 [PATCH v1 0/4] cpuidle: governors: teo: Assorted improvements Rafael J. Wysocki
2025-11-12 16:22 ` [PATCH v1 1/4] cpuidle: governors: teo: Drop incorrect target residency check Rafael J. Wysocki
2025-11-13 11:32 ` Christian Loehle
2025-11-13 11:41 ` Rafael J. Wysocki
2025-11-13 11:47 ` Rafael J. Wysocki
2025-11-13 13:26 ` Rafael J. Wysocki
2025-11-13 13:24 ` [PATCH v2 1/4] cpuidle: governors: teo: Drop misguided " Rafael J. Wysocki
2025-11-14 9:16 ` Christian Loehle
2025-11-12 16:23 ` [PATCH v1 2/4] cpuidle: governors: teo: Drop redundant function parameter Rafael J. Wysocki
2025-11-13 11:46 ` Christian Loehle
2025-11-12 16:24 ` [PATCH v1 3/4] cpuidle: governors: teo: Use s64 consistently in teo_update() Rafael J. Wysocki
2025-11-13 11:48 ` Christian Loehle
2025-11-12 16:25 ` [PATCH v1 4/4] cpuidle: governors: teo: Decay metrics below DECAY_SHIFT threshold Rafael J. Wysocki
2025-11-12 17:29 ` Christian Loehle
2025-11-12 17:51 ` Rafael J. Wysocki
2025-11-12 18:00 ` Christian Loehle [this message]
2025-11-12 18:03 ` [PATCH v2 " Rafael J. Wysocki
2025-11-13 11:49 ` Christian Loehle
2025-11-13 15:21 ` [PATCH v1 0/4] cpuidle: governors: teo: Assorted improvements Christian Loehle
2025-11-13 15:25 ` Rafael J. Wysocki
2025-11-19 22:52 ` Doug Smythies
2025-11-20 11:02 ` Rafael J. Wysocki
2025-11-20 13:35 ` Christian Loehle
2025-11-20 13:38 ` Rafael J. Wysocki
2025-11-20 13:57 ` Rafael J. Wysocki
2025-11-20 15:21 ` Rafael J. Wysocki
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=8baa1d22-c3ad-4c62-a70e-fc64bfbfdf0e@arm.com \
--to=christian.loehle@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=rekanorman@chromium.org \
/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