Re: [PATCH 2/2] tools/virtio: virtio_test tool

2011-09-06 Thread Zhi Yong Wu
Thanks. very good learning material.

On Tue, Nov 30, 2010 at 1:16 AM, Michael S. Tsirkin m...@redhat.com wrote:
 This is the userspace part of the tool: it includes a bunch of stubs for
 linux APIs, somewhat simular to linuxsched. This makes it possible to
 recompile the ring code in userspace.

 A small test example is implemented combining this with vhost_test
 module.

 Signed-off-by: Michael S. Tsirkin m...@redhat.com

 ---

 diff --git a/tools/virtio/Makefile b/tools/virtio/Makefile
 new file mode 100644
 index 000..d1d442e
 --- /dev/null
 +++ b/tools/virtio/Makefile
 @@ -0,0 +1,12 @@
 +all: test mod
 +test: virtio_test
 +virtio_test: virtio_ring.o virtio_test.o
 +CFLAGS += -g -O2 -Wall -I. -I ../../usr/include/ -Wno-pointer-sign 
 -fno-strict-overflow  -MMD
 +vpath %.c ../../drivers/virtio
 +mod:
 +       ${MAKE} -C `pwd`/../.. M=`pwd`/vhost_test
 +.PHONY: all test mod clean
 +clean:
 +       ${RM} *.o vhost_test/*.o vhost_test/.*.cmd \
 +              vhost_test/Module.symvers vhost_test/modules.order *.d
 +-include *.d
 diff --git a/tools/virtio/linux/device.h b/tools/virtio/linux/device.h
 new file mode 100644
 index 000..4ad7e1d
 --- /dev/null
 +++ b/tools/virtio/linux/device.h
 @@ -0,0 +1,2 @@
 +#ifndef LINUX_DEVICE_H
 +#endif
 diff --git a/tools/virtio/linux/slab.h b/tools/virtio/linux/slab.h
 new file mode 100644
 index 000..81baeac
 --- /dev/null
 +++ b/tools/virtio/linux/slab.h
 @@ -0,0 +1,2 @@
 +#ifndef LINUX_SLAB_H
 +#endif
 diff --git a/tools/virtio/linux/virtio.h b/tools/virtio/linux/virtio.h
 new file mode 100644
 index 000..669bcdd
 --- /dev/null
 +++ b/tools/virtio/linux/virtio.h
 @@ -0,0 +1,223 @@
 +#ifndef LINUX_VIRTIO_H
 +#define LINUX_VIRTIO_H
 +
 +#include stdbool.h
 +#include stdlib.h
 +#include stddef.h
 +#include stdio.h
 +#include string.h
 +#include assert.h
 +
 +#include linux/types.h
 +#include errno.h
 +
 +typedef unsigned long long dma_addr_t;
 +
 +struct scatterlist {
 +       unsigned long   page_link;
 +       unsigned int    offset;
 +       unsigned int    length;
 +       dma_addr_t      dma_address;
 +};
 +
 +struct page {
 +       unsigned long long dummy;
 +};
 +
 +#define BUG_ON(__BUG_ON_cond) assert(!(__BUG_ON_cond))
 +
 +/* Physical == Virtual */
 +#define virt_to_phys(p) ((unsigned long)p)
 +#define phys_to_virt(a) ((void *)(unsigned long)(a))
 +/* Page address: Virtual / 4K */
 +#define virt_to_page(p) ((struct page*)((virt_to_phys(p) / 4096) * \
 +                                       sizeof(struct page)))
 +#define offset_in_page(p) (((unsigned long)p) % 4096)
 +#define sg_phys(sg) ((sg-page_link  ~0x3) / sizeof(struct page) * 4096 + \
 +                    sg-offset)
 +static inline void sg_mark_end(struct scatterlist *sg)
 +{
 +       /*
 +        * Set termination bit, clear potential chain bit
 +        */
 +       sg-page_link |= 0x02;
 +       sg-page_link = ~0x01;
 +}
 +static inline void sg_init_table(struct scatterlist *sgl, unsigned int nents)
 +{
 +       memset(sgl, 0, sizeof(*sgl) * nents);
 +       sg_mark_end(sgl[nents - 1]);
 +}
 +static inline void sg_assign_page(struct scatterlist *sg, struct page *page)
 +{
 +       unsigned long page_link = sg-page_link  0x3;
 +
 +       /*
 +        * In order for the low bit stealing approach to work, pages
 +        * must be aligned at a 32-bit boundary as a minimum.
 +        */
 +       BUG_ON((unsigned long) page  0x03);
 +       sg-page_link = page_link | (unsigned long) page;
 +}
 +
 +static inline void sg_set_page(struct scatterlist *sg, struct page *page,
 +                              unsigned int len, unsigned int offset)
 +{
 +       sg_assign_page(sg, page);
 +       sg-offset = offset;
 +       sg-length = len;
 +}
 +
 +static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
 +                             unsigned int buflen)
 +{
 +       sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
 +}
 +
 +static inline void sg_init_one(struct scatterlist *sg, const void *buf, 
 unsigned int buflen)
 +{
 +       sg_init_table(sg, 1);
 +       sg_set_buf(sg, buf, buflen);
 +}
 +
 +typedef __u16 u16;
 +
 +typedef enum {
 +       GFP_KERNEL,
 +       GFP_ATOMIC,
 +} gfp_t;
 +typedef enum {
 +       IRQ_NONE,
 +       IRQ_HANDLED
 +} irqreturn_t;
 +
 +static inline void *kmalloc(size_t s, gfp_t gfp)
 +{
 +       return malloc(s);
 +}
 +
 +static inline void kfree(void *p)
 +{
 +       free(p);
 +}
 +
 +#define container_of(ptr, type, member) ({                     \
 +       const typeof( ((type *)0)-member ) *__mptr = (ptr);    \
 +       (type *)( (char *)__mptr - offsetof(type,member) );})
 +
 +#define uninitialized_var(x) x = x
 +
 +# ifndef likely
 +#  define likely(x)    (__builtin_expect(!!(x), 1))
 +# endif
 +# ifndef unlikely
 +#  define unlikely(x)  (__builtin_expect(!!(x), 0))
 +# endif
 +
 +#define pr_err(format, ...) fprintf (stderr, format, ## __VA_ARGS__)
 +#ifdef DEBUG
 +#define pr_debug(format, ...) fprintf (stderr, format, ## 

