get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 2532,
    "url": "https://patches.dpdk.org/api/patches/2532/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/1422326164-13697-17-git-send-email-changchun.ouyang@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": "<1422326164-13697-17-git-send-email-changchun.ouyang@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1422326164-13697-17-git-send-email-changchun.ouyang@intel.com",
    "date": "2015-01-27T02:35:56",
    "name": "[dpdk-dev,v2,16/24] virtio: Free mbuf's with threshold",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "732394e2f812d86dc6380bb335520fb70a1d7557",
    "submitter": {
        "id": 31,
        "url": "https://patches.dpdk.org/api/people/31/?format=api",
        "name": "Ouyang Changchun",
        "email": "changchun.ouyang@intel.com"
    },
    "delegate": null,
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/1422326164-13697-17-git-send-email-changchun.ouyang@intel.com/mbox/",
    "series": [],
    "comments": "https://patches.dpdk.org/api/patches/2532/comments/",
    "check": "pending",
    "checks": "https://patches.dpdk.org/api/patches/2532/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@dpdk.org",
        "Delivered-To": "patchwork@dpdk.org",
        "Received": [
            "from [92.243.14.124] (localhost [IPv6:::1])\n\tby dpdk.org (Postfix) with ESMTP id CD1AC5AE0;\n\tTue, 27 Jan 2015 03:38:07 +0100 (CET)",
            "from mga11.intel.com (mga11.intel.com [192.55.52.93])\n\tby dpdk.org (Postfix) with ESMTP id 21BFF5A9F\n\tfor <dev@dpdk.org>; Tue, 27 Jan 2015 03:36:52 +0100 (CET)",
            "from fmsmga003.fm.intel.com ([10.253.24.29])\n\tby fmsmga102.fm.intel.com with ESMTP; 26 Jan 2015 18:36:48 -0800",
            "from shvmail01.sh.intel.com ([10.239.29.42])\n\tby FMSMGA003.fm.intel.com with ESMTP; 26 Jan 2015 18:23:08 -0800",
            "from shecgisg004.sh.intel.com (shecgisg004.sh.intel.com\n\t[10.239.29.89])\n\tby shvmail01.sh.intel.com with ESMTP id t0R2akLs015704;\n\tTue, 27 Jan 2015 10:36:46 +0800",
            "from shecgisg004.sh.intel.com (localhost [127.0.0.1])\n\tby shecgisg004.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP\n\tid t0R2ahA6013842; Tue, 27 Jan 2015 10:36:45 +0800",
            "(from couyang@localhost)\n\tby shecgisg004.sh.intel.com (8.13.6/8.13.6/Submit) id t0R2ahpH013838; \n\tTue, 27 Jan 2015 10:36:43 +0800"
        ],
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"4.97,862,1389772800\"; d=\"scan'208\";a=\"445541611\"",
        "From": "Ouyang Changchun <changchun.ouyang@intel.com>",
        "To": "dev@dpdk.org",
        "Date": "Tue, 27 Jan 2015 10:35:56 +0800",
        "Message-Id": "<1422326164-13697-17-git-send-email-changchun.ouyang@intel.com>",
        "X-Mailer": "git-send-email 1.7.12.2",
        "In-Reply-To": "<1422326164-13697-1-git-send-email-changchun.ouyang@intel.com>",
        "References": "<1421298930-15210-1-git-send-email-changchun.ouyang@intel.com>\n\t<1422326164-13697-1-git-send-email-changchun.ouyang@intel.com>",
        "Subject": "[dpdk-dev] [PATCH v2 16/24] virtio: Free mbuf's with threshold",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "patches and discussions about DPDK <dev.dpdk.org>",
        "List-Unsubscribe": "<http://dpdk.org/ml/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://dpdk.org/ml/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<http://dpdk.org/ml/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "This makes virtio driver work like ixgbe. Transmit buffers are\nheld until a transmit threshold is reached. The previous behavior\nwas to hold mbuf's until the ring entry was reused which caused\nmore memory usage than needed.\n\nSigned-off-by: Stephen Hemminger <stephen@networkplumber.org>\nSigned-off-by: Changchun Ouyang <changchun.ouyang@intel.com>\n---\n lib/librte_pmd_virtio/virtio_ethdev.c |  7 ++--\n lib/librte_pmd_virtio/virtio_rxtx.c   | 75 +++++++++++++++++++++++++----------\n lib/librte_pmd_virtio/virtqueue.h     |  3 +-\n 3 files changed, 60 insertions(+), 25 deletions(-)",
    "diff": "diff --git a/lib/librte_pmd_virtio/virtio_ethdev.c b/lib/librte_pmd_virtio/virtio_ethdev.c\nindex b30ab2a..8cd2d51 100644\n--- a/lib/librte_pmd_virtio/virtio_ethdev.c\n+++ b/lib/librte_pmd_virtio/virtio_ethdev.c\n@@ -176,15 +176,16 @@ virtio_send_command(struct virtqueue *vq, struct virtio_pmd_ctrl *ctrl,\n \n \tvirtqueue_notify(vq);\n \n-\twhile (vq->vq_used_cons_idx == vq->vq_ring.used->idx)\n+\trte_rmb();\n+\twhile (vq->vq_used_cons_idx == vq->vq_ring.used->idx) {\n+\t\trte_rmb();\n \t\tusleep(100);\n+\t}\n \n \twhile (vq->vq_used_cons_idx != vq->vq_ring.used->idx) {\n \t\tuint32_t idx, desc_idx, used_idx;\n \t\tstruct vring_used_elem *uep;\n \n-\t\tvirtio_rmb();\n-\n \t\tused_idx = (uint32_t)(vq->vq_used_cons_idx\n \t\t\t\t& (vq->vq_nentries - 1));\n \t\tuep = &vq->vq_ring.used->ring[used_idx];\ndiff --git a/lib/librte_pmd_virtio/virtio_rxtx.c b/lib/librte_pmd_virtio/virtio_rxtx.c\nindex b6d6832..580701a 100644\n--- a/lib/librte_pmd_virtio/virtio_rxtx.c\n+++ b/lib/librte_pmd_virtio/virtio_rxtx.c\n@@ -129,17 +129,32 @@ virtqueue_dequeue_burst_rx(struct virtqueue *vq, struct rte_mbuf **rx_pkts,\n \treturn i;\n }\n \n+#ifndef DEFAULT_TX_FREE_THRESH\n+#define DEFAULT_TX_FREE_THRESH 32\n+#endif\n+\n+/* Cleanup from completed transmits. */\n static void\n-virtqueue_dequeue_pkt_tx(struct virtqueue *vq)\n+virtio_xmit_cleanup(struct virtqueue *vq, uint16_t num)\n {\n-\tstruct vring_used_elem *uep;\n-\tuint16_t used_idx, desc_idx;\n+\tuint16_t i, used_idx, desc_idx;\n+\tfor (i = 0; i < num; i++) {\n+\t\tstruct vring_used_elem *uep;\n+\t\tstruct vq_desc_extra *dxp;\n+\n+\t\tused_idx = (uint16_t)(vq->vq_used_cons_idx & (vq->vq_nentries - 1));\n+\t\tuep = &vq->vq_ring.used->ring[used_idx];\n+\t\tdxp = &vq->vq_descx[used_idx];\n+\n+\t\tdesc_idx = (uint16_t) uep->id;\n+\t\tvq->vq_used_cons_idx++;\n+\t\tvq_ring_free_chain(vq, desc_idx);\n \n-\tused_idx = (uint16_t)(vq->vq_used_cons_idx & (vq->vq_nentries - 1));\n-\tuep = &vq->vq_ring.used->ring[used_idx];\n-\tdesc_idx = (uint16_t) uep->id;\n-\tvq->vq_used_cons_idx++;\n-\tvq_ring_free_chain(vq, desc_idx);\n+\t\tif (dxp->cookie != NULL) {\n+\t\t\trte_pktmbuf_free(dxp->cookie);\n+\t\t\tdxp->cookie = NULL;\n+\t\t}\n+\t}\n }\n \n \n@@ -203,8 +218,6 @@ virtqueue_enqueue_xmit(struct virtqueue *txvq, struct rte_mbuf *cookie)\n \n \tidx = head_idx;\n \tdxp = &txvq->vq_descx[idx];\n-\tif (dxp->cookie != NULL)\n-\t\trte_pktmbuf_free(dxp->cookie);\n \tdxp->cookie = (void *)cookie;\n \tdxp->ndescs = needed;\n \n@@ -404,6 +417,7 @@ virtio_dev_tx_queue_setup(struct rte_eth_dev *dev,\n {\n \tuint8_t vtpci_queue_idx = 2 * queue_idx + VTNET_SQ_TQ_QUEUE_IDX;\n \tstruct virtqueue *vq;\n+\tuint16_t tx_free_thresh;\n \tint ret;\n \n \tPMD_INIT_FUNC_TRACE();\n@@ -421,6 +435,22 @@ virtio_dev_tx_queue_setup(struct rte_eth_dev *dev,\n \t\treturn ret;\n \t}\n \n+\ttx_free_thresh = tx_conf->tx_free_thresh;\n+\tif (tx_free_thresh == 0)\n+\t\ttx_free_thresh =\n+\t\t\tRTE_MIN(vq->vq_nentries / 4, DEFAULT_TX_FREE_THRESH);\n+\n+\tif (tx_free_thresh >= (vq->vq_nentries - 3)) {\n+\t\tRTE_LOG(ERR, PMD, \"tx_free_thresh must be less than the \"\n+\t\t\t\"number of TX entries minus 3 (%u).\"\n+\t\t\t\" (tx_free_thresh=%u port=%u queue=%u)\\n\",\n+\t\t\tvq->vq_nentries - 3,\n+\t\t\ttx_free_thresh, dev->data->port_id, queue_idx);\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tvq->vq_free_thresh = tx_free_thresh;\n+\n \tdev->data->tx_queues[queue_idx] = vq;\n \treturn 0;\n }\n@@ -688,11 +718,9 @@ virtio_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)\n {\n \tstruct virtqueue *txvq = tx_queue;\n \tstruct rte_mbuf *txm;\n-\tuint16_t nb_used, nb_tx, num;\n+\tuint16_t nb_used, nb_tx;\n \tint error;\n \n-\tnb_tx = 0;\n-\n \tif (unlikely(nb_pkts < 1))\n \t\treturn nb_pkts;\n \n@@ -700,21 +728,26 @@ virtio_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)\n \tnb_used = VIRTQUEUE_NUSED(txvq);\n \n \tvirtio_rmb();\n+\tif (likely(nb_used > txvq->vq_free_thresh))\n+\t\tvirtio_xmit_cleanup(txvq, nb_used);\n \n-\tnum = (uint16_t)(likely(nb_used < VIRTIO_MBUF_BURST_SZ) ? nb_used : VIRTIO_MBUF_BURST_SZ);\n+\tnb_tx = 0;\n \n \twhile (nb_tx < nb_pkts) {\n \t\t/* Need one more descriptor for virtio header. */\n \t\tint need = tx_pkts[nb_tx]->nb_segs - txvq->vq_free_cnt + 1;\n-\t\tint deq_cnt = RTE_MIN(need, (int)num);\n \n-\t\tnum -= (deq_cnt > 0) ? deq_cnt : 0;\n-\t\twhile (deq_cnt > 0) {\n-\t\t\tvirtqueue_dequeue_pkt_tx(txvq);\n-\t\t\tdeq_cnt--;\n+\t\t/*Positive value indicates it need free vring descriptors */\n+\t\tif (unlikely(need > 0)) {\n+\t\t\tnb_used = VIRTQUEUE_NUSED(txvq);\n+\t\t\tvirtio_rmb();\n+\t\t\tneed = RTE_MIN(need, (int)nb_used);\n+\n+\t\t\tvirtio_xmit_cleanup(txvq, need);\n+\t\t\tneed = (int)tx_pkts[nb_tx]->nb_segs -\n+\t\t\t\ttxvq->vq_free_cnt + 1;\n \t\t}\n \n-\t\tneed = (int)tx_pkts[nb_tx]->nb_segs - txvq->vq_free_cnt + 1;\n \t\t/*\n \t\t * Zero or negative value indicates it has enough free\n \t\t * descriptors to use for transmitting.\n@@ -723,7 +756,7 @@ virtio_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)\n \t\t\ttxm = tx_pkts[nb_tx];\n \n \t\t\t/* Do VLAN tag insertion */\n-\t\t\tif (txm->ol_flags & PKT_TX_VLAN_PKT) {\n+\t\t\tif (unlikely(txm->ol_flags & PKT_TX_VLAN_PKT)) {\n \t\t\t\terror = rte_vlan_insert(&txm);\n \t\t\t\tif (unlikely(error)) {\n \t\t\t\t\trte_pktmbuf_free(txm);\ndiff --git a/lib/librte_pmd_virtio/virtqueue.h b/lib/librte_pmd_virtio/virtqueue.h\nindex d210f4f..6c45c27 100644\n--- a/lib/librte_pmd_virtio/virtqueue.h\n+++ b/lib/librte_pmd_virtio/virtqueue.h\n@@ -164,6 +164,7 @@ struct virtqueue {\n \tstruct rte_mempool       *mpool;  /**< mempool for mbuf allocation */\n \tuint16_t    queue_id;             /**< DPDK queue index. */\n \tuint8_t     port_id;              /**< Device port identifier. */\n+\tuint16_t    vq_queue_index;       /**< PCI queue index */\n \n \tvoid        *vq_ring_virt_mem;    /**< linear address of vring*/\n \tunsigned int vq_ring_size;\n@@ -172,7 +173,7 @@ struct virtqueue {\n \tstruct vring vq_ring;    /**< vring keeping desc, used and avail */\n \tuint16_t    vq_free_cnt; /**< num of desc available */\n \tuint16_t    vq_nentries; /**< vring desc numbers */\n-\tuint16_t    vq_queue_index;       /**< PCI queue index */\n+\tuint16_t    vq_free_thresh; /**< free threshold */\n \t/**\n \t * Head of the free chain in the descriptor table. If\n \t * there are no free descriptors, this will be set to\n",
    "prefixes": [
        "dpdk-dev",
        "v2",
        "16/24"
    ]
}