get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 42073,
    "url": "http://patches.dpdk.org/api/patches/42073/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/20180702081629.29258-8-maxime.coquelin@redhat.com/",
    "project": {
        "id": 1,
        "url": "http://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": "<20180702081629.29258-8-maxime.coquelin@redhat.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20180702081629.29258-8-maxime.coquelin@redhat.com",
    "date": "2018-07-02T08:16:21",
    "name": "[v6,07/15] vhost: extract split ring handling from Rx and Tx functions",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "cabba707d34ec608b97244c2a053a072873902e0",
    "submitter": {
        "id": 512,
        "url": "http://patches.dpdk.org/api/people/512/?format=api",
        "name": "Maxime Coquelin",
        "email": "maxime.coquelin@redhat.com"
    },
    "delegate": {
        "id": 2642,
        "url": "http://patches.dpdk.org/api/users/2642/?format=api",
        "username": "mcoquelin",
        "first_name": "Maxime",
        "last_name": "Coquelin",
        "email": "maxime.coquelin@redhat.com"
    },
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/20180702081629.29258-8-maxime.coquelin@redhat.com/mbox/",
    "series": [
        {
            "id": 348,
            "url": "http://patches.dpdk.org/api/series/348/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=348",
            "date": "2018-07-02T08:16:14",
            "name": "Vhost: add support to packed ring layout",
            "version": 6,
            "mbox": "http://patches.dpdk.org/series/348/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/42073/comments/",
    "check": "fail",
    "checks": "http://patches.dpdk.org/api/patches/42073/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 [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id 48EAA5F33;\n\tMon,  2 Jul 2018 10:17:09 +0200 (CEST)",
            "from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73])\n\tby dpdk.org (Postfix) with ESMTP id AC0C15F30\n\tfor <dev@dpdk.org>; Mon,  2 Jul 2018 10:17:07 +0200 (CEST)",
            "from smtp.corp.redhat.com\n\t(int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5])\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 46C404023336;\n\tMon,  2 Jul 2018 08:17:07 +0000 (UTC)",
            "from localhost.localdomain (ovpn-112-41.ams2.redhat.com\n\t[10.36.112.41])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id B6D871C589;\n\tMon,  2 Jul 2018 08:17:05 +0000 (UTC)"
        ],
        "From": "Maxime Coquelin <maxime.coquelin@redhat.com>",
        "To": "tiwei.bie@intel.com, zhihong.wang@intel.com, jfreimann@redhat.com,\n\tdev@dpdk.org",
        "Cc": "mst@redhat.com, jasowang@redhat.com, wexu@redhat.com,\n\tMaxime Coquelin <maxime.coquelin@redhat.com>",
        "Date": "Mon,  2 Jul 2018 10:16:21 +0200",
        "Message-Id": "<20180702081629.29258-8-maxime.coquelin@redhat.com>",
        "In-Reply-To": "<20180702081629.29258-1-maxime.coquelin@redhat.com>",
        "References": "<20180702081629.29258-1-maxime.coquelin@redhat.com>",
        "X-Scanned-By": "MIMEDefang 2.79 on 10.11.54.5",
        "X-Greylist": [
            "Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.11.55.6]); Mon, 02 Jul 2018 08:17:07 +0000 (UTC)",
            "inspected by milter-greylist-4.5.16 (mx1.redhat.com\n\t[10.11.55.6]); \n\tMon, 02 Jul 2018 08:17:07 +0000 (UTC) for IP:'10.11.54.5'\n\tDOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com'\n\tHELO:'smtp.corp.redhat.com' FROM:'maxime.coquelin@redhat.com' RCPT:''"
        ],
        "Subject": "[dpdk-dev] [PATCH v6 07/15] vhost: extract split ring handling from\n\tRx and Tx functions",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "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>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "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>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>\n---\n lib/librte_vhost/virtio_net.c | 240 +++++++++++++++++++++++-------------------\n 1 file changed, 131 insertions(+), 109 deletions(-)",
    "diff": "diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c\nindex 816d5fc1d..385876527 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@@ -317,13 +317,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@@ -341,7 +341,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_RO) < 0))\n \t\t\treturn -1;\n@@ -528,48 +529,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@@ -602,6 +577,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@@ -609,7 +620,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@@ -1014,48 +1025,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@@ -1082,39 +1058,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@@ -1126,10 +1073,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@@ -1188,6 +1135,81 @@ 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+\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+\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@@ -1200,10 +1222,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": [
        "v6",
        "07/15"
    ]
}