LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: John Stultz <john.stultz@linaro.org>
To: lkml <linux-kernel@vger.kernel.org>
Cc: Nicolas Pitre <nicolas.pitre@linaro.org>,
	Arnd Bergmann <arnd.bergmann@linaro.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@kernel.org>, Nicolas Pitre <nico@linaro.org>,
	John Stultz <john.stultz@linaro.org>
Subject: [PATCH 1/8] ktime: Optimize ktime_divns for constant divisors
Date: Fri, 23 Jan 2015 17:43:53 -0800	[thread overview]
Message-ID: <1422063840-2837-2-git-send-email-john.stultz@linaro.org> (raw)
In-Reply-To: <1422063840-2837-1-git-send-email-john.stultz@linaro.org>

From: Nicolas Pitre <nicolas.pitre@linaro.org>

At least on ARM, do_div() is optimized to turn constant divisors into
an inline multiplication by the reciprocal value at compile time.
However this optimization is missed entirely whenever ktime_divns() is
used and the slow out-of-line division code is used all the time.

Let ktime_divns() use do_div() inline whenever the divisor is constant
and small enough.  This will make things like ktime_to_us() and
ktime_to_ms() much faster.

Cc: Arnd Bergmann <arnd.bergmann@linaro.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Nicolas Pitre <nico@linaro.org>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Nicolas Pitre <nico@linaro.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 include/linux/ktime.h | 12 +++++++++++-
 kernel/time/hrtimer.c |  4 ++--
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/include/linux/ktime.h b/include/linux/ktime.h
index c9d645a..411dd8b 100644
--- a/include/linux/ktime.h
+++ b/include/linux/ktime.h
@@ -166,7 +166,17 @@ static inline bool ktime_before(const ktime_t cmp1, const ktime_t cmp2)
 }
 
 #if BITS_PER_LONG < 64
-extern u64 ktime_divns(const ktime_t kt, s64 div);
+extern u64 __ktime_divns(const ktime_t kt, s64 div);
+static inline u64 ktime_divns(const ktime_t kt, s64 div)
+{
+	if (__builtin_constant_p(div) && !(div >> 32)) {
+		u64 ns = kt.tv64;
+		do_div(ns, div);
+		return ns;
+	} else {
+		return __ktime_divns(kt, div);
+	}
+}
 #else /* BITS_PER_LONG < 64 */
 # define ktime_divns(kt, div)		(u64)((kt).tv64 / (div))
 #endif
diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index 37e50aa..890535c 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -266,7 +266,7 @@ lock_hrtimer_base(const struct hrtimer *timer, unsigned long *flags)
 /*
  * Divide a ktime value by a nanosecond value
  */
-u64 ktime_divns(const ktime_t kt, s64 div)
+u64 __ktime_divns(const ktime_t kt, s64 div)
 {
 	u64 dclc;
 	int sft = 0;
@@ -282,7 +282,7 @@ u64 ktime_divns(const ktime_t kt, s64 div)
 
 	return dclc;
 }
-EXPORT_SYMBOL_GPL(ktime_divns);
+EXPORT_SYMBOL_GPL(__ktime_divns);
 #endif /* BITS_PER_LONG >= 64 */
 
 /*
-- 
1.9.1


  reply	other threads:[~2015-01-24  1:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-24  1:43 [GIT PULL] Time items for 3.20 John Stultz
2015-01-24  1:43 ` John Stultz [this message]
2015-01-24  1:43 ` [PATCH 2/8] time: Expose getboottime64 for in-kernel uses John Stultz
2015-01-24  1:43 ` [PATCH 3/8] time: Expose get_monotonic_boottime64 for in-kernel use John Stultz
2015-01-24  1:43 ` [PATCH 4/8] rtc: Update interface.c to use y2038-safe time interfaces John Stultz
2015-01-24  1:43 ` [PATCH 5/8] rtc: Update rtc-dev " John Stultz
2015-01-24  1:43 ` [PATCH 6/8] rtc: Modify rtc_hctosys() to address y2038 issues John Stultz
2015-01-24  1:43 ` [PATCH 7/8] rtc: Remove redundant rtc_valid_tm() from rtc_hctosys() John Stultz
2015-01-24  1:44 ` [PATCH 8/8] rtc: Convert rtc_set_ntp_time() to use timespec64 John Stultz

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=1422063840-2837-2-git-send-email-john.stultz@linaro.org \
    --to=john.stultz@linaro.org \
    --cc=arnd.bergmann@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=nico@linaro.org \
    --cc=nicolas.pitre@linaro.org \
    --cc=tglx@linutronix.de \
    --subject='Re: [PATCH 1/8] ktime: Optimize ktime_divns for constant divisors' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).