get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 138965,
    "url": "https://patches.dpdk.org/api/patches/138965/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/20240328233338.56544-1-rdna@apple.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": "<20240328233338.56544-1-rdna@apple.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20240328233338.56544-1-rdna@apple.com",
    "date": "2024-03-28T23:33:38",
    "name": "vhost: optimize mbuf allocation in virtio Tx packed path",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "6aebd8d9760866cb537dea62bcf575b507c731db",
    "submitter": {
        "id": 3203,
        "url": "https://patches.dpdk.org/api/people/3203/?format=api",
        "name": "Andrey Ignatov",
        "email": "rdna@apple.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/20240328233338.56544-1-rdna@apple.com/mbox/",
    "series": [
        {
            "id": 31645,
            "url": "https://patches.dpdk.org/api/series/31645/?format=api",
            "web_url": "https://patches.dpdk.org/project/dpdk/list/?series=31645",
            "date": "2024-03-28T23:33:38",
            "name": "vhost: optimize mbuf allocation in virtio Tx packed path",
            "version": 1,
            "mbox": "https://patches.dpdk.org/series/31645/mbox/"
        }
    ],
    "comments": "https://patches.dpdk.org/api/patches/138965/comments/",
    "check": "fail",
    "checks": "https://patches.dpdk.org/api/patches/138965/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 3B2C243D73;\n\tFri, 29 Mar 2024 00:35:54 +0100 (CET)",
            "from mails.dpdk.org (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 1946040268;\n\tFri, 29 Mar 2024 00:35:52 +0100 (CET)",
            "from rn-mailsvcp-mx-lapp03.apple.com\n (rn-mailsvcp-mx-lapp03.apple.com [17.179.253.24])\n by mails.dpdk.org (Postfix) with ESMTP id 74E7840042\n for <dev@dpdk.org>; Fri, 29 Mar 2024 00:35:49 +0100 (CET)",
            "from rn-mailsvcp-mta-lapp02.rno.apple.com\n (rn-mailsvcp-mta-lapp02.rno.apple.com [10.225.203.150])\n by rn-mailsvcp-mx-lapp03.rno.apple.com\n (Oracle Communications Messaging Server 8.1.0.23.20230328 64bit (built Mar 28\n 2023)) with ESMTPS id <0SB3011TZ07OQ500@rn-mailsvcp-mx-lapp03.rno.apple.com>\n for dev@dpdk.org; Thu, 28 Mar 2024 16:35:48 -0700 (PDT)",
            "from rn-mailsvcp-mmp-lapp02.rno.apple.com\n (rn-mailsvcp-mmp-lapp02.rno.apple.com [17.179.253.15])\n by rn-mailsvcp-mta-lapp02.rno.apple.com\n (Oracle Communications Messaging Server 8.1.0.23.20230328 64bit (built Mar 28\n 2023)) with ESMTPS id\n <0SB3004KL07OQUA0@rn-mailsvcp-mta-lapp02.rno.apple.com>;\n Thu, 28 Mar 2024 16:35:48 -0700 (PDT)",
            "from process_milters-daemon.rn-mailsvcp-mmp-lapp02.rno.apple.com by\n rn-mailsvcp-mmp-lapp02.rno.apple.com\n (Oracle Communications Messaging Server 8.1.0.23.20230328 64bit (built Mar 28\n 2023)) id <0SB300S000231300@rn-mailsvcp-mmp-lapp02.rno.apple.com>; Thu,\n 28 Mar 2024 16:35:48 -0700 (PDT)",
            "from localhost (unknown [17.192.171.224])\n by rn-mailsvcp-mmp-lapp02.rno.apple.com\n (Oracle Communications Messaging Server 8.1.0.23.20230328 64bit (built Mar 28\n 2023))\n with ESMTPSA id <0SB300JAK07OQ600@rn-mailsvcp-mmp-lapp02.rno.apple.com>; Thu,\n 28 Mar 2024 16:35:48 -0700 (PDT)"
        ],
        "X-Proofpoint-Virus-Version": [
            "vendor=baseguard\n engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26\n definitions=2024-03-28_17,2024-03-28_01,2023-05-22_02",
            "vendor=baseguard\n engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26\n definitions=2024-03-28_17,2024-03-28_01,2023-05-22_02"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=apple.com; h=from : to\n : cc : subject : date : message-id : mime-version :\n content-transfer-encoding;\n s=20180706; bh=vfGhas7yJSeKXbAp5HUn/ZCLEX1xfhOOR4QzMXiksZU=;\n b=BKIAP9Iwxhuf4BJpF+eiO1taMwFefqe9Jazpcu5ZEePaO6YfiLgvUxy4md7e/0EHExXX\n pL+hTo98XWWXVh4cJbAojFq++o9aTlDuZOm3+ebaDCJv1UgwGWl16tkBmiwbX5cvYUA7\n 6Whx9xzdJQOi5LPk72eTqAkyAewLTGBIGnXHgyWIyq4Q2lrAPz0wpwpmyvl933CjTZX7\n 92wfhAYkWlfWykYtB04+mzAiDFGEglKrKtuS6LSbrNnBywQQiueHSg/IgFV9XKk2mQ4f\n 8SpL6c2hoMIF0SMiWmS6MfFB74xCgY9msmmgSWDk3txKWHRkcbU1eJ2bMrJMfPJ22E13 iQ==",
        "X-Va-A": "",
        "X-Va-T-CD": "890ecbe268e4da4a9b8ebf5646b77237",
        "X-Va-E-CD": "562329c792fa7855219cca3742546f23",
        "X-Va-R-CD": "b1971efc66bc3425806df554b278f494",
        "X-Va-ID": "33691462-f8f9-410d-8e09-cfe330421288",
        "X-Va-CD": "0",
        "X-V-A": "",
        "X-V-T-CD": "890ecbe268e4da4a9b8ebf5646b77237",
        "X-V-E-CD": "562329c792fa7855219cca3742546f23",
        "X-V-R-CD": "b1971efc66bc3425806df554b278f494",
        "X-V-ID": "026902e4-9260-46d6-9487-a86b6c6074ac",
        "X-V-CD": "0",
        "From": "Andrey Ignatov <rdna@apple.com>",
        "To": "dev@dpdk.org",
        "Cc": "Maxime Coquelin <maxime.coquelin@redhat.com>,\n Chenbo Xia <chenbox@nvidia.com>, Wei Shen <wshen0123@apple.com>,\n Andrey Ignatov <rdna@apple.com>",
        "Subject": "[PATCH] vhost: optimize mbuf allocation in virtio Tx packed path",
        "Date": "Thu, 28 Mar 2024 16:33:38 -0700",
        "Message-id": "<20240328233338.56544-1-rdna@apple.com>",
        "X-Mailer": "git-send-email 2.39.3 (Apple Git-147)",
        "MIME-version": "1.0",
        "Content-transfer-encoding": "8bit",
        "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"
    },
    "content": "Currently virtio_dev_tx_packed() always allocates requested @count of\npackets, no matter how many packets are really available on the virtio\nTx ring. Later it has to free all packets it didn't use and if, for\nexample, there were zero available packets on the ring, then all @count\nmbufs would be allocated just to be freed afterwards.\n\nThis wastes CPU cycles since rte_pktmbuf_alloc_bulk() /\nrte_pktmbuf_free_bulk() do quite a lot of work.\n\nOptimize it by using the same idea as the virtio_dev_tx_split() uses on\nthe Tx split path: estimate the number of available entries on the ring\nand allocate only that number of mbufs.\n\nOn the split path it's pretty easy to estimate.\n\nOn the packed path it's more work since it requires checking flags for\nup to @count of descriptors. Still it's much less expensive than the\nalloc/free pair.\n\nThe new get_nb_avail_entries_packed() function doesn't change how\nvirtio_dev_tx_packed() works with regard to memory barriers since the\nbarrier between checking flags and other descriptor fields is still in\nplace later in virtio_dev_tx_batch_packed() and\nvirtio_dev_tx_single_packed().\n\nThe difference for a guest transmitting ~17Gbps with MTU 1500 on a `perf\nrecord` / `perf report` (on lower pps the savings will be bigger):\n\n* Before the change:\n\n    Samples: 18K of event 'cycles:P', Event count (approx.): 19206831288\n      Children      Self      Pid:Command\n    -  100.00%   100.00%   798808:dpdk-worker1\n                <... skip ...>\n                - 99.09% pkt_burst_io_forward\n                   - 90.26% common_fwd_stream_receive\n                      - 90.04% rte_eth_rx_burst\n                         - 75.53% eth_vhost_rx\n                            - 74.29% rte_vhost_dequeue_burst\n                               - 71.48% virtio_dev_tx_packed_compliant\n                                  + 17.11% rte_pktmbuf_alloc_bulk\n                                  + 11.80% rte_pktmbuf_free_bulk\n                                  + 2.11% vhost_user_inject_irq\n                                    0.75% rte_pktmbuf_reset\n                                    0.53% __rte_pktmbuf_free_seg_via_array\n                                 0.88% vhost_queue_stats_update\n                         + 13.66% mlx5_rx_burst_vec\n                   + 8.69% common_fwd_stream_transmit\n\n* After:\n\n    Samples: 18K of event 'cycles:P', Event count (approx.): 19225310840\n      Children      Self      Pid:Command\n    -  100.00%   100.00%   859754:dpdk-worker1\n                <... skip ...>\n                - 98.61% pkt_burst_io_forward\n                   - 86.29% common_fwd_stream_receive\n                      - 85.84% rte_eth_rx_burst\n                         - 61.94% eth_vhost_rx\n                            - 60.05% rte_vhost_dequeue_burst\n                               - 55.98% virtio_dev_tx_packed_compliant\n                                  + 3.43% rte_pktmbuf_alloc_bulk\n                                  + 2.50% vhost_user_inject_irq\n                                 1.17% vhost_queue_stats_update\n                                 0.76% rte_rwlock_read_unlock\n                                 0.54% rte_rwlock_read_trylock\n                         + 22.21% mlx5_rx_burst_vec\n                   + 12.00% common_fwd_stream_transmit\n\nIt can be seen that virtio_dev_tx_packed_compliant() goes from 71.48% to\n55.98% with rte_pktmbuf_alloc_bulk() going from 17.11% to 3.43% and\nrte_pktmbuf_free_bulk() going away completely.\n\nSigned-off-by: Andrey Ignatov <rdna@apple.com>\n---\n lib/vhost/virtio_net.c | 33 +++++++++++++++++++++++++++++++++\n 1 file changed, 33 insertions(+)",
    "diff": "diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c\nindex 1359c5fb1f..b406b5d7d9 100644\n--- a/lib/vhost/virtio_net.c\n+++ b/lib/vhost/virtio_net.c\n@@ -3484,6 +3484,35 @@ virtio_dev_tx_single_packed(struct virtio_net *dev,\n \treturn ret;\n }\n \n+static __rte_always_inline uint16_t\n+get_nb_avail_entries_packed(const struct vhost_virtqueue *__rte_restrict vq,\n+\t\t\t    uint16_t max_nb_avail_entries)\n+{\n+\tconst struct vring_packed_desc *descs = vq->desc_packed;\n+\tbool avail_wrap = vq->avail_wrap_counter;\n+\tuint16_t avail_idx = vq->last_avail_idx;\n+\tuint16_t nb_avail_entries = 0;\n+\tuint16_t flags;\n+\n+\twhile (nb_avail_entries < max_nb_avail_entries) {\n+\t\tflags = descs[avail_idx].flags;\n+\n+\t\tif ((avail_wrap != !!(flags & VRING_DESC_F_AVAIL)) ||\n+\t\t    (avail_wrap == !!(flags & VRING_DESC_F_USED)))\n+\t\t\treturn nb_avail_entries;\n+\n+\t\tif (!(flags & VRING_DESC_F_NEXT))\n+\t\t\t++nb_avail_entries;\n+\n+\t\tif (unlikely(++avail_idx >= vq->size)) {\n+\t\t\tavail_idx -= vq->size;\n+\t\t\tavail_wrap = !avail_wrap;\n+\t\t}\n+\t}\n+\n+\treturn nb_avail_entries;\n+}\n+\n __rte_always_inline\n static uint16_t\n virtio_dev_tx_packed(struct virtio_net *dev,\n@@ -3497,6 +3526,10 @@ virtio_dev_tx_packed(struct virtio_net *dev,\n {\n \tuint32_t pkt_idx = 0;\n \n+\tcount = get_nb_avail_entries_packed(vq, count);\n+\tif (count == 0)\n+\t\treturn 0;\n+\n \tif (rte_pktmbuf_alloc_bulk(mbuf_pool, pkts, count)) {\n \t\tvq->stats.mbuf_alloc_failed += count;\n \t\treturn 0;\n",
    "prefixes": []
}