diff options
author | Nicolas Pitre <nicolas.pitre@linaro.org> | 2014-12-03 14:43:06 -0500 |
---|---|---|
committer | John Stultz <john.stultz@linaro.org> | 2015-01-23 20:21:31 -0500 |
commit | 8b618628b2bf83512fc8df5e8672619d65adfdfb (patch) | |
tree | c295bed4f4e702f5f39fcce622258e55242b1d93 /include/linux/ktime.h | |
parent | eaa27f34e91a14cdceed26ed6c6793ec1d186115 (diff) |
ktime: Optimize ktime_divns for constant divisors
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>
Diffstat (limited to 'include/linux/ktime.h')
-rw-r--r-- | include/linux/ktime.h | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/include/linux/ktime.h b/include/linux/ktime.h index c9d645ad98ff..411dd8bfe539 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) | |||
166 | } | 166 | } |
167 | 167 | ||
168 | #if BITS_PER_LONG < 64 | 168 | #if BITS_PER_LONG < 64 |
169 | extern u64 ktime_divns(const ktime_t kt, s64 div); | 169 | extern u64 __ktime_divns(const ktime_t kt, s64 div); |
170 | static inline u64 ktime_divns(const ktime_t kt, s64 div) | ||
171 | { | ||
172 | if (__builtin_constant_p(div) && !(div >> 32)) { | ||
173 | u64 ns = kt.tv64; | ||
174 | do_div(ns, div); | ||
175 | return ns; | ||
176 | } else { | ||
177 | return __ktime_divns(kt, div); | ||
178 | } | ||
179 | } | ||
170 | #else /* BITS_PER_LONG < 64 */ | 180 | #else /* BITS_PER_LONG < 64 */ |
171 | # define ktime_divns(kt, div) (u64)((kt).tv64 / (div)) | 181 | # define ktime_divns(kt, div) (u64)((kt).tv64 / (div)) |
172 | #endif | 182 | #endif |