Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/60564/?format=api
https://patches.dpdk.org/api/patches/60564/?format=api", "web_url": "https://patches.dpdk.org/project/dpdk/patch/20191004214743.24686-5-stephen@networkplumber.org/", "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": "<20191004214743.24686-5-stephen@networkplumber.org>", "list_archive_url": "https://inbox.dpdk.org/dev/20191004214743.24686-5-stephen@networkplumber.org", "date": "2019-10-04T21:47:43", "name": "[v4,4/4] mbuf: add a pktmbuf copy routine", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": true, "hash": "90c85c2ce476427ea671af7877e9e6a4a429d634", "submitter": { "id": 27, "url": "https://patches.dpdk.org/api/people/27/?format=api", "name": "Stephen Hemminger", "email": "stephen@networkplumber.org" }, "delegate": null, "mbox": "https://patches.dpdk.org/project/dpdk/patch/20191004214743.24686-5-stephen@networkplumber.org/mbox/", "series": [ { "id": 6702, "url": "https://patches.dpdk.org/api/series/6702/?format=api", "web_url": "https://patches.dpdk.org/project/dpdk/list/?series=6702", "date": "2019-10-04T21:47:39", "name": "mbuf copy/cloning enhancements", "version": 4, "mbox": "https://patches.dpdk.org/series/6702/mbox/" } ], "comments": "https://patches.dpdk.org/api/patches/60564/comments/", "check": "success", "checks": "https://patches.dpdk.org/api/patches/60564/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 [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id 17E9B1C435;\n\tFri, 4 Oct 2019 23:47:59 +0200 (CEST)", "from mail-pf1-f195.google.com (mail-pf1-f195.google.com\n\t[209.85.210.195]) by dpdk.org (Postfix) with ESMTP id 60EAC1C433\n\tfor <dev@dpdk.org>; Fri, 4 Oct 2019 23:47:56 +0200 (CEST)", "by mail-pf1-f195.google.com with SMTP id q12so4670898pff.9\n\tfor <dev@dpdk.org>; Fri, 04 Oct 2019 14:47:56 -0700 (PDT)", "from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127])\n\tby smtp.gmail.com with ESMTPSA id\n\tq71sm6191355pjb.26.2019.10.04.14.47.53\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 04 Oct 2019 14:47:53 -0700 (PDT)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=networkplumber-org.20150623.gappssmtp.com; s=20150623;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=L6dCrdpamwAtzqWE8QnS/8KT5Z5U75CZzPCVYebQ4Lo=;\n\tb=nBzp8YX9+aSozmZcX/HPf1VbV4aQTJci4LDVmmwzJppLQ5uwfZzU+k34GGVAhX3emY\n\tBZ/Xg/Kj3i45jFFlj1l976OhH8wdnhFjNLaoCHFlHr79yJgmj3kcQUnovxKO0F0nzJ0v\n\tLaZNX8QK7p+5udzUzW0Oe3Loju88Pc0h3mJY6f2BKwz01nsxPdUlNM/npnokYR4dWvA/\n\t23sGp9fnNsFNHRbs8GbkCKI40PG6xWfnfHFmU976Qh8YnfcUWmgar2FIZO5ohLsicJlU\n\tmeVcQvAVhTq7A9YwwPuMwg9bJuNDFLKh2REFLfI8yWOmWU2uMIRxZ0Yb1UJsASPgbVax\n\tZstw==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=L6dCrdpamwAtzqWE8QnS/8KT5Z5U75CZzPCVYebQ4Lo=;\n\tb=Yofw9ssIxtIvhT47D9gDMKyX4iuGsjnEN5NtRp+4GavxRpLP/RrHtod4+yC06LGSZS\n\tDWqKtFXKMNaqTQwTZD+6RzNRlyEI1I7mhMwnCv/yKh+lAEoIYNPCFrXH/TICwFqUkJv9\n\tCdo5kojv230NnUj7iLfgELVhrLsrsdy3z8I+ML+X2YV/SQJZl5/rfdvV3QH/H4HOWzda\n\tdQFTKIVWPURhilLaA3cgN1RJfZ98056arQ0pQMBhcWTfXZgFGVQ7gNzvW84e6I4ED5HD\n\tMhf2akHrqVZ9h5XKhuDlBjuKdcddlt/huJctZv6KU0JPtmr+y49IgIsP+jsx1YkQZN77\n\tqiog==", "X-Gm-Message-State": "APjAAAW8DrxLtgbtVMmsQ6QLbjlf0vdOzQNAwJJZ5WfrX8RdYqw76/j+\n\t/H/2LydwQ/C24wbZYEFPjoX+JoADLEUVEQ==", "X-Google-Smtp-Source": "APXvYqxGx1D7oHcdI4uZ/dFfaXFg0wm6t5be2Yvb99ZwgWx7N0xddHtD4HtnYqrvHOVqd6HndRQ6rg==", "X-Received": "by 2002:a63:e001:: with SMTP id e1mr6531700pgh.358.1570225674806;\n\tFri, 04 Oct 2019 14:47:54 -0700 (PDT)", "From": "Stephen Hemminger <stephen@networkplumber.org>", "To": "dev@dpdk.org", "Cc": "Stephen Hemminger <stephen@networkplumber.org>", "Date": "Fri, 4 Oct 2019 14:47:43 -0700", "Message-Id": "<20191004214743.24686-5-stephen@networkplumber.org>", "X-Mailer": "git-send-email 2.20.1", "In-Reply-To": "<20191004214743.24686-1-stephen@networkplumber.org>", "References": "<20190928003758.18489-1-stephen@networkplumber.org>\n\t<20191004214743.24686-1-stephen@networkplumber.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[dpdk-dev] [PATCH v4 4/4] mbuf: add a pktmbuf copy routine", "X-BeenThere": "dev@dpdk.org", "X-Mailman-Version": "2.1.15", "Precedence": "list", "List-Id": "DPDK patches and discussions <dev.dpdk.org>", "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n\t<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\t<mailto:dev-request@dpdk.org?subject=subscribe>", "Errors-To": "dev-bounces@dpdk.org", "Sender": "\"dev\" <dev-bounces@dpdk.org>" }, "content": "This is a commonly used operation that surprisingly the\nDPDK has not supported. The new rte_pktmbuf_copy does a\ndeep copy of packet. This is a complete copy including\nmeta-data.\n\nIt handles the case where the source mbuf comes from a pool\nwith larger data area than the destination pool. The routine\nalso has options for skipping data, or truncating at a fixed\nlength.\n\nThis patch also introduces internal inline to copy the\nmetadata fields of mbuf.\n\nSigned-off-by: Stephen Hemminger <stephen@networkplumber.org>\n---\n lib/librte_mbuf/rte_mbuf.c | 69 ++++++++++++++++++++++++++++\n lib/librte_mbuf/rte_mbuf.h | 53 +++++++++++++++++----\n lib/librte_mbuf/rte_mbuf_version.map | 1 +\n 3 files changed, 113 insertions(+), 10 deletions(-)", "diff": "diff --git a/lib/librte_mbuf/rte_mbuf.c b/lib/librte_mbuf/rte_mbuf.c\nindex 9a1a1b5f9468..d5c9488fa213 100644\n--- a/lib/librte_mbuf/rte_mbuf.c\n+++ b/lib/librte_mbuf/rte_mbuf.c\n@@ -321,6 +321,75 @@ __rte_pktmbuf_linearize(struct rte_mbuf *mbuf)\n \treturn 0;\n }\n \n+/* Create a deep copy of mbuf */\n+struct rte_mbuf *\n+rte_pktmbuf_copy(const struct rte_mbuf *m, struct rte_mempool *mp,\n+\t\t uint32_t off, uint32_t len)\n+{\n+\tconst struct rte_mbuf *seg = m;\n+\tstruct rte_mbuf *mc, *m_last, **prev;\n+\tuint16_t priv_size;\n+\n+\tif (unlikely(off >= m->pkt_len))\n+\t\treturn NULL;\n+\n+\tmc = rte_pktmbuf_alloc(mp);\n+\tif (unlikely(mc == NULL))\n+\t\treturn NULL;\n+\n+\tif (len > m->pkt_len - off)\n+\t\tlen = m->pkt_len - off;\n+\n+\t__rte_pktmbuf_copy_hdr(mc, m);\n+\n+\t/* copy private area (can be 0) */\n+\tpriv_size = RTE_MIN(rte_pktmbuf_priv_size(mp),\n+\t\t\t rte_pktmbuf_priv_size(m->pool));\n+\trte_memcpy(mc + 1, m + 1, priv_size);\n+\n+\tprev = &mc->next;\n+\tm_last = mc;\n+\twhile (len > 0) {\n+\t\tuint32_t copy_len;\n+\n+\t\twhile (off >= seg->data_len) {\n+\t\t\toff -= seg->data_len;\n+\t\t\tseg = seg->next;\n+\t\t}\n+\n+\t\t/* current buffer is full, chain a new one */\n+\t\tif (rte_pktmbuf_tailroom(m_last) == 0) {\n+\t\t\tm_last = rte_pktmbuf_alloc(mp);\n+\t\t\tif (unlikely(m_last == NULL)) {\n+\t\t\t\trte_pktmbuf_free(mc);\n+\t\t\t\treturn NULL;\n+\t\t\t}\n+\t\t\t++mc->nb_segs;\n+\t\t\t*prev = m_last;\n+\t\t\tprev = &m_last->next;\n+\t\t}\n+\n+\t\tcopy_len = RTE_MIN(seg->data_len - off, len);\n+\t\tif (copy_len > rte_pktmbuf_tailroom(m_last))\n+\t\t\tcopy_len = rte_pktmbuf_tailroom(m_last);\n+\n+\t\t/* append from seg to m_last */\n+\t\trte_memcpy(rte_pktmbuf_mtod_offset(m_last, char *,\n+\t\t\t\t\t\t m_last->data_len),\n+\t\t\t rte_pktmbuf_mtod_offset(seg, char *,\n+\t\t\t\t\t\t off),\n+\t\t\t copy_len);\n+\n+\t\tm_last->data_len += copy_len;\n+\t\tmc->pkt_len += copy_len;\n+\t\toff += copy_len;\n+\t\tlen -= copy_len;\n+\t}\n+\n+\t__rte_mbuf_sanity_check(mc, 1);\n+\treturn mc;\n+}\n+\n /* dump a mbuf on console */\n void\n rte_pktmbuf_dump(FILE *f, const struct rte_mbuf *m, unsigned dump_len)\ndiff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h\nindex 6133f12172ae..803ddf28496e 100644\n--- a/lib/librte_mbuf/rte_mbuf.h\n+++ b/lib/librte_mbuf/rte_mbuf.h\n@@ -1684,6 +1684,19 @@ rte_pktmbuf_attach_extbuf(struct rte_mbuf *m, void *buf_addr,\n */\n #define rte_pktmbuf_detach_extbuf(m) rte_pktmbuf_detach(m)\n \n+/* internal */\n+static inline void\n+__rte_pktmbuf_copy_hdr(struct rte_mbuf *mi, const struct rte_mbuf *m)\n+{\n+\tmi->port = m->port;\n+\tmi->vlan_tci = m->vlan_tci;\n+\tmi->vlan_tci_outer = m->vlan_tci_outer;\n+\tmi->tx_offload = m->tx_offload;\n+\tmi->hash = m->hash;\n+\tmi->packet_type = m->packet_type;\n+\tmi->timestamp = m->timestamp;\n+}\n+\n /**\n * Attach packet mbuf to another packet mbuf.\n *\n@@ -1721,23 +1734,17 @@ static inline void rte_pktmbuf_attach(struct rte_mbuf *mi, struct rte_mbuf *m)\n \t\tmi->ol_flags = m->ol_flags | IND_ATTACHED_MBUF;\n \t}\n \n-\tmi->buf_iova = m->buf_iova;\n-\tmi->buf_addr = m->buf_addr;\n-\tmi->buf_len = m->buf_len;\n+\t__rte_pktmbuf_copy_hdr(mi, m);\n \n \tmi->data_off = m->data_off;\n \tmi->data_len = m->data_len;\n-\tmi->port = m->port;\n-\tmi->vlan_tci = m->vlan_tci;\n-\tmi->vlan_tci_outer = m->vlan_tci_outer;\n-\tmi->tx_offload = m->tx_offload;\n-\tmi->hash = m->hash;\n+\tmi->buf_iova = m->buf_iova;\n+\tmi->buf_addr = m->buf_addr;\n+\tmi->buf_len = m->buf_len;\n \n \tmi->next = NULL;\n \tmi->pkt_len = mi->data_len;\n \tmi->nb_segs = 1;\n-\tmi->packet_type = m->packet_type;\n-\tmi->timestamp = m->timestamp;\n \n \t__rte_mbuf_sanity_check(mi, 1);\n \t__rte_mbuf_sanity_check(m, 0);\n@@ -1927,6 +1934,32 @@ static inline void rte_pktmbuf_free(struct rte_mbuf *m)\n struct rte_mbuf *\n rte_pktmbuf_clone(struct rte_mbuf *md, struct rte_mempool *mp);\n \n+/**\n+ * Creates a full copy of a given packet mbuf.\n+ *\n+ * Copies all the data from a given packet mbuf to a newly allocated\n+ * set of mbufs.\n+ *\n+ * @param m\n+ * The packet mbuf to be cloned.\n+ * @param mp\n+ * The mempool from which the \"clone\" mbufs are allocated.\n+ * @param offset\n+ * The number of bytes to skip before copying.\n+ * If the mbuf does not have that many bytes, it is an error\n+ * and NULL is returned.\n+ * @param length\n+ * The upper limit on bytes to copy. Passing UINT32_MAX\n+ * means all data (after offset).\n+ * @return\n+ * - The pointer to the new \"clone\" mbuf on success.\n+ * - NULL if allocation fails.\n+ */\n+__rte_experimental\n+struct rte_mbuf *\n+rte_pktmbuf_copy(const struct rte_mbuf *m, struct rte_mempool *mp,\n+\t\t uint32_t offset, uint32_t length);\n+\n /**\n * Adds given value to the refcnt of all packet mbuf segments.\n *\ndiff --git a/lib/librte_mbuf/rte_mbuf_version.map b/lib/librte_mbuf/rte_mbuf_version.map\nindex ff5c18a5559b..a50dcb6db9ec 100644\n--- a/lib/librte_mbuf/rte_mbuf_version.map\n+++ b/lib/librte_mbuf/rte_mbuf_version.map\n@@ -57,4 +57,5 @@ EXPERIMENTAL {\n \tglobal:\n \n \trte_mbuf_check;\n+\trte_pktmbuf_copy;\n } DPDK_18.08;\n", "prefixes": [ "v4", "4/4" ] }{ "id": 60564, "url": "