From: Peter Zijlstra <peterz@infradead.org>
To: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>,
"Rafael J. Wysocki" <rjw@rjwysocki.net>,
Ingo Molnar <mingo@kernel.org>,
"open list:CPUIDLE DRIVERS" <linux-pm@vger.kernel.org>,
open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH V2] cpuidle: Change ktime_get() with local_clock()
Date: Fri, 22 Apr 2016 08:42:40 +0200 [thread overview]
Message-ID: <20160422064240.GO3408@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <CAJZ5v0je2kdDF6J4XVmWkySKUvby3bYpCTr51m3+MKGpWYcw=Q@mail.gmail.com>
On Thu, Apr 21, 2016 at 09:41:14PM +0200, Rafael J. Wysocki wrote:
> On Thu, Apr 21, 2016 at 10:56 AM, Daniel Lezcano
> <daniel.lezcano@linaro.org> wrote:
> > The ktime_get() can have a non negligeable overhead, use local_clock()
> > instead.
> >
> > In order to test the difference between ktime_get() and local_clock(),
> > a quick hack has been added to trigger, via debugfs, 10000 times a
> > call to ktime_get() and local_clock() and measure the elapsed time.
> >
> > Then the average value, the min and max is computed for each call.
> >
> > From userspace, the test above was called 100 times every 2 seconds.
> >
> > So, ktime_get() and local_clock() have been called 1000000 times in
> > total.
> >
> > The results are:
> >
> > ktime_get():
> > ============
> > * average: 101 ns (stddev: 27.4)
> > * maximum: 38313 ns
> > * minimum: 65 ns
> >
> > local_clock():
> > ==============
> > * average: 60 ns (stddev: 9.8)
> > * maximum: 13487 ns
> > * minimum: 46 ns
> >
> > The local_clock() is faster and more stable.
> >
> > Even if it is a drop in the ocean, changing the ktime_get() by the
> > local_clock() allows to save 80ns at idle time (entry + exit). And
> > in some circumstances, especially when there are several CPUs racing
> > for the clock access, we save tens of microseconds.
> >
> > The idle duration resulting from a diff is converted from nanosec to
> > microsec. This could be done with integer division (div 1000) - which is
> > an expensive operation or by 10 bits shifting (div 1024) - which is fast
> > but unprecise.
> >
> > The following table gives some results at the limits.
> >
> > ------------------------------------------
> > | nsec | div(1000) | div(1024) |
> > ------------------------------------------
> > | 1e3 | 1 usec | 976 nsec |
> > ------------------------------------------
> > | 1e6 | 1000 usec | 976 usec |
> > ------------------------------------------
> > | 1e9 | 1000000 usec | 976562 usec |
> > ------------------------------------------
> >
> > There is a linear deviation of 2.34%. This loss of precision is acceptable
> > in the context of the resulting diff which is used for statistics. These
> > ones are processed to guess estimate an approximation of the duration of the
> > next idle period which ends up into an idle state selection. The selection
> > criteria takes into account the next duration based on large intervals,
> > represented by the idle state's target residency.
> >
> > The 2^10 division is enough because the approximation regarding the 1e3
> > division is lost in all the approximations done for the next idle duration
> > computation.
> >
> > Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
>
> Looks good to me.
>
> Peter, are you happy with the changelog now?
Yep, works for me:
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
next prev parent reply other threads:[~2016-04-22 6:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-21 8:56 Daniel Lezcano
2016-04-21 19:41 ` Rafael J. Wysocki
2016-04-22 6:42 ` Peter Zijlstra [this message]
2016-04-27 21:35 ` 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=20160422064240.GO3408@twins.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=daniel.lezcano@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=rafael@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
Powered by JetHome