Skip to contentSkip to conversation

kvm tools: Add optional callbacks for VQs

PATCH In review Sasha Levin 1 participant 3 messages Nov 16, 2011 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 kvm tools: Add optional callbacks for VQs

This patch adds optional callbacks which get called when the VQ gets assigned an eventfd for notifications, and when it gets assigned with a GSI.

This allows the device to pass the eventfds to 3rd parties which can use them to notify and get notifications regarding the VQ.

---
 tools/kvm/include/kvm/virtio-trans.h |    2 ++
 tools/kvm/virtio/pci.c               |    6 ++++++
 2 files changed, 8 insertions(+), 0 deletions(-)
tools/kvm/include/kvm/virtio-trans.h +2 -0
index d9f4b95..e7c186e 100644
@@ -20,6 +20,8 @@ struct virtio_ops {
 	int (*notify_vq)(struct kvm *kvm, void *dev, u32 vq);
 	int (*get_pfn_vq)(struct kvm *kvm, void *dev, u32 vq);
 	int (*get_size_vq)(struct kvm *kvm, void *dev, u32 vq);
+	void (*notify_vq_gsi)(struct kvm *kvm, void *dev, u32 vq, u32 gsi);
+	void (*notify_vq_eventfd)(struct kvm *kvm, void *dev, u32 vq, u32 efd);
 };
 
 struct virtio_trans_ops {
tools/kvm/virtio/pci.c +6 -0
index 1660f06..0737ae7 100644
@@ -51,6 +51,9 @@ static int virtio_pci__init_ioeventfd(struct kvm *kvm, struct virtio_trans *vtra
 
 	ioeventfd__add_event(&ioevent);
 
+	if (vtrans->virtio_ops->notify_vq_eventfd)
+		vtrans->virtio_ops->notify_vq_eventfd(kvm, vpci->dev, vq, ioevent.fd);
+
 	return 0;
 }
 
@@ -152,6 +155,9 @@ static bool virtio_pci__specific_io_out(struct kvm *kvm, struct virtio_trans *vt
 
 			gsi = irq__add_msix_route(kvm, &vpci->msix_table[vec].msg);
 			vpci->gsis[vpci->queue_selector] = gsi;
+			if (vtrans->virtio_ops->notify_vq_gsi)
+				vtrans->virtio_ops->notify_vq_gsi(kvm, vpci->dev,
+							vpci->queue_selector, gsi);
 			break;
 		}
 		};
Signature · 1 line
1.7.8.rc1
#1 lore raw

PATCH 2/2 kvm tools: Add vhost-net support

This patch adds support to using the vhost-net device when using a tap backed virtio-net device.

Activating vhost-net is done by appending a 'vhost=1' flag to the net device configuration. For example:

'kvm run -n mode=tap,vhost=1'

Cc Michael S. Tsirkin <[email protected]>
---
 tools/kvm/builtin-run.c            |    2 +
 tools/kvm/include/kvm/virtio-net.h |    1 +
 tools/kvm/virtio/net.c             |  120 +++++++++++++++++++++++++++++++++++-
 3 files changed, 122 insertions(+), 1 deletions(-)
tools/kvm/builtin-run.c +2 -0
index 13025db..3b00bf0 100644
@@ -217,6 +217,8 @@ static int set_net_param(struct virtio_net_params *p, const char *param,
 		p->guest_ip = strdup(val);
 	} else if (strcmp(param, "host_ip") == 0) {
 		p->host_ip = strdup(val);
+	} else if (strcmp(param, "vhost") == 0) {
+		p->vhost = atoi(val);
 	}
 
 	return 0;
tools/kvm/include/kvm/virtio-net.h +1 -0
index 58ae162..dade8cb 100644
@@ -11,6 +11,7 @@ struct virtio_net_params {
 	char host_mac[6];
 	struct kvm *kvm;
 	int mode;
+	int vhost;
 };
 
 void virtio_net__init(const struct virtio_net_params *params);
tools/kvm/virtio/net.c +119 -1

170 lines not on this page · raw message

Signature · 1 line
1.7.8.rc1
#2 lore raw

Re: [PATCH 2/2] kvm tools: Add vhost-net support

Quoted 11 lines · Sasha Levin

This patch adds support to using the vhost-net device when using a tap backed virtio-net device.

Activating vhost-net is done by appending a 'vhost=1' flag to the net device configuration. For example:

'kvm run -n mode=tap,vhost=1'

Cc Michael S. Tsirkin <[email protected]>

---

I forgot to attach performance numbers to the changelog, so here they are:

Short version
------------------

TCP Throughput: +29%
UDP Throughput: +10%
TCP Latency: -15%
UDP Latency: -12%

Long version
------------------

MIGRATED TCP STREAM TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 192.168.33.4 (192.168.33.4) port 0 AF_INET

Recv   Send    Send                          
Socket Socket  Message  Elapsed              
Size   Size    Size     Time     Throughput  
bytes  bytes   bytes    secs.    10^6bits/sec  

87380 16384 16384 10.00 4895.04

MIGRATED UDP STREAM TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 192.168.33.4 (192.168.33.4) port 0 AF_INET

Socket  Message  Elapsed      Messages                
Size    Size     Time         Okay Errors   Throughput
bytes   bytes    secs            #      #   10^6bits/sec
229376   65507   10.00      125287      0    6565.60
229376           10.00      106910           5602.57

MIGRATED TCP REQUEST/RESPONSE TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 192.168.33.4 (192.168.33.4) port 0 AF_INET : first burst 0 Local /Remote

Socket Size   Request  Resp.   Elapsed  Trans.
Send   Recv   Size     Size    Time     Rate         
bytes  Bytes  bytes    bytes   secs.    per sec   

16384 87380 1 1 10.00 14811.55

MIGRATED UDP REQUEST/RESPONSE TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 192.168.33.4 (192.168.33.4) port 0 AF_INET : first burst 0 Local /Remote

Socket Size   Request  Resp.   Elapsed  Trans.
Send   Recv   Size     Size    Time     Rate         
bytes  Bytes  bytes    bytes   secs.    per sec   

229376 229376 1 1 10.00 16000.44
229376 229376

After:

MIGRATED TCP STREAM TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 192.168.33.4 (192.168.33.4) port 0 AF_INET

Recv   Send    Send                          
Socket Socket  Message  Elapsed              
Size   Size    Size     Time     Throughput  
bytes  bytes   bytes    secs.    10^6bits/sec  

87380 16384 16384 10.00 6340.74

MIGRATED UDP STREAM TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 192.168.33.4 (192.168.33.4) port 0 AF_INET

Socket  Message  Elapsed      Messages                
Size    Size     Time         Okay Errors   Throughput
bytes   bytes    secs            #      #   10^6bits/sec
229376   65507   10.00      131478      0    6890.09
229376           10.00      118136           6190.90

MIGRATED TCP REQUEST/RESPONSE TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 192.168.33.4 (192.168.33.4) port 0 AF_INET : first burst 0 Local /Remote

Socket Size   Request  Resp.   Elapsed  Trans.
Send   Recv   Size     Size    Time     Rate         
bytes  Bytes  bytes    bytes   secs.    per sec   

16384 87380 1 1 10.00 17126.10

MIGRATED UDP REQUEST/RESPONSE TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 192.168.33.4 (192.168.33.4) port 0 AF_INET : first burst 0 Local /Remote

Socket Size   Request  Resp.   Elapsed  Trans.
Send   Recv   Size     Size    Time     Rate         
bytes  Bytes  bytes    bytes   secs.    per sec   

229376 229376 1 1 10.00 17944.51

Signature · 1 line
Sasha.