Skip to contentSkip to conversation

kvm tools: Support VIRTIO_RING_F_EVENT_IDX

PATCH In review Sasha Levin 2 participants 7 messages Nov 17, 2011 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 kvm tools: Support VIRTIO_RING_F_EVENT_IDX

Support the event index feature in the virtio spec.

The results are less notifications between the guest and host, and in result faster operation of the virt queues.

---
 tools/kvm/include/kvm/virtio.h |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
tools/kvm/include/kvm/virtio.h +7 -0
index c6c380d..cd24285 100644
@@ -38,6 +38,8 @@ static inline bool virt_queue__available(struct virt_queue *vq)
 {
 	if (!vq->vring.avail)
 		return 0;
+
+	vring_avail_event(&vq->vring) = vq->last_avail_idx;
 	return vq->vring.avail->idx !=  vq->last_avail_idx;
 }
 
@@ -51,6 +53,11 @@ static inline void *guest_pfn_to_host(struct kvm *kvm, u32 pfn)
 	return guest_flat_to_host(kvm, (unsigned long)pfn << VIRTIO_PCI_QUEUE_ADDR_SHIFT);
 }
 
+static inline int virtio_queue__should_signal(struct virt_queue *vq)
+{
+	return vring_used_event(&vq->vring) <= vq->vring.used->idx;
+}
+
 struct vring_used_elem *virt_queue__set_used_elem(struct virt_queue *queue, u32 head, u32 len);
 
 u16 virt_queue__get_iov(struct virt_queue *queue, struct iovec iov[], u16 *out, u16 *in, struct kvm *kvm);
Signature · 1 line
1.7.8.rc1
#1 lore raw

PATCH 2/4 kvm tools: Add '--no-dhcp' to disable kernel DHCP

This new option disables the kernel DHCP which runs when starting a custom rootfs.

This is useful when we want to start a rootfs but are using a network other than the usermode IP proxy (a network which doesn't provide DHCP).

---
 tools/kvm/builtin-run.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
tools/kvm/builtin-run.c +7 -2
index 3b00bf0..43cf2c4 100644
@@ -91,6 +91,7 @@ static bool balloon;
 static bool using_rootfs;
 static bool custom_rootfs;
 static bool no_net;
+static bool no_dhcp;
 extern bool ioport_debug;
 extern int  active_console;
 extern int  debug_iodelay;
@@ -432,6 +433,7 @@ static const struct option options[] = {
 	OPT_CALLBACK_DEFAULT('n', "network", NULL, "network params",
 		     "Create a new guest NIC",
 		     netdev_parser, NULL),
+	OPT_BOOLEAN('\0', "no-dhcp", &no_dhcp, "Disable kernel DHCP in rootfs mode"),
 
 	OPT_GROUP("BIOS options:"),
 	OPT_INTEGER('\0', "vidmode", &vidmode,
@@ -861,8 +863,11 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
 
 	if (using_rootfs) {
 		strcat(real_cmdline, " root=/dev/root rw rootflags=rw,trans=virtio,version=9p2000.L rootfstype=9p");
-		if (custom_rootfs)
-			strcat(real_cmdline, " init=/virt/init ip=dhcp");
+		if (custom_rootfs) {
+			strcat(real_cmdline, " init=/virt/init");
+			if (!no_dhcp)
+				strcat(real_cmdline, "  ip=dhcp");
+		}
 	} else if (!strstr(real_cmdline, "root=")) {
 		strlcat(real_cmdline, " root=/dev/vda rw ", sizeof(real_cmdline));
 	}
Signature · 1 line
1.7.8.rc1
#2 lore raw

PATCH 3/4 kvm tools: Support event idx in virtio-net

In reply to Sasha Levin

Support event idx both when using vhost and when using simple TAP mode.

I did simple TCP stream performance test with vhost, and it showed another 9% increase over regular vhost mode.

---
 tools/kvm/virtio/net.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)
tools/kvm/virtio/net.c +8 -4
index 58ca4ed..118517f 100644
@@ -102,7 +102,9 @@ static void *virtio_net_rx_thread(void *p)
 			virt_queue__set_used_elem(vq, head, len);
 
 			/* We should interrupt guest right now, otherwise latency is huge. */
-			ndev->vtrans.trans_ops->signal_vq(kvm, &ndev->vtrans, VIRTIO_NET_RX_QUEUE);
+			if (virtio_queue__should_signal(&ndev->vqs[VIRTIO_NET_RX_QUEUE]))
+				ndev->vtrans.trans_ops->signal_vq(kvm, &ndev->vtrans,
+								VIRTIO_NET_RX_QUEUE);
 		}
 
 	}
@@ -140,7 +142,8 @@ static void *virtio_net_tx_thread(void *p)
 			virt_queue__set_used_elem(vq, head, len);
 		}
 
-		ndev->vtrans.trans_ops->signal_vq(kvm, &ndev->vtrans, VIRTIO_NET_TX_QUEUE);
+		if (virtio_queue__should_signal(&ndev->vqs[VIRTIO_NET_TX_QUEUE]))
+			ndev->vtrans.trans_ops->signal_vq(kvm, &ndev->vtrans, VIRTIO_NET_TX_QUEUE);
 	}
 
 	pthread_exit(NULL);
@@ -314,7 +317,8 @@ static u32 get_host_features(struct kvm *kvm, void *dev)
 		| 1UL << VIRTIO_NET_F_HOST_TSO6
 		| 1UL << VIRTIO_NET_F_GUEST_UFO
 		| 1UL << VIRTIO_NET_F_GUEST_TSO4
-		| 1UL << VIRTIO_NET_F_GUEST_TSO6;
+		| 1UL << VIRTIO_NET_F_GUEST_TSO6
+		| 1UL << VIRTIO_RING_F_EVENT_IDX;
 }
 
 static void set_guest_features(struct kvm *kvm, void *dev, u32 features)
@@ -453,7 +457,7 @@ static struct virtio_ops net_dev_virtio_ops = (struct virtio_ops) {
 
 static void virtio_net__vhost_init(struct kvm *kvm, struct net_dev *ndev)
 {
-	u64 features = 0;
+	u64 features = 1UL << VIRTIO_RING_F_EVENT_IDX;
 	struct vhost_memory *mem;
 	int r;
 
Signature · 1 line
1.7.8.rc1
#3 lore raw

PATCH 4/4 kvm tool: Add event idx support to virtio-blk

In reply to Sasha Levin
---
 tools/kvm/virtio/blk.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
tools/kvm/virtio/blk.c +5 -2
index ed4e099..9495f28 100644
@@ -93,7 +93,8 @@ void virtio_blk_complete(void *param, long len)
 	virt_queue__set_used_elem(req->vq, req->head, len);
 	mutex_unlock(&bdev->mutex);
 
-	bdev->vtrans.trans_ops->signal_vq(req->kvm, &bdev->vtrans, queueid);
+	if (virtio_queue__should_signal(&bdev->vqs[queueid]))
+		bdev->vtrans.trans_ops->signal_vq(req->kvm, &bdev->vtrans, queueid);
 
 	virtio_blk_req_push(req->bdev, req);
 }
@@ -170,7 +171,9 @@ static u8 get_config(struct kvm *kvm, void *dev, u32 offset)
 
 static u32 get_host_features(struct kvm *kvm, void *dev)
 {
-	return 1UL << VIRTIO_BLK_F_SEG_MAX | 1UL << VIRTIO_BLK_F_FLUSH;
+	return	1UL << VIRTIO_BLK_F_SEG_MAX
+		| 1UL << VIRTIO_BLK_F_FLUSH
+		| 1UL << VIRTIO_RING_F_EVENT_IDX;
 }
 
 static void set_guest_features(struct kvm *kvm, void *dev, u32 features)
Signature · 1 line
1.7.8.rc1
#4 lore raw
In reply to Sasha Levin
Quoted 6 lines · Sasha Levin

Support the event index feature in the virtio spec.

The results are less notifications between the guest and host, and in result faster operation of the virt queues.

What's this patch doing? There's no mention of VIRTIO_RING_F_EVENT_IDX in the diff...

Quoted 37 lines

---
 tools/kvm/include/kvm/virtio.h |    7 +++++++

 1 files changed, 7 insertions(+), 0 deletions(-)
tools/kvm/include/kvm/virtio.h +7 -1
index c6c380d..cd24285 100644
@@ -38,6 +38,8 @@ static inline bool virt_queue__available(struct virt_queue *vq)
  {
        if (!vq->vring.avail)
                return 0;
+
+       vring_avail_event(&vq->vring) = vq->last_avail_idx;
        return vq->vring.avail->idx !=  vq->last_avail_idx;
  }
 
@@ -51,6 +53,11 @@ static inline void *guest_pfn_to_host(struct kvm *kvm, u32 pfn)
        return guest_flat_to_host(kvm, (unsigned long)pfn << VIRTIO_PCI_QUEUE_ADDR_SHIFT);
  }
 
+static inline int virtio_queue__should_signal(struct virt_queue *vq)
+{
+       return vring_used_event(&vq->vring) <= vq->vring.used->idx;
+}
+
  struct vring_used_elem *virt_queue__set_used_elem(struct virt_queue *queue, u32 head, u32 len);
 
  u16 virt_queue__get_iov(struct virt_queue *queue, struct iovec iov[], u16 *out, u16 *in, struct kvm *kvm);
--

1.7.8.rc1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

#5 lore raw
Quoted 10 lines · Pekka Enberg
Quoted 6 lines · Sasha Levin

Support the event index feature in the virtio spec.

The results are less notifications between the guest and host, and in result faster operation of the virt queues.

What's this patch doing? There's no mention of VIRTIO_RING_F_EVENT_IDX in the diff...

It allows enabling the VIRTIO_RING_F_EVENT_IDX feature in various virtio-* devices by updating the avail event idx and providing a function to allow the devices to query the vq and decide if they need to signal the VQ or not.

Signature · 1 line
Sasha.
#6 lore raw
Quoted 11 lines · Pekka Enberg
Quoted 10 lines · Sasha Levin
Quoted 6 lines

Support the event index feature in the virtio spec.

The results are less notifications between the guest and host, and in result faster operation of the virt queues.

What's this patch doing? There's no mention of VIRTIO_RING_F_EVENT_IDX in the diff...

Quoted 4 lines · Sasha Levin

It allows enabling the VIRTIO_RING_F_EVENT_IDX feature in various virtio-* devices by updating the avail event idx and providing a function to allow the devices to query the vq and decide if they need to signal the VQ or not.

Right. The changelog is extremely confusing as is the ordering in the patch series. You usually write something like "in preparation for enabling XYZ support, add helper functions" and include the conversions immediately after the helpers.

I'll fix the issues myself later today when I have the change to merge patches. That is, unless you beat me to it and send a v2 of the series.

Pekka