[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [xen staging] tools/include: move xc_bitops.h to xen-tools/bitops.h
commit b0bdfbfc8899f88fe093a5e32c38751d02af6a15 Author: Denis Mukhin <dmukhin@xxxxxxxx> AuthorDate: Mon Sep 1 11:15:16 2025 +0200 Commit: Jan Beulich <jbeulich@xxxxxxxx> CommitDate: Mon Sep 1 13:07:01 2025 +0200 tools/include: move xc_bitops.h to xen-tools/bitops.h Move xc_bitops.h to common tools location to be shared between the toolstack and unit test code. Adjust the guard in xen-tools/bitops.h Correct the #include directives and comments referring to the old xc_bitops.h in the toolstack code. Signed-off-by: Denis Mukhin <dmukhin@xxxxxxxx> Acked-by: Anthony PERARD <anthony.perard@xxxxxxxxxx> --- tools/include/xen-tools/bitops.h | 84 +++++++++++++++++++++++++++++++++++++ tools/libs/ctrl/xc_bitops.h | 84 ------------------------------------- tools/libs/ctrl/xc_misc.c | 13 +++--- tools/libs/guest/xg_dom_elfloader.c | 1 - tools/libs/guest/xg_dom_hvmloader.c | 1 - tools/libs/guest/xg_private.h | 2 +- tools/libs/guest/xg_sr_common.h | 2 - 7 files changed, 92 insertions(+), 95 deletions(-) diff --git a/tools/include/xen-tools/bitops.h b/tools/include/xen-tools/bitops.h new file mode 100644 index 0000000000..681482f675 --- /dev/null +++ b/tools/include/xen-tools/bitops.h @@ -0,0 +1,84 @@ +#ifndef __XEN_TOOLS_BITOPS_H__ +#define __XEN_TOOLS_BITOPS_H__ + +/* bitmap operations for single threaded access */ + +#include <stdlib.h> +#include <string.h> + +#ifdef __LP64__ +#define BITS_PER_LONG 64 +#else +#define BITS_PER_LONG 32 +#endif + +#define BITMAP_ENTRY(_nr,_bmap) ((_bmap))[(_nr) / 8] +#define BITMAP_SHIFT(_nr) ((_nr) % 8) + +/* calculate required space for number of bytes needed to hold nr_bits */ +static inline unsigned long bitmap_size(unsigned long nr_bits) +{ + return (nr_bits + 7) / 8; +} + +static inline void *bitmap_alloc(unsigned long 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) +{ + memset(addr, 0xff, bitmap_size(nr_bits)); +} + +static inline void bitmap_clear(void *addr, unsigned long nr_bits) +{ + memset(addr, 0, bitmap_size(nr_bits)); +} + +static inline int test_bit(unsigned long nr, const void *_addr) +{ + const char *addr = _addr; + return (BITMAP_ENTRY(nr, addr) >> BITMAP_SHIFT(nr)) & 1; +} + +static inline void clear_bit(unsigned long nr, void *_addr) +{ + char *addr = _addr; + BITMAP_ENTRY(nr, addr) &= ~(1UL << BITMAP_SHIFT(nr)); +} + +static inline void set_bit(unsigned long nr, void *_addr) +{ + char *addr = _addr; + BITMAP_ENTRY(nr, addr) |= (1UL << BITMAP_SHIFT(nr)); +} + +static inline int test_and_clear_bit(unsigned long nr, void *addr) +{ + int oldbit = test_bit(nr, addr); + clear_bit(nr, addr); + return oldbit; +} + +static inline int test_and_set_bit(unsigned long nr, void *addr) +{ + int oldbit = test_bit(nr, addr); + set_bit(nr, addr); + return oldbit; +} + +static inline void bitmap_or(void *_dst, const void *_other, + unsigned long nr_bits) +{ + char *dst = _dst; + const char *other = _other; + unsigned long i; + for ( i = 0; i < bitmap_size(nr_bits); ++i ) + dst[i] |= other[i]; +} + +#endif /* __XEN_TOOLS_BITOPS_H__ */ diff --git a/tools/libs/ctrl/xc_bitops.h b/tools/libs/ctrl/xc_bitops.h deleted file mode 100644 index 4a776dc3a5..0000000000 --- a/tools/libs/ctrl/xc_bitops.h +++ /dev/null @@ -1,84 +0,0 @@ -#ifndef XC_BITOPS_H -#define XC_BITOPS_H 1 - -/* bitmap operations for single threaded access */ - -#include <stdlib.h> -#include <string.h> - -#ifdef __LP64__ -#define BITS_PER_LONG 64 -#else -#define BITS_PER_LONG 32 -#endif - -#define BITMAP_ENTRY(_nr,_bmap) ((_bmap))[(_nr) / 8] -#define BITMAP_SHIFT(_nr) ((_nr) % 8) - -/* calculate required space for number of bytes needed to hold nr_bits */ -static inline unsigned long bitmap_size(unsigned long nr_bits) -{ - return (nr_bits + 7) / 8; -} - -static inline void *bitmap_alloc(unsigned long 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) -{ - memset(addr, 0xff, bitmap_size(nr_bits)); -} - -static inline void bitmap_clear(void *addr, unsigned long nr_bits) -{ - memset(addr, 0, bitmap_size(nr_bits)); -} - -static inline int test_bit(unsigned long nr, const void *_addr) -{ - const char *addr = _addr; - return (BITMAP_ENTRY(nr, addr) >> BITMAP_SHIFT(nr)) & 1; -} - -static inline void clear_bit(unsigned long nr, void *_addr) -{ - char *addr = _addr; - BITMAP_ENTRY(nr, addr) &= ~(1UL << BITMAP_SHIFT(nr)); -} - -static inline void set_bit(unsigned long nr, void *_addr) -{ - char *addr = _addr; - BITMAP_ENTRY(nr, addr) |= (1UL << BITMAP_SHIFT(nr)); -} - -static inline int test_and_clear_bit(unsigned long nr, void *addr) -{ - int oldbit = test_bit(nr, addr); - clear_bit(nr, addr); - return oldbit; -} - -static inline int test_and_set_bit(unsigned long nr, void *addr) -{ - int oldbit = test_bit(nr, addr); - set_bit(nr, addr); - return oldbit; -} - -static inline void bitmap_or(void *_dst, const void *_other, - unsigned long nr_bits) -{ - char *dst = _dst; - const char *other = _other; - unsigned long i; - for ( i = 0; i < bitmap_size(nr_bits); ++i ) - dst[i] |= other[i]; -} - -#endif /* XC_BITOPS_H */ diff --git a/tools/libs/ctrl/xc_misc.c b/tools/libs/ctrl/xc_misc.c index 33e87bac28..10ddf85667 100644 --- a/tools/libs/ctrl/xc_misc.c +++ b/tools/libs/ctrl/xc_misc.c @@ -17,8 +17,8 @@ * License along with this library; If not, see <http://www.gnu.org/licenses/>. */ -#include "xc_bitops.h" #include "xc_private.h" +#include <xen-tools/bitops.h> #include <xen/hvm/hvm_op.h> int xc_get_max_cpus(xc_interface *xch) @@ -94,11 +94,12 @@ xc_cpumap_t xc_cpumap_alloc(xc_interface *xch) } /* - * xc_bitops.h has macros that do this as well - however they assume that - * the bitmask is word aligned but xc_cpumap_t is only guaranteed to be - * byte aligned and so we need byte versions for architectures which do - * not support misaligned accesses (which is basically everyone - * but x86, although even on x86 it can be inefficient). + * <xen-tools/bitops.h> has macros that do this as well - however they + * assume that the bitmask is word aligned but xc_cpumap_t is only + * guaranteed to be byte aligned and so we need byte versions for + * architectures which do not support misaligned accesses (which is + * basically everyone but x86, although even on x86 it can be + * inefficient). * * NOTE: The xc_bitops macros now use byte alignment. * TODO: Clean up the users of this interface. diff --git a/tools/libs/guest/xg_dom_elfloader.c b/tools/libs/guest/xg_dom_elfloader.c index f17930d98b..a55b5e8c3c 100644 --- a/tools/libs/guest/xg_dom_elfloader.c +++ b/tools/libs/guest/xg_dom_elfloader.c @@ -26,7 +26,6 @@ #include <inttypes.h> #include "xg_private.h" -#include "xc_bitops.h" #define XEN_VER "xen-3.0" diff --git a/tools/libs/guest/xg_dom_hvmloader.c b/tools/libs/guest/xg_dom_hvmloader.c index 39e1e5f579..a98c7fe5d8 100644 --- a/tools/libs/guest/xg_dom_hvmloader.c +++ b/tools/libs/guest/xg_dom_hvmloader.c @@ -25,7 +25,6 @@ #include <assert.h> #include "xg_private.h" -#include "xc_bitops.h" /* ------------------------------------------------------------------------ */ /* parse elf binary */ diff --git a/tools/libs/guest/xg_private.h b/tools/libs/guest/xg_private.h index d73947094f..285229cf82 100644 --- a/tools/libs/guest/xg_private.h +++ b/tools/libs/guest/xg_private.h @@ -28,9 +28,9 @@ #include <sys/stat.h> #include "xc_private.h" -#include "xc_bitops.h" #include "xenguest.h" +#include <xen-tools/bitops.h> #include <xen/memory.h> #include <xen/elfnote.h> #include <xen/libelf/libelf.h> diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_common.h index 2f058ee3a6..0e419c3a96 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -5,8 +5,6 @@ #include "xg_private.h" #include "xg_save_restore.h" -#include "xc_bitops.h" - #include "xg_sr_stream_format.h" /* String representation of Domain Header types. */ -- generated by git-patchbot for /home/xen/git/xen.git#staging
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |