get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 94691,
    "url": "https://patches.dpdk.org/api/patches/94691/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/20210623150014.1015484-4-wenwux.ma@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": "<20210623150014.1015484-4-wenwux.ma@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20210623150014.1015484-4-wenwux.ma@intel.com",
    "date": "2021-06-23T15:00:13",
    "name": "[v3,3/4] vhost: support async dequeue for split ring",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "0361bfb0eb60c3a01b267b9b87b508dbbab3c99e",
    "submitter": {
        "id": 2163,
        "url": "https://patches.dpdk.org/api/people/2163/?format=api",
        "name": "Ma, WenwuX",
        "email": "wenwux.ma@intel.com"
    },
    "delegate": {
        "id": 2642,
        "url": "https://patches.dpdk.org/api/users/2642/?format=api",
        "username": "mcoquelin",
        "first_name": "Maxime",
        "last_name": "Coquelin",
        "email": "maxime.coquelin@redhat.com"
    },
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/20210623150014.1015484-4-wenwux.ma@intel.com/mbox/",
    "series": [
        {
            "id": 17447,
            "url": "https://patches.dpdk.org/api/series/17447/?format=api",
            "web_url": "https://patches.dpdk.org/project/dpdk/list/?series=17447",
            "date": "2021-06-23T15:00:10",
            "name": "vhost: support async dequeue for split ring",
            "version": 3,
            "mbox": "https://patches.dpdk.org/series/17447/mbox/"
        }
    ],
    "comments": "https://patches.dpdk.org/api/patches/94691/comments/",
    "check": "success",
    "checks": "https://patches.dpdk.org/api/patches/94691/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@inbox.dpdk.org",
        "Delivered-To": "patchwork@inbox.dpdk.org",
        "Received": [
            "from mails.dpdk.org (mails.dpdk.org [217.70.189.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id 5BE97A0C41;\n\tWed, 23 Jun 2021 05:07:26 +0200 (CEST)",
            "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 44077410E8;\n\tWed, 23 Jun 2021 05:07:15 +0200 (CEST)",
            "from mga06.intel.com (mga06.intel.com [134.134.136.31])\n by mails.dpdk.org (Postfix) with ESMTP id 2C6E240687\n for <dev@dpdk.org>; Wed, 23 Jun 2021 05:07:10 +0200 (CEST)",
            "from orsmga001.jf.intel.com ([10.7.209.18])\n by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 22 Jun 2021 20:07:09 -0700",
            "from unknown (HELO localhost.localdomain) ([10.240.183.109])\n by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 22 Jun 2021 20:07:07 -0700"
        ],
        "IronPort-SDR": [
            "\n cmA6+e4r1f4uV2c+X3jjrXEOicRmhrWDT01i1ZUfxfRbbBAC5H2nNdia2Any4UR1g/0C1T0ZYx\n AsYtGH3pjtwA==",
            "\n GOH1s5SEm4qNxKM3I2GkHbqf7pzeotIpt6LYueFySEOV+n/ljeDeu1B0McOfpAeqwRQJiaSw4k\n DJxXHtYnjumA=="
        ],
        "X-IronPort-AV": [
            "E=McAfee;i=\"6200,9189,10023\"; a=\"268322048\"",
            "E=Sophos;i=\"5.83,293,1616482800\"; d=\"scan'208\";a=\"268322048\"",
            "E=Sophos;i=\"5.83,293,1616482800\"; d=\"scan'208\";a=\"487141346\""
        ],
        "From": "Wenwu Ma <wenwux.ma@intel.com>",
        "To": "dev@dpdk.org",
        "Cc": "maxime.coquelin@redhat.com, chenbo.xia@intel.com, cheng1.jiang@intel.com,\n Yuan Wang <yuanx.wang@intel.com>, Jiayu Hu <jiayu.hu@intel.com>,\n Wenwu Ma <wenwux.ma@intel.com>",
        "Date": "Wed, 23 Jun 2021 15:00:13 +0000",
        "Message-Id": "<20210623150014.1015484-4-wenwux.ma@intel.com>",
        "X-Mailer": "git-send-email 2.25.1",
        "In-Reply-To": "<20210623150014.1015484-1-wenwux.ma@intel.com>",
        "References": "<20210602083110.5530-1-yuanx.wang@intel.com>\n <20210623150014.1015484-1-wenwux.ma@intel.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[dpdk-dev] [PATCH v3 3/4] vhost: support async dequeue for split\n ring",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <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 <mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "From: Yuan Wang <yuanx.wang@intel.com>\n\nThis patch implements asynchronous dequeue data path for split ring.\nA new asynchronous dequeue function is introduced. With this function,\nthe application can try to receive packets from the guest with\noffloading large copies to the DMA engine, thus saving precious CPU\ncycles.\n\nSigned-off-by: Yuan Wang <yuanx.wang@intel.com>\nSigned-off-by: Jiayu Hu <jiayu.hu@intel.com>\nSigned-off-by: Wenwu Ma <wenwux.ma@intel.com>\n---\n doc/guides/prog_guide/vhost_lib.rst |  10 +\n lib/vhost/rte_vhost_async.h         |  44 ++-\n lib/vhost/version.map               |   3 +\n lib/vhost/virtio_net.c              | 579 ++++++++++++++++++++++++++++\n 4 files changed, 633 insertions(+), 3 deletions(-)",
    "diff": "diff --git a/doc/guides/prog_guide/vhost_lib.rst b/doc/guides/prog_guide/vhost_lib.rst\nindex d18fb98910..05c42c9b11 100644\n--- a/doc/guides/prog_guide/vhost_lib.rst\n+++ b/doc/guides/prog_guide/vhost_lib.rst\n@@ -281,6 +281,16 @@ The following is an overview of some key Vhost API functions:\n   Poll enqueue completion status from async data path. Completed packets\n   are returned to applications through ``pkts``.\n \n+* ``rte_vhost_async_try_dequeue_burst(vid, queue_id, mbuf_pool, pkts, count, nr_inflight)``\n+\n+  Try to receive packets from the guest with offloading large packets\n+  to the DMA engine. Successfully dequeued packets are transfer\n+  completed and returned in ``pkts``. But there may be other packets\n+  that are sent from the guest but being transferred by the DMA engine,\n+  called in-flight packets. This function will return in-flight packets\n+  only after the DMA engine finishes transferring. The amount of\n+  in-flight packets by now is returned in ``nr_inflight``.\n+\n Vhost-user Implementations\n --------------------------\n \ndiff --git a/lib/vhost/rte_vhost_async.h b/lib/vhost/rte_vhost_async.h\nindex 6faa31f5ad..58019408f1 100644\n--- a/lib/vhost/rte_vhost_async.h\n+++ b/lib/vhost/rte_vhost_async.h\n@@ -84,13 +84,21 @@ struct rte_vhost_async_channel_ops {\n };\n \n /**\n- * inflight async packet information\n+ * in-flight async packet information\n  */\n+struct async_nethdr {\n+\tstruct virtio_net_hdr hdr;\n+\tbool valid;\n+};\n+\n struct async_inflight_info {\n \tstruct rte_mbuf *mbuf;\n-\tuint16_t descs; /* num of descs inflight */\n+\tunion {\n+\t\tuint16_t descs; /* num of descs in-flight */\n+\t\tstruct async_nethdr nethdr;\n+\t};\n \tuint16_t nr_buffers; /* num of buffers inflight for packed ring */\n-};\n+} __rte_cache_aligned;\n \n /**\n  *  dma channel feature bit definition\n@@ -193,4 +201,34 @@ __rte_experimental\n uint16_t rte_vhost_poll_enqueue_completed(int vid, uint16_t queue_id,\n \t\tstruct rte_mbuf **pkts, uint16_t count);\n \n+/**\n+ * This function tries to receive packets from the guest with offloading\n+ * large copies to the DMA engine. Successfully dequeued packets are\n+ * transfer completed, either by the CPU or the DMA engine, and they are\n+ * returned in \"pkts\". There may be other packets that are sent from\n+ * the guest but being transferred by the DMA engine, called in-flight\n+ * packets. The amount of in-flight packets by now is returned in\n+ * \"nr_inflight\". This function will return in-flight packets only after\n+ * the DMA engine finishes transferring.\n+ *\n+ * @param vid\n+ *  id of vhost device to dequeue data\n+ * @param queue_id\n+ *  queue id to dequeue data\n+ * @param pkts\n+ *  blank array to keep successfully dequeued packets\n+ * @param count\n+ *  size of the packet array\n+ * @param nr_inflight\n+ *  the amount of in-flight packets by now. If error occurred, its\n+ *  value is set to -1.\n+ * @return\n+ *  num of successfully dequeued packets\n+ */\n+__rte_experimental\n+uint16_t\n+rte_vhost_async_try_dequeue_burst(int vid, uint16_t queue_id,\n+\tstruct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count,\n+\tint *nr_inflight);\n+\n #endif /* _RTE_VHOST_ASYNC_H_ */\ndiff --git a/lib/vhost/version.map b/lib/vhost/version.map\nindex 9103a23cd4..a320f889cd 100644\n--- a/lib/vhost/version.map\n+++ b/lib/vhost/version.map\n@@ -79,4 +79,7 @@ EXPERIMENTAL {\n \n \t# added in 21.05\n \trte_vhost_get_negotiated_protocol_features;\n+\n+\t# added in 21.08\n+\trte_vhost_async_try_dequeue_burst;\n };\ndiff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c\nindex b93482587c..89a6715e7a 100644\n--- a/lib/vhost/virtio_net.c\n+++ b/lib/vhost/virtio_net.c\n@@ -2673,6 +2673,32 @@ virtio_dev_pktmbuf_prep(struct virtio_net *dev, struct rte_mbuf *pkt,\n \treturn -1;\n }\n \n+/*\n+ * Allocate a host supported pktmbuf.\n+ */\n+static __rte_always_inline struct rte_mbuf *\n+virtio_dev_pktmbuf_alloc(struct virtio_net *dev, struct rte_mempool *mp,\n+\t\t\t uint32_t data_len)\n+{\n+\tstruct rte_mbuf *pkt = rte_pktmbuf_alloc(mp);\n+\n+\tif (unlikely(pkt == NULL)) {\n+\t\tVHOST_LOG_DATA(ERR,\n+\t\t\t\"Failed to allocate memory for mbuf.\\n\");\n+\t\treturn NULL;\n+\t}\n+\n+\tif (virtio_dev_pktmbuf_prep(dev, pkt, data_len)) {\n+\t\t/* Data doesn't fit into the buffer and the host supports\n+\t\t * only linear buffers\n+\t\t */\n+\t\trte_pktmbuf_free(pkt);\n+\t\treturn NULL;\n+\t}\n+\n+\treturn pkt;\n+}\n+\n __rte_always_inline\n static uint16_t\n virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq,\n@@ -3147,3 +3173,556 @@ rte_vhost_dequeue_burst(int vid, uint16_t queue_id,\n \n \treturn count;\n }\n+\n+static __rte_always_inline int\n+async_desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq,\n+\t\t  struct buf_vector *buf_vec, uint16_t nr_vec,\n+\t\t  struct rte_mbuf *m, struct rte_mempool *mbuf_pool,\n+\t\t  struct iovec *src_iovec, struct iovec *dst_iovec,\n+\t\t  struct rte_vhost_iov_iter *src_it,\n+\t\t  struct rte_vhost_iov_iter *dst_it,\n+\t\t  struct async_nethdr *nethdr,\n+\t\t  bool legacy_ol_flags)\n+{\n+\tuint64_t buf_addr;\n+\tuint32_t tlen = 0;\n+\tuint32_t buf_avail, buf_offset, buf_len;\n+\tuint32_t mbuf_avail, mbuf_offset;\n+\tuint32_t cpy_len, cpy_threshold;\n+\t/* A counter to avoid desc dead loop chain */\n+\tuint16_t vec_idx = 0;\n+\tint tvec_idx = 0;\n+\tstruct rte_mbuf *cur = m, *prev = m;\n+\tstruct virtio_net_hdr tmp_hdr;\n+\tstruct virtio_net_hdr *hdr = NULL;\n+\tstruct batch_copy_elem *batch_copy = vq->batch_copy_elems;\n+\n+\tbuf_addr = buf_vec[vec_idx].buf_addr;\n+\tbuf_len = buf_vec[vec_idx].buf_len;\n+\n+\tif (unlikely(buf_len < dev->vhost_hlen && nr_vec <= 1))\n+\t\treturn -1;\n+\n+\tcpy_threshold = vq->async_threshold;\n+\n+\tif (virtio_net_with_host_offload(dev)) {\n+\t\tif (unlikely(buf_len < sizeof(struct virtio_net_hdr))) {\n+\t\t\t/*\n+\t\t\t * No luck, the virtio-net header doesn't fit\n+\t\t\t * in a contiguous virtual area.\n+\t\t\t */\n+\t\t\tcopy_vnet_hdr_from_desc(&tmp_hdr, buf_vec);\n+\t\t\thdr = &tmp_hdr;\n+\t\t} else {\n+\t\t\thdr = (struct virtio_net_hdr *)((uintptr_t)buf_addr);\n+\t\t}\n+\t}\n+\n+\t/*\n+\t * A virtio driver normally uses at least 2 desc buffers\n+\t * for Tx: the first for storing the header, and others\n+\t * for storing the data.\n+\t */\n+\tif (unlikely(buf_len < dev->vhost_hlen)) {\n+\t\tbuf_offset = dev->vhost_hlen - buf_len;\n+\t\tvec_idx++;\n+\t\tbuf_addr = buf_vec[vec_idx].buf_addr;\n+\t\tbuf_len = buf_vec[vec_idx].buf_len;\n+\t\tbuf_avail  = buf_len - buf_offset;\n+\t} else if (buf_len == dev->vhost_hlen) {\n+\t\tif (unlikely(++vec_idx >= nr_vec))\n+\t\t\treturn -1;\n+\t\tbuf_addr = buf_vec[vec_idx].buf_addr;\n+\t\tbuf_len = buf_vec[vec_idx].buf_len;\n+\n+\t\tbuf_offset = 0;\n+\t\tbuf_avail = buf_len;\n+\t} else {\n+\t\tbuf_offset = dev->vhost_hlen;\n+\t\tbuf_avail = buf_vec[vec_idx].buf_len - dev->vhost_hlen;\n+\t}\n+\n+\tPRINT_PACKET(dev, (uintptr_t)(buf_addr + buf_offset),\n+\t\t\t(uint32_t)buf_avail, 0);\n+\n+\tmbuf_offset = 0;\n+\tmbuf_avail  = m->buf_len - RTE_PKTMBUF_HEADROOM;\n+\twhile (1) {\n+\t\tcpy_len = RTE_MIN(buf_avail, mbuf_avail);\n+\n+\t\tif (cpy_len >= cpy_threshold) {\n+\t\t\tasync_fill_vec(src_iovec + tvec_idx,\n+\t\t\t\t(void *)((uintptr_t)(buf_addr + buf_offset)),\n+\t\t\t\t(size_t)cpy_len);\n+\t\t\tasync_fill_vec(dst_iovec + tvec_idx,\n+\t\t\t\trte_pktmbuf_mtod_offset(cur,\n+\t\t\t\t\tvoid *, mbuf_offset),\n+\t\t\t\t(size_t)cpy_len);\n+\t\t\ttvec_idx++;\n+\t\t\ttlen += cpy_len;\n+\t\t} else if (likely(cpy_len > MAX_BATCH_LEN ||\n+\t\t\t\tvq->batch_copy_nb_elems >= vq->size ||\n+\t\t\t\t(hdr && cur == m))) {\n+\t\t\trte_memcpy(rte_pktmbuf_mtod_offset(cur,\n+\t\t\t\t\tvoid *, mbuf_offset),\n+\t\t\t\t(void *)((uintptr_t)(buf_addr + buf_offset)),\n+\t\t\t\tcpy_len);\n+\t\t} else {\n+\t\t\tbatch_copy[vq->batch_copy_nb_elems].dst =\n+\t\t\t\trte_pktmbuf_mtod_offset(cur,\n+\t\t\t\t\tvoid *, mbuf_offset);\n+\t\t\tbatch_copy[vq->batch_copy_nb_elems].src =\n+\t\t\t\t(void *)((uintptr_t)(buf_addr + buf_offset));\n+\t\t\tbatch_copy[vq->batch_copy_nb_elems].len = cpy_len;\n+\t\t\tvq->batch_copy_nb_elems++;\n+\t\t}\n+\n+\t\tmbuf_avail  -= cpy_len;\n+\t\tmbuf_offset += cpy_len;\n+\t\tbuf_avail  -= cpy_len;\n+\t\tbuf_offset += cpy_len;\n+\n+\t\t/* This buf reaches to its end, get the next one */\n+\t\tif (buf_avail == 0) {\n+\t\t\tif (++vec_idx >= nr_vec)\n+\t\t\t\tbreak;\n+\n+\t\t\tbuf_addr = buf_vec[vec_idx].buf_addr;\n+\t\t\tbuf_len = buf_vec[vec_idx].buf_len;\n+\n+\t\t\tbuf_offset = 0;\n+\t\t\tbuf_avail = buf_len;\n+\n+\t\t\tPRINT_PACKET(dev, (uintptr_t)buf_addr,\n+\t\t\t\t\t(uint32_t)buf_avail, 0);\n+\t\t}\n+\n+\t\t/*\n+\t\t * This mbuf reaches to its end, get a new one\n+\t\t * to hold more data.\n+\t\t */\n+\t\tif (mbuf_avail == 0) {\n+\t\t\tcur = rte_pktmbuf_alloc(mbuf_pool);\n+\t\t\tif (unlikely(cur == NULL)) {\n+\t\t\t\tVHOST_LOG_DATA(ERR, \"Failed to \"\n+\t\t\t\t\t\"allocate memory for mbuf.\\n\");\n+\t\t\t\treturn -1;\n+\t\t\t}\n+\n+\t\t\tprev->next = cur;\n+\t\t\tprev->data_len = mbuf_offset;\n+\t\t\tm->nb_segs += 1;\n+\t\t\tm->pkt_len += mbuf_offset;\n+\t\t\tprev = cur;\n+\n+\t\t\tmbuf_offset = 0;\n+\t\t\tmbuf_avail = cur->buf_len - RTE_PKTMBUF_HEADROOM;\n+\t\t}\n+\t}\n+\n+\tprev->data_len = mbuf_offset;\n+\tm->pkt_len += mbuf_offset;\n+\n+\tif (hdr && tlen) {\n+\t\tnethdr->valid = true;\n+\t\tnethdr->hdr = *hdr;\n+\t} else if (hdr)\n+\t\tvhost_dequeue_offload(hdr, m, legacy_ol_flags);\n+\n+\tif (tlen) {\n+\t\tasync_fill_iter(src_it, tlen, src_iovec, tvec_idx);\n+\t\tasync_fill_iter(dst_it, tlen, dst_iovec, tvec_idx);\n+\t} else\n+\t\tsrc_it->count = 0;\n+\n+\treturn 0;\n+}\n+\n+static __rte_always_inline uint16_t\n+async_poll_dequeue_completed_split(struct virtio_net *dev,\n+\t\tstruct vhost_virtqueue *vq, uint16_t queue_id,\n+\t\tstruct rte_mbuf **pkts, uint16_t count, bool legacy_ol_flags)\n+{\n+\tuint16_t n_pkts_cpl = 0, n_pkts_put = 0;\n+\tuint16_t start_idx, pkt_idx, from;\n+\tstruct async_inflight_info *pkts_info;\n+\n+\tpkt_idx = vq->async_pkts_idx & (vq->size - 1);\n+\tpkts_info = vq->async_pkts_info;\n+\tstart_idx = virtio_dev_rx_async_get_info_idx(pkt_idx, vq->size,\n+\t\t\tvq->async_pkts_inflight_n);\n+\n+\tif (count > vq->async_last_pkts_n) {\n+\t\tn_pkts_cpl = vq->async_ops.check_completed_copies(dev->vid,\n+\t\t\tqueue_id, 0, count - vq->async_last_pkts_n);\n+\t}\n+\n+\tn_pkts_cpl += vq->async_last_pkts_n;\n+\tif (unlikely(n_pkts_cpl == 0))\n+\t\treturn 0;\n+\n+\tn_pkts_put = RTE_MIN(count, n_pkts_cpl);\n+\n+\tfor (pkt_idx = 0; pkt_idx < n_pkts_put; pkt_idx++) {\n+\t\tfrom = (start_idx + pkt_idx) & (vq->size - 1);\n+\t\tpkts[pkt_idx] = pkts_info[from].mbuf;\n+\n+\t\tif (pkts_info[from].nethdr.valid) {\n+\t\t\tvhost_dequeue_offload(&pkts_info[from].nethdr.hdr,\n+\t\t\t\t\tpkts[pkt_idx], legacy_ol_flags);\n+\t\t}\n+\t}\n+\tvq->async_last_pkts_n = n_pkts_cpl - n_pkts_put;\n+\n+\tif (n_pkts_put) {\n+\t\t/* write back completed descs to used ring */\n+\t\twrite_back_completed_descs_split(vq, n_pkts_put);\n+\t\t/* update used ring */\n+\t\t__atomic_add_fetch(&vq->used->idx,\n+\t\t\t\tn_pkts_put, __ATOMIC_RELEASE);\n+\n+\t\tvq->async_pkts_inflight_n -= n_pkts_put;\n+\t}\n+\n+\treturn n_pkts_put;\n+}\n+\n+static __rte_always_inline uint16_t\n+virtio_dev_tx_async_split(struct virtio_net *dev,\n+\t\tstruct vhost_virtqueue *vq, uint16_t queue_id,\n+\t\tstruct rte_mempool *mbuf_pool, struct rte_mbuf **pkts,\n+\t\tuint16_t count, bool legacy_ol_flags)\n+{\n+\tstatic bool allocerr_warned;\n+\tuint16_t pkt_idx;\n+\tuint16_t free_entries;\n+\tuint16_t slot_idx = 0;\n+\tuint16_t segs_await = 0;\n+\tuint16_t nr_done_pkts = 0, nr_async_pkts = 0, nr_async_cmpl_pkts = 0;\n+\tuint16_t nr_async_burst = 0;\n+\tuint16_t pkt_err = 0;\n+\tuint16_t iovec_idx = 0, it_idx = 0;\n+\n+\tstruct rte_vhost_iov_iter *it_pool = vq->it_pool;\n+\tstruct iovec *vec_pool = vq->vec_pool;\n+\tstruct iovec *src_iovec = vec_pool;\n+\tstruct iovec *dst_iovec = vec_pool + (VHOST_MAX_ASYNC_VEC >> 1);\n+\tstruct rte_vhost_async_desc tdes[MAX_PKT_BURST];\n+\tstruct async_inflight_info *pkts_info = vq->async_pkts_info;\n+\n+\tstruct async_pkt_index {\n+\t\tuint16_t last_avail_idx;\n+\t} async_pkts_log[MAX_PKT_BURST];\n+\n+\t/**\n+\t * The ordering between avail index and\n+\t * desc reads needs to be enforced.\n+\t */\n+\tfree_entries = __atomic_load_n(&vq->avail->idx, __ATOMIC_ACQUIRE) -\n+\t\t\tvq->last_avail_idx;\n+\tif (free_entries == 0)\n+\t\tgoto out;\n+\n+\trte_prefetch0(&vq->avail->ring[vq->last_avail_idx & (vq->size - 1)]);\n+\n+\tcount = RTE_MIN(count, MAX_PKT_BURST);\n+\tcount = RTE_MIN(count, free_entries);\n+\tVHOST_LOG_DATA(DEBUG, \"(%d) about to dequeue %u buffers\\n\",\n+\t\t\tdev->vid, count);\n+\n+\tfor (pkt_idx = 0; pkt_idx < count; pkt_idx++) {\n+\t\tuint16_t head_idx = 0;\n+\t\tuint16_t nr_vec = 0;\n+\t\tuint32_t buf_len;\n+\t\tint err;\n+\t\tstruct buf_vector buf_vec[BUF_VECTOR_MAX];\n+\t\tstruct rte_mbuf *pkt;\n+\n+\t\tif (unlikely(fill_vec_buf_split(dev, vq, vq->last_avail_idx,\n+\t\t\t\t\t\t&nr_vec, buf_vec,\n+\t\t\t\t\t\t&head_idx, &buf_len,\n+\t\t\t\t\t\tVHOST_ACCESS_RO) < 0))\n+\t\t\tbreak;\n+\n+\t\tpkt = virtio_dev_pktmbuf_alloc(dev, mbuf_pool, buf_len);\n+\t\tif (unlikely(pkt == NULL)) {\n+\t\t\t/**\n+\t\t\t * mbuf allocation fails for jumbo packets when external\n+\t\t\t * buffer allocation is not allowed and linear buffer\n+\t\t\t * is required. Drop this packet.\n+\t\t\t */\n+\t\t\tif (!allocerr_warned) {\n+\t\t\t\tVHOST_LOG_DATA(ERR,\n+\t\t\t\t\t\"Failed mbuf alloc of size %d from %s on %s.\\n\",\n+\t\t\t\t\tbuf_len, mbuf_pool->name, dev->ifname);\n+\t\t\t\tallocerr_warned = true;\n+\t\t\t}\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tslot_idx = (vq->async_pkts_idx + nr_async_pkts) &\n+\t\t\t\t(vq->size - 1);\n+\t\terr = async_desc_to_mbuf(dev, vq, buf_vec, nr_vec, pkt,\n+\t\t\t\tmbuf_pool, &src_iovec[iovec_idx],\n+\t\t\t\t&dst_iovec[iovec_idx], &it_pool[it_idx],\n+\t\t\t\t&it_pool[it_idx + 1],\n+\t\t\t\t&pkts_info[slot_idx].nethdr, legacy_ol_flags);\n+\t\tif (unlikely(err)) {\n+\t\t\trte_pktmbuf_free(pkt);\n+\t\t\tif (!allocerr_warned) {\n+\t\t\t\tVHOST_LOG_DATA(ERR,\n+\t\t\t\t\t\"Failed to copy desc to mbuf on %s.\\n\",\n+\t\t\t\t\tdev->ifname);\n+\t\t\t\tallocerr_warned = true;\n+\t\t\t}\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tif (it_pool[it_idx].count) {\n+\t\t\tuint16_t to = vq->async_desc_idx_split & (vq->size - 1);\n+\n+\t\t\tasync_fill_desc(&tdes[nr_async_burst], &it_pool[it_idx],\n+\t\t\t\t&it_pool[it_idx + 1]);\n+\t\t\tpkts_info[slot_idx].mbuf = pkt;\n+\t\t\tasync_pkts_log[nr_async_pkts++].last_avail_idx =\n+\t\t\t\tvq->last_avail_idx;\n+\t\t\tnr_async_burst++;\n+\t\t\tiovec_idx += it_pool[it_idx].nr_segs;\n+\t\t\tit_idx += 2;\n+\t\t\tsegs_await += it_pool[it_idx].nr_segs;\n+\n+\t\t\t/* keep used desc */\n+\t\t\tvq->async_descs_split[to].id = head_idx;\n+\t\t\tvq->async_descs_split[to].len = 0;\n+\t\t\tvq->async_desc_idx_split++;\n+\t\t} else {\n+\t\t\tupdate_shadow_used_ring_split(vq, head_idx, 0);\n+\t\t\tpkts[nr_done_pkts++] = pkt;\n+\t\t}\n+\n+\t\tvq->last_avail_idx++;\n+\n+\t\tif (unlikely((nr_async_burst >= VHOST_ASYNC_BATCH_THRESHOLD) ||\n+\t\t\t\t\t((VHOST_MAX_ASYNC_VEC >> 1) -\n+\t\t\t\t\t segs_await < BUF_VECTOR_MAX))) {\n+\t\t\tuint16_t nr_pkts;\n+\n+\t\t\tnr_pkts = vq->async_ops.transfer_data(dev->vid,\n+\t\t\t\t\tqueue_id, tdes, 0, nr_async_burst);\n+\t\t\tsrc_iovec = vec_pool;\n+\t\t\tdst_iovec = vec_pool + (VHOST_MAX_ASYNC_VEC >> 1);\n+\t\t\tit_idx = 0;\n+\t\t\tsegs_await = 0;\n+\t\t\tvq->async_pkts_inflight_n += nr_pkts;\n+\n+\t\t\tif (unlikely(nr_pkts < nr_async_burst)) {\n+\t\t\t\tpkt_err = nr_async_burst - nr_pkts;\n+\t\t\t\tnr_async_burst = 0;\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t\tnr_async_burst = 0;\n+\t\t}\n+\t}\n+\n+\tif (nr_async_burst) {\n+\t\tuint32_t nr_pkts;\n+\n+\t\tnr_pkts = vq->async_ops.transfer_data(dev->vid, queue_id,\n+\t\t\t\ttdes, 0, nr_async_burst);\n+\t\tvq->async_pkts_inflight_n += nr_pkts;\n+\n+\t\tif (unlikely(nr_pkts < nr_async_burst))\n+\t\t\tpkt_err = nr_async_burst - nr_pkts;\n+\t}\n+\n+\tdo_data_copy_dequeue(vq);\n+\n+\tif (unlikely(pkt_err)) {\n+\t\tuint16_t nr_err_dma = pkt_err;\n+\t\tuint16_t nr_err_sw;\n+\n+\t\tnr_async_pkts -= nr_err_dma;\n+\n+\t\t/**\n+\t\t * revert shadow used ring and free pktmbufs for\n+\t\t * CPU-copied pkts after the first DMA-error pkt.\n+\t\t */\n+\t\tnr_err_sw = vq->last_avail_idx -\n+\t\t\tasync_pkts_log[nr_async_pkts].last_avail_idx -\n+\t\t\tnr_err_dma;\n+\t\tvq->shadow_used_idx -= nr_err_sw;\n+\t\twhile (nr_err_sw-- > 0)\n+\t\t\trte_pktmbuf_free(pkts[--nr_done_pkts]);\n+\n+\t\t/**\n+\t\t * recover DMA-copy related structures and free pktmbufs\n+\t\t * for DMA-error pkts.\n+\t\t */\n+\t\tvq->async_desc_idx_split -= nr_err_dma;\n+\t\twhile (nr_err_dma-- > 0) {\n+\t\t\trte_pktmbuf_free(\n+\t\t\t\tpkts_info[slot_idx & (vq->size - 1)].mbuf);\n+\t\t\tslot_idx--;\n+\t\t}\n+\n+\t\t/* recover available ring */\n+\t\tvq->last_avail_idx =\n+\t\t\tasync_pkts_log[nr_async_pkts].last_avail_idx;\n+\t}\n+\n+\tvq->async_pkts_idx += nr_async_pkts;\n+\n+\tif (likely(vq->shadow_used_idx))\n+\t\tflush_shadow_used_ring_split(dev, vq);\n+\n+out:\n+\tif (nr_done_pkts < count && vq->async_pkts_inflight_n > 0) {\n+\t\tnr_async_cmpl_pkts = async_poll_dequeue_completed_split(dev, vq,\n+\t\t\t\t\tqueue_id, pkts, count - nr_done_pkts,\n+\t\t\t\t\tlegacy_ol_flags);\n+\t\tnr_done_pkts += nr_async_cmpl_pkts;\n+\t}\n+\tif (likely(nr_done_pkts))\n+\t\tvhost_vring_call_split(dev, vq);\n+\n+\treturn nr_done_pkts;\n+}\n+\n+__rte_noinline\n+static uint16_t\n+virtio_dev_tx_async_split_legacy(struct virtio_net *dev,\n+\t\tstruct vhost_virtqueue *vq, uint16_t queue_id,\n+\t\tstruct rte_mempool *mbuf_pool, struct rte_mbuf **pkts,\n+\t\tuint16_t count)\n+{\n+\treturn virtio_dev_tx_async_split(dev, vq, queue_id, mbuf_pool,\n+\t\t\t\tpkts, count, true);\n+}\n+\n+__rte_noinline\n+static uint16_t\n+virtio_dev_tx_async_split_compliant(struct virtio_net *dev,\n+\t\tstruct vhost_virtqueue *vq, uint16_t queue_id,\n+\t\tstruct rte_mempool *mbuf_pool, struct rte_mbuf **pkts,\n+\t\tuint16_t count)\n+{\n+\treturn virtio_dev_tx_async_split(dev, vq, queue_id, mbuf_pool,\n+\t\t\t\tpkts, count, false);\n+}\n+\n+uint16_t\n+rte_vhost_async_try_dequeue_burst(int vid, uint16_t queue_id,\n+\tstruct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count,\n+\tint *nr_inflight)\n+{\n+\tstruct virtio_net *dev;\n+\tstruct rte_mbuf *rarp_mbuf = NULL;\n+\tstruct vhost_virtqueue *vq;\n+\tint16_t success = 1;\n+\n+\t*nr_inflight = -1;\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\tVHOST_LOG_DATA(ERR,\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\tVHOST_LOG_DATA(ERR,\n+\t\t\t\"(%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\tcount = 0;\n+\t\tgoto out_access_unlock;\n+\t}\n+\n+\tif (unlikely(!vq->async_registered)) {\n+\t\tVHOST_LOG_DATA(ERR, \"(%d) %s: async not registered for queue id %d.\\n\",\n+\t\t\tdev->vid, __func__, queue_id);\n+\t\tcount = 0;\n+\t\tgoto out_access_unlock;\n+\t}\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\tcount = 0;\n+\t\t\tgoto out_access_unlock;\n+\t\t}\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 * __atomic_compare_exchange_n causes a write if performed compare\n+\t * and exchange. This could result in false sharing between enqueue\n+\t * and dequeue.\n+\t *\n+\t * Prevent unnecessary false sharing by reading broadcast_rarp first\n+\t * and only performing compare and exchange if the read indicates it\n+\t * is likely to be set.\n+\t */\n+\tif (unlikely(__atomic_load_n(&dev->broadcast_rarp, __ATOMIC_ACQUIRE) &&\n+\t\t\t__atomic_compare_exchange_n(&dev->broadcast_rarp,\n+\t\t\t&success, 0, 0, __ATOMIC_RELEASE, __ATOMIC_RELAXED))) {\n+\n+\t\trarp_mbuf = rte_net_make_rarp_packet(mbuf_pool, &dev->mac);\n+\t\tif (rarp_mbuf == NULL) {\n+\t\t\tVHOST_LOG_DATA(ERR, \"Failed to make RARP packet.\\n\");\n+\t\t\tcount = 0;\n+\t\t\tgoto out;\n+\t\t}\n+\t\tcount -= 1;\n+\t}\n+\n+\tif (unlikely(vq_is_packed(dev)))\n+\t\treturn 0;\n+\n+\tif (dev->flags & VIRTIO_DEV_LEGACY_OL_FLAGS)\n+\t\tcount = virtio_dev_tx_async_split_legacy(dev, vq, queue_id,\n+\t\t\t\tmbuf_pool, pkts, count);\n+\telse\n+\t\tcount = virtio_dev_tx_async_split_compliant(dev, vq, queue_id,\n+\t\t\t\tmbuf_pool, pkts, count);\n+\n+out:\n+\t*nr_inflight = vq->async_pkts_inflight_n;\n+\n+\tif (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))\n+\t\tvhost_user_iotlb_rd_unlock(vq);\n+\n+out_access_unlock:\n+\trte_spinlock_unlock(&vq->access_lock);\n+\n+\tif (unlikely(rarp_mbuf != NULL)) {\n+\t\t/*\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, count * sizeof(struct rte_mbuf *));\n+\t\tpkts[0] = rarp_mbuf;\n+\t\tcount += 1;\n+\t}\n+\n+\treturn count;\n+}\n",
    "prefixes": [
        "v3",
        "3/4"
    ]
}