Re: [PATCH 2/2] tools/virtio: virtio_test tool

2010-12-13 Thread Michael S. Tsirkin
On Mon, Dec 06, 2010 at 03:23:02PM +1030, Rusty Russell wrote:
 On Tue, 30 Nov 2010 03:46:37 am Michael S. Tsirkin wrote:
  This is the userspace part of the tool: it includes a bunch of stubs for
  linux APIs, somewhat simular to linuxsched. This makes it possible to
  recompile the ring code in userspace.
  
  A small test example is implemented combining this with vhost_test
  module.
  
  Signed-off-by: Michael S. Tsirkin m...@redhat.com
 
 Hi Michael,
 
   I'm not sure what the point is of this work?  You'll still need to
 benchmark on real systems, but it's not low-level enough to measure
 things like cache misses.

The point is to be able to create easy to test workloads:
(just running the single test included here produces a
 result that seems repeatable to a high degree)
while still staying as close as possible to what we might expect in real
life.

I also want to be able to measure just the overhead of the ring,
without involving block or network core in guest and host.

In other words, it's a synthetic benchmark.

 I'm assuming you're thinking of playing with layout to measure cache
 behaviour.

In one example, using this test I saw that different publish
used index layouts don't seem to behave at all differently.

But I also saw that the extra pointer hasing
added by my publish used index patches did add
measureable overhead.

Plan to look into that.

  I was thinking of a complete userspace implementation

The disadvantage is that any work done there needs to be
redone in real life, though. And implementation details often matter.
What I did let me actually use the virtio/vhost code that we have and see how
it performs.

 where
 either it was run under cachegrind, or each access was wrapped to allow
 tracking of cachelines to give an exact measure of cache movement

perf stat not good enough?

 under
 various scenarios (esp. ring mostly empty, ring in steady state, ring
 mostly full).

Yes, I do want to add tests to stress various scenarios.

 
 Cheers,
 Rusty.


-- 
MST
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


Re: [PATCH 2/2] tools/virtio: virtio_test tool

2010-12-07 Thread Thiago Farina
On Mon, Nov 29, 2010 at 3:16 PM, Michael S. Tsirkin m...@redhat.com wrote:
 +#define container_of(ptr, type, member) ({                     \
 +       const typeof( ((type *)0)-member ) *__mptr = (ptr);    \
 +       (type *)( (char *)__mptr - offsetof(type,member) );})
 +
 +#define uninitialized_var(x) x = x
 +
 +# ifndef likely
 +#  define likely(x)    (__builtin_expect(!!(x), 1))
 +# endif
 +# ifndef unlikely
 +#  define unlikely(x)  (__builtin_expect(!!(x), 0))
 +# endif

It seems you are not using these macros. Do you really need them here?
Can't you include the right linux header files for these macros
instead?
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization