mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] include: ktime: implement __ktime_divns for 32-bit systems
@ 2024-05-02 15:14 Ahmad Fatoum
  2024-05-02 15:14 ` [PATCH 2/2] poller: report pollers taking more than 20 milliseconds Ahmad Fatoum
  2024-05-03  6:53 ` [PATCH 1/2] include: ktime: implement __ktime_divns for 32-bit systems Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2024-05-02 15:14 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

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@pengutronix.de>
---
 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




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-05-03  6:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-02 15:14 [PATCH 1/2] include: ktime: implement __ktime_divns for 32-bit systems Ahmad Fatoum
2024-05-02 15:14 ` [PATCH 2/2] poller: report pollers taking more than 20 milliseconds Ahmad Fatoum
2024-05-03  6:53 ` [PATCH 1/2] include: ktime: implement __ktime_divns for 32-bit systems Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox