tools: Fix math.h breakage
Matthew Wilcox (Oracle)
maintainerPATCH 1/1 tools: Fix math.h breakage
Commit 98e1385ef24b 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.
--- tools/include/linux/kernel.h | 22 +-------------------- tools/include/linux/math.h | 25 ++++++++++++++++++++++++ tools/testing/radix-tree/linux/lockdep.h | 3 +++ 3 files changed, 29 insertions(+), 21 deletions(-) create mode 100644 tools/include/linux/math.h
tools/include/linux/kernel.h +1 -21
@@ -7,6 +7,7 @@#include <assert.h> #include <linux/build_bug.h> #include <linux/compiler.h> +#include <linux/math.h> #include <endian.h> #include <byteswap.h>
@@ -14,8 +15,6 @@#define UINT_MAX (~0U)#endif -#define DIV_ROUND_UP (n,d) (((n) + (d) - 1) / (d)) -#define PERF_ALIGN (x, a) __PERF_ALIGN_MASK(x, (typeof(x))(a)-1)#define __PERF_ALIGN_MASK (x, mask) (((x)+(mask))&~(mask))
@@ -52,15 +51,6 @@ _min1 < _min2 ? _min1 : _min2; })#endif -#ifndef roundup -#define roundup (x, y) ( \ -{ \ - const typeof(y) __y = y; \ - (((x) + (__y - 1)) / __y) * __y; \ -} \ -) -#endif -#ifndef BUG_ON #ifdef NDEBUG #define BUG_ON (cond) do { if (cond) {} } while (0)
@@ -104,16 +94,6 @@ int scnprintf_pad(char * buf, size_t size, const char * fmt, ...);#define ARRAY_SIZE (arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) -/* -* 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 current_gfp_context (k) 0#define synchronize_rcu ()
tools/include/linux/math.h new file +25 -0
@@ -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
tools/testing/radix-tree/linux/lockdep.h +3 -0
@@ -1,5 +1,8 @@#ifndef _LINUX_LOCKDEP_H#define _LINUX_LOCKDEP_H + +#include <linux/spinlock.h> +struct lock_class_key {unsigned int a; };
Signature · 1 line
2.33.0
Quoted 4 lines · Matthew Wilcox (Oracle)
Commit
98e1385ef24bbroke the radix tree test suite in two different ways; first by includingmath.hwhich didn't exist in the tools directory, and second by removing an implicit include ofspinlock.hbeforelockdep.h. Fix both issues.
Sorry for that and thank you for the fix.
I'm wondering if there is a way of not copying kernel headers manually, otherwise we always will have such breakages.
Quoted 110 lines
Cc Andy Shevchenko <[email protected]>Signed-off-by Matthew Wilcox (Oracle) <[email protected]>--- tools/include/linux/kernel.h | 22 +-------------------- tools/include/linux/math.h | 25 ++++++++++++++++++++++++ tools/testing/radix-tree/linux/lockdep.h | 3 +++ 3 files changed, 29 insertions(+), 21 deletions(-) create mode 100644 tools/include/linux/math.htools/include/linux/kernel.h +1
-21@@ -7,6 +7,7 @@#include <assert.h> #include <linux/build_bug.h> #include <linux/compiler.h> +#include <linux/math.h> #include <endian.h> #include <byteswap.h> @@ -14,8 +15,6 @@#define UINT_MAX (~0U)#endif -#define DIV_ROUND_UP (n,d) (((n) + (d) - 1) / (d)) -#define PERF_ALIGN (x, a) __PERF_ALIGN_MASK(x, (typeof(x))(a)-1)#define __PERF_ALIGN_MASK (x, mask) (((x)+(mask))&~(mask))@@ -52,15 +51,6 @@ _min1 < _min2 ? _min1 : _min2; })#endif -#ifndef roundup -#define roundup (x, y) ( \ -{ \ - const typeof(y) __y = y; \ - (((x) + (__y - 1)) / __y) * __y; \ -} \ -) -#endif -#ifndef BUG_ON #ifdef NDEBUG #define BUG_ON (cond) do { if (cond) {} } while (0)@@ -104,16 +94,6 @@ int scnprintf_pad(char * buf, size_t size, const char * fmt, ...);#define ARRAY_SIZE (arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) -/* -* 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 current_gfp_context (k) 0#define synchronize_rcu ()tools/include/linux/math.h new file +25
-0@@ -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 tools/testing/radix-tree/linux/lockdep.h +3
-0@@ -1,5 +1,8 @@#ifndef _LINUX_LOCKDEP_H#define _LINUX_LOCKDEP_H + +#include <linux/spinlock.h> +struct lock_class_key {unsigned int a; };Signature · 1 line
2.33.0
Signature · 2 lines
With Best Regards, Andy Shevchenko
Matthew Wilcox
maintainerQuoted 11 lines · Andy Shevchenko
Quoted 4 lines · Matthew Wilcox (Oracle)
Commit
98e1385ef24bbroke the radix tree test suite in two different ways; first by includingmath.hwhich didn't exist in the tools directory, and second by removing an implicit include ofspinlock.hbeforelockdep.h. Fix both issues.Sorry for that and thank you for the fix.
Acked-by Andy Shevchenko <[email protected]>I'm wondering if there is a way of not copying kernel headers manually, otherwise we always will have such breakages.
It's not necessarily that these are _copies_ of kernel headers, so much as they're ways of mocking kernel interfaces when building userspace code. We could separate out pieces and include them from each direction, but that has its own problems, and doesn't necessarily solve these kinds of problems either.
I think the only way to prevent these kinds of breakages is to make sure the build bots are also building things.
Quoted 13 lines · Matthew Wilcox
Quoted 11 lines · Andy Shevchenko
Quoted 4 lines · Matthew Wilcox (Oracle)
Commit
98e1385ef24bbroke the radix tree test suite in two different ways; first by includingmath.hwhich didn't exist in the tools directory, and second by removing an implicit include ofspinlock.hbeforelockdep.h. Fix both issues.Sorry for that and thank you for the fix.
Acked-by Andy Shevchenko <[email protected]>I'm wondering if there is a way of not copying kernel headers manually, otherwise we always will have such breakages.
Quoted 8 lines
It's not necessarily that these are _copies_ of kernel headers, so much as they're ways of mocking kernel interfaces when building userspace code. We could separate out pieces and include them from each direction, but that has its own problems, and doesn't necessarily solve these kinds of problems either.
I think the only way to prevent these kinds of breakages is to make sure the build bots are also building things.
I don't know how to achieve this locally because I'm using make O=... and it's broken for many tools/ folders. At some point I simply gave up.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 20 lines · Andy Shevchenko
Quoted 19 lines · Matthew Wilcox
Quoted 11 lines · Andy Shevchenko
Quoted 4 lines · Matthew Wilcox (Oracle)
Commit
98e1385ef24bbroke the radix tree test suite in two different ways; first by includingmath.hwhich didn't exist in the tools directory, and second by removing an implicit include ofspinlock.hbeforelockdep.h. Fix both issues.Sorry for that and thank you for the fix.
Acked-by Andy Shevchenko <[email protected]>I'm wondering if there is a way of not copying kernel headers manually, otherwise we always will have such breakages.
It's not necessarily that these are _copies_ of kernel headers, so much as they're ways of mocking kernel interfaces when building userspace code. We could separate out pieces and include them from each direction, but that has its own problems, and doesn't necessarily solve these kinds of problems either.
Quoted 5 lines
Quoted 2 lines
I think the only way to prevent these kinds of breakages is to make sure the build bots are also building things.
I don't know how to achieve this locally because I'm using
make O=...and it's broken for manytools/folders. At some point I simply gave up.
To be clear, it's an argument to support your idea that CI can do it for us.
Signature · 2 lines
With Best Regards, Andy Shevchenko