get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 98071,
    "url": "http://patches.dpdk.org/api/patches/98071/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/20210906204837.112466-2-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": "<20210906204837.112466-2-wenwux.ma@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20210906204837.112466-2-wenwux.ma@intel.com",
    "date": "2021-09-06T20:48:34",
    "name": "[1/4] vhost: support async dequeue for split ring",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "02fe2095a831128c5894b666f1797c076d1b0bf4",
    "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/20210906204837.112466-2-wenwux.ma@intel.com/mbox/",
    "series": [
        {
            "id": 18701,
            "url": "http://patches.dpdk.org/api/series/18701/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=18701",
            "date": "2021-09-06T20:48:33",
            "name": "support async dequeue for split ring",
            "version": 1,
            "mbox": "http://patches.dpdk.org/series/18701/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/98071/comments/",
    "check": "warning",
    "checks": "http://patches.dpdk.org/api/patches/98071/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 4419EA0C4D;\n\tMon,  6 Sep 2021 10:56:16 +0200 (CEST)",
            "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 8050141124;\n\tMon,  6 Sep 2021 10:56:15 +0200 (CEST)",
            "from mga12.intel.com (mga12.intel.com [192.55.52.136])\n by mails.dpdk.org (Postfix) with ESMTP id 57CE141121\n for <dev@dpdk.org>; Mon,  6 Sep 2021 10:56:12 +0200 (CEST)",
            "from fmsmga003.fm.intel.com ([10.253.24.29])\n by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 06 Sep 2021 01:56:11 -0700",
            "from unknown (HELO localhost.localdomain) ([10.240.183.109])\n by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 06 Sep 2021 01:56:08 -0700"
        ],
        "X-IronPort-AV": [
            "E=McAfee;i=\"6200,9189,10098\"; a=\"199453737\"",
            "E=Sophos;i=\"5.85,271,1624345200\"; d=\"scan'208\";a=\"199453737\"",
            "E=Sophos;i=\"5.85,271,1624345200\"; d=\"scan'208\";a=\"536671266\""
        ],
        "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, Sunil.Pai.G@intel.com, yvonnex.yang@intel.com,\n Yuan Wang <yuanx.wang@intel.com>, Wenwu Ma <wenwux.ma@intel.com>,\n Yinan Wang <yinan.wang@intel.com>",
        "Date": "Mon,  6 Sep 2021 20:48:34 +0000",
        "Message-Id": "<20210906204837.112466-2-wenwux.ma@intel.com>",
        "X-Mailer": "git-send-email 2.25.1",
        "In-Reply-To": "<20210906204837.112466-1-wenwux.ma@intel.com>",
        "References": "<20210906204837.112466-1-wenwux.ma@intel.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[dpdk-dev] [PATCH 1/4] vhost: support async dequeue for split 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 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>\nTested-by: Yinan Wang <yinan.wang@intel.com>\n---\n doc/guides/prog_guide/vhost_lib.rst |   9 +\n lib/vhost/rte_vhost_async.h         |  36 +-\n lib/vhost/version.map               |   3 +\n lib/vhost/vhost.h                   |   3 +-\n lib/vhost/virtio_net.c              | 531 ++++++++++++++++++++++++++++\n 5 files changed, 579 insertions(+), 3 deletions(-)",
    "diff": "diff --git a/doc/guides/prog_guide/vhost_lib.rst b/doc/guides/prog_guide/vhost_lib.rst\nindex 171e0096f6..9ed544db7a 100644\n--- a/doc/guides/prog_guide/vhost_lib.rst\n+++ b/doc/guides/prog_guide/vhost_lib.rst\n@@ -303,6 +303,15 @@ The following is an overview of some key Vhost API functions:\n   Clear inflight packets which are submitted to DMA engine in vhost async data\n   path. Completed packets 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+  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 ad71555a7f..5e2429ab70 100644\n--- a/lib/vhost/rte_vhost_async.h\n+++ b/lib/vhost/rte_vhost_async.h\n@@ -83,12 +83,18 @@ 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+\tstruct async_nethdr nethdr;\n+\tuint16_t descs; /* num of descs in-flight */\n \tuint16_t nr_buffers; /* num of buffers inflight for packed ring */\n };\n \n@@ -255,5 +261,31 @@ int rte_vhost_async_get_inflight(int vid, uint16_t queue_id);\n __rte_experimental\n uint16_t rte_vhost_clear_queue_thread_unsafe(int vid, uint16_t queue_id,\n \t\tstruct rte_mbuf **pkts, uint16_t count);\n+/**\n+ * This function tries to receive packets from the guest with offloading\n+ * 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 c92a9d4962..1e033ad8e2 100644\n--- a/lib/vhost/version.map\n+++ b/lib/vhost/version.map\n@@ -85,4 +85,7 @@ EXPERIMENTAL {\n \trte_vhost_async_channel_register_thread_unsafe;\n \trte_vhost_async_channel_unregister_thread_unsafe;\n \trte_vhost_clear_queue_thread_unsafe;\n+\n+\t# added in 21.11\n+\trte_vhost_async_try_dequeue_burst;\n };\ndiff --git a/lib/vhost/vhost.h b/lib/vhost/vhost.h\nindex 1e56311725..89a31e4ca8 100644\n--- a/lib/vhost/vhost.h\n+++ b/lib/vhost/vhost.h\n@@ -49,7 +49,8 @@\n #define MAX_PKT_BURST 32\n \n #define VHOST_MAX_ASYNC_IT (MAX_PKT_BURST * 2)\n-#define VHOST_MAX_ASYNC_VEC (BUF_VECTOR_MAX * 4)\n+#define MAX_ASYNC_COPY_VECTOR 1024\n+#define VHOST_MAX_ASYNC_VEC (MAX_ASYNC_COPY_VECTOR * 2)\n \n #define PACKED_DESC_ENQUEUE_USED_FLAG(w)\t\\\n \t((w) ? (VRING_DESC_F_AVAIL | VRING_DESC_F_USED | VRING_DESC_F_WRITE) : \\\ndiff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c\nindex 0350f6fcce..67a8cd2c41 100644\n--- a/lib/vhost/virtio_net.c\n+++ b/lib/vhost/virtio_net.c\n@@ -3170,3 +3170,534 @@ 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,\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  int nr_iovec)\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;\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+\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+\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_iova = buf_vec[vec_idx].buf_iova;\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_iova = buf_vec[vec_idx].buf_iova;\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), (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) {\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+\t\t\tif (unlikely(!hpa)) {\n+\t\t\t\tVHOST_LOG_DATA(ERR, \"(%d) %s: failed to get hpa.\\n\",\n+\t\t\t\t\tdev->vid, __func__);\n+\t\t\t\treturn -1;\n+\t\t\t}\n+\t\t\tif (unlikely(tvec_idx >= nr_iovec)) {\n+\t\t\t\tVHOST_LOG_DATA(ERR, \"iovec is not enough for offloading\\n\");\n+\t\t\t\treturn -1;\n+\t\t\t}\n+\n+\t\t\tasync_fill_vec(src_iovec + tvec_idx, hpa, (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, mbuf_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\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_iova = buf_vec[vec_idx].buf_iova;\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, (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 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 (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\tif (hdr) {\n+\t\t\tnethdr->valid = true;\n+\t\t\tnethdr->hdr = *hdr;\n+\t\t} else\n+\t\t\tnethdr->valid = false;\n+\t}\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\tint ret;\n+\n+\t\tret = vq->async_ops.check_completed_copies(dev->vid, queue_id,\n+\t\t\t\t0, count - vq->async_last_pkts_n);\n+\t\tif (unlikely(ret < 0)) {\n+\t\t\tVHOST_LOG_DATA(ERR, \"(%d) async channel poll error\\n\", dev->vid);\n+\t\t\tret = 0;\n+\t\t}\n+\t\tn_pkts_cpl = ret;\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+\n+\t/* write back completed descs to used ring and update used idx */\n+\twrite_back_completed_descs_split(vq, n_pkts_put);\n+\t__atomic_add_fetch(&vq->used->idx, n_pkts_put, __ATOMIC_RELEASE);\n+\tvhost_vring_call_split(dev, vq);\n+\n+\tvq->async_last_pkts_n = n_pkts_cpl - n_pkts_put;\n+\tvq->async_pkts_inflight_n -= n_pkts_put;\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 free_entries;\n+\tuint16_t pkt_idx, slot_idx = 0;\n+\tuint16_t nr_done_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+\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) - vq->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\", dev->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\tuint16_t to;\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 = pkts_prealloc[pkt_idx];\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\tdropped = true;\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\terr = virtio_dev_pktmbuf_prep(dev, pkt, buf_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\tslot_idx = (vq->async_pkts_idx + pkt_idx) & (vq->size - 1);\n+\t\terr = async_desc_to_mbuf(dev, 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,\n+\t\t\t\t(VHOST_MAX_ASYNC_VEC >> 1) - iovec_idx);\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 offload copies to async channel %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\tasync_fill_desc(&tdes[nr_async_burst], &it_pool[it_idx], &it_pool[it_idx + 1]);\n+\t\tpkts_info[slot_idx].mbuf = pkt;\n+\t\tnr_async_burst++;\n+\n+\t\tiovec_idx += it_pool[it_idx].nr_segs;\n+\t\tit_idx += 2;\n+\n+\t\t/* store used descs */\n+\t\tto = vq->async_desc_idx_split & (vq->size - 1);\n+\t\tvq->async_descs_split[to].id = head_idx;\n+\t\tvq->async_descs_split[to].len = 0;\n+\t\tvq->async_desc_idx_split++;\n+\n+\t\tvq->last_avail_idx++;\n+\n+\t\tif (unlikely(nr_async_burst >= VHOST_ASYNC_BATCH_THRESHOLD)) {\n+\t\t\tuint16_t nr_pkts;\n+\t\t\tint32_t ret;\n+\n+\t\t\tret = vq->async_ops.transfer_data(dev->vid, queue_id,\n+\t\t\t\t\ttdes, 0, nr_async_burst);\n+\t\t\tif (unlikely(ret < 0)) {\n+\t\t\t\tVHOST_LOG_DATA(ERR, \"(%d) async channel submit error\\n\", dev->vid);\n+\t\t\t\tret = 0;\n+\t\t\t}\n+\t\t\tnr_pkts = ret;\n+\n+\t\t\tvq->async_pkts_inflight_n += nr_pkts;\n+\t\t\tit_idx = 0;\n+\t\t\tiovec_idx = 0;\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\tpkt_idx++;\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\tuint16_t nr_pkts;\n+\t\tint32_t ret;\n+\n+\t\tret = vq->async_ops.transfer_data(dev->vid, queue_id, tdes, 0, nr_async_burst);\n+\t\tif (unlikely(ret < 0)) {\n+\t\t\tVHOST_LOG_DATA(ERR, \"(%d) async channel submit error\\n\", dev->vid);\n+\t\t\tret = 0;\n+\t\t}\n+\t\tnr_pkts = ret;\n+\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+\tif (unlikely(pkt_err)) {\n+\t\tuint16_t nr_err_dma = pkt_err;\n+\n+\t\tpkt_idx -= nr_err_dma;\n+\n+\t\t/**\n+\t\t * recover async channel copy related structures and free pktmbufs\n+\t\t * for 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(pkts_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 -= pkt_err;\n+\t}\n+\n+\tvq->async_pkts_idx += pkt_idx;\n+\n+out:\n+\tif (vq->async_pkts_inflight_n > 0) {\n+\t\tnr_done_pkts = async_poll_dequeue_completed_split(dev, vq,\n+\t\t\t\t\tqueue_id, pkts, count, legacy_ol_flags);\n+\t}\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": [
        "1/4"
    ]
}