tools: allocate bitmaps in units of unsigned long
PATCH 1/3 tools: allocate bitmaps in units of unsigned long
Allocate enough memory so that the returned pointer can be safely accessed as an array of unsigned long.
The actual bitmap size in units of bytes, as returned by bitmap_size, remains unchanged.
--- tools/libs/ctrl/xc_bitops.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/libs/ctrl/xc_bitops.h +4 -1
@@ -21,7 +21,10 @@ static inline unsigned long bitmap_size(unsigned long nr_bits)static inline void *bitmap_alloc (unsigned long nr_bits) { -return calloc (1 ,bitmap_size (nr_bits)); +unsigned long longs; + + longs = (nr_bits +BITS_PER_LONG -1 ) /BITS_PER_LONG ; +return calloc (longs,sizeof (unsigned long )); }static inline void bitmap_set (void *addr,unsigned long nr_bits)
PATCH 2/3 tools: remove unused ORDER_LONG
There are no users left, xenpaging has its own variant.
The last user was removed with commit 11d0044a168994de85b9b328452292852aedc871
--- tools/libs/ctrl/xc_bitops.h | 2 -- 1 file changed, 2 deletions(-)
tools/libs/ctrl/xc_bitops.h +0 -2
@@ -6,9 +6,7 @@#include <stdlib.h> #include <string.h> -/* Needed by several includees, but no longer used for bitops. */ #define BITS_PER_LONG (sizeof(unsigned long) * 8) -#define ORDER_LONG (sizeof(unsigned long) == 4 ? 5 : 6)#define BITMAP_ENTRY (_nr,_bmap) ((_bmap))[(_nr) / 8]#define BITMAP_SHIFT (_nr) ((_nr) % 8)
Re: [PATCH v1 2/3] tools: remove unused ORDER_LONG
Quoted 4 lines · Olaf Hering
There are no users left, xenpaging has its own variant.
The last user was removed with commit11d0044a168994de85b9b328452292852aedc871Signed-off-by Olaf Hering <[email protected]>
PATCH 3/3 tools: add API to work with sevaral bits at once
In reply to Olaf HeringIntroduce new API to test if a fixed number of bits is clear or set, and clear or set them all at once.
The caller has to make sure the input bitnumber is a multiply of BITS_PER_LONG.
This API avoids the loop over each bit in a known range just to see if all of them are either clear or set.
--- tools/libs/ctrl/xc_bitops.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
tools/libs/ctrl/xc_bitops.h +25 -0
@@ -77,4 +77,29 @@ static inline void bitmap_or(void *_dst, const void *_other, dst[i] |= other[i]; } +static inline int test_bit_long_set (unsigned long nr_base,const void *_addr) +{ +const unsigned long *addr = _addr; +unsigned long val = addr[nr_base /BITS_PER_LONG ]; +return val == ~0 ; +} + +static inline int test_bit_long_clear (unsigned long nr_base,const void *_addr) +{ +const unsigned long *addr = _addr; +unsigned long val = addr[nr_base /BITS_PER_LONG ]; +return val ==0 ; +} + +static inline void clear_bit_long (unsigned long nr_base,void *_addr) +{ +unsigned long *addr = _addr; + addr[nr_base /BITS_PER_LONG ] =0 ; +} + +static inline void set_bit_long (unsigned long nr_base,void *_addr) +{ +unsigned long *addr = _addr; + addr[nr_base /BITS_PER_LONG ] = ~0 ; +}#endif /* XC_BITOPS_H */
Re: [PATCH v1 3/3] tools: add API to work with sevaral bits at once
Quoted 9 lines · Olaf Hering
Introduce new API to test if a fixed number of bits is clear or set, and clear or set them all at once.
The caller has to make sure the input bitnumber is a multiply of
BITS_PER_LONG.This API avoids the loop over each bit in a known range just to see if all of them are either clear or set.
Signed-off-by Olaf Hering <[email protected]>
I would rather these be introduced along side their callers.
tools/libs/ctrl/xc_bitops.h static inline void bitmap_or(void *_dst, const void *_other, · line 80
Quoted 13 lines
--- tools/libs/ctrl/xc_bitops.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)tools/libs/ctrl/xc_bitops.h +1
-0@@ -77,4 +77,29 @@ static inline void bitmap_or(void *_dst, const void *_other, dst[i] |= other[i]; } +static inline int test_bit_long_set (unsigned long nr_base,const void *_addr)
What's wrong with requiring the input addr be const unsigned long *?
Re: [PATCH v1 3/3] tools: add API to work with sevaral bits at once
Am Tue, 15 Dec 2020 16:22:44 +0000
schrieb Wei Liu <[email protected]>:
Quoted 1 line
What's wrong with requiring the input addr be const unsigned long *?
Probably nothing. In the end I just borrowed the prototypes from the other functions in this file.
I will resend with this change once I have the consumers ready.
Olaf
Re: [PATCH v1 3/3] tools: add API to work with sevaral bits at once
Quoted 8 lines · Olaf Hering
Am Tue, 15 Dec 2020 16:22:44 +0000
schrieb Wei Liu <[email protected]>:Quoted 1 line
What's wrong with requiring the input addr be const unsigned long *?
Probably nothing. In the end I just borrowed the prototypes from the other functions in this file.
I will resend with this change once I have the consumers ready.
Okay.
I will push the first two shortly.
Wei.
Quoted 2 lines
Olaf
Quoted 7 lines · Olaf Hering
Allocate enough memory so that the returned pointer can be safely accessed as an array of unsigned long.
The actual bitmap size in units of bytes, as returned by
bitmap_size, remains unchanged.Signed-off-by Olaf Hering <[email protected]>
I can see where you're coming from. This (internal) API's returned pointer is being assigned to unsigned long *.
Quoted 20 lines
--- tools/libs/ctrl/xc_bitops.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)tools/libs/ctrl/xc_bitops.h +4
-1@@ -21,7 +21,10 @@ static inline unsigned long bitmap_size(unsigned long nr_bits)static inline void *bitmap_alloc (unsigned long nr_bits) { -return calloc (1 ,bitmap_size (nr_bits)); +unsigned long longs; + + longs = (nr_bits +BITS_PER_LONG -1 ) /BITS_PER_LONG ; +return calloc (longs,sizeof (unsigned long )); }static inline void bitmap_set (void *addr,unsigned long nr_bits)