ktime_devns is an inline function for constant divisors. For non-constant divisors, it's only inline for 64-bit systems and calls to an out-of-line __ktime_divns function otherwise. Implement the out-of-line function, so it's use of the function in common code is portable. Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx> --- lib/math/div64.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/math/div64.c b/lib/math/div64.c index 386497592b0b..3d646c487b3d 100644 --- a/lib/math/div64.c +++ b/lib/math/div64.c @@ -21,6 +21,7 @@ #include <linux/bitops.h> #include <module.h> #include <linux/kernel.h> +#include <linux/ktime.h> #include <linux/math64.h> #include <linux/log2.h> @@ -233,3 +234,32 @@ u64 mul_u64_u64_div_u64(u64 a, u64 b, u64 c) return res + div64_u64(a * b, c); } #endif + +/* + * Functions for the union type storage format of ktime_t which are + * too large for inlining: + */ +#if BITS_PER_LONG < 64 +/* + * Divide a ktime value by a nanosecond value + */ +s64 __ktime_divns(const ktime_t kt, s64 div) +{ + int sft = 0; + s64 dclc; + u64 tmp; + + dclc = ktime_to_ns(kt); + tmp = dclc < 0 ? -dclc : dclc; + + /* Make sure the divisor is less than 2^32: */ + while (div >> 32) { + sft++; + div >>= 1; + } + tmp >>= sft; + do_div(tmp, (u32) div); + return dclc < 0 ? -tmp : tmp; +} +EXPORT_SYMBOL_GPL(__ktime_divns); +#endif /* BITS_PER_LONG >= 64 */ -- 2.39.2