tools/virtio updates for API testing
Subsystems (2)
Michael S. Tsirkin
maintainercover tools/virtio updates for API testing
Here's a patchset to update tools/virtio with changes in 3.8, as well as the proposed API extension.
Useful to see whether the extra level of indirection adds measureable overhead.
I will upstream at least patch 1 soon.
Michael S. Tsirkin (2):
tools/virtio: fix build for 3.8
tools/virtio: update for the new virtio API
drivers/vhost/test.c | 4 +++- tools/virtio/Makefile | 2 +- tools/virtio/linux/virtio.h | 52 ++++++++++++++++++++++++++++++++++++++------- tools/virtio/virtio_test.c | 3 ++- 4 files changed, 50 insertions(+), 11 deletions(-)
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH 1/2 tools/virtio: fix build for 3.8
--- drivers/vhost/test.c | 4 +++- tools/virtio/Makefile | 2 +- tools/virtio/linux/virtio.h | 7 ++++++- tools/virtio/virtio_test.c | 3 ++- 4 files changed, 12 insertions(+), 4 deletions(-)
drivers/vhost/test.c +3 -1
@@ -275,7 +275,9 @@ static long vhost_test_ioctl(struct file *f, unsigned int ioctl,return vhost_test_reset_owner (n);default :mutex_lock (&n->dev.mutex); - r =vhost_dev_ioctl (&n->dev, ioctl, arg); + r =vhost_dev_ioctl (&n->dev, ioctl, argp); +if (r == -ENOIOCTLCMD ) + r =vhost_vring_ioctl (&n->dev, ioctl, argp);vhost_test_flush (n);mutex_unlock (&n->dev.mutex);return r;
tools/virtio/Makefile +1 -1
@@ -1,7 +1,7 @@ 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 +CFLAGS += -g -O2 -Wall -I. -I ../../usr/include/ -Wno-pointer-sign -fno-strict-overflow -fno-strict-aliasing -fno-common -MMD vpath %.c ../../drivers/virtio mod: ${MAKE} -C `pwd`/../.. M=`pwd`/vhost_test
tools/virtio/linux/virtio.h +6 -1
@@ -85,6 +85,8 @@ typedef __u16 u16;typedef enum {GFP_KERNEL ,GFP_ATOMIC , + __GFP_HIGHMEM, + __GFP_HIGH }gfp_t ; typedef enum { IRQ_NONE,
@@ -163,6 +165,8 @@ struct virtqueue {void (*callback)(struct virtqueue *vq);const char *name;struct virtio_device *vdev; +unsigned int index; +unsigned int num_free;void *priv; };
@@ -206,7 +210,8 @@ bool virtqueue_enable_cb(struct virtqueue *vq);bool virtqueue_enable_cb_delayed (struct virtqueue *vq);void *virtqueue_detach_unused_buf (struct virtqueue *vq); -struct virtqueue *vring_new_virtqueue(unsigned int num, +struct virtqueue *vring_new_virtqueue(unsigned int index, + unsigned int num, unsigned int vring_align, struct virtio_device *vdev, bool weak_barriers,
tools/virtio/virtio_test.c +2 -1
@@ -92,7 +92,8 @@ static void vq_info_add(struct vdev_info *dev, int num)assert (r >=0 );memset (info->ring,0 ,vring_size (num,4096 ));vring_init (&info->vring, num, info->ring,4096 ); - info->vq =vring_new_virtqueue (info->vring.num,4096 , &dev->vdev, + info->vq =vring_new_virtqueue (info->idx, + info->vring.num,4096 , &dev->vdev, true, info->ring, vq_notify, vq_callback,"test" );assert (info->vq);
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH 2/2 tools/virtio: update for the new virtio API
In reply to Michael S. Tsirkin--- tools/virtio/linux/virtio.h | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-)
tools/virtio/linux/virtio.h +38 -7
@@ -11,6 +11,13 @@#include <linux/types.h> #include <errno.h> +# ifndef likely +# define likely (x) (__builtin_expect(!!(x), 1)) +# endif +# ifndef unlikely +# define unlikely (x) (__builtin_expect(!!(x), 0)) +# endif +typedef unsigned long long dma_addr_t ;struct scatterlist {
@@ -43,6 +50,10 @@ static inline void sg_mark_end(struct scatterlist *sg) sg->page_link |=0x02 ; sg->page_link &= ~0x01 ; } +static inline void sg_unmark_end (struct scatterlist *sg) +{ + sg->page_link &= ~0x02 ; +}static inline void sg_init_table (struct scatterlist *sgl,unsigned int nents) {memset (sgl,0 ,sizeof (*sgl) * nents);
@@ -79,6 +90,26 @@ static inline void sg_init_one(struct scatterlist *sg, const void *buf, unsignedsg_init_table (sg,1 );sg_set_buf (sg, buf, buflen); } +/* +* We overload the LSB of the page pointer to indicate whether it's +* a valid sg entry, or whether it points to the start of a new scatterlist. +* Those low bits are there for everyone! (thanks mason :-) +*/ +#define sg_is_chain (sg) ((sg)->page_link & 0x01) +#define sg_is_last (sg) ((sg)->page_link & 0x02) +#define sg_chain_ptr (sg) \ + ((struct scatterlist *) ((sg)->page_link & ~0x03)) +static inline struct scatterlist *sg_next (struct scatterlist *sg) +{ +if (sg_is_last (sg)) +return NULL ; + + sg++; +if (unlikely (sg_is_chain (sg))) + sg =sg_chain_ptr (sg); + +return sg; +}typedef __u16 u16 ;
@@ -109,13 +140,6 @@ static inline void kfree(void *p)#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, ## __VA_ARGS__)
@@ -200,6 +224,13 @@ int virtqueue_add_buf(struct virtqueue *vq,void *data, gfp_t gfp); +int virtqueue_add_sgs (struct virtqueue *vq, +struct scatterlist *sgs[], +unsigned int out_sgs, +unsigned int in_sgs, +void *data, +gfp_t gfp); +void virtqueue_kick (struct virtqueue *vq);void *virtqueue_get_buf (struct virtqueue *vq,unsigned int *len);
Signature · 1 line
MST
Quoted 7 lines · Michael S. Tsirkin
Here's a patchset to update
tools/virtiowith changes in 3.8, as well as the proposed API extension.Useful to see whether the extra level of indirection adds measureable overhead.
I will upstream at least patch 1 soon.
What happened to this, BTW?
Quoted 2 lines
Michael S. Tsirkin (2):
tools/virtio: fix build for 3.8
Thanks,
Rusty.