From: Arnd Bergmann <arnd@arndb.de>
To: Tina Ruchandani <ruchandani.tina@gmail.com>
Cc: y2038 <y2038@lists.linaro.org>,
Linux Kernel List <linux-kernel@vger.kernel.org>,
dri-devel@lists.freedesktop.org,
Thierry Reding <treding@nvidia.com>
Subject: Re: [PATCH v2] drm/msm: Use 64-bit timekeeping
Date: Thu, 21 Apr 2016 14:21:28 +0200 [thread overview]
Message-ID: <4114093.bsncTYaCqE@wuerfel> (raw)
In-Reply-To: <CAB__kk=CW0AKCGvRGnEw-ggxEbUNeCQ=q=PmnCVUh1oBebMBQA@mail.gmail.com>
On Thursday 21 April 2016 04:39:04 Tina Ruchandani wrote:
> >> which only does one 64-bit division, and it's one that we can probably
> >> optimize out in the future (we can check in ktime_ms_delta whether the
> >> difference is more than 2^32 nanoseconds as the fast path).
>
> It looks like ktime_divns already has that optimization for 32-bit divisor,
> so your solution should avoid the 64-bit division.
I meant an optimization for a 32-bit dividend, not divisor,
e.g. doing:
diff --git a/include/linux/ktime.h b/include/linux/ktime.h
index 2b6a204bd8d4..4fbf735ec0af 100644
--- a/include/linux/ktime.h
+++ b/include/linux/ktime.h
@@ -169,13 +169,17 @@ static inline bool ktime_before(const ktime_t cmp1, const ktime_t cmp2)
extern s64 __ktime_divns(const ktime_t kt, s64 div);
static inline s64 ktime_divns(const ktime_t kt, s64 div)
{
+ s64 ns = kt.tv64;
+
/*
* Negative divisors could cause an inf loop,
* so bug out here.
*/
BUG_ON(div < 0);
- if (__builtin_constant_p(div) && !(div >> 32)) {
- s64 ns = kt.tv64;
+
+ if ((ns >> 32) == 0) {
+ return (s32)ns / div;
+ else if (__builtin_constant_p(div) && !(div >> 32)) {
u64 tmp = ns < 0 ? -ns : ns;
do_div(tmp, div);
I also just looked at the implementation of do_div() in
include/asm-generic/div64.h, and it already does that for
non-constant divisors, but I don't understand __div64_const32()
enough to know if the compiler end up doing the same
optimization for the constant divisor we have here.
Arnd
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
WARNING: multiple messages have this Message-ID (diff)
From: Arnd Bergmann <arnd@arndb.de>
To: Tina Ruchandani <ruchandani.tina@gmail.com>
Cc: y2038 <y2038@lists.linaro.org>,
dri-devel@lists.freedesktop.org,
Linux Kernel List <linux-kernel@vger.kernel.org>,
Wentao Xu <wentaox@codeaurora.org>,
Thierry Reding <treding@nvidia.com>, Hai Li <hali@codeaurora.org>
Subject: Re: [PATCH v2] drm/msm: Use 64-bit timekeeping
Date: Thu, 21 Apr 2016 14:21:28 +0200 [thread overview]
Message-ID: <4114093.bsncTYaCqE@wuerfel> (raw)
In-Reply-To: <CAB__kk=CW0AKCGvRGnEw-ggxEbUNeCQ=q=PmnCVUh1oBebMBQA@mail.gmail.com>
On Thursday 21 April 2016 04:39:04 Tina Ruchandani wrote:
> >> which only does one 64-bit division, and it's one that we can probably
> >> optimize out in the future (we can check in ktime_ms_delta whether the
> >> difference is more than 2^32 nanoseconds as the fast path).
>
> It looks like ktime_divns already has that optimization for 32-bit divisor,
> so your solution should avoid the 64-bit division.
I meant an optimization for a 32-bit dividend, not divisor,
e.g. doing:
diff --git a/include/linux/ktime.h b/include/linux/ktime.h
index 2b6a204bd8d4..4fbf735ec0af 100644
--- a/include/linux/ktime.h
+++ b/include/linux/ktime.h
@@ -169,13 +169,17 @@ static inline bool ktime_before(const ktime_t cmp1, const ktime_t cmp2)
extern s64 __ktime_divns(const ktime_t kt, s64 div);
static inline s64 ktime_divns(const ktime_t kt, s64 div)
{
+ s64 ns = kt.tv64;
+
/*
* Negative divisors could cause an inf loop,
* so bug out here.
*/
BUG_ON(div < 0);
- if (__builtin_constant_p(div) && !(div >> 32)) {
- s64 ns = kt.tv64;
+
+ if ((ns >> 32) == 0) {
+ return (s32)ns / div;
+ else if (__builtin_constant_p(div) && !(div >> 32)) {
u64 tmp = ns < 0 ? -ns : ns;
do_div(tmp, div);
I also just looked at the implementation of do_div() in
include/asm-generic/div64.h, and it already does that for
non-constant divisors, but I don't understand __div64_const32()
enough to know if the compiler end up doing the same
optimization for the constant divisor we have here.
Arnd
next prev parent reply other threads:[~2016-04-21 12:21 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-13 9:52 [PATCH v2] drm/msm: Use 64-bit timekeeping Tina Ruchandani
2016-04-13 9:52 ` Tina Ruchandani
2016-04-16 23:47 ` Arnd Bergmann
2016-04-16 23:47 ` Arnd Bergmann
2016-04-21 11:35 ` Tina Ruchandani
2016-04-21 11:39 ` Tina Ruchandani
2016-04-21 11:39 ` Tina Ruchandani
2016-04-21 12:21 ` Arnd Bergmann [this message]
2016-04-21 12:21 ` Arnd Bergmann
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=4114093.bsncTYaCqE@wuerfel \
--to=arnd@arndb.de \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ruchandani.tina@gmail.com \
--cc=treding@nvidia.com \
--cc=y2038@lists.linaro.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.