From f73324bb1e15ef28852c91c15207bd0404eee303 Mon Sep 17 00:00:00 2001 From: Sasha Levin Date: Fri, 27 May 2011 19:18:39 +0300 Subject: [PATCH] kvm tools: Use ioeventfd in virtio-net Use ioeventfds to receive notifications of IO events in virtio-net. Doing so prevents an exit every time we receive/send a packet. Signed-off-by: Sasha Levin Signed-off-by: Pekka Enberg --- tools/kvm/virtio/net.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tools/kvm/virtio/net.c b/tools/kvm/virtio/net.c index 3064da612554..5c39c437086c 100644 --- a/tools/kvm/virtio/net.c +++ b/tools/kvm/virtio/net.c @@ -8,6 +8,7 @@ #include "kvm/kvm.h" #include "kvm/pci.h" #include "kvm/irq.h" +#include "kvm/ioeventfd.h" #include #include @@ -280,6 +281,11 @@ static bool virtio_net_pci_io_out(struct ioport *ioport, struct kvm *kvm, u16 po return ret; } +static void ioevent_callback(struct kvm *kvm, void *param) +{ + virtio_net_handle_callback(kvm, (u64)param); +} + static struct ioport_operations virtio_net_io_ops = { .io_in = virtio_net_pci_io_in, .io_out = virtio_net_pci_io_out, @@ -388,6 +394,8 @@ void virtio_net__init(const struct virtio_net_parameters *params) if (virtio_net__tap_init(params)) { u8 dev, line, pin; u16 net_base_addr; + u64 i; + struct ioevent ioevent; if (irq__register_device(VIRTIO_ID_NET, &dev, &pin, &line) < 0) return; @@ -401,5 +409,19 @@ void virtio_net__init(const struct virtio_net_parameters *params) pci__register(&pci_header, dev); virtio_net__io_thread_init(params->kvm); + + for (i = 0; i < VIRTIO_NET_NUM_QUEUES; i++) { + ioevent = (struct ioevent) { + .io_addr = net_base_addr + VIRTIO_PCI_QUEUE_NOTIFY, + .io_len = sizeof(u16), + .fn = ioevent_callback, + .datamatch = i, + .fn_ptr = (void *)i, + .fn_kvm = params->kvm, + .fd = eventfd(0, 0), + }; + + ioeventfd__add_event(&ioevent); + } } } -- 2.39.5