get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/23108/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 23108,
    "url": "https://patches.dpdk.org/api/patches/23108/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/1491031380-1499-10-git-send-email-yuanhan.liu@linux.intel.com/",
    "project": {
        "id": 1,
        "url": "https://patches.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<1491031380-1499-10-git-send-email-yuanhan.liu@linux.intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1491031380-1499-10-git-send-email-yuanhan.liu@linux.intel.com",
    "date": "2017-04-01T07:22:47",
    "name": "[dpdk-dev,v4,09/22] vhost: turn queue pair to vring",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": true,
    "hash": "35595be43581bdf3d01c2e94e5d6cfc3ab0c7e6a",
    "submitter": {
        "id": 307,
        "url": "https://patches.dpdk.org/api/people/307/?format=api",
        "name": "Yuanhan Liu",
        "email": "yuanhan.liu@linux.intel.com"
    },
    "delegate": {
        "id": 355,
        "url": "https://patches.dpdk.org/api/users/355/?format=api",
        "username": "yliu",
        "first_name": "Yuanhan",
        "last_name": "Liu",
        "email": "yuanhan.liu@linux.intel.com"
    },
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/1491031380-1499-10-git-send-email-yuanhan.liu@linux.intel.com/mbox/",
    "series": [],
    "comments": "https://patches.dpdk.org/api/patches/23108/comments/",
    "check": "fail",
    "checks": "https://patches.dpdk.org/api/patches/23108/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@dpdk.org",
        "Delivered-To": "patchwork@dpdk.org",
        "Received": [
            "from [92.243.14.124] (localhost [IPv6:::1])\n\tby dpdk.org (Postfix) with ESMTP id 877B25598;\n\tSat,  1 Apr 2017 09:26:14 +0200 (CEST)",
            "from mga09.intel.com (mga09.intel.com [134.134.136.24])\n\tby dpdk.org (Postfix) with ESMTP id C0E762C2E\n\tfor <dev@dpdk.org>; Sat,  1 Apr 2017 09:25:53 +0200 (CEST)",
            "from orsmga002.jf.intel.com ([10.7.209.21])\n\tby orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t01 Apr 2017 00:25:50 -0700",
            "from yliu-dev.sh.intel.com ([10.239.67.162])\n\tby orsmga002.jf.intel.com with ESMTP; 01 Apr 2017 00:25:34 -0700"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=simple/simple;\n\td=intel.com; i=@intel.com; q=dns/txt; s=intel;\n\tt=1491031553; x=1522567553;\n\th=from:to:cc:subject:date:message-id:in-reply-to: references;\n\tbh=/H+Xua5Prvtzq9wMW61+Pk2g5PqbveajwRNWjk/u10g=;\n\tb=MpOUlIvRB74lyusvZZ7cPfvPpaqQk9y+OGMYIr3NFQxvZH5SySlVK003\n\t9mxrTHBptkwK6sQ960OAivqGMBzQCQ==;",
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.36,256,1486454400\"; d=\"scan'208\";a=\"67700680\"",
        "From": "Yuanhan Liu <yuanhan.liu@linux.intel.com>",
        "To": "dev@dpdk.org",
        "Cc": "Maxime Coquelin <maxime.coquelin@redhat.com>,\n\tHarris James R <james.r.harris@intel.com>,\n\tLiu Changpeng <changpeng.liu@intel.com>,\n\tYuanhan Liu <yuanhan.liu@linux.intel.com>",
        "Date": "Sat,  1 Apr 2017 15:22:47 +0800",
        "Message-Id": "<1491031380-1499-10-git-send-email-yuanhan.liu@linux.intel.com>",
        "X-Mailer": "git-send-email 1.9.0",
        "In-Reply-To": "<1491031380-1499-1-git-send-email-yuanhan.liu@linux.intel.com>",
        "References": "<1490705142-893-1-git-send-email-yuanhan.liu@linux.intel.com>\n\t<1491031380-1499-1-git-send-email-yuanhan.liu@linux.intel.com>",
        "Subject": "[dpdk-dev] [PATCH v4 09/22] vhost: turn queue pair to vring",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<http://dpdk.org/ml/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://dpdk.org/ml/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<http://dpdk.org/ml/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "The queue pair is very virtio-net specific, other devices don't have\nsuch concept. To make it generic, we should log the number of vrings\ninstead of the number of queue pairs.\n\nThis patch just does a simple convert, a later patch would export the\nnumber of vrings to applications.\n\nSigned-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>\nReviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>\n---\n\nv2: enable all vrings by unconditionally\n---\n lib/librte_vhost/vhost.c      | 80 +++++++++++++++----------------------------\n lib/librte_vhost/vhost.h      |  4 +--\n lib/librte_vhost/vhost_user.c | 28 +++++----------\n lib/librte_vhost/virtio_net.c | 10 +++---\n 4 files changed, 42 insertions(+), 80 deletions(-)",
    "diff": "diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c\nindex 4b9d781..f0ed729 100644\n--- a/lib/librte_vhost/vhost.c\n+++ b/lib/librte_vhost/vhost.c\n@@ -84,10 +84,8 @@ struct virtio_net *\n \n \tvhost_backend_cleanup(dev);\n \n-\tfor (i = 0; i < dev->virt_qp_nb; i++) {\n-\t\tcleanup_vq(dev->virtqueue[i * VIRTIO_QNUM + VIRTIO_RXQ], destroy);\n-\t\tcleanup_vq(dev->virtqueue[i * VIRTIO_QNUM + VIRTIO_TXQ], destroy);\n-\t}\n+\tfor (i = 0; i < dev->nr_vring; i++)\n+\t\tcleanup_vq(dev->virtqueue[i], destroy);\n }\n \n /*\n@@ -97,24 +95,21 @@ struct virtio_net *\n free_device(struct virtio_net *dev)\n {\n \tuint32_t i;\n-\tstruct vhost_virtqueue *rxq, *txq;\n+\tstruct vhost_virtqueue *vq;\n \n-\tfor (i = 0; i < dev->virt_qp_nb; i++) {\n-\t\trxq = dev->virtqueue[i * VIRTIO_QNUM + VIRTIO_RXQ];\n-\t\ttxq = dev->virtqueue[i * VIRTIO_QNUM + VIRTIO_TXQ];\n+\tfor (i = 0; i < dev->nr_vring; i++) {\n+\t\tvq = dev->virtqueue[i];\n \n-\t\trte_free(rxq->shadow_used_ring);\n-\t\trte_free(txq->shadow_used_ring);\n+\t\trte_free(vq->shadow_used_ring);\n \n-\t\t/* rxq and txq are allocated together as queue-pair */\n-\t\trte_free(rxq);\n+\t\trte_free(vq);\n \t}\n \n \trte_free(dev);\n }\n \n static void\n-init_vring_queue(struct vhost_virtqueue *vq, int qp_idx)\n+init_vring_queue(struct vhost_virtqueue *vq)\n {\n \tmemset(vq, 0, sizeof(struct vhost_virtqueue));\n \n@@ -124,69 +119,48 @@ struct virtio_net *\n \t/* Backends are set to -1 indicating an inactive device. */\n \tvq->backend = -1;\n \n-\t/* always set the default vq pair to enabled */\n-\tif (qp_idx == 0)\n-\t\tvq->enabled = 1;\n+\t/*\n+\t * always set the vq to enabled; this is to keep compatibility\n+\t * with the old QEMU, whereas there is no SET_VRING_ENABLE message.\n+\t */\n+\tvq->enabled = 1;\n \n \tTAILQ_INIT(&vq->zmbuf_list);\n }\n \n static void\n-init_vring_queue_pair(struct virtio_net *dev, uint32_t qp_idx)\n-{\n-\tuint32_t base_idx = qp_idx * VIRTIO_QNUM;\n-\n-\tinit_vring_queue(dev->virtqueue[base_idx + VIRTIO_RXQ], qp_idx);\n-\tinit_vring_queue(dev->virtqueue[base_idx + VIRTIO_TXQ], qp_idx);\n-}\n-\n-static void\n-reset_vring_queue(struct vhost_virtqueue *vq, int qp_idx)\n+reset_vring_queue(struct vhost_virtqueue *vq)\n {\n \tint callfd;\n \n \tcallfd = vq->callfd;\n-\tinit_vring_queue(vq, qp_idx);\n+\tinit_vring_queue(vq);\n \tvq->callfd = callfd;\n }\n \n-static void\n-reset_vring_queue_pair(struct virtio_net *dev, uint32_t qp_idx)\n-{\n-\tuint32_t base_idx = qp_idx * VIRTIO_QNUM;\n-\n-\treset_vring_queue(dev->virtqueue[base_idx + VIRTIO_RXQ], qp_idx);\n-\treset_vring_queue(dev->virtqueue[base_idx + VIRTIO_TXQ], qp_idx);\n-}\n-\n int\n-alloc_vring_queue_pair(struct virtio_net *dev, uint32_t qp_idx)\n+alloc_vring_queue(struct virtio_net *dev, uint32_t vring_idx)\n {\n-\tstruct vhost_virtqueue *virtqueue = NULL;\n-\tuint32_t virt_rx_q_idx = qp_idx * VIRTIO_QNUM + VIRTIO_RXQ;\n-\tuint32_t virt_tx_q_idx = qp_idx * VIRTIO_QNUM + VIRTIO_TXQ;\n+\tstruct vhost_virtqueue *vq;\n \n-\tvirtqueue = rte_malloc(NULL,\n-\t\t\t       sizeof(struct vhost_virtqueue) * VIRTIO_QNUM, 0);\n-\tif (virtqueue == NULL) {\n+\tvq = rte_malloc(NULL, sizeof(struct vhost_virtqueue), 0);\n+\tif (vq == NULL) {\n \t\tRTE_LOG(ERR, VHOST_CONFIG,\n-\t\t\t\"Failed to allocate memory for virt qp:%d.\\n\", qp_idx);\n+\t\t\t\"Failed to allocate memory for vring:%u.\\n\", vring_idx);\n \t\treturn -1;\n \t}\n \n-\tdev->virtqueue[virt_rx_q_idx] = virtqueue;\n-\tdev->virtqueue[virt_tx_q_idx] = virtqueue + VIRTIO_TXQ;\n-\n-\tinit_vring_queue_pair(dev, qp_idx);\n+\tdev->virtqueue[vring_idx] = vq;\n+\tinit_vring_queue(vq);\n \n-\tdev->virt_qp_nb += 1;\n+\tdev->nr_vring += 1;\n \n \treturn 0;\n }\n \n /*\n  * Reset some variables in device structure, while keeping few\n- * others untouched, such as vid, ifname, virt_qp_nb: they\n+ * others untouched, such as vid, ifname, nr_vring: they\n  * should be same unless the device is removed.\n  */\n void\n@@ -198,8 +172,8 @@ struct virtio_net *\n \tdev->protocol_features = 0;\n \tdev->flags = 0;\n \n-\tfor (i = 0; i < dev->virt_qp_nb; i++)\n-\t\treset_vring_queue_pair(dev, i);\n+\tfor (i = 0; i < dev->nr_vring; i++)\n+\t\treset_vring_queue(dev->virtqueue[i]);\n }\n \n /*\n@@ -340,7 +314,7 @@ struct virtio_net *\n \tif (dev == NULL)\n \t\treturn 0;\n \n-\treturn dev->virt_qp_nb;\n+\treturn dev->nr_vring / 2;\n }\n \n int\ndiff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h\nindex b5c5046..84e379a 100644\n--- a/lib/librte_vhost/vhost.h\n+++ b/lib/librte_vhost/vhost.h\n@@ -176,7 +176,7 @@ struct virtio_net {\n \tuint16_t\t\tvhost_hlen;\n \t/* to tell if we need broadcast rarp packet */\n \trte_atomic16_t\t\tbroadcast_rarp;\n-\tuint32_t\t\tvirt_qp_nb;\n+\tuint32_t\t\tnr_vring;\n \tint\t\t\tdequeue_zero_copy;\n \tstruct vhost_virtqueue\t*virtqueue[VHOST_MAX_QUEUE_PAIRS * 2];\n #define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)\n@@ -256,7 +256,7 @@ static inline phys_addr_t __attribute__((always_inline))\n void reset_device(struct virtio_net *dev);\n void vhost_destroy_device(int);\n \n-int alloc_vring_queue_pair(struct virtio_net *dev, uint32_t qp_idx);\n+int alloc_vring_queue(struct virtio_net *dev, uint32_t vring_idx);\n \n void vhost_set_ifname(int, const char *if_name, unsigned int if_len);\n void vhost_enable_dequeue_zero_copy(int vid);\ndiff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c\nindex 30cf8f8..4337ce7 100644\n--- a/lib/librte_vhost/vhost_user.c\n+++ b/lib/librte_vhost/vhost_user.c\n@@ -233,13 +233,6 @@\n \tstruct vhost_virtqueue *old_vq, *vq;\n \tint ret;\n \n-\t/*\n-\t * vq is allocated on pairs, we should try to do realloc\n-\t * on first queue of one queue pair only.\n-\t */\n-\tif (index % VIRTIO_QNUM != 0)\n-\t\treturn dev;\n-\n \told_dev = dev;\n \tvq = old_vq = dev->virtqueue[index];\n \n@@ -257,8 +250,7 @@\n \tif (oldnode != newnode) {\n \t\tRTE_LOG(INFO, VHOST_CONFIG,\n \t\t\t\"reallocate vq from %d to %d node\\n\", oldnode, newnode);\n-\t\tvq = rte_malloc_socket(NULL, sizeof(*vq) * VIRTIO_QNUM, 0,\n-\t\t\t\t       newnode);\n+\t\tvq = rte_malloc_socket(NULL, sizeof(*vq), 0, newnode);\n \t\tif (!vq)\n \t\t\treturn dev;\n \n@@ -290,7 +282,6 @@\n \n out:\n \tdev->virtqueue[index] = vq;\n-\tdev->virtqueue[index + 1] = vq + 1;\n \tvhost_devices[dev->vid] = dev;\n \n \treturn dev;\n@@ -621,14 +612,13 @@\n static int\n virtio_is_ready(struct virtio_net *dev)\n {\n-\tstruct vhost_virtqueue *rvq, *tvq;\n+\tstruct vhost_virtqueue *vq;\n \tuint32_t i;\n \n-\tfor (i = 0; i < dev->virt_qp_nb; i++) {\n-\t\trvq = dev->virtqueue[i * VIRTIO_QNUM + VIRTIO_RXQ];\n-\t\ttvq = dev->virtqueue[i * VIRTIO_QNUM + VIRTIO_TXQ];\n+\tfor (i = 0; i < dev->nr_vring; i++) {\n+\t\tvq = dev->virtqueue[i];\n \n-\t\tif (!vq_is_ready(rvq) || !vq_is_ready(tvq)) {\n+\t\tif (!vq_is_ready(vq)) {\n \t\t\tRTE_LOG(INFO, VHOST_CONFIG,\n \t\t\t\t\"virtio is not ready for processing.\\n\");\n \t\t\treturn 0;\n@@ -940,7 +930,6 @@\n vhost_user_check_and_alloc_queue_pair(struct virtio_net *dev, VhostUserMsg *msg)\n {\n \tuint16_t vring_idx;\n-\tuint16_t qp_idx;\n \n \tswitch (msg->request) {\n \tcase VHOST_USER_SET_VRING_KICK:\n@@ -960,17 +949,16 @@\n \t\treturn 0;\n \t}\n \n-\tqp_idx = vring_idx / VIRTIO_QNUM;\n-\tif (qp_idx >= VHOST_MAX_QUEUE_PAIRS) {\n+\tif (vring_idx >= VHOST_MAX_VRING) {\n \t\tRTE_LOG(ERR, VHOST_CONFIG,\n \t\t\t\"invalid vring index: %u\\n\", vring_idx);\n \t\treturn -1;\n \t}\n \n-\tif (dev->virtqueue[qp_idx])\n+\tif (dev->virtqueue[vring_idx])\n \t\treturn 0;\n \n-\treturn alloc_vring_queue_pair(dev, qp_idx);\n+\treturn alloc_vring_queue(dev, vring_idx);\n }\n \n int\ndiff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c\nindex c1187d4..28542cf 100644\n--- a/lib/librte_vhost/virtio_net.c\n+++ b/lib/librte_vhost/virtio_net.c\n@@ -86,9 +86,9 @@ static inline void __attribute__((always_inline))\n }\n \n static bool\n-is_valid_virt_queue_idx(uint32_t idx, int is_tx, uint32_t qp_nb)\n+is_valid_virt_queue_idx(uint32_t idx, int is_tx, uint32_t nr_vring)\n {\n-\treturn (is_tx ^ (idx & 1)) == 0 && idx < qp_nb * VIRTIO_QNUM;\n+\treturn (is_tx ^ (idx & 1)) == 0 && idx < nr_vring;\n }\n \n static inline void __attribute__((always_inline))\n@@ -283,7 +283,7 @@ static inline uint32_t __attribute__((always_inline))\n \tuint32_t i, sz;\n \n \tLOG_DEBUG(VHOST_DATA, \"(%d) %s\\n\", dev->vid, __func__);\n-\tif (unlikely(!is_valid_virt_queue_idx(queue_id, 0, dev->virt_qp_nb))) {\n+\tif (unlikely(!is_valid_virt_queue_idx(queue_id, 0, dev->nr_vring))) {\n \t\tRTE_LOG(ERR, VHOST_DATA, \"(%d) %s: invalid virtqueue idx %d.\\n\",\n \t\t\tdev->vid, __func__, queue_id);\n \t\treturn 0;\n@@ -554,7 +554,7 @@ static inline uint32_t __attribute__((always_inline))\n \tuint16_t avail_head;\n \n \tLOG_DEBUG(VHOST_DATA, \"(%d) %s\\n\", dev->vid, __func__);\n-\tif (unlikely(!is_valid_virt_queue_idx(queue_id, 0, dev->virt_qp_nb))) {\n+\tif (unlikely(!is_valid_virt_queue_idx(queue_id, 0, dev->nr_vring))) {\n \t\tRTE_LOG(ERR, VHOST_DATA, \"(%d) %s: invalid virtqueue idx %d.\\n\",\n \t\t\tdev->vid, __func__, queue_id);\n \t\treturn 0;\n@@ -1019,7 +1019,7 @@ static inline bool __attribute__((always_inline))\n \tif (!dev)\n \t\treturn 0;\n \n-\tif (unlikely(!is_valid_virt_queue_idx(queue_id, 1, dev->virt_qp_nb))) {\n+\tif (unlikely(!is_valid_virt_queue_idx(queue_id, 1, dev->nr_vring))) {\n \t\tRTE_LOG(ERR, VHOST_DATA, \"(%d) %s: invalid virtqueue idx %d.\\n\",\n \t\t\tdev->vid, __func__, queue_id);\n \t\treturn 0;\n",
    "prefixes": [
        "dpdk-dev",
        "v4",
        "09/22"
    ]
}