From: Daniel Lezcano <daniel.lezcano@linaro.org>
To: Peter Zijlstra <peterz@infradead.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
"Rafael J. Wysocki" <rjw@rjwysocki.net>,
Linux PM <linux-pm@vger.kernel.org>,
Giovanni Gherdovich <ggherdovich@suse.cz>,
Doug Smythies <dsmythies@telus.net>,
Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Frederic Weisbecker <frederic@kernel.org>,
Mel Gorman <mgorman@suse.de>,
Nicolas Pitre <nicolas.pitre@linaro.org>
Subject: Re: [PATCH] irq/timings: Fix model validity
Date: Thu, 8 Nov 2018 09:10:26 +0100 [thread overview]
Message-ID: <c9d8152a-566e-7ae6-e41c-5817c884c277@linaro.org> (raw)
In-Reply-To: <20181107130507.GD9761@hirez.programming.kicks-ass.net>
On 07/11/2018 14:05, Peter Zijlstra wrote:
> On Wed, Nov 07, 2018 at 11:52:31AM +0100, Daniel Lezcano wrote:
>>> @@ -146,11 +152,38 @@ static void irqs_update(struct irqt_stat *irqs, u64 ts)
>>> */
>>> diff = interval - irqs->avg;
>>>
>>> + /*
>>> + * Online average algorithm:
>>> + *
>>> + * new_average = average + ((value - average) / count)
>>> + *
>>> + * The variance computation depends on the new average
>>> + * to be computed here first.
>>> + *
>>> + */
>>> + irqs->avg = irqs->avg + (diff >> IRQ_TIMINGS_SHIFT);
>>> +
>>> + /*
>>> + * Online variance algorithm:
>>> + *
>>> + * new_variance = variance + (value - average) x (value - new_average)
>>> + *
>>> + * Warning: irqs->avg is updated with the line above, hence
>>> + * 'interval - irqs->avg' is no longer equal to 'diff'
>>> + */
>>> + irqs->variance = irqs->variance + (diff * (interval - irqs->avg));
>>> +
>>> /*
>>> * Increment the number of samples.
>>> */
>>> irqs->nr_samples++;
>
> FWIW, I'm confused on this. The normal (Welford's) online algorithm
> does:
>
> count++;
> delta = value - mean;
> mean += delta / count;
> M2 += delta * (value - mean);
>
> But the above uses:
>
> mean += delta / 32;
>
> Which, for count >> 32, over-estimates the mean adjustment. But worse,
> it significantly under-estimates the mean during training.
>
> How is the computed variance still correct with this? I can not find any
> comments that clarifies this. I'm thinking that since the mean will
> slowly wander towards it's actual location (assuming an actual standard
> distribution input) the resulting variance will be far too large, since
> the (value - mean) term will be much larger than 'expected'.
You are right, initially it was divided by min(count, 32) but for
optimization reason, we decided to change that by a power of two
constant assuming the number of samples will reach quickly 32 and the
compiler will replace that by a shift.
https://lkml.org/lkml/2017/3/23/696
>>> @@ -158,16 +191,12 @@ static void irqs_update(struct irqt_stat *irqs, u64 ts)
>>> * more than 32 and dividing by 32 instead of 31 is enough
>>> * precise.
>>> */
>>> + variance = irqs->variance >> IRQ_TIMINGS_SHIFT;
>
> Worse; variance is actually (as the comment states):
>
> s^2 = M2 / (count -1)
>
> But instead you compute:
>
> s^2 = M2 / 32;
>
> Which is again much larger than the actual result; assuming count >> 32.
>
> So you compute a variance that is inflated in two different ways.
>
>
> I'm not seeing how this thing works reliably.
I have to revisit this part of code soon, I will double check that.
--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
next prev parent reply other threads:[~2018-11-08 8:10 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-04 16:31 [RFC/RFT][PATCH v3] cpuidle: New timer events oriented governor for tickless systems Rafael J. Wysocki
2018-11-05 19:32 ` Giovanni Gherdovich
2018-11-06 14:55 ` Rafael J. Wysocki
2018-11-06 17:04 ` Peter Zijlstra
2018-11-06 18:19 ` Rafael J. Wysocki
2018-11-06 19:51 ` Peter Zijlstra
2018-11-06 23:39 ` Rafael J. Wysocki
2018-11-07 8:59 ` Peter Zijlstra
2018-11-07 9:46 ` [PATCH] irq/timings: Fix model validity Peter Zijlstra
2018-11-07 10:52 ` Daniel Lezcano
2018-11-07 13:05 ` Peter Zijlstra
2018-11-08 8:10 ` Daniel Lezcano [this message]
2018-11-07 12:09 ` [RFC/RFT][PATCH v3] cpuidle: New timer events oriented governor for tickless systems Rafael J. Wysocki
2018-11-07 10:09 ` [RFC][PATCH] irq/timings: Ignore predictions in the past Peter Zijlstra
2018-11-07 10:13 ` [RFC/RFT][PATCH v3] cpuidle: New timer events oriented governor for tickless systems Daniel Lezcano
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=c9d8152a-566e-7ae6-e41c-5817c884c277@linaro.org \
--to=daniel.lezcano@linaro.org \
--cc=dsmythies@telus.net \
--cc=frederic@kernel.org \
--cc=ggherdovich@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=nicolas.pitre@linaro.org \
--cc=peterz@infradead.org \
--cc=rafael@kernel.org \
--cc=rjw@rjwysocki.net \
--cc=srinivas.pandruvada@linux.intel.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