From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 1/2] include: ktime: implement __ktime_divns for 32-bit systems
Date: Thu, 2 May 2024 17:14:29 +0200 [thread overview]
Message-ID: <20240502151430.3963160-1-a.fatoum@pengutronix.de> (raw)
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
next reply other threads:[~2024-05-02 15:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-02 15:14 Ahmad Fatoum [this message]
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
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=20240502151430.3963160-1-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox