Commit 627d6874 authored by Asias He's avatar Asias He Committed by Will Deacon
Browse files

kvm tools: Do not poll ioeventfd if vhost is enabled



If vhost is enabled for a virtio device, vhost will poll the ioeventfd
in kernel side and there is no need to poll it in userspace. Otherwise,
both vhost kernel and userspace will race to poll.

Signed-off-by: default avatarAsias He <asias.hejun@gmail.com>
Signed-off-by: default avatarPekka Enberg <penberg@kernel.org>
parent 8b795457
......@@ -22,7 +22,7 @@ struct ioevent {
int ioeventfd__init(struct kvm *kvm);
int ioeventfd__exit(struct kvm *kvm);
int ioeventfd__add_event(struct ioevent *ioevent, bool is_pio);
int ioeventfd__add_event(struct ioevent *ioevent, bool is_pio, bool poll_in_userspace);
int ioeventfd__del_event(u64 addr, u64 datamatch);
#endif
......@@ -72,6 +72,7 @@ enum virtio_trans {
};
struct virtio_device {
bool use_vhost;
void *virtio;
struct virtio_ops *ops;
};
......
......@@ -117,7 +117,7 @@ int ioeventfd__exit(struct kvm *kvm)
return 0;
}
int ioeventfd__add_event(struct ioevent *ioevent, bool is_pio)
int ioeventfd__add_event(struct ioevent *ioevent, bool is_pio, bool poll_in_userspace)
{
struct kvm_ioeventfd kvm_ioevent;
struct epoll_event epoll_event;
......@@ -151,6 +151,9 @@ int ioeventfd__add_event(struct ioevent *ioevent, bool is_pio)
goto cleanup;
}
if (!poll_in_userspace)
return 0;
epoll_event = (struct epoll_event) {
.events = EPOLLIN,
.data.ptr = new_ioevent,
......
......@@ -48,7 +48,15 @@ static int virtio_mmio_init_ioeventfd(struct kvm *kvm,
.fd = eventfd(0, 0),
};
err = ioeventfd__add_event(&ioevent, false);
if (vdev->use_vhost)
/*
* Vhost will poll the eventfd in host kernel side,
* no need to poll in userspace.
*/
err = ioeventfd__add_event(&ioevent, true, false);
else
/* Need to poll in userspace. */
err = ioeventfd__add_event(&ioevent, true, true);
if (err)
return err;
......
......@@ -492,6 +492,9 @@ static void virtio_net__vhost_init(struct kvm *kvm, struct net_dev *ndev)
r = ioctl(ndev->vhost_fd, VHOST_SET_MEM_TABLE, mem);
if (r != 0)
die_perror("VHOST_SET_MEM_TABLE failed");
ndev->vdev.use_vhost = true;
free(mem);
}
......
......@@ -40,7 +40,15 @@ static int virtio_pci__init_ioeventfd(struct kvm *kvm, struct virtio_device *vde
.fd = eventfd(0, 0),
};
r = ioeventfd__add_event(&ioevent, true);
if (vdev->use_vhost)
/*
* Vhost will poll the eventfd in host kernel side,
* no need to poll in userspace.
*/
r = ioeventfd__add_event(&ioevent, true, false);
else
/* Need to poll in userspace. */
r = ioeventfd__add_event(&ioevent, true, true);
if (r)
return r;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment