Message ID | 20110505082215.GA20719@elte.hu (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Thu, 2011-05-05 at 10:22 +0200, Ingo Molnar wrote: > * Ingo Molnar <mingo@elte.hu> wrote: > > > * Ingo Molnar <mingo@elte.hu> wrote: > > > > > I'm not entirely happy about how it has added dependent includes to virtio.c > > > but that's a property of this messy header file. Might be worth adding a > > > comment about that. > > > > This block: > > > > > +#include <linux/stringify.h> > > > +#include <linux/bitops.h> > > > +#include <asm/alternative.h> > > > #include <asm/system.h> > > > > Could be put into a new tools/kvm/include/kvm/barrier.h file, with a comment - > > that way the virtio.c inclusion looks very clean. > > > > Note: i'd not put it into linux/barrier.h, to not clash with any possible > > future linux/barrier.h file, and to also make it clear that this is a kvm > > specific wrapper. > > Like the more complete patch below. Build-tested on 32-bit and 64-bit systems, > boot tested on a 64-bit box. Applied, thanks Ingo! Asias, please let me know if master doesn't build for you still. -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On 05/05/2011 10:45 PM, Pekka Enberg wrote: > On Thu, 2011-05-05 at 10:22 +0200, Ingo Molnar wrote: >> * Ingo Molnar <mingo@elte.hu> wrote: >> >>> * Ingo Molnar <mingo@elte.hu> wrote: >>> >>>> I'm not entirely happy about how it has added dependent includes to virtio.c >>>> but that's a property of this messy header file. Might be worth adding a >>>> comment about that. >>> >>> This block: >>> >>>> +#include <linux/stringify.h> >>>> +#include <linux/bitops.h> >>>> +#include <asm/alternative.h> >>>> #include <asm/system.h> >>> >>> Could be put into a new tools/kvm/include/kvm/barrier.h file, with a comment - >>> that way the virtio.c inclusion looks very clean. >>> >>> Note: i'd not put it into linux/barrier.h, to not clash with any possible >>> future linux/barrier.h file, and to also make it clear that this is a kvm >>> specific wrapper. >> >> Like the more complete patch below. Build-tested on 32-bit and 64-bit systems, >> boot tested on a 64-bit box. > > Applied, thanks Ingo! Asias, please let me know if master doesn't build > for you still. Works for me now.
diff --git a/tools/kvm/include/asm/hweight.h b/tools/kvm/include/asm/hweight.h new file mode 100644 index 0000000..1a43977 --- /dev/null +++ b/tools/kvm/include/asm/hweight.h @@ -0,0 +1,8 @@ +#ifndef _KVM_ASM_HWEIGHT_H_ +#define _KVM_ASM_HWEIGHT_H_ + +#include <linux/types.h> +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 0000000..c11a239 --- /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 <linux/stringify.h> +#include <linux/bitops.h> +#include <asm/alternative.h> +#include <asm/system.h> + +#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 0000000..56448b7 --- /dev/null +++ b/tools/kvm/include/linux/bitops.h @@ -0,0 +1,33 @@ +#ifndef _KVM_LINUX_BITOPS_H_ +#define _KVM_LINUX_BITOPS_H_ + +#include <linux/kernel.h> +#include <linux/compiler.h> +#include <asm/hweight.h> + +#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 266a1b6..4dcd092 100644 --- a/tools/kvm/virtio.c +++ b/tools/kvm/virtio.c @@ -1,7 +1,9 @@ #include <linux/virtio_ring.h> #include <stdint.h> #include <sys/uio.h> -#include <asm/system.h> + +#include "kvm/barrier.h" + #include "kvm/kvm.h" #include "kvm/virtio.h"