From d0ded3d6cf9224594a8ee8593600163bc1eb2663 Mon Sep 17 00:00:00 2001 From: Ingo Molnar Date: Thu, 5 May 2011 10:00:45 +0200 Subject: [PATCH] kvm tools: Fix 32-bit build of the asm/system.h include Provide wrappers and other environmental dependencies that the asm/system.h header file from hell needs to build fine in user-space. Sidenote: right now alternative() defaults to the compatible, slightly slower barrier instructions that work on all x86 systems. If this ever shows up in profiles then kvm could provide an alternatives patching machinery as well. Right now those instructions are emitted into special sections and then discarded by the linker harmlessly. Signed-off-by: Ingo Molnar Signed-off-by: Pekka Enberg --- tools/kvm/include/asm/hweight.h | 8 ++++++++ tools/kvm/include/kvm/barrier.h | 15 +++++++++++++++ tools/kvm/include/linux/bitops.h | 33 ++++++++++++++++++++++++++++++++ tools/kvm/virtio.c | 4 +++- 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 tools/kvm/include/asm/hweight.h create mode 100644 tools/kvm/include/kvm/barrier.h create mode 100644 tools/kvm/include/linux/bitops.h diff --git a/tools/kvm/include/asm/hweight.h b/tools/kvm/include/asm/hweight.h new file mode 100644 index 000000000000..1a439777bb45 --- /dev/null +++ b/tools/kvm/include/asm/hweight.h @@ -0,0 +1,8 @@ +#ifndef _KVM_ASM_HWEIGHT_H_ +#define _KVM_ASM_HWEIGHT_H_ + +#include +unsigned int hweight32(unsigned int w); +unsigned long hweight64(__u64 w); + +#endif /* _KVM_ASM_HWEIGHT_H_ */ diff --git a/tools/kvm/include/kvm/barrier.h b/tools/kvm/include/kvm/barrier.h new file mode 100644 index 000000000000..c11a2391e17f --- /dev/null +++ b/tools/kvm/include/kvm/barrier.h @@ -0,0 +1,15 @@ +#ifndef _KVM_BARRIER_H_ +#define _KVM_BARRIER_H_ + +/* + * asm/system.h cannot be #included standalone on 32-bit x86 yet. + * + * Provide the dependencies here - we can drop these wrappers once + * the header is fixed upstream: + */ +#include +#include +#include +#include + +#endif /* _KVM_BARRIER_H_ */ diff --git a/tools/kvm/include/linux/bitops.h b/tools/kvm/include/linux/bitops.h new file mode 100644 index 000000000000..56448b71ebbf --- /dev/null +++ b/tools/kvm/include/linux/bitops.h @@ -0,0 +1,33 @@ +#ifndef _KVM_LINUX_BITOPS_H_ +#define _KVM_LINUX_BITOPS_H_ + +#include +#include +#include + +#define BITS_PER_LONG __WORDSIZE +#define BITS_PER_BYTE 8 +#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long)) + +static inline void set_bit(int nr, unsigned long *addr) +{ + addr[nr / BITS_PER_LONG] |= 1UL << (nr % BITS_PER_LONG); +} + +static inline void clear_bit(int nr, unsigned long *addr) +{ + addr[nr / BITS_PER_LONG] &= ~(1UL << (nr % BITS_PER_LONG)); +} + +static __always_inline int test_bit(unsigned int nr, const unsigned long *addr) +{ + return ((1UL << (nr % BITS_PER_LONG)) & + (((unsigned long *)addr)[nr / BITS_PER_LONG])) != 0; +} + +static inline unsigned long hweight_long(unsigned long w) +{ + return sizeof(w) == 4 ? hweight32(w) : hweight64(w); +} + +#endif diff --git a/tools/kvm/virtio.c b/tools/kvm/virtio.c index 266a1b6be7ef..4dcd092d4eb6 100644 --- a/tools/kvm/virtio.c +++ b/tools/kvm/virtio.c @@ -1,7 +1,9 @@ #include #include #include -#include + +#include "kvm/barrier.h" + #include "kvm/kvm.h" #include "kvm/virtio.h" -- 2.39.5