Re: [PATCH 4/4] cpufreq: intel_pstate: enable boost for Skylake Xeon

From: Francisco Jerez
Date: Wed Aug 01 2018 - 03:09:39 EST


Giovanni Gherdovich <ggherdovich@xxxxxxx> writes:

> On Mon, 2018-07-30 at 11:32 -0700, Francisco Jerez wrote:
>> Mel Gorman <mgorman@xxxxxxxxxxxxxxxxxxx> writes:
>
>> > On Sat, Jul 28, 2018 at 01:21:51PM -0700, Francisco Jerez wrote:
>> > > > > Please revert this series, it led to significant energy usage and
>> > > > > graphics performance regressions [1].ÂÂThe reasons are roughly the ones
>> > > > > we discussed by e-mail off-list last April: This causes the intel_pstate
>> > > > > driver to decrease the EPP to zero when the workload blocks on IO
>> > > > > frequently enough, which for the regressing benchmarks detailed in [1]
>> > > > > is a symptom of the workload being heavily IO-bound, which means they
>> > > > > won't benefit at all from the EPP boost since they aren't significantly
>> > > > > CPU-bound, and they will suffer a decrease in parallelism due to the
>> > > > > active CPU core using a larger fraction of the TDP in order to achieve
>> > > > > the same work, causing the GPU to have a lower power budget available,
>> > > > > leading to a decrease in system performance.
>> > > >Â
>> > > > It slices both ways.
>> > >Â
>> > > I don't think it's acceptable to land an optimization that trades
>> > > performance of one use-case for another,
>> >Â
>> > The same logic applies to a revert
>
>> No, it doesn't, the responsibility of addressing the fallout from a
>> change that happens to hurt performance even though it was supposed to
>> improve it lies on the author of the change, not on the reporter of the
>> regression.
>
> The server and desktop worlds have different characteristics and needs, which
> in this particular case appear to be conflicting. Luckily we can can
> differentiate the two scenarios (as in the bugfix patch by Srinivas a few
> hours ago).
>

I'm skeptical that the needs of the server and desktop world are really
as different and conflicting as this discussion may make them seem. In
a server environment it can be as much (if not more) of a factor how
many requests the system can process per second rather than the latency
of any individual request (since the latency of the network can easily
be an order of magnitude higher than the latency reduction that can
possibly be achieved by tricking the HWP into reacting faster). I'm not
convinced about the usefulness of trading the former for the latter in a
server environment, particularly since we could achieve both goals
simultaneously.

>> The task scheduler does go through the effort of attempting to re-use
>> the most frequently active CPU when a task wakes up, at least last time
>> I checked.
>
> Unfortunately that doesn't happen in practice; the load balancer in the
> scheduler is in a constant tension between spreading tasks evenly across all
> cores (necessary when the machine is under heavy load) and packing on just a
> few (which makes more sense when only a few threads are working and the box is
> almost idle otherwise). Recent evolutions favour spreading. We often observe
> tasks helplessly bounce from core to core losing all their accrued utilisation
> score, and intel_pstate (with or without HWP) penalizes that.
>

That's unfortunate. Luckily it's easy enough for the cpufreq governor
to differentiate those cases from the applications that have enough
parallelism to utilize at least one system resource close to its maximum
throughput and become non-CPU-bound.

