get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 95941,
    "url": "http://patches.dpdk.org/api/patches/95941/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/20210716191808.19316-4-wenwux.ma@intel.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": "<20210716191808.19316-4-wenwux.ma@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20210716191808.19316-4-wenwux.ma@intel.com",
    "date": "2021-07-16T19:18:07",
    "name": "[v6,3/4] vhost: support async dequeue for split ring",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "91b3e3cfe46e889116424aead54010c229a95c86",
    "submitter": {
        "id": 2163,
        "url": "http://patches.dpdk.org/api/people/2163/?format=api",
        "name": "Ma, WenwuX",
        "email": "wenwux.ma@intel.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/20210716191808.19316-4-wenwux.ma@intel.com/mbox/",
    "series": [
        {
            "id": 17852,
            "url": "http://patches.dpdk.org/api/series/17852/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=17852",
            "date": "2021-07-16T19:18:04",
            "name": "support async dequeue for split ring",
            "version": 6,
            "mbox": "http://patches.dpdk.org/series/17852/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/95941/comments/",
    "check": "success",
    "checks": "http://patches.dpdk.org/api/patches/95941/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 0F1FDA0C52;\n\tFri, 16 Jul 2021 09:25:38 +0200 (CEST)",
            "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id A9A774133B;\n\tFri, 16 Jul 2021 09:25:22 +0200 (CEST)",
            "from mga04.intel.com (mga04.intel.com [192.55.52.120])\n by mails.dpdk.org (Postfix) with ESMTP id CA3DE412F8\n for <dev@dpdk.org>; Fri, 16 Jul 2021 09:25:18 +0200 (CEST)",
            "from fmsmga001.fm.intel.com ([10.253.24.23])\n by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 16 Jul 2021 00:25:17 -0700",
            "from unknown (HELO localhost.localdomain) ([10.240.183.109])\n by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 16 Jul 2021 00:25:15 -0700"
        ],
        "X-IronPort-AV": [
            "E=McAfee;i=\"6200,9189,10046\"; a=\"208872652\"",
            "E=Sophos;i=\"5.84,244,1620716400\"; d=\"scan'208\";a=\"208872652\"",
            "E=Sophos;i=\"5.84,244,1620716400\"; d=\"scan'208\";a=\"573496193\""
        ],
        "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 jiayu.hu@intel.com, Yuan Wang <yuanx.wang@intel.com>,\n Wenwu Ma <wenwux.ma@intel.com>",
        "Date": "Fri, 16 Jul 2021 19:18:07 +0000",
        "Message-Id": "<20210716191808.19316-4-wenwux.ma@intel.com>",
        "X-Mailer": "git-send-email 2.25.1",
        "In-Reply-To": "<20210716191808.19316-1-wenwux.ma@intel.com>",
        "References": "<20210602083110.5530-1-yuanx.wang@intel.com>\n <20210716191808.19316-1-wenwux.ma@intel.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[dpdk-dev] [PATCH v6 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 async channel, 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 |   9 +\n lib/vhost/rte_vhost_async.h         |  39 +-\n lib/vhost/version.map               |   3 +\n lib/vhost/virtio_net.c              | 586 ++++++++++++++++++++++++++++\n 4 files changed, 635 insertions(+), 2 deletions(-)",
    "diff": "diff --git a/doc/guides/prog_guide/vhost_lib.rst b/doc/guides/prog_guide/vhost_lib.rst\nindex d18fb98910..bf90a2663b 100644\n--- a/doc/guides/prog_guide/vhost_lib.rst\n+++ b/doc/guides/prog_guide/vhost_lib.rst\n@@ -281,6 +281,15 @@ 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+  This function tries to receive packets from the guest with offloading\n+  large copies to the async channel. The packets that are transfer completed\n+  are returned in ``pkts``. The other packets that their copies are submitted\n+  to the async channel but not completed are called \"in-flight packets\".\n+  This function will not return in-flight packets until their copies are\n+  completed by the async channel.\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..04d7588217 100644\n--- a/lib/vhost/rte_vhost_async.h\n+++ b/lib/vhost/rte_vhost_async.h\n@@ -83,12 +83,20 @@ struct rte_vhost_async_channel_ops {\n \t\tuint16_t max_packets);\n };\n \n+struct async_nethdr {\n+\tstruct virtio_net_hdr hdr;\n+\tbool valid;\n+};\n+\n /**\n- * inflight async packet information\n+ * in-flight async packet information\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 \n@@ -193,4 +201,31 @@ __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 async channel. The packets that are transfer completed\n+ * are returned in \"pkts\". The other packets that their copies are submitted to\n+ * the async channel but not completed are called \"in-flight packets\".\n+ * This function will not return in-flight packets until their copies are\n+ * completed by the async channel.\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. If error occurred, its 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..58317d7b75 100644\n--- a/lib/vhost/virtio_net.c\n+++ b/lib/vhost/virtio_net.c\n@@ -3147,3 +3147,589 @@ 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, buf_iova;\n+\tuint64_t mapped_len;\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+\tbuf_iova = buf_vec[vec_idx].buf_iova;\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\twhile (cpy_len && cpy_len >= cpy_threshold) {\n+\t\t\tvoid *hpa = (void *)(uintptr_t)gpa_to_first_hpa(dev,\n+\t\t\t\t\t\tbuf_iova + buf_offset, cpy_len,\n+\t\t\t\t\t\t&mapped_len);\n+\n+\t\t\tif (unlikely(!hpa || mapped_len < cpy_threshold))\n+\t\t\t\tbreak;\n+\n+\t\t\tasync_fill_vec(src_iovec + tvec_idx, hpa,\n+\t\t\t\t(size_t)mapped_len);\n+\t\t\tasync_fill_vec(dst_iovec + tvec_idx,\n+\t\t\t\t(void *)(uintptr_t)rte_pktmbuf_iova_offset(cur,\n+\t\t\t\t\t\t\tmbuf_offset),\n+\t\t\t\t(size_t)mapped_len);\n+\n+\t\t\ttvec_idx++;\n+\t\t\ttlen += (uint32_t)mapped_len;\n+\t\t\tcpy_len -= (uint32_t)mapped_len;\n+\t\t\tmbuf_avail -= (uint32_t)mapped_len;\n+\t\t\tmbuf_offset += (uint32_t)mapped_len;\n+\t\t\tbuf_avail -= (uint32_t)mapped_len;\n+\t\t\tbuf_offset += (uint32_t)mapped_len;\n+\t\t}\n+\n+\t\tif (cpy_len) {\n+\t\t\tif (vq->batch_copy_nb_elems >= vq->size ||\n+\t\t\t\t(hdr && cur == m)) {\n+\t\t\t\trte_memcpy(\n+\t\t\t\t\trte_pktmbuf_mtod_offset(cur, void *,\n+\t\t\t\t\t\t\tmbuf_offset),\n+\t\t\t\t\t(void *)((uintptr_t)(buf_addr +\n+\t\t\t\t\t\t\t\tbuf_offset)),\n+\t\t\t\t\tcpy_len);\n+\t\t\t} else {\n+\t\t\t\tbatch_copy[vq->batch_copy_nb_elems].dst =\n+\t\t\t\t\trte_pktmbuf_mtod_offset(cur, void *,\n+\t\t\t\t\t\t\tmbuf_offset);\n+\t\t\t\tbatch_copy[vq->batch_copy_nb_elems].src =\n+\t\t\t\t\t(void *)((uintptr_t)(buf_addr +\n+\t\t\t\t\t\t\t\tbuf_offset));\n+\t\t\t\tbatch_copy[vq->batch_copy_nb_elems].len =\n+\t\t\t\t\tcpy_len;\n+\t\t\t\tvq->batch_copy_nb_elems++;\n+\t\t\t}\n+\n+\t\t\tmbuf_avail  -= cpy_len;\n+\t\t\tmbuf_offset += cpy_len;\n+\t\t\tbuf_avail -= cpy_len;\n+\t\t\tbuf_offset += cpy_len;\n+\t\t}\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+\tbool dropped = false;\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+\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+\tstruct rte_mbuf *pkts_prealloc[MAX_PKT_BURST];\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+\tif (rte_pktmbuf_alloc_bulk(mbuf_pool, pkts_prealloc, count))\n+\t\tgoto out;\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\terr = virtio_dev_pktmbuf_prep(dev, pkts_prealloc[pkt_idx],\n+\t\t\t\t\t\tbuf_len);\n+\t\tif (unlikely(err)) {\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\tdropped = true;\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tpkt = pkts_prealloc[pkt_idx];\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\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\tdropped = true;\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 (unlikely(dropped))\n+\t\trte_pktmbuf_free_bulk(&pkts_prealloc[pkt_idx], count - pkt_idx);\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[nr_done_pkts],\n+\t\t\t\t\tcount - 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": [
        "v6",
        "3/4"
    ]
}