Show a patch.

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

{
    "id": 42274,
    "url": "http://patches.dpdk.org/api/patches/42274/",
    "web_url": "http://patches.dpdk.org/patch/42274/",
    "project": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/projects/1/",
        "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"
    },
    "msgid": "<20180704215438.5579-8-maxime.coquelin@redhat.com>",
    "date": "2018-07-04T21:54:30",
    "name": "[v7,07/15] vhost: extract split ring handling from Rx and Tx functions",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "031a6de3c4f97122577c822bc232659e85f8fa01",
    "submitter": {
        "id": 512,
        "url": "http://patches.dpdk.org/api/people/512/",
        "name": "Maxime Coquelin",
        "email": "maxime.coquelin@redhat.com"
    },
    "delegate": {
        "id": 2642,
        "url": "http://patches.dpdk.org/api/users/2642/",
        "username": "mcoquelin",
        "first_name": "Maxime",
        "last_name": "Coquelin",
        "email": "maxime.coquelin@redhat.com"
    },
    "mbox": "http://patches.dpdk.org/patch/42274/mbox/",
    "series": [
        {
            "id": 404,
            "url": "http://patches.dpdk.org/api/series/404/",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=404",
            "date": "2018-07-04T21:54:23",
            "name": "Vhost: add support to packed ring layout",
            "version": 7,
            "mbox": "http://patches.dpdk.org/series/404/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/42274/comments/",
    "check": "fail",
    "checks": "http://patches.dpdk.org/api/patches/42274/checks/",
    "tags": {},
    "headers": {
        "X-Mailman-Version": "2.1.15",
        "In-Reply-To": "<20180704215438.5579-1-maxime.coquelin@redhat.com>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Received": [
            "from [92.243.14.124] (localhost [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id 931511BF0F;\n\tWed,  4 Jul 2018 23:55:01 +0200 (CEST)",
            "from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73])\n\tby dpdk.org (Postfix) with ESMTP id 03C0C1BF10\n\tfor <dev@dpdk.org>; Wed,  4 Jul 2018 23:55:00 +0200 (CEST)",
            "from smtp.corp.redhat.com\n\t(int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id 998174075184;\n\tWed,  4 Jul 2018 21:54:59 +0000 (UTC)",
            "from localhost.localdomain (ovpn-112-34.ams2.redhat.com\n\t[10.36.112.34])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id C6FC72156880;\n\tWed,  4 Jul 2018 21:54:57 +0000 (UTC)"
        ],
        "References": "<20180704215438.5579-1-maxime.coquelin@redhat.com>",
        "Delivered-To": "patchwork@dpdk.org",
        "X-BeenThere": "dev@dpdk.org",
        "X-Scanned-By": "MIMEDefang 2.78 on 10.11.54.6",
        "Message-Id": "<20180704215438.5579-8-maxime.coquelin@redhat.com>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "Precedence": "list",
        "From": "Maxime Coquelin <maxime.coquelin@redhat.com>",
        "X-Original-To": "patchwork@dpdk.org",
        "Return-Path": "<dev-bounces@dpdk.org>",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>",
        "X-Greylist": [
            "Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.11.55.7]); Wed, 04 Jul 2018 21:54:59 +0000 (UTC)",
            "inspected by milter-greylist-4.5.16 (mx1.redhat.com\n\t[10.11.55.7]); \n\tWed, 04 Jul 2018 21:54:59 +0000 (UTC) for IP:'10.11.54.6'\n\tDOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com'\n\tHELO:'smtp.corp.redhat.com' FROM:'maxime.coquelin@redhat.com' RCPT:''"
        ],
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "To": "tiwei.bie@intel.com, zhihong.wang@intel.com, jfreimann@redhat.com,\n\tdev@dpdk.org",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "Date": "Wed,  4 Jul 2018 23:54:30 +0200",
        "Cc": "mst@redhat.com, jasowang@redhat.com, wexu@redhat.com,\n\tMaxime Coquelin <maxime.coquelin@redhat.com>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "Subject": "[dpdk-dev] [PATCH v7 07/15] vhost: extract split ring handling from\n\tRx and Tx functions"
    },
    "content": "Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>\n---\n lib/librte_vhost/virtio_net.c | 238 +++++++++++++++++++++++-------------------\n 1 file changed, 129 insertions(+), 109 deletions(-)",
    "diff": "diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c\nindex b5f4f14df..7705c853b 100644\n--- a/lib/librte_vhost/virtio_net.c\n+++ b/lib/librte_vhost/virtio_net.c\n@@ -226,13 +226,13 @@ virtio_enqueue_offload(struct rte_mbuf *m_buf, struct virtio_net_hdr *net_hdr)\n }\n \n static __rte_always_inline int\n-fill_vec_buf(struct virtio_net *dev, struct vhost_virtqueue *vq,\n-\t\t\t uint32_t avail_idx, uint32_t *vec_idx,\n+fill_vec_buf_split(struct virtio_net *dev, struct vhost_virtqueue *vq,\n+\t\t\t uint32_t avail_idx, uint16_t *vec_idx,\n \t\t\t struct buf_vector *buf_vec, uint16_t *desc_chain_head,\n \t\t\t uint16_t *desc_chain_len, uint8_t perm)\n {\n \tuint16_t idx = vq->avail->ring[avail_idx & (vq->size - 1)];\n-\tuint32_t vec_id = *vec_idx;\n+\tuint16_t vec_id = *vec_idx;\n \tuint32_t len    = 0;\n \tuint64_t dlen, desc_avail, desc_iova;\n \tstruct vring_desc *descs = vq->desc;\n@@ -323,13 +323,13 @@ fill_vec_buf(struct virtio_net *dev, struct vhost_virtqueue *vq,\n  * Returns -1 on fail, 0 on success\n  */\n static inline int\n-reserve_avail_buf(struct virtio_net *dev, struct vhost_virtqueue *vq,\n+reserve_avail_buf_split(struct virtio_net *dev, struct vhost_virtqueue *vq,\n \t\t\t\tuint32_t size, struct buf_vector *buf_vec,\n \t\t\t\tuint16_t *num_buffers, uint16_t avail_head,\n \t\t\t\tuint16_t *nr_vec)\n {\n \tuint16_t cur_idx;\n-\tuint32_t vec_idx = 0;\n+\tuint16_t vec_idx = 0;\n \tuint16_t max_tries, tries = 0;\n \n \tuint16_t head_idx = 0;\n@@ -347,7 +347,8 @@ reserve_avail_buf(struct virtio_net *dev, struct vhost_virtqueue *vq,\n \t\tif (unlikely(cur_idx == avail_head))\n \t\t\treturn -1;\n \n-\t\tif (unlikely(fill_vec_buf(dev, vq, cur_idx, &vec_idx, buf_vec,\n+\t\tif (unlikely(fill_vec_buf_split(dev, vq, cur_idx,\n+\t\t\t\t\t\t&vec_idx, buf_vec,\n \t\t\t\t\t\t&head_idx, &len,\n \t\t\t\t\t\tVHOST_ACCESS_RW) < 0))\n \t\t\treturn -1;\n@@ -534,48 +535,22 @@ copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq,\n }\n \n static __rte_always_inline uint32_t\n-virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,\n+virtio_dev_rx_split(struct virtio_net *dev, struct vhost_virtqueue *vq,\n \tstruct rte_mbuf **pkts, uint32_t count)\n {\n-\tstruct vhost_virtqueue *vq;\n \tuint32_t pkt_idx = 0;\n \tuint16_t num_buffers;\n \tstruct buf_vector buf_vec[BUF_VECTOR_MAX];\n \tuint16_t avail_head;\n \n-\tVHOST_LOG_DEBUG(VHOST_DATA, \"(%d) %s\\n\", dev->vid, __func__);\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-\t}\n-\n-\tvq = dev->virtqueue[queue_id];\n-\n-\trte_spinlock_lock(&vq->access_lock);\n-\n-\tif (unlikely(vq->enabled == 0))\n-\t\tgoto out_access_unlock;\n-\n-\tif (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))\n-\t\tvhost_user_iotlb_rd_lock(vq);\n-\n-\tif (unlikely(vq->access_ok == 0))\n-\t\tif (unlikely(vring_translate(dev, vq) < 0))\n-\t\t\tgoto out;\n-\n-\tcount = RTE_MIN((uint32_t)MAX_PKT_BURST, count);\n-\tif (count == 0)\n-\t\tgoto out;\n-\n \trte_prefetch0(&vq->avail->ring[vq->last_avail_idx & (vq->size - 1)]);\n-\n \tavail_head = *((volatile uint16_t *)&vq->avail->idx);\n+\n \tfor (pkt_idx = 0; pkt_idx < count; pkt_idx++) {\n \t\tuint32_t pkt_len = pkts[pkt_idx]->pkt_len + dev->vhost_hlen;\n \t\tuint16_t nr_vec = 0;\n \n-\t\tif (unlikely(reserve_avail_buf(dev, vq,\n+\t\tif (unlikely(reserve_avail_buf_split(dev, vq,\n \t\t\t\t\t\tpkt_len, buf_vec, &num_buffers,\n \t\t\t\t\t\tavail_head, &nr_vec) < 0)) {\n \t\t\tVHOST_LOG_DEBUG(VHOST_DATA,\n@@ -608,6 +583,42 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,\n \t\tvhost_vring_call(dev, vq);\n \t}\n \n+\treturn pkt_idx;\n+}\n+\n+static __rte_always_inline uint32_t\n+virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,\n+\tstruct rte_mbuf **pkts, uint32_t count)\n+{\n+\tstruct vhost_virtqueue *vq;\n+\n+\tVHOST_LOG_DEBUG(VHOST_DATA, \"(%d) %s\\n\", dev->vid, __func__);\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+\t}\n+\n+\tvq = dev->virtqueue[queue_id];\n+\n+\trte_spinlock_lock(&vq->access_lock);\n+\n+\tif (unlikely(vq->enabled == 0))\n+\t\tgoto out_access_unlock;\n+\n+\tif (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))\n+\t\tvhost_user_iotlb_rd_lock(vq);\n+\n+\tif (unlikely(vq->access_ok == 0))\n+\t\tif (unlikely(vring_translate(dev, vq) < 0))\n+\t\t\tgoto out;\n+\n+\tcount = RTE_MIN((uint32_t)MAX_PKT_BURST, count);\n+\tif (count == 0)\n+\t\tgoto out;\n+\n+\tcount = virtio_dev_rx_split(dev, vq, pkts, count);\n+\n out:\n \tif (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))\n \t\tvhost_user_iotlb_rd_unlock(vq);\n@@ -615,7 +626,7 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,\n out_access_unlock:\n \trte_spinlock_unlock(&vq->access_lock);\n \n-\treturn pkt_idx;\n+\treturn count;\n }\n \n uint16_t\n@@ -1020,48 +1031,13 @@ restore_mbuf(struct rte_mbuf *m)\n \t}\n }\n \n-uint16_t\n-rte_vhost_dequeue_burst(int vid, uint16_t queue_id,\n+static __rte_always_inline uint16_t\n+virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq,\n \tstruct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count)\n {\n-\tstruct virtio_net *dev;\n-\tstruct rte_mbuf *rarp_mbuf = NULL;\n-\tstruct vhost_virtqueue *vq;\n-\tuint32_t i = 0;\n+\tuint16_t i;\n \tuint16_t free_entries;\n \n-\tdev = get_device(vid);\n-\tif (!dev)\n-\t\treturn 0;\n-\n-\tif (unlikely(!(dev->flags & VIRTIO_DEV_BUILTIN_VIRTIO_NET))) {\n-\t\tRTE_LOG(ERR, VHOST_DATA,\n-\t\t\t\"(%d) %s: built-in vhost net backend is disabled.\\n\",\n-\t\t\tdev->vid, __func__);\n-\t\treturn 0;\n-\t}\n-\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-\t}\n-\n-\tvq = dev->virtqueue[queue_id];\n-\n-\tif (unlikely(rte_spinlock_trylock(&vq->access_lock) == 0))\n-\t\treturn 0;\n-\n-\tif (unlikely(vq->enabled == 0))\n-\t\tgoto out_access_unlock;\n-\n-\tif (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))\n-\t\tvhost_user_iotlb_rd_lock(vq);\n-\n-\tif (unlikely(vq->access_ok == 0))\n-\t\tif (unlikely(vring_translate(dev, vq) < 0))\n-\t\t\tgoto out;\n-\n \tif (unlikely(dev->dequeue_zero_copy)) {\n \t\tstruct zcopy_mbuf *zmbuf, *next;\n \t\tint nr_updated = 0;\n@@ -1088,39 +1064,10 @@ rte_vhost_dequeue_burst(int vid, uint16_t queue_id,\n \n \trte_prefetch0(&vq->avail->ring[vq->last_avail_idx & (vq->size - 1)]);\n \n-\t/*\n-\t * Construct a RARP broadcast packet, and inject it to the \"pkts\"\n-\t * array, to looks like that guest actually send such packet.\n-\t *\n-\t * Check user_send_rarp() for more information.\n-\t *\n-\t * broadcast_rarp shares a cacheline in the virtio_net structure\n-\t * with some fields that are accessed during enqueue and\n-\t * rte_atomic16_cmpset() causes a write if using cmpxchg. This could\n-\t * result in false sharing between enqueue and dequeue.\n-\t *\n-\t * Prevent unnecessary false sharing by reading broadcast_rarp first\n-\t * and only performing cmpset if the read indicates it is likely to\n-\t * be set.\n-\t */\n-\n-\tif (unlikely(rte_atomic16_read(&dev->broadcast_rarp) &&\n-\t\t\trte_atomic16_cmpset((volatile uint16_t *)\n-\t\t\t\t&dev->broadcast_rarp.cnt, 1, 0))) {\n-\n-\t\trarp_mbuf = rte_net_make_rarp_packet(mbuf_pool, &dev->mac);\n-\t\tif (rarp_mbuf == NULL) {\n-\t\t\tRTE_LOG(ERR, VHOST_DATA,\n-\t\t\t\t\"Failed to make RARP packet.\\n\");\n-\t\t\treturn 0;\n-\t\t}\n-\t\tcount -= 1;\n-\t}\n-\n \tfree_entries = *((volatile uint16_t *)&vq->avail->idx) -\n \t\tvq->last_avail_idx;\n \tif (free_entries == 0)\n-\t\tgoto out;\n+\t\treturn 0;\n \n \tVHOST_LOG_DEBUG(VHOST_DATA, \"(%d) %s\\n\", dev->vid, __func__);\n \n@@ -1132,10 +1079,10 @@ rte_vhost_dequeue_burst(int vid, uint16_t queue_id,\n \tfor (i = 0; i < count; i++) {\n \t\tstruct buf_vector buf_vec[BUF_VECTOR_MAX];\n \t\tuint16_t head_idx, dummy_len;\n-\t\tuint32_t nr_vec = 0;\n+\t\tuint16_t nr_vec = 0;\n \t\tint err;\n \n-\t\tif (unlikely(fill_vec_buf(dev, vq,\n+\t\tif (unlikely(fill_vec_buf_split(dev, vq,\n \t\t\t\t\t\tvq->last_avail_idx + i,\n \t\t\t\t\t\t&nr_vec, buf_vec,\n \t\t\t\t\t\t&head_idx, &dummy_len,\n@@ -1194,6 +1141,79 @@ rte_vhost_dequeue_burst(int vid, uint16_t queue_id,\n \t\tvhost_vring_call(dev, vq);\n \t}\n \n+\treturn i;\n+}\n+\n+uint16_t\n+rte_vhost_dequeue_burst(int vid, uint16_t queue_id,\n+\tstruct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count)\n+{\n+\tstruct virtio_net *dev;\n+\tstruct rte_mbuf *rarp_mbuf = NULL;\n+\tstruct vhost_virtqueue *vq;\n+\n+\tdev = get_device(vid);\n+\tif (!dev)\n+\t\treturn 0;\n+\n+\tif (unlikely(!(dev->flags & VIRTIO_DEV_BUILTIN_VIRTIO_NET))) {\n+\t\tRTE_LOG(ERR, VHOST_DATA,\n+\t\t\t\"(%d) %s: built-in vhost net backend is disabled.\\n\",\n+\t\t\tdev->vid, __func__);\n+\t\treturn 0;\n+\t}\n+\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+\t}\n+\n+\tvq = dev->virtqueue[queue_id];\n+\n+\tif (unlikely(rte_spinlock_trylock(&vq->access_lock) == 0))\n+\t\treturn 0;\n+\n+\tif (unlikely(vq->enabled == 0))\n+\t\tgoto out_access_unlock;\n+\n+\tif (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))\n+\t\tvhost_user_iotlb_rd_lock(vq);\n+\n+\tif (unlikely(vq->access_ok == 0))\n+\t\tif (unlikely(vring_translate(dev, vq) < 0))\n+\t\t\tgoto out;\n+\n+\t/*\n+\t * Construct a RARP broadcast packet, and inject it to the \"pkts\"\n+\t * array, to looks like that guest actually send such packet.\n+\t *\n+\t * Check user_send_rarp() for more information.\n+\t *\n+\t * broadcast_rarp shares a cacheline in the virtio_net structure\n+\t * with some fields that are accessed during enqueue and\n+\t * rte_atomic16_cmpset() causes a write if using cmpxchg. This could\n+\t * result in false sharing between enqueue and dequeue.\n+\t *\n+\t * Prevent unnecessary false sharing by reading broadcast_rarp first\n+\t * and only performing cmpset if the read indicates it is likely to\n+\t * be set.\n+\t */\n+\tif (unlikely(rte_atomic16_read(&dev->broadcast_rarp) &&\n+\t\t\trte_atomic16_cmpset((volatile uint16_t *)\n+\t\t\t\t&dev->broadcast_rarp.cnt, 1, 0))) {\n+\n+\t\trarp_mbuf = rte_net_make_rarp_packet(mbuf_pool, &dev->mac);\n+\t\tif (rarp_mbuf == NULL) {\n+\t\t\tRTE_LOG(ERR, VHOST_DATA,\n+\t\t\t\t\"Failed to make RARP packet.\\n\");\n+\t\t\treturn 0;\n+\t\t}\n+\t\tcount -= 1;\n+\t}\n+\n+\tcount = virtio_dev_tx_split(dev, vq, mbuf_pool, pkts, count);\n+\n out:\n \tif (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))\n \t\tvhost_user_iotlb_rd_unlock(vq);\n@@ -1206,10 +1226,10 @@ rte_vhost_dequeue_burst(int vid, uint16_t queue_id,\n \t\t * Inject it to the head of \"pkts\" array, so that switch's mac\n \t\t * learning table will get updated first.\n \t\t */\n-\t\tmemmove(&pkts[1], pkts, i * sizeof(struct rte_mbuf *));\n+\t\tmemmove(&pkts[1], pkts, count * sizeof(struct rte_mbuf *));\n \t\tpkts[0] = rarp_mbuf;\n-\t\ti += 1;\n+\t\tcount += 1;\n \t}\n \n-\treturn i;\n+\treturn count;\n }\n",
    "prefixes": [
        "v7",
        "07/15"
    ]
}