From patchwork Wed Jan 31 14:42:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Dewar X-Patchwork-Id: 34777 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 874E01B7C4; Wed, 31 Jan 2018 15:42:35 +0100 (CET) Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by dpdk.org (Postfix) with ESMTP id 7E8B81B789 for ; Wed, 31 Jan 2018 15:42:34 +0100 (CET) Received: by mail-wm0-f66.google.com with SMTP id v123so8465835wmd.5 for ; Wed, 31 Jan 2018 06:42:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=7ZDAVJqzKIE/FcgHWxMMM5tLvDzN9amPsK+Woz2hUjg=; b=OrcNtUQa3LJ5G8Snaxd7+47AHUG5qfgsRLUEY63uBJ3o94vwMKVAnxuwejFyP3hWss yjZWkR9NAcT1bfowdiEgU4i4cgg3axu0mhmzjOQcVAZyE34QtIVACmuJ8I1h9J/Lid5m YcCDenUlA7XC14xI94QoIuoCULMOExImCIZxfZgNw/4rmLLctDeINojYq8cbKgLsipam LwskPxNV5OncjzNJoLbawbGG9RdLYY4FEym4S6sieczOUWVZDaRxaHXR9dclvKLbCf4A 92A7fZ7U7uOZrflH+MXjetptFsb645hB80bh6xWJNBNJOqewxrk1ZZ2AqdkMyppg2Zto 21ZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=7ZDAVJqzKIE/FcgHWxMMM5tLvDzN9amPsK+Woz2hUjg=; b=KLphhHSQqDqF9/V3fBp3ZrHv9KmvuY/Y5vdl1KHYWwUFGihYp88S9Nk6yIqAHpVK7U gF+1MqsBLKBEuLn9ZLQ+AnmLeyXABJSAWiY6j5tpv9fniTCo6mV8PlXiw8kWEo7Gfk+n K9q+gzzTq/wTNaaY1gDfveKbBx6Q4VI/k9FhJUwN1sbRH0qdrHZlLgizpDUkizgd/TVD 56Vy6crKCV5nR1pDO8TFJETCfWTTR9L4yV1kcBzDdtCwRZA6ZjcXgMO2S2rSfxl+OeXq 7OCZfisfPi5Nw2MDhJKvnn1iZclsSoYmHe5enJrabQdkdCaxProdHZt24Zi1POkZu6la yB7Q== X-Gm-Message-State: AKwxytd2QURHcm0AXpJKLLp5zogdm1JnVmSmGiaqq4SQI6jm9QZtovNN FuCaaycmZac6KPuD1yBiHMF3 X-Google-Smtp-Source: AH8x224wxtM8OYhmDjLVCGiPYlrWJc/1oFzVwFYPv84VA4YKhXYcNqFoKQwJLLfIKsCQNmHJCLAwXw== X-Received: by 10.28.20.8 with SMTP id 8mr23107740wmu.106.1517409754007; Wed, 31 Jan 2018 06:42:34 -0800 (PST) Received: from adewar-Precision-7520.edi.vyatta.net ([213.251.34.146]) by smtp.gmail.com with ESMTPSA id c19sm11588898wmd.5.2018.01.31.06.42.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 31 Jan 2018 06:42:33 -0800 (PST) From: alangordondewar@gmail.com X-Google-Original-From: alan.dewar@att.com To: dev@dpdk.org Cc: Alan Dewar Date: Wed, 31 Jan 2018 14:42:23 +0000 Message-Id: <1517409743-24332-1-git-send-email-alan.dewar@att.com> X-Mailer: git-send-email 2.7.4 Subject: [dpdk-dev] [PATCH] vhost: support non multiqueue guests X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Alan Dewar Performance of vhost interfaces can be improved by having multiple TX/RX queue-pairs. QEMU can be told to use multiple queue-pairs for a vhost interface when starting the guest VM. The DPDK will also configure multiple queue-pairs in response to requests from QEMU. Later when the guest VM reaches the running state, it can decide to not support the multiqueue option. This information is passed down from the guest VM to QEMU, and from QEMU to the DPDK, but the DPDK ignores it. Because the guest VM doesn't support the multiqueue option it will only initialise the first queue-pair, and in turn the DPDK will not signal that the vhost interface is up. This change allows the DPDK to signal that the vhost interface is up after only the first queue-pair is fully initialised if the guest VM does not support the multiqueue option. Signed-off-by: Alan Dewar --- lib/librte_vhost/vhost.c | 6 +++--- lib/librte_vhost/vhost_user.c | 8 +++++++- lib/librte_vhost/virtio_net.c | 12 +++++++++--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c index 1dd9adb..c952756 100644 --- a/lib/librte_vhost/vhost.c +++ b/lib/librte_vhost/vhost.c @@ -397,7 +397,7 @@ rte_vhost_get_queue_num(int vid) if (dev == NULL) return 0; - return dev->nr_vring / 2; + return (dev->features & VIRTIO_NET_F_MQ) ? (dev->nr_vring / 2) : 1; } uint16_t @@ -408,7 +408,7 @@ rte_vhost_get_vring_num(int vid) if (dev == NULL) return 0; - return dev->nr_vring; + return (dev->features & VIRTIO_NET_F_MQ) ? dev->nr_vring : 2; } int @@ -590,7 +590,7 @@ rte_vhost_rx_queue_count(int vid, uint16_t qid) if (dev == NULL) return 0; - if (unlikely(qid >= dev->nr_vring || (qid & 1) == 0)) { + if (unlikely(qid >= rte_vhost_get_vring_num(vid) || (qid & 1) == 0)) { RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n", dev->vid, __func__, qid); return 0; diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 1dd1a61..d709cb6 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -773,11 +773,17 @@ virtio_is_ready(struct virtio_net *dev) { struct vhost_virtqueue *vq; uint32_t i; + uint32_t vrings_init; if (dev->nr_vring == 0) return 0; - for (i = 0; i < dev->nr_vring; i++) { + /* + * If the guest VM doesn't support the multiqueue feature, only the + * first two vrings will be fully initialised. + */ + vrings_init = (dev->features & VIRTIO_NET_F_MQ) ? dev->nr_vring : 2; + for (i = 0; i < vrings_init; i++) { vq = dev->virtqueue[i]; if (!vq_is_ready(vq)) diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c index edfab3b..ca48499 100644 --- a/lib/librte_vhost/virtio_net.c +++ b/lib/librte_vhost/virtio_net.c @@ -294,9 +294,11 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id, struct vring_desc *descs; uint16_t used_idx; uint32_t i, sz; + uint16_t nr_vring; LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->vid, __func__); - if (unlikely(!is_valid_virt_queue_idx(queue_id, 0, dev->nr_vring))) { + nr_vring = rte_vhost_get_vring_num(dev->vid); + if (unlikely(!is_valid_virt_queue_idx(queue_id, 0, nr_vring))) { RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n", dev->vid, __func__, queue_id); return 0; @@ -619,9 +621,11 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id, uint16_t num_buffers; struct buf_vector buf_vec[BUF_VECTOR_MAX]; uint16_t avail_head; + uint16_t nr_vring; LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->vid, __func__); - if (unlikely(!is_valid_virt_queue_idx(queue_id, 0, dev->nr_vring))) { + nr_vring = rte_vhost_get_vring_num(dev->vid); + if (unlikely(!is_valid_virt_queue_idx(queue_id, 0, nr_vring))) { RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n", dev->vid, __func__, queue_id); return 0; @@ -1123,12 +1127,14 @@ rte_vhost_dequeue_burst(int vid, uint16_t queue_id, uint32_t i = 0; uint16_t free_entries; uint16_t avail_idx; + uint16_t nr_vring; dev = get_device(vid); if (!dev) return 0; - if (unlikely(!is_valid_virt_queue_idx(queue_id, 1, dev->nr_vring))) { + nr_vring = rte_vhost_get_vring_num(dev->vid); + if (unlikely(!is_valid_virt_queue_idx(queue_id, 1, nr_vring))) { RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n", dev->vid, __func__, queue_id); return 0;