get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 98074,
    "url": "http://patches.dpdk.org/api/patches/98074/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/20210906204837.112466-5-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-5-wenwux.ma@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20210906204837.112466-5-wenwux.ma@intel.com",
    "date": "2021-09-06T20:48:37",
    "name": "[4/4] examples/vhost: support vhost async dequeue data path",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "e6b8833dc1caad23f9a3ee95f6d4e7ab92db82ac",
    "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-5-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/98074/comments/",
    "check": "warning",
    "checks": "http://patches.dpdk.org/api/patches/98074/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 3E613A0C4D;\n\tMon,  6 Sep 2021 10:56:34 +0200 (CEST)",
            "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 514E041140;\n\tMon,  6 Sep 2021 10:56:22 +0200 (CEST)",
            "from mga12.intel.com (mga12.intel.com [192.55.52.136])\n by mails.dpdk.org (Postfix) with ESMTP id F3D6341140\n for <dev@dpdk.org>; Mon,  6 Sep 2021 10:56:20 +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:20 -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:17 -0700"
        ],
        "X-IronPort-AV": [
            "E=McAfee;i=\"6200,9189,10098\"; a=\"199453813\"",
            "E=Sophos;i=\"5.85,271,1624345200\"; d=\"scan'208\";a=\"199453813\"",
            "E=Sophos;i=\"5.85,271,1624345200\"; d=\"scan'208\";a=\"536671342\""
        ],
        "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 Wenwu Ma <wenwux.ma@intel.com>",
        "Date": "Mon,  6 Sep 2021 20:48:37 +0000",
        "Message-Id": "<20210906204837.112466-5-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 4/4] examples/vhost: support vhost async dequeue\n data path",
        "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": "This patch is to add vhost async dequeue data-path in vhost sample.\nvswitch can leverage IOAT to accelerate vhost async dequeue data-path.\n\nSigned-off-by: Wenwu Ma <wenwux.ma@intel.com>\nReviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>\n---\n doc/guides/sample_app_ug/vhost.rst |   9 +-\n examples/vhost/ioat.c              |  61 +++++++--\n examples/vhost/ioat.h              |  25 ++++\n examples/vhost/main.c              | 201 +++++++++++++++++++----------\n examples/vhost/main.h              |   3 +-\n 5 files changed, 216 insertions(+), 83 deletions(-)",
    "diff": "diff --git a/doc/guides/sample_app_ug/vhost.rst b/doc/guides/sample_app_ug/vhost.rst\nindex 9afde9c7f5..63dcf181e1 100644\n--- a/doc/guides/sample_app_ug/vhost.rst\n+++ b/doc/guides/sample_app_ug/vhost.rst\n@@ -169,9 +169,12 @@ demonstrates how to use the async vhost APIs. It's used in combination with dmas\n **--dmas**\n This parameter is used to specify the assigned DMA device of a vhost device.\n Async vhost-user net driver will be used if --dmas is set. For example\n---dmas [txd0@00:04.0,txd1@00:04.1] means use DMA channel 00:04.0 for vhost\n-device 0 enqueue operation and use DMA channel 00:04.1 for vhost device 1\n-enqueue operation.\n+--dmas [txd0@00:04.0,txd1@00:04.1,rxd0@00:04.2,rxd1@00:04.3] means use\n+DMA channel 00:04.0/00:04.2 for vhost device 0 enqueue/dequeue operation\n+and use DMA channel 00:04.1/00:04.3 for vhost device 1 enqueue/dequeue\n+operation. The index of the device corresponds to the socket file in order,\n+that means vhost device 0 is created through the first socket file, vhost\n+device 1 is created through the second socket file, and so on.\n \n Common Issues\n -------------\ndiff --git a/examples/vhost/ioat.c b/examples/vhost/ioat.c\nindex 6adc30b622..540b61fff6 100644\n--- a/examples/vhost/ioat.c\n+++ b/examples/vhost/ioat.c\n@@ -21,6 +21,8 @@ struct packet_tracker {\n \n struct packet_tracker cb_tracker[MAX_VHOST_DEVICE];\n \n+int vid2socketid[MAX_VHOST_DEVICE];\n+\n int\n open_ioat(const char *value)\n {\n@@ -29,7 +31,7 @@ open_ioat(const char *value)\n \tchar *addrs = input;\n \tchar *ptrs[2];\n \tchar *start, *end, *substr;\n-\tint64_t vid, vring_id;\n+\tint64_t socketid, vring_id;\n \tstruct rte_ioat_rawdev_config config;\n \tstruct rte_rawdev_info info = { .dev_private = &config };\n \tchar name[32];\n@@ -60,6 +62,7 @@ open_ioat(const char *value)\n \t\tgoto out;\n \t}\n \twhile (i < args_nr) {\n+\t\tbool is_txd;\n \t\tchar *arg_temp = dma_arg[i];\n \t\tuint8_t sub_nr;\n \t\tsub_nr = rte_strsplit(arg_temp, strlen(arg_temp), ptrs, 2, '@');\n@@ -68,27 +71,39 @@ open_ioat(const char *value)\n \t\t\tgoto out;\n \t\t}\n \n-\t\tstart = strstr(ptrs[0], \"txd\");\n-\t\tif (start == NULL) {\n+\t\tint async_flag;\n+\t\tchar *txd, *rxd;\n+\t\ttxd = strstr(ptrs[0], \"txd\");\n+\t\trxd = strstr(ptrs[0], \"rxd\");\n+\t\tif (txd) {\n+\t\t\tis_txd = true;\n+\t\t\tstart = txd;\n+\t\t\tasync_flag = ASYNC_ENQUEUE_VHOST;\n+\t\t} else if (rxd) {\n+\t\t\tis_txd = false;\n+\t\t\tstart = rxd;\n+\t\t\tasync_flag = ASYNC_DEQUEUE_VHOST;\n+\t\t} else {\n \t\t\tret = -1;\n \t\t\tgoto out;\n \t\t}\n \n \t\tstart += 3;\n-\t\tvid = strtol(start, &end, 0);\n+\t\tsocketid = strtol(start, &end, 0);\n \t\tif (end == start) {\n \t\t\tret = -1;\n \t\t\tgoto out;\n \t\t}\n \n-\t\tvring_id = 0 + VIRTIO_RXQ;\n+\t\tvring_id = is_txd ? VIRTIO_RXQ : VIRTIO_TXQ;\n+\n \t\tif (rte_pci_addr_parse(ptrs[1],\n-\t\t\t\t&(dma_info + vid)->dmas[vring_id].addr) < 0) {\n+\t\t\t&(dma_info + socketid)->dmas[vring_id].addr) < 0) {\n \t\t\tret = -1;\n \t\t\tgoto out;\n \t\t}\n \n-\t\trte_pci_device_name(&(dma_info + vid)->dmas[vring_id].addr,\n+\t\trte_pci_device_name(&(dma_info + socketid)->dmas[vring_id].addr,\n \t\t\t\tname, sizeof(name));\n \t\tdev_id = rte_rawdev_get_dev_id(name);\n \t\tif (dev_id == (uint16_t)(-ENODEV) ||\n@@ -103,8 +118,9 @@ open_ioat(const char *value)\n \t\t\tgoto out;\n \t\t}\n \n-\t\t(dma_info + vid)->dmas[vring_id].dev_id = dev_id;\n-\t\t(dma_info + vid)->dmas[vring_id].is_valid = true;\n+\t\t(dma_info + socketid)->dmas[vring_id].dev_id = dev_id;\n+\t\t(dma_info + socketid)->dmas[vring_id].is_valid = true;\n+\t\t(dma_info + socketid)->async_flag |= async_flag;\n \t\tconfig.ring_size = IOAT_RING_SIZE;\n \t\tconfig.hdls_disable = true;\n \t\tif (rte_rawdev_configure(dev_id, &info, sizeof(config)) < 0) {\n@@ -126,13 +142,16 @@ ioat_transfer_data_cb(int vid, uint16_t queue_id,\n \t\tstruct rte_vhost_async_status *opaque_data, uint16_t count)\n {\n \tuint32_t i_desc;\n-\tuint16_t dev_id = dma_bind[vid].dmas[queue_id * 2 + VIRTIO_RXQ].dev_id;\n \tstruct rte_vhost_iov_iter *src = NULL;\n \tstruct rte_vhost_iov_iter *dst = NULL;\n \tunsigned long i_seg;\n \tunsigned short mask = MAX_ENQUEUED_SIZE - 1;\n-\tunsigned short write = cb_tracker[dev_id].next_write;\n \n+\tif (queue_id >= MAX_RING_COUNT)\n+\t\treturn -1;\n+\n+\tuint16_t dev_id = dma_bind[vid2socketid[vid]].dmas[queue_id].dev_id;\n+\tunsigned short write = cb_tracker[dev_id].next_write;\n \tif (!opaque_data) {\n \t\tfor (i_desc = 0; i_desc < count; i_desc++) {\n \t\t\tsrc = descs[i_desc].src;\n@@ -170,16 +189,16 @@ ioat_check_completed_copies_cb(int vid, uint16_t queue_id,\n \t\tstruct rte_vhost_async_status *opaque_data,\n \t\tuint16_t max_packets)\n {\n-\tif (!opaque_data) {\n+\tif (!opaque_data && (queue_id < MAX_RING_COUNT)) {\n \t\tuintptr_t dump[255];\n \t\tint n_seg;\n \t\tunsigned short read, write;\n \t\tunsigned short nb_packet = 0;\n \t\tunsigned short mask = MAX_ENQUEUED_SIZE - 1;\n \t\tunsigned short i;\n+\t\tuint16_t dev_id;\n \n-\t\tuint16_t dev_id = dma_bind[vid].dmas[queue_id * 2\n-\t\t\t\t+ VIRTIO_RXQ].dev_id;\n+\t\tdev_id = dma_bind[vid2socketid[vid]].dmas[queue_id].dev_id;\n \t\tn_seg = rte_ioat_completed_ops(dev_id, 255, NULL, NULL, dump, dump);\n \t\tif (n_seg < 0) {\n \t\t\tRTE_LOG(ERR,\n@@ -215,4 +234,18 @@ ioat_check_completed_copies_cb(int vid, uint16_t queue_id,\n \treturn -1;\n }\n \n+uint32_t get_async_flag_by_vid(int vid)\n+{\n+\treturn dma_bind[vid2socketid[vid]].async_flag;\n+}\n+\n+uint32_t get_async_flag_by_socketid(int socketid)\n+{\n+\treturn dma_bind[socketid].async_flag;\n+}\n+\n+void init_vid2socketid_array(int vid, int socketid)\n+{\n+\tvid2socketid[vid] = socketid;\n+}\n #endif /* RTE_RAW_IOAT */\ndiff --git a/examples/vhost/ioat.h b/examples/vhost/ioat.h\nindex 62e163c585..fa5086e662 100644\n--- a/examples/vhost/ioat.h\n+++ b/examples/vhost/ioat.h\n@@ -12,6 +12,9 @@\n #define MAX_VHOST_DEVICE 1024\n #define IOAT_RING_SIZE 4096\n #define MAX_ENQUEUED_SIZE 4096\n+#define MAX_RING_COUNT\t2\n+#define ASYNC_ENQUEUE_VHOST\t1\n+#define ASYNC_DEQUEUE_VHOST\t2\n \n struct dma_info {\n \tstruct rte_pci_addr addr;\n@@ -20,6 +23,7 @@ struct dma_info {\n };\n \n struct dma_for_vhost {\n+\tint async_flag;\n \tstruct dma_info dmas[RTE_MAX_QUEUES_PER_PORT * 2];\n \tuint16_t nr;\n };\n@@ -36,6 +40,10 @@ int32_t\n ioat_check_completed_copies_cb(int vid, uint16_t queue_id,\n \t\tstruct rte_vhost_async_status *opaque_data,\n \t\tuint16_t max_packets);\n+\n+uint32_t get_async_flag_by_vid(int vid);\n+uint32_t get_async_flag_by_socketid(int socketid);\n+void init_vid2socketid_array(int vid, int socketid);\n #else\n static int open_ioat(const char *value __rte_unused)\n {\n@@ -59,5 +67,22 @@ ioat_check_completed_copies_cb(int vid __rte_unused,\n {\n \treturn -1;\n }\n+\n+static uint32_t\n+get_async_flag_by_vid(int vid __rte_unused)\n+{\n+\treturn 0;\n+}\n+\n+static uint32_t\n+get_async_flag_by_socketid(int socketid __rte_unused)\n+{\n+\treturn 0;\n+}\n+\n+static void\n+init_vid2socketid_array(int vid __rte_unused, int socketid __rte_unused)\n+{\n+}\n #endif\n #endif /* _IOAT_H_ */\ndiff --git a/examples/vhost/main.c b/examples/vhost/main.c\nindex e246b640ea..b34534111d 100644\n--- a/examples/vhost/main.c\n+++ b/examples/vhost/main.c\n@@ -93,8 +93,6 @@ static int client_mode;\n \n static int builtin_net_driver;\n \n-static int async_vhost_driver;\n-\n static char *dma_type;\n \n /* Specify timeout (in useconds) between retries on RX. */\n@@ -679,7 +677,6 @@ us_vhost_parse_args(int argc, char **argv)\n \t\t\t\tus_vhost_usage(prgname);\n \t\t\t\treturn -1;\n \t\t\t}\n-\t\t\tasync_vhost_driver = 1;\n \t\t\tbreak;\n \n \t\tcase OPT_CLIENT_NUM:\n@@ -855,7 +852,8 @@ complete_async_pkts(struct vhost_dev *vdev)\n \t\t\t\t\tVIRTIO_RXQ, p_cpl, MAX_PKT_BURST);\n \tif (complete_count) {\n \t\tfree_pkts(p_cpl, complete_count);\n-\t\t__atomic_sub_fetch(&vdev->pkts_inflight, complete_count, __ATOMIC_SEQ_CST);\n+\t\t__atomic_sub_fetch(&vdev->pkts_enq_inflight,\n+\t\t\t\tcomplete_count, __ATOMIC_SEQ_CST);\n \t}\n \n }\n@@ -900,7 +898,7 @@ drain_vhost(struct vhost_dev *vdev)\n \t\t\t\t__ATOMIC_SEQ_CST);\n \t}\n \n-\tif (!async_vhost_driver)\n+\tif ((get_async_flag_by_vid(vdev->vid) & ASYNC_ENQUEUE_VHOST) == 0)\n \t\tfree_pkts(m, nr_xmit);\n }\n \n@@ -1180,8 +1178,8 @@ async_enqueue_pkts(struct vhost_dev *vdev, uint16_t queue_id,\n \tcomplete_async_pkts(vdev);\n \tenqueue_count = rte_vhost_submit_enqueue_burst(vdev->vid,\n \t\t\t\tqueue_id, pkts, rx_count);\n-\t__atomic_add_fetch(&vdev->pkts_inflight, enqueue_count,\n-\t\t\t\t\t__ATOMIC_SEQ_CST);\n+\t__atomic_add_fetch(&vdev->pkts_enq_inflight,\n+\t\t\tenqueue_count, __ATOMIC_SEQ_CST);\n \n \tenqueue_fail = rx_count - enqueue_count;\n \tif (enqueue_fail)\n@@ -1237,10 +1235,23 @@ drain_eth_rx(struct vhost_dev *vdev)\n \t\t\t\t__ATOMIC_SEQ_CST);\n \t}\n \n-\tif (!async_vhost_driver)\n+\tif ((get_async_flag_by_vid(vdev->vid) & ASYNC_ENQUEUE_VHOST) == 0)\n \t\tfree_pkts(pkts, rx_count);\n }\n \n+uint16_t async_dequeue_pkts(struct vhost_dev *dev, uint16_t queue_id,\n+\t\t\t\tstruct rte_mempool *mbuf_pool,\n+\t\t\t\tstruct rte_mbuf **pkts, uint16_t count)\n+{\n+\tint nr_inflight;\n+\tuint16_t dequeue_count;\n+\tdequeue_count = rte_vhost_async_try_dequeue_burst(dev->vid, queue_id,\n+\t\t\tmbuf_pool, pkts, count, &nr_inflight);\n+\tif (likely(nr_inflight != -1))\n+\t\tdev->pkts_deq_inflight = nr_inflight;\n+\treturn dequeue_count;\n+}\n+\n uint16_t sync_dequeue_pkts(struct vhost_dev *dev, uint16_t queue_id,\n \t\t\tstruct rte_mempool *mbuf_pool,\n \t\t\tstruct rte_mbuf **pkts, uint16_t count)\n@@ -1336,6 +1347,32 @@ switch_worker(void *arg __rte_unused)\n \treturn 0;\n }\n \n+static void\n+vhost_clear_queue_thread_unsafe(struct vhost_dev *vdev, uint16_t queue_id)\n+{\n+\tuint16_t n_pkt = 0;\n+\tstruct rte_mbuf *m_enq_cpl[vdev->pkts_enq_inflight];\n+\tstruct rte_mbuf *m_deq_cpl[vdev->pkts_deq_inflight];\n+\n+\tif ((queue_id % VIRTIO_QNUM) == 0) {\n+\t\twhile (vdev->pkts_enq_inflight) {\n+\t\t\tn_pkt = rte_vhost_clear_queue_thread_unsafe(vdev->vid,\n+\t\t\t\tqueue_id, m_enq_cpl, vdev->pkts_enq_inflight);\n+\t\t\tfree_pkts(m_enq_cpl, n_pkt);\n+\t\t\t__atomic_sub_fetch(&vdev->pkts_enq_inflight,\n+\t\t\t\t\tn_pkt, __ATOMIC_SEQ_CST);\n+\t\t}\n+\t} else {\n+\t\twhile (vdev->pkts_deq_inflight) {\n+\t\t\tn_pkt = rte_vhost_clear_queue_thread_unsafe(vdev->vid,\n+\t\t\t\tqueue_id, m_deq_cpl, vdev->pkts_deq_inflight);\n+\t\t\tfree_pkts(m_deq_cpl, n_pkt);\n+\t\t\t__atomic_sub_fetch(&vdev->pkts_deq_inflight,\n+\t\t\t\t\tn_pkt, __ATOMIC_SEQ_CST);\n+\t\t}\n+\t}\n+}\n+\n /*\n  * Remove a device from the specific data core linked list and from the\n  * main linked list. Synchonization  occurs through the use of the\n@@ -1392,21 +1429,91 @@ destroy_device(int vid)\n \t\t\"(%d) device has been removed from data core\\n\",\n \t\tvdev->vid);\n \n-\tif (async_vhost_driver) {\n-\t\tuint16_t n_pkt = 0;\n-\t\tstruct rte_mbuf *m_cpl[vdev->pkts_inflight];\n+\tif (get_async_flag_by_vid(vid) & ASYNC_ENQUEUE_VHOST) {\n+\t\tvhost_clear_queue_thread_unsafe(vdev, VIRTIO_RXQ);\n+\t\trte_vhost_async_channel_unregister(vid, VIRTIO_RXQ);\n+\t}\n+\tif (get_async_flag_by_vid(vid) & ASYNC_DEQUEUE_VHOST) {\n+\t\tvhost_clear_queue_thread_unsafe(vdev, VIRTIO_TXQ);\n+\t\trte_vhost_async_channel_unregister(vid, VIRTIO_TXQ);\n+\t}\n+\n+\trte_free(vdev);\n+}\n+\n+static int\n+get_socketid_by_vid(int vid)\n+{\n+\tint i;\n+\tchar ifname[PATH_MAX];\n+\trte_vhost_get_ifname(vid, ifname, sizeof(ifname));\n+\n+\tfor (i = 0; i < nb_sockets; i++) {\n+\t\tchar *file = socket_files + i * PATH_MAX;\n+\t\tif (strcmp(file, ifname) == 0)\n+\t\t\treturn i;\n+\t}\n+\n+\treturn -1;\n+}\n+\n+static int\n+init_vhost_queue_ops(int vid)\n+{\n+\tint socketid = get_socketid_by_vid(vid);\n+\tif (socketid == -1)\n+\t\treturn -1;\n+\n+\tinit_vid2socketid_array(vid, socketid);\n+\tif (builtin_net_driver) {\n+\t\tvdev_queue_ops[vid].enqueue_pkt_burst = builtin_enqueue_pkts;\n+\t\tvdev_queue_ops[vid].dequeue_pkt_burst = builtin_dequeue_pkts;\n+\t} else {\n+\t\tif (get_async_flag_by_vid(vid) & ASYNC_ENQUEUE_VHOST) {\n+\t\t\tvdev_queue_ops[vid].enqueue_pkt_burst =\n+\t\t\t\t\t\tasync_enqueue_pkts;\n+\t\t} else {\n+\t\t\tvdev_queue_ops[vid].enqueue_pkt_burst =\n+\t\t\t\t\t\tsync_enqueue_pkts;\n+\t\t}\n \n-\t\twhile (vdev->pkts_inflight) {\n-\t\t\tn_pkt = rte_vhost_clear_queue_thread_unsafe(vid, VIRTIO_RXQ,\n-\t\t\t\t\t\tm_cpl, vdev->pkts_inflight);\n-\t\t\tfree_pkts(m_cpl, n_pkt);\n-\t\t\t__atomic_sub_fetch(&vdev->pkts_inflight, n_pkt, __ATOMIC_SEQ_CST);\n+\t\tif (get_async_flag_by_vid(vid) & ASYNC_DEQUEUE_VHOST) {\n+\t\t\tvdev_queue_ops[vid].dequeue_pkt_burst =\n+\t\t\t\t\t\tasync_dequeue_pkts;\n+\t\t} else {\n+\t\t\tvdev_queue_ops[vid].dequeue_pkt_burst =\n+\t\t\t\t\t\tsync_dequeue_pkts;\n \t\t}\n+\t}\n \n-\t\trte_vhost_async_channel_unregister(vid, VIRTIO_RXQ);\n+\treturn 0;\n+}\n+\n+static int\n+vhost_async_channel_register(int vid)\n+{\n+\tint ret = 0;\n+\tstruct rte_vhost_async_config config = {0};\n+\tstruct rte_vhost_async_channel_ops channel_ops;\n+\n+\tif (dma_type != NULL && strncmp(dma_type, \"ioat\", 4) == 0) {\n+\t\tchannel_ops.transfer_data = ioat_transfer_data_cb;\n+\t\tchannel_ops.check_completed_copies =\n+\t\t\tioat_check_completed_copies_cb;\n+\n+\t\tconfig.features = RTE_VHOST_ASYNC_INORDER;\n+\n+\t\tif (get_async_flag_by_vid(vid) & ASYNC_ENQUEUE_VHOST) {\n+\t\t\tret |= rte_vhost_async_channel_register(vid, VIRTIO_RXQ,\n+\t\t\t\t\tconfig, &channel_ops);\n+\t\t}\n+\t\tif (get_async_flag_by_vid(vid) & ASYNC_DEQUEUE_VHOST) {\n+\t\t\tret |= rte_vhost_async_channel_register(vid, VIRTIO_TXQ,\n+\t\t\t\t\tconfig, &channel_ops);\n+\t\t}\n \t}\n \n-\trte_free(vdev);\n+\treturn ret;\n }\n \n /*\n@@ -1442,20 +1549,8 @@ new_device(int vid)\n \t\t}\n \t}\n \n-\tif (builtin_net_driver) {\n-\t\tvdev_queue_ops[vid].enqueue_pkt_burst = builtin_enqueue_pkts;\n-\t\tvdev_queue_ops[vid].dequeue_pkt_burst = builtin_dequeue_pkts;\n-\t} else {\n-\t\tif (async_vhost_driver) {\n-\t\t\tvdev_queue_ops[vid].enqueue_pkt_burst =\n-\t\t\t\t\t\t\tasync_enqueue_pkts;\n-\t\t} else {\n-\t\t\tvdev_queue_ops[vid].enqueue_pkt_burst =\n-\t\t\t\t\t\t\tsync_enqueue_pkts;\n-\t\t}\n-\n-\t\tvdev_queue_ops[vid].dequeue_pkt_burst = sync_dequeue_pkts;\n-\t}\n+\tif (init_vhost_queue_ops(vid) != 0)\n+\t\treturn -1;\n \n \tif (builtin_net_driver)\n \t\tvs_vhost_net_setup(vdev);\n@@ -1484,27 +1579,13 @@ new_device(int vid)\n \trte_vhost_enable_guest_notification(vid, VIRTIO_RXQ, 0);\n \trte_vhost_enable_guest_notification(vid, VIRTIO_TXQ, 0);\n \n+\tint ret = vhost_async_channel_register(vid);\n+\n \tRTE_LOG(INFO, VHOST_DATA,\n \t\t\"(%d) device has been added to data core %d\\n\",\n \t\tvid, vdev->coreid);\n \n-\tif (async_vhost_driver) {\n-\t\tstruct rte_vhost_async_config config = {0};\n-\t\tstruct rte_vhost_async_channel_ops channel_ops;\n-\n-\t\tif (dma_type != NULL && strncmp(dma_type, \"ioat\", 4) == 0) {\n-\t\t\tchannel_ops.transfer_data = ioat_transfer_data_cb;\n-\t\t\tchannel_ops.check_completed_copies =\n-\t\t\t\tioat_check_completed_copies_cb;\n-\n-\t\t\tconfig.features = RTE_VHOST_ASYNC_INORDER;\n-\n-\t\t\treturn rte_vhost_async_channel_register(vid, VIRTIO_RXQ,\n-\t\t\t\tconfig, &channel_ops);\n-\t\t}\n-\t}\n-\n-\treturn 0;\n+\treturn ret;\n }\n \n static int\n@@ -1522,19 +1603,8 @@ vring_state_changed(int vid, uint16_t queue_id, int enable)\n \tif (queue_id != VIRTIO_RXQ)\n \t\treturn 0;\n \n-\tif (async_vhost_driver) {\n-\t\tif (!enable) {\n-\t\t\tuint16_t n_pkt = 0;\n-\t\t\tstruct rte_mbuf *m_cpl[vdev->pkts_inflight];\n-\n-\t\t\twhile (vdev->pkts_inflight) {\n-\t\t\t\tn_pkt = rte_vhost_clear_queue_thread_unsafe(vid, queue_id,\n-\t\t\t\t\t\t\tm_cpl, vdev->pkts_inflight);\n-\t\t\t\tfree_pkts(m_cpl, n_pkt);\n-\t\t\t\t__atomic_sub_fetch(&vdev->pkts_inflight, n_pkt, __ATOMIC_SEQ_CST);\n-\t\t\t}\n-\t\t}\n-\t}\n+\tif (!enable)\n+\t\tvhost_clear_queue_thread_unsafe(vdev, queue_id);\n \n \treturn 0;\n }\n@@ -1778,10 +1848,11 @@ main(int argc, char *argv[])\n \tfor (i = 0; i < nb_sockets; i++) {\n \t\tchar *file = socket_files + i * PATH_MAX;\n \n-\t\tif (async_vhost_driver)\n-\t\t\tflags = flags | RTE_VHOST_USER_ASYNC_COPY;\n+\t\tuint64_t flag = flags;\n+\t\tif (get_async_flag_by_socketid(i) != 0)\n+\t\t\tflag |= RTE_VHOST_USER_ASYNC_COPY;\n \n-\t\tret = rte_vhost_driver_register(file, flags);\n+\t\tret = rte_vhost_driver_register(file, flag);\n \t\tif (ret != 0) {\n \t\t\tunregister_drivers(i);\n \t\t\trte_exit(EXIT_FAILURE,\ndiff --git a/examples/vhost/main.h b/examples/vhost/main.h\nindex 948a23efa6..5af7e7d97f 100644\n--- a/examples/vhost/main.h\n+++ b/examples/vhost/main.h\n@@ -51,7 +51,8 @@ struct vhost_dev {\n \tuint64_t features;\n \tsize_t hdr_len;\n \tuint16_t nr_vrings;\n-\tuint16_t pkts_inflight;\n+\tuint16_t pkts_enq_inflight;\n+\tuint16_t pkts_deq_inflight;\n \tstruct rte_vhost_memory *mem;\n \tstruct device_statistics stats;\n \tTAILQ_ENTRY(vhost_dev) global_vdev_entry;\n",
    "prefixes": [
        "4/4"
    ]
}