diff mbox

kvm tools: make virtio-net mq max queues configurable

Message ID 1365898844-1879-1-git-send-email-sasha.levin@oracle.com (mailing list archive)
State New, archived
Headers show

Commit Message

Sasha Levin April 14, 2013, 12:20 a.m. UTC
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.

Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
---
 tools/kvm/include/kvm/virtio-net.h |  1 +
 tools/kvm/virtio/net.c             | 19 +++++++++++++------
 2 files changed, 14 insertions(+), 6 deletions(-)

Comments

Will Deacon April 15, 2013, 9:19 a.m. UTC | #1
Hi Sasha,

On Sun, Apr 14, 2013 at 01:20:44AM +0100, Sasha Levin wrote:
> 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.

This works a treat, thanks for addressing it so quickly!

  Acked-by: Will Deacon <will.deacon@arm.com>
  Tested-by: Will Deacon <will.deacon@arm.com>

Will
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Pekka Enberg April 15, 2013, 10:21 a.m. UTC | #2
On 04/15/2013 12:19 PM, Will Deacon wrote:
> Hi Sasha,
>
> On Sun, Apr 14, 2013 at 01:20:44AM +0100, Sasha Levin wrote:
>> 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.
>
> This works a treat, thanks for addressing it so quickly!
>
>    Acked-by: Will Deacon <will.deacon@arm.com>
>    Tested-by: Will Deacon <will.deacon@arm.com>

Applied, thanks guys!

			Pekka

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

Patch

diff --git a/tools/kvm/include/kvm/virtio-net.h b/tools/kvm/include/kvm/virtio-net.h
index db43d98..0f4d1e5 100644
--- a/tools/kvm/include/kvm/virtio-net.h
+++ b/tools/kvm/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/tools/kvm/virtio/net.c b/tools/kvm/virtio/net.c
index 9911d77..c0a8f12 100644
--- a/tools/kvm/virtio/net.c
+++ b/tools/kvm/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];