diff options
author | Sasha Levin <sasha.levin@oracle.com> | 2013-04-13 20:20:44 -0400 |
---|---|---|
committer | Will Deacon <will.deacon@arm.com> | 2015-06-01 16:39:54 +0100 |
commit | 79052597edaae6167129f9b7cee0ac6d7ecfb95c (patch) | |
tree | 4b6a2f0cb1ab2831e7cd5c7fd88470af72160ddf | |
parent | 7bcceb95fd5435ef6f27c2f4caff134b9060257e (diff) | |
download | kvmtool-79052597edaae6167129f9b7cee0ac6d7ecfb95c.tar.gz |
kvm tools: make virtio-net mq max queues configurable
This patch makes the maximum amount of vqs configurable. To use it pass a 'mq'
option to network device configuration. For example:
vm run -n mode=tap,mq=4
Will allow up to 4 queue pairs for that network device.
Note that not specifiying mq, or setting mq=0 will disable virtio-net
multiqueuing.
Acked-by: Will Deacon <will.deacon@arm.com>
Tested-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
-rw-r--r-- | include/kvm/virtio-net.h | 1 | ||||
-rw-r--r-- | virtio/net.c | 19 |
2 files changed, 14 insertions, 6 deletions
diff --git a/include/kvm/virtio-net.h b/include/kvm/virtio-net.h index db43d987..0f4d1e58 100644 --- a/include/kvm/virtio-net.h +++ b/include/kvm/virtio-net.h @@ -16,6 +16,7 @@ struct virtio_net_params { int mode; int vhost; int fd; + int mq; }; int virtio_net__init(struct kvm *kvm); diff --git a/virtio/net.c b/virtio/net.c index 9911d777..c0a8f125 100644 --- a/virtio/net.c +++ b/virtio/net.c @@ -43,7 +43,7 @@ struct net_dev { struct virt_queue vqs[VIRTIO_NET_NUM_QUEUES * 2 + 1]; struct virtio_net_config config; - u32 features, rx_vqs, tx_vqs; + u32 features, rx_vqs, tx_vqs, queue_pairs; pthread_t io_thread[VIRTIO_NET_NUM_QUEUES * 2 + 1]; struct mutex io_lock[VIRTIO_NET_NUM_QUEUES * 2 + 1]; @@ -159,7 +159,7 @@ static void *virtio_net_ctrl_thread(void *p) u16 out, in, head; struct net_dev *ndev = p; struct kvm *kvm = ndev->kvm; - u32 id = ndev->config.max_virtqueue_pairs * 2; + u32 id = ndev->queue_pairs * 2; struct virt_queue *vq = &ndev->vqs[id]; struct virtio_net_ctrl_hdr *ctrl; virtio_net_ctrl_ack *ack; @@ -197,7 +197,7 @@ static void *virtio_net_ctrl_thread(void *p) static void virtio_net_handle_callback(struct kvm *kvm, struct net_dev *ndev, int queue) { - if (queue >= (ndev->config.max_virtqueue_pairs * 2 + 1)) { + if ((u32)queue >= (ndev->queue_pairs * 2 + 1)) { pr_warning("Unknown queue index %u", queue); return; } @@ -334,6 +334,8 @@ static u8 *get_config(struct kvm *kvm, void *dev) static u32 get_host_features(struct kvm *kvm, void *dev) { + struct net_dev *ndev = dev; + return 1UL << VIRTIO_NET_F_MAC | 1UL << VIRTIO_NET_F_CSUM | 1UL << VIRTIO_NET_F_HOST_UFO @@ -345,7 +347,7 @@ static u32 get_host_features(struct kvm *kvm, void *dev) | 1UL << VIRTIO_RING_F_EVENT_IDX | 1UL << VIRTIO_RING_F_INDIRECT_DESC | 1UL << VIRTIO_NET_F_CTRL_VQ - | 1UL << VIRTIO_NET_F_MQ; + | 1UL << (ndev->queue_pairs > 1 ? VIRTIO_NET_F_MQ : 0); } static void set_guest_features(struct kvm *kvm, void *dev, u32 features) @@ -376,7 +378,7 @@ static int init_vq(struct kvm *kvm, void *dev, u32 vq, u32 page_size, u32 align, mutex_init(&ndev->io_lock[vq]); pthread_cond_init(&ndev->io_cond[vq], NULL); if (ndev->vhost_fd == 0) { - if (vq == (u32)(ndev->config.max_virtqueue_pairs * 2)) + if (vq == (u32)(ndev->queue_pairs * 2)) pthread_create(&ndev->io_thread[vq], NULL, virtio_net_ctrl_thread, ndev); else if (vq & 1) pthread_create(&ndev->io_thread[vq], NULL, virtio_net_tx_thread, ndev); @@ -574,6 +576,8 @@ static int set_net_param(struct kvm *kvm, struct virtio_net_params *p, p->vhost = atoi(val); } else if (strcmp(param, "fd") == 0) { p->fd = atoi(val); + } else if (strcmp(param, "mq") == 0) { + p->mq = atoi(val); } else die("Unknown network parameter %s", param); @@ -643,8 +647,11 @@ static int virtio_net__init_one(struct virtio_net_params *params) ndev->kvm = params->kvm; mutex_init(&ndev->mutex); + ndev->queue_pairs = max(1, min(VIRTIO_NET_NUM_QUEUES, params->mq)); ndev->config.status = VIRTIO_NET_S_LINK_UP; - ndev->config.max_virtqueue_pairs = VIRTIO_NET_NUM_QUEUES; + if (ndev->queue_pairs > 1) + ndev->config.max_virtqueue_pairs = ndev->queue_pairs; + for (i = 0 ; i < 6 ; i++) { ndev->config.mac[i] = params->guest_mac[i]; ndev->info.guest_mac.addr[i] = params->guest_mac[i]; |