aboutsummaryrefslogtreecommitdiffstats
path: root/tools/include/linux/math.h
diff options
context:
space:
mode:
authorMatthew Wilcox (Oracle) <willy@infradead.org>2021-11-30 14:13:16 +0000
committerLinus Torvalds <torvalds@linux-foundation.org>2021-11-30 09:14:42 -0800
commitd6e6a27d960f9f07aef0b979c49c6736ede28f75 (patch)
tree06c3d62e8c750cfd72e3d2a44637acc027b39b0a /tools/include/linux/math.h
parentnetfs: Adjust docs after foliation (diff)
downloadlinux-rng-d6e6a27d960f9f07aef0b979c49c6736ede28f75.tar.xz
linux-rng-d6e6a27d960f9f07aef0b979c49c6736ede28f75.zip
tools: Fix math.h breakage
Commit 98e1385ef24b ("include/linux/radix-tree.h: replace kernel.h with the necessary inclusions") broke the radix tree test suite in two different ways; first by including math.h which didn't exist in the tools directory, and second by removing an implicit include of spinlock.h before lockdep.h. Fix both issues. Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'tools/include/linux/math.h')
-rw-r--r--tools/include/linux/math.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/tools/include/linux/math.h b/tools/include/linux/math.h
new file mode 100644
index 000000000000..4e7af99ec9eb
--- /dev/null
+++ b/tools/include/linux/math.h
@@ -0,0 +1,25 @@
+#ifndef _TOOLS_MATH_H
+#define _TOOLS_MATH_H
+
+/*
+ * This looks more complex than it should be. But we need to
+ * get the type for the ~ right in round_down (it needs to be
+ * as wide as the result!), and we want to evaluate the macro
+ * arguments just once each.
+ */
+#define __round_mask(x, y) ((__typeof__(x))((y)-1))
+#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
+#define round_down(x, y) ((x) & ~__round_mask(x, y))
+
+#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
+
+#ifndef roundup
+#define roundup(x, y) ( \
+{ \
+ const typeof(y) __y = y; \
+ (((x) + (__y - 1)) / __y) * __y; \
+} \
+)
+#endif
+
+#endif