summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMike Snitzer <snitzer@redhat.com>2013-08-20 15:05:17 -0400
committerChanho Park <chanho61.park@samsung.com>2014-03-20 17:43:57 +0900
commit27ef0a9763eeacc639aeccb610a8cc8596412f4b (patch)
tree1fa11387d0300efe15c129a880ce0f2880fc3896 /lib
parent75b4dccedb252c8160a3eb606979cc4f55012a08 (diff)
downloadlinux-3.10-27ef0a9763eeacc639aeccb610a8cc8596412f4b.tar.gz
linux-3.10-27ef0a9763eeacc639aeccb610a8cc8596412f4b.tar.bz2
linux-3.10-27ef0a9763eeacc639aeccb610a8cc8596412f4b.zip
math64: New separate div64_u64_rem helper
Commit f792685006274a850e6cc0ea9ade275ccdfc90bc ("math64: New div64_u64_rem helper") implemented div64_u64 in terms of div64_u64_rem. But div64_u64_rem was removed because it slowed down div64_u64 (and there were no other users of div64_u64_rem). Device Mapper's I/O statistics support has a need for div64_u64_rem; reintroduce this helper as a separate method that doesn't slow down div64_u64, especially on 32-bit systems. Signed-off-by: Mike Snitzer <snitzer@redhat.com> Cc: Stanislaw Gruszka <sgruszka@redhat.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Mikulas Patocka <mpatocka@redhat.com> Signed-off-by: Alasdair G Kergon <agk@redhat.com> [backport] Signed-off-by: Maciej Wereski <m.wereski@partner.samsung.com> Change-Id: Icd721ff57c6d127e7acb0bf17d233d0a50ff24da
Diffstat (limited to 'lib')
-rw-r--r--lib/div64.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/div64.c b/lib/div64.c
index a163b6caef7..4382ad77777 100644
--- a/lib/div64.c
+++ b/lib/div64.c
@@ -79,6 +79,46 @@ EXPORT_SYMBOL(div_s64_rem);
#endif
/**
+ * div64_u64_rem - unsigned 64bit divide with 64bit divisor and remainder
+ * @dividend: 64bit dividend
+ * @divisor: 64bit divisor
+ * @remainder: 64bit remainder
+ *
+ * This implementation is a comparable to algorithm used by div64_u64.
+ * But this operation, which includes math for calculating the remainder,
+ * is kept distinct to avoid slowing down the div64_u64 operation on 32bit
+ * systems.
+ */
+#ifndef div64_u64_rem
+u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
+{
+ u32 high = divisor >> 32;
+ u64 quot;
+
+ if (high == 0) {
+ u32 rem32;
+ quot = div_u64_rem(dividend, divisor, &rem32);
+ *remainder = rem32;
+ } else {
+ int n = 1 + fls(high);
+ quot = div_u64(dividend >> n, divisor >> n);
+
+ if (quot != 0)
+ quot--;
+
+ *remainder = dividend - quot * divisor;
+ if (*remainder >= divisor) {
+ quot++;
+ *remainder -= divisor;
+ }
+ }
+
+ return quot;
+}
+EXPORT_SYMBOL(div64_u64_rem);
+#endif
+
+/**
* div64_u64 - unsigned 64bit divide with 64bit divisor
* @dividend: 64bit dividend
* @divisor: 64bit divisor