get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 1136,
    "url": "https://patches.dpdk.org/api/patches/1136/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/1415171435-24252-3-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": "<1415171435-24252-3-git-send-email-changchun.ouyang@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1415171435-24252-3-git-send-email-changchun.ouyang@intel.com",
    "date": "2014-11-05T07:10:34",
    "name": "[dpdk-dev,v4,2/3] vhost: Remove duplicated codes",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": true,
    "hash": "446c152c7ceecd1daa0a67f9ed90d5691f2e9366",
    "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/1415171435-24252-3-git-send-email-changchun.ouyang@intel.com/mbox/",
    "series": [],
    "comments": "https://patches.dpdk.org/api/patches/1136/comments/",
    "check": "pending",
    "checks": "https://patches.dpdk.org/api/patches/1136/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 BFF0D7F34;\n\tWed,  5 Nov 2014 08:01:30 +0100 (CET)",
            "from mga03.intel.com (mga03.intel.com [134.134.136.65])\n\tby dpdk.org (Postfix) with ESMTP id CF8E07F28\n\tfor <dev@dpdk.org>; Wed,  5 Nov 2014 08:01:25 +0100 (CET)",
            "from orsmga001.jf.intel.com ([10.7.209.18])\n\tby orsmga103.jf.intel.com with ESMTP; 04 Nov 2014 23:08:44 -0800",
            "from shvmail01.sh.intel.com ([10.239.29.42])\n\tby orsmga001.jf.intel.com with ESMTP; 04 Nov 2014 23:10:45 -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 sA57AhFN031787;\n\tWed, 5 Nov 2014 15:10:43 +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 sA57Af5K024299; Wed, 5 Nov 2014 15:10:43 +0800",
            "(from couyang@localhost)\n\tby shecgisg004.sh.intel.com (8.13.6/8.13.6/Submit) id sA57AfmL024295; \n\tWed, 5 Nov 2014 15:10:41 +0800"
        ],
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.07,317,1413270000\"; d=\"scan'208\";a=\"602539943\"",
        "From": "Ouyang Changchun <changchun.ouyang@intel.com>",
        "To": "dev@dpdk.org",
        "Date": "Wed,  5 Nov 2014 15:10:34 +0800",
        "Message-Id": "<1415171435-24252-3-git-send-email-changchun.ouyang@intel.com>",
        "X-Mailer": "git-send-email 1.7.12.2",
        "In-Reply-To": "<1415171435-24252-1-git-send-email-changchun.ouyang@intel.com>",
        "References": "<1415084708-8192-1-git-send-email-changchun.ouyang@intel.com>\n\t<1415171435-24252-1-git-send-email-changchun.ouyang@intel.com>",
        "Subject": "[dpdk-dev] [PATCH v4 2/3] vhost: Remove duplicated codes",
        "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": "Extract a function to replace duplicated codes in one copy and zero copy TX function.\n\nSigned-off-by: Changchun Ouyang <changchun.ouyang@intel.com>\n---\n examples/vhost/main.c | 139 +++++++++++++++++++++-----------------------------\n 1 file changed, 58 insertions(+), 81 deletions(-)",
    "diff": "diff --git a/examples/vhost/main.c b/examples/vhost/main.c\nindex 5ca8dce..2916313 100644\n--- a/examples/vhost/main.c\n+++ b/examples/vhost/main.c\n@@ -1040,6 +1040,57 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)\n }\n \n /*\n+ * Check if the destination MAC of a packet is one local VM,\n+ * and get its vlan tag, and offset if it is.\n+ */\n+static inline int __attribute__((always_inline))\n+find_local_dest(struct virtio_net *dev, struct rte_mbuf *m,\n+\tuint32_t *offset, uint16_t *vlan_tag)\n+{\n+\tstruct virtio_net_data_ll *dev_ll = ll_root_used;\n+\tstruct ether_hdr *pkt_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);\n+\n+\twhile (dev_ll != NULL) {\n+\t\tif ((dev_ll->vdev->ready == DEVICE_RX)\n+\t\t\t&& ether_addr_cmp(&(pkt_hdr->d_addr),\n+\t\t&dev_ll->vdev->mac_address)) {\n+\t\t\t/*\n+\t\t\t * Drop the packet if the TX packet is\n+\t\t\t * destined for the TX device.\n+\t\t\t */\n+\t\t\tif (dev_ll->vdev->dev->device_fh == dev->device_fh) {\n+\t\t\t\tLOG_DEBUG(VHOST_DATA,\n+\t\t\t\t\"(%\"PRIu64\") TX: Source and destination\"\n+\t\t\t\t\" MAC addresses are the same. Dropping \"\n+\t\t\t\t\"packet.\\n\",\n+\t\t\t\tdev_ll->vdev->dev->device_fh);\n+\t\t\t\treturn -1;\n+\t\t\t}\n+\n+\t\t\t/*\n+\t\t\t * HW vlan strip will reduce the packet length\n+\t\t\t * by minus length of vlan tag, so need restore\n+\t\t\t * the packet length by plus it.\n+\t\t\t */\n+\t\t\t*offset = VLAN_HLEN;\n+\t\t\t*vlan_tag =\n+\t\t\t(uint16_t)\n+\t\t\tvlan_tags[(uint16_t)dev_ll->vdev->dev->device_fh];\n+\n+\t\t\tLOG_DEBUG(VHOST_DATA,\n+\t\t\t\"(%\"PRIu64\") TX: pkt to local VM device id:\"\n+\t\t\t\"(%\"PRIu64\") vlan tag: %d.\\n\",\n+\t\t\tdev->device_fh, dev_ll->vdev->dev->device_fh,\n+\t\t\tvlan_tag);\n+\n+\t\t\tbreak;\n+\t\t}\n+\t\tdev_ll = dev_ll->next;\n+\t}\n+\treturn 0;\n+}\n+\n+/*\n  * This function routes the TX packet to the correct interface. This may be a local device\n  * or the physical port.\n  */\n@@ -1050,8 +1101,6 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)\n \tstruct rte_mbuf **m_table;\n \tunsigned len, ret, offset = 0;\n \tconst uint16_t lcore_id = rte_lcore_id();\n-\tstruct virtio_net_data_ll *dev_ll = ll_root_used;\n-\tstruct ether_hdr *pkt_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);\n \tstruct virtio_net *dev = vdev->dev;\n \n \t/*check if destination is local VM*/\n@@ -1061,43 +1110,9 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)\n \t}\n \n \tif (vm2vm_mode == VM2VM_HARDWARE) {\n-\t\twhile (dev_ll != NULL) {\n-\t\t\tif ((dev_ll->vdev->ready == DEVICE_RX)\n-\t\t\t\t&& ether_addr_cmp(&(pkt_hdr->d_addr),\n-\t\t\t\t&dev_ll->vdev->mac_address)) {\n-\t\t\t\t/*\n-\t\t\t\t * Drop the packet if the TX packet is\n-\t\t\t\t * destined for the TX device.\n-\t\t\t\t */\n-\t\t\t\tif (dev_ll->vdev->dev->device_fh == dev->device_fh) {\n-\t\t\t\t\tLOG_DEBUG(VHOST_DATA,\n-\t\t\t\t\t\"(%\"PRIu64\") TX: Source and destination\"\n-\t\t\t\t\t\" MAC addresses are the same. Dropping \"\n-\t\t\t\t\t\"packet.\\n\",\n-\t\t\t\t\tdev_ll->vdev->dev->device_fh);\n-\t\t\t\t\trte_pktmbuf_free(m);\n-\t\t\t\t\treturn;\n-\t\t\t\t}\n-\n-\t\t\t\t/*\n-\t\t\t\t * HW vlan strip will reduce the packet length\n-\t\t\t\t * by minus length of vlan tag, so need restore\n-\t\t\t\t * the packet length by plus it.\n-\t\t\t\t */\n-\t\t\t\toffset = VLAN_HLEN;\n-\t\t\t\tvlan_tag =\n-\t\t\t\t(uint16_t)\n-\t\t\t\tvlan_tags[(uint16_t)dev_ll->vdev->dev->device_fh];\n-\n-\t\t\t\tLOG_DEBUG(VHOST_DATA,\n-\t\t\t\t\"(%\"PRIu64\") TX: pkt to local VM device id:\"\n-\t\t\t\t\"(%\"PRIu64\") vlan tag: %d.\\n\",\n-\t\t\t\tdev->device_fh, dev_ll->vdev->dev->device_fh,\n-\t\t\t\tvlan_tag);\n-\n-\t\t\t\tbreak;\n-\t\t\t}\n-\t\t\tdev_ll = dev_ll->next;\n+\t\tif (find_local_dest(dev, m, &offset, &vlan_tag) != 0) {\n+\t\t\trte_pktmbuf_free(m);\n+\t\t\treturn;\n \t\t}\n \t}\n \n@@ -1726,8 +1741,6 @@ virtio_tx_route_zcp(struct virtio_net *dev, struct rte_mbuf *m,\n \tstruct rte_mbuf *mbuf = NULL;\n \tunsigned len, ret, offset = 0;\n \tstruct vpool *vpool;\n-\tstruct virtio_net_data_ll *dev_ll = ll_root_used;\n-\tstruct ether_hdr *pkt_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);\n \tuint16_t vlan_tag = (uint16_t)vlan_tags[(uint16_t)dev->device_fh];\n \tuint16_t vmdq_rx_q = ((struct vhost_dev *)dev->priv)->vmdq_rx_q;\n \n@@ -1756,46 +1769,10 @@ virtio_tx_route_zcp(struct virtio_net *dev, struct rte_mbuf *m,\n \t\t * such a ambiguous situation, so pkt will lost.\n \t\t */\n \t\tvlan_tag = external_pkt_default_vlan_tag;\n-\t\twhile (dev_ll != NULL) {\n-\t\t\tif (likely(dev_ll->vdev->ready == DEVICE_RX) &&\n-\t\t\t\tether_addr_cmp(&(pkt_hdr->d_addr),\n-\t\t\t\t&dev_ll->vdev->mac_address)) {\n-\n-\t\t\t\t/*\n-\t\t\t\t * Drop the packet if the TX packet is destined\n-\t\t\t\t * for the TX device.\n-\t\t\t\t */\n-\t\t\t\tif (unlikely(dev_ll->vdev->dev->device_fh\n-\t\t\t\t\t== dev->device_fh)) {\n-\t\t\t\t\tLOG_DEBUG(VHOST_DATA,\n-\t\t\t\t\t\"(%\"PRIu64\") TX: Source and destination\"\n-\t\t\t\t\t\"MAC addresses are the same. Dropping \"\n-\t\t\t\t\t\"packet.\\n\",\n-\t\t\t\t\tdev_ll->vdev->dev->device_fh);\n-\t\t\t\t\tMBUF_HEADROOM_UINT32(mbuf)\n-\t\t\t\t\t\t= (uint32_t)desc_idx;\n-\t\t\t\t\t__rte_mbuf_raw_free(mbuf);\n-\t\t\t\t\treturn;\n-\t\t\t\t}\n-\n-\t\t\t\t/*\n-\t\t\t\t * Packet length offset 4 bytes for HW vlan\n-\t\t\t\t * strip when L2 switch back.\n-\t\t\t\t */\n-\t\t\t\toffset = 4;\n-\t\t\t\tvlan_tag =\n-\t\t\t\t(uint16_t)\n-\t\t\t\tvlan_tags[(uint16_t)dev_ll->vdev->dev->device_fh];\n-\n-\t\t\t\tLOG_DEBUG(VHOST_DATA,\n-\t\t\t\t\"(%\"PRIu64\") TX: pkt to local VM device id:\"\n-\t\t\t\t\"(%\"PRIu64\") vlan tag: %d.\\n\",\n-\t\t\t\tdev->device_fh, dev_ll->vdev->dev->device_fh,\n-\t\t\t\tvlan_tag);\n-\n-\t\t\t\tbreak;\n-\t\t\t}\n-\t\t\tdev_ll = dev_ll->next;\n+\t\tif (find_local_dest(dev, m, &offset, &vlan_tag) != 0) {\n+\t\t\tMBUF_HEADROOM_UINT32(mbuf) = (uint32_t)desc_idx;\n+\t\t\t__rte_mbuf_raw_free(mbuf);\n+\t\t\treturn;\n \t\t}\n \t}\n \n",
    "prefixes": [
        "dpdk-dev",
        "v4",
        "2/3"
    ]
}