summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorSalman Qazi <sqazi@google.com>2012-03-09 16:41:01 -0800
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>2012-10-05 14:47:27 +0300
commit9280bea5b78b6a619c78b63f8273f5ec2e9b8d62 (patch)
treea6eb610d3bde4e636a24e442e081d9d2757af140 /include
parentc1f1992e69791d7bfc59b097491f560c97015a08 (diff)
sched/x86: Fix overflow in cyc2ns_offset
Artem: only left the 'mult_frac' addition from this patch, as we need it in ubi. Signed-off-by: Salman Qazi <sqazi@google.com> Acked-by: John Stultz <john.stultz@linaro.org> Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Paul Turner <pjt@google.com> Cc: john stultz <johnstul@us.ibm.com> Link: http://lkml.kernel.org/r/20120310004027.19291.88460.stgit@dungbeetle.mtv.corp.google.com Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'include')
-rw-r--r--include/linux/kernel.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 46ac9a50528d..349180f93fa0 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -85,6 +85,19 @@
} \
)
+/*
+ * Multiplies an integer by a fraction, while avoiding unnecessary
+ * overflow or loss of precision.
+ */
+#define mult_frac(x, numer, denom)( \
+{ \
+ typeof(x) quot = (x) / (denom); \
+ typeof(x) rem = (x) % (denom); \
+ (quot * (numer)) + ((rem * (numer)) / (denom)); \
+} \
+)
+
+
#define _RET_IP_ (unsigned long)__builtin_return_address(0)
#define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; })