> On Mon, 2018-07-30 at 11:32 -0700, Francisco Jerez wrote:
>> Mel Gorman <mgorman@xxxxxxxxxxxxxxxxxxx> writes:
>>
>> [...]
>> > One pattern is a small fsync which ends up context switching between
>> > the process and a journalling thread (may be dedicated thread, may be
>> > workqueue depending on filesystem) and the process waking again in the
>> > very near future on IO completion. While the workload may be single
>> > threaded, more than one core is in use because of how the short sleeps
>> > migrate the task to other cores.ÂÂHWP does not necessarily notice that
>> > the task is quite CPU-intensive due to the migrations and so the
>> > performance suffers.
>> >Â
>> > Some effort is made to minimise the number of cores used with this sort
>> > of waker/wakee relationship but it's not necessarily enough for HWP to
>> > boost the frequency.ÂÂMinimally, the journalling thread woken up will
>> > not wake on the same CPU as the IO issuer except under extremely heavily
>> > utilisation and this is not likely to change (stacking stacks too often
>> > increases wakeup latency).
>> >Â
>
>> The task scheduler does go through the effort of attempting to re-use
>> the most frequently active CPU when a task wakes up, at least last time
>> I checked.ÂÂBut yes some migration patterns can exacerbate the downward
>> bias of the response of the HWP to an intermittent workload, primarily
>> in cases where the application is unable to take advantage of the
>> parallelism between CPU and the IO device involved, like you're
>> describing above.
>
> Unfortunately that doesn't happen in practice; the load balancer in the
> scheduler is in a constant tension between spreading tasks evenly across all
> cores (necessary when the machine is under heavy load) and packing on just a
> few (which makes more sense when only a few threads are working and the box is
> idle otherwise). Recent evolutions favour spreading. We often observe tasks
> helplessly bounce from core to core losing all their accrued utilization
> score, and intel_pstate (with or without HWP) penalizes that.
>
> That's why in our distro SLES-15 (which is based on 4.12.14) we're sporting a
> patch like this:
> https://kernel.opensuse.org/cgit/kernel/commit/?h=SLE15&id=3a287868cb7a9 which
> boosts tasks that have been placed on a previously idle CPU. We haven't even
> proposed this patch upstream as we hope to solve those problems at a more
> fundamental level, but when you're supporting power management (freq scaling)
> in the server world you get compared to the performance governor, so your
> policy needs to be aggressive.
>
>
>> > > > With the series, there are large boosts to performance on other
>> > > > workloads where a slight increase in power usage is acceptable in
>> > > > exchange for performance. For example,
>> > > >Â
>> > > > Single socket skylake running sqlite
>> > > >ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂv4.17ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ41ab43c9
>> > > > MinÂÂÂÂÂÂÂTransÂÂÂÂÂ2580.85 (ÂÂÂ0.00%)ÂÂÂÂÂ5401.58 ( 109.29%)
>> > > > HmeanÂÂÂÂÂTransÂÂÂÂÂ2610.38 (ÂÂÂ0.00%)ÂÂÂÂÂ5518.36 ( 111.40%)
>> > > > StddevÂÂÂÂTransÂÂÂÂÂÂÂ28.08 (ÂÂÂ0.00%)ÂÂÂÂÂÂ208.90 (-644.02%)
>> > > > CoeffVarÂÂTransÂÂÂÂÂÂÂÂ1.08 (ÂÂÂ0.00%)ÂÂÂÂÂÂÂÂ3.78 (-251.57%)
>> > > > MaxÂÂÂÂÂÂÂTransÂÂÂÂÂ2648.02 (ÂÂÂ0.00%)ÂÂÂÂÂ5992.74 ( 126.31%)
>> > > > BHmean-50 TransÂÂÂÂÂ2629.78 (ÂÂÂ0.00%)ÂÂÂÂÂ5643.81 ( 114.61%)
>> > > > BHmean-95 TransÂÂÂÂÂ2620.38 (ÂÂÂ0.00%)ÂÂÂÂÂ5538.32 ( 111.36%)
>> > > > BHmean-99 TransÂÂÂÂÂ2620.38 (ÂÂÂ0.00%)ÂÂÂÂÂ5538.32 ( 111.36%)
>> > > >Â
>> > > > That's over doubling the transactions per second for that workload.
>> > > >Â
>> > > > Two-socket skylake running dbench4
>> > > >ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂv4.17ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ41ab43c9
>> > > > AmeanÂÂÂÂÂÂ1ÂÂÂÂÂÂÂÂÂ40.85 (ÂÂÂ0.00%)ÂÂÂÂÂÂÂ14.97 (ÂÂ63.36%)
>> > > > AmeanÂÂÂÂÂÂ2ÂÂÂÂÂÂÂÂÂ42.31 (ÂÂÂ0.00%)ÂÂÂÂÂÂÂ17.33 (ÂÂ59.04%)
>> > > > AmeanÂÂÂÂÂÂ4ÂÂÂÂÂÂÂÂÂ53.77 (ÂÂÂ0.00%)ÂÂÂÂÂÂÂ27.85 (ÂÂ48.20%)
>> > > > AmeanÂÂÂÂÂÂ8ÂÂÂÂÂÂÂÂÂ68.86 (ÂÂÂ0.00%)ÂÂÂÂÂÂÂ43.78 (ÂÂ36.42%)
>> > > > AmeanÂÂÂÂÂÂ16ÂÂÂÂÂÂÂÂ82.62 (ÂÂÂ0.00%)ÂÂÂÂÂÂÂ56.51 (ÂÂ31.60%)
>> > > > AmeanÂÂÂÂÂÂ32ÂÂÂÂÂÂÂ135.80 (ÂÂÂ0.00%)ÂÂÂÂÂÂ116.06 (ÂÂ14.54%)
>> > > > AmeanÂÂÂÂÂÂ64ÂÂÂÂÂÂÂ737.51 (ÂÂÂ0.00%)ÂÂÂÂÂÂ701.00 (ÂÂÂ4.95%)
>> > > > AmeanÂÂÂÂÂÂ512ÂÂÂÂ14996.60 (ÂÂÂ0.00%)ÂÂÂÂ14755.05 (ÂÂÂ1.61%)
>> > > >Â
>> > > > This is reporting the average latency of operations running
>> > > > dbench. The series over halves the latencies. There are many examples
>> > > > of basic workloads that benefit heavily from the series and while I
>> > > > accept it may not be universal, such as the case where the graphics
>> > > > card needs the power and not the CPU, a straight revert is not the
>> > > > answer. Without the series, HWP cripplies the CPU.
>> > > >Â
>> > >Â
>> > > That seems like a huge overstatement.ÂÂHWP doesn't "cripple" the CPU
>> > > without this series.ÂÂIt will certainly set lower clocks than with this
>> > > series for workloads like you show above that utilize the CPU very
>> > > intermittently (i.e. they underutilize it).Â
>> >Â
>> > Dbench for example can be quite CPU intensive. When bound to a single
>> > core, it shows up to 80% utilisation of a single core.
>
>> So even with an oracle cpufreq governor able to guess that the
>> application relies on the CPU being locked to the maximum frequency
>> despite it utilizing less than 80% of the CPU cycles, the application
>> will still perform 20% worse than an alternative application handling
>> its IO work asynchronously.
>
> It's a matter of being pragmatic. You're saying that a given application is
> badly designed and should be rewritten to leverage parallelism between CPU and
> IO.

Maybe some of them should be rewritten but that wasn't what I was trying
to say -- The point was that the kind of applications that benefit from
boosting on IO wait are necessarily within this category of workloads
that aren't able to take full advantage of any system resource anyway.
It's not like HWP would be "crippling" the CPU for a well-behaved
application.

> But in the field you *have* applications that behave that way, and the OS
> is in a position to do something to mitigate the damage.
>

Even when such a mitigation may actually reduce the performance of the
*same* applications when they are TDP-bound and the parallelism of the
system is limited by its energy usage? I'm not objecting to optimizing
for latency-sensitive applications a priori, but such optimizations
shouldn't be applied unless we have an indication that the performance
of the system can possibly improve as a result (e.g. because the
application doesn't already have a bottleneck on some IO device).

>
>> > When unbound, the usage of individual cores appears low due to the
>> > migrations. It may be intermittent usage as it context switches to
>> > worker threads but it's not low utilisation either.
>> >Â
>> > intel_pstate also had logic for IO-boosting before HWPÂ
>
>> The IO-boosting logic of the intel_pstate governor has the same flaw as
>> this unfortunately.
>>
>
> Again it's a matter of pragmatism. You'll find that another governor uses
> IO-boosting: schedutil. And while intel_pstate needs it because it gets
> otherwise killed by migrating tasks,

Right, I've been working on an alternative to that.

> schedutil is based on the PELT utilization signal and doesn't have
> that problem at all.

Yes, I agree that the reaction time of PELT can be superior to HWP at
times.

> The principle there is plain and simple: if I've been "wasting time"
> waiting on "slow" IO (disk), that probably means I'm getting late and
> there is soon some compute to do: better catch up on the lost time and
> speed up. IO-wait boosting on schedutil was discussed at
> https://lore.kernel.org/lkml/3752826.3sXAQIvcIA@xxxxxxxxxxxxxx/
>

That principle is nowhere close to a universal rule. Waiting on an IO
device repeatedly is often a sign that the IO device is itself
overloaded and the CPU is running at an unnecessarily high frequency
(which means lower parallelism than optimal while TDP-bound), since
otherwise the CPU wouldn't need to wait on the IO device as frequently.
In such cases IOWAIT boosting gives you the opposite of what the
application needs.

>
> Giovanni Gherdovich
> SUSE Labs

Attachment: signature.asc
Description: PGP signature