From patchwork Mon Sep 30 19:20:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 60249 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id F11A48F96; Mon, 30 Sep 2019 21:21:05 +0200 (CEST) Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by dpdk.org (Postfix) with ESMTP id 1F55D37A2 for ; Mon, 30 Sep 2019 21:21:02 +0200 (CEST) Received: by mail-pg1-f195.google.com with SMTP id t14so7920446pgs.3 for ; Mon, 30 Sep 2019 12:21:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Q4INw0jXclEiki3qquDLRi7spTdZl6ftU0aD9i1ySi8=; b=Kcd0kDgCEOitNeWDoOk9NH9UbSwvT/rWWQ0M78ajcZa8gJgqo/TekpOXDTVP/uG9N8 ySoN1APCGfSBSPLb/Jf+rnoSDXfUun9dc1t3JLhPjI24kkFXFa7SN2wZNmNN0lC63fGd Md752RjSxk+e2V7O1vYmWWWZMGUpQhsk4t5kt5opMaI18zSn3FWHsJRrEgbHOPJaEjjG 9R5kIr6XXYaRcOe2jn69hm1XtV92enDK2aRQ9GenOb8nfQxuetcBuPUSORETAnz3bg3k AusilBnz8haYomKWflbQTfdhDxvgkP+5sKA2Nh0QUeMY/enS1hHdBoIJXgBnE6K3qnEl rh9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Q4INw0jXclEiki3qquDLRi7spTdZl6ftU0aD9i1ySi8=; b=jCh7ubAd7m3Rz/JtK1OLutWJNVyQOgqyLgTIMhXG5s1Dk5ory8LtCE22Y/81EpAbeb hWwokt6vTqiH6fJuLtFKGdJTqCC7Gus62A08fr4O+VT+kgwDofTO3qnMQpuo70skq3Fn kg6LodX0hIHcZoXKmKjl+k+ea1hI+dFfgR9jAIDCnUlzrTpPeomEIefqL3/Ey+9CDVHP O18XUiIe9DsFqe52hARqm7Eli1CWbd5etx7cDdeTmTCOVuYMHRI0TdVbanH5c+Zllnq3 wGgNsjPHtkqaoiUR2Z5GSDmwGsPTmJdB6Icfk7E4VuXXmFdJE15BiESWq/uYMnj1YS4U 19IQ== X-Gm-Message-State: APjAAAXq7doyMaVk4y6bI+Yl98v5ABhun1zOX+3at2IKj6RjmZ8LTY1I 7c/RRlNpZOA/7WhTXnTaNyDEu1vo7eAKmA== X-Google-Smtp-Source: APXvYqwEqbcFAAtDlhN96md+9RFz3NCWhlHCx3XGXJBnrvmOzbPQDXDeyzho0UbQWEe2PIcLFchNeg== X-Received: by 2002:a63:408:: with SMTP id 8mr26492636pge.334.1569871260972; Mon, 30 Sep 2019 12:21:00 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id c64sm14788304pfc.19.2019.09.30.12.20.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2019 12:20:59 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Mon, 30 Sep 2019 12:20:51 -0700 Message-Id: <20190930192056.26828-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190930192056.26828-1-stephen@networkplumber.org> References: <20190928003758.18489-1-stephen@networkplumber.org> <20190930192056.26828-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 1/6] mbuf: don't generate invalid mbuf in clone test X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The test for cloning changed mbuf would generate an mbuf whose length and segments were invalid. This would cause a crash if test was run with mbuf debugging enabled. Fixes: f1022aba76a5 ("app/test: rename mbuf variable") Signed-off-by: Stephen Hemminger --- app/test/test_mbuf.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/test/test_mbuf.c b/app/test/test_mbuf.c index 2a97afe2044a..aafad0cf6206 100644 --- a/app/test/test_mbuf.c +++ b/app/test/test_mbuf.c @@ -332,8 +332,11 @@ testclone_testupdate_testdetach(struct rte_mempool *pktmbuf_pool) m->next = rte_pktmbuf_alloc(pktmbuf_pool); if (m->next == NULL) GOTO_FAIL("Next Pkt Null\n"); + m->nb_segs = 2; rte_pktmbuf_append(m->next, sizeof(uint32_t)); + m->pkt_len = 2 * sizeof(uint32_t); + data = rte_pktmbuf_mtod(m->next, unaligned_uint32_t *); *data = MAGIC_DATA; From patchwork Mon Sep 30 19:20:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 60250 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D0E231BE8D; Mon, 30 Sep 2019 21:21:07 +0200 (CEST) Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by dpdk.org (Postfix) with ESMTP id AAADF5B3C for ; Mon, 30 Sep 2019 21:21:03 +0200 (CEST) Received: by mail-pf1-f196.google.com with SMTP id y22so6155117pfr.3 for ; Mon, 30 Sep 2019 12:21:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DMtaGL54rpYbgFJ3Nj6b9u9VO3VzDh2cf0qWrQrQF2o=; b=TFrCo3jQfqxkmEgeXH0cild2G5Z1HDH2IQvUruSY0J812hdIVJ48PiRdx3w4URgOjK +izl3LrO1xRHCxdKuwgoeC5GTn48y1nOaHjrMZOjHF/PQ1Hi8PUwNUDX8kqrfoB5p/m/ 9WZmCyyy1GKCTlLREXX20NfoqQdG81QkuiICxywvOQ8H7y4613UZsvfwTdXR7W0naRg4 u1GmUt1SuA3dTdoICkd+OnkDdRiTIzLOhu7mRVdzXRPvBL/WDiioNbZaoOLJWQjPYsPb 6HAeS3Wh80/J7ANcoVSCykXMGzsVTAGWbAVQ32PNlY2aRMfsghHa9nv9Lb0uqcfbgQE3 j8oQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DMtaGL54rpYbgFJ3Nj6b9u9VO3VzDh2cf0qWrQrQF2o=; b=JJTf7VNLCt2qWm2r6/D2KDV9T1oboUCQ2MRRMBmXW0uqLtZdJx5O60Fu/G3ByAOq7Q eROMAs3FmiEr7vszcd9BdHODeYUIQH3JVlBsOchrTuUIc8AHrWhwLaWgh+a9iNg7ls17 iAlstnsomR0ypIMbV+1kZIHZAXFfi2KRGSLSGVhkQIZ7Pto6wiShCuu97x5zciyGGvxH MaJNb5Y/GyoRUKB525BeHBq5heX+C6/HClgHr+a2N/9O2rvD7wxmDH2YTncmPuXTRh4w xiUJ2/iBIX8O5EHoDEg3HrosLlViC3wteFCMdu378CBr3NJjKYni0KtIumXdz0FqDmP4 7C7w== X-Gm-Message-State: APjAAAXyk4qt0boWzOVBvX2haGXQC4W1GJQUM1CDvtyfqLkbHzMRYmOd Qllee4BiH4Hw5s+WuoQ91RBSAmngZFZXuA== X-Google-Smtp-Source: APXvYqzCn3zgu5pbuWcOk2ubLg9YZk4cx1hGf6GT74C9ITHswInAL3LO5vfoCjXSqCkUSQVvK6MT9w== X-Received: by 2002:a65:6147:: with SMTP id o7mr24742918pgv.97.1569871262322; Mon, 30 Sep 2019 12:21:02 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id c64sm14788304pfc.19.2019.09.30.12.21.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2019 12:21:01 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Mon, 30 Sep 2019 12:20:52 -0700 Message-Id: <20190930192056.26828-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190930192056.26828-1-stephen@networkplumber.org> References: <20190928003758.18489-1-stephen@networkplumber.org> <20190930192056.26828-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 2/6] mbuf: delinline rte_pktmbuf_linearize X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This copy part of this function is too big to be put inline. The places it is used are only in special exception paths where a highly fragmented mbuf arrives at a device that can't handle it. Signed-off-by: Stephen Hemminger Acked-by: Andrew Rybchenko --- lib/librte_mbuf/rte_mbuf.c | 37 +++++++++++++++++++++++++++ lib/librte_mbuf/rte_mbuf.h | 38 +++++----------------------- lib/librte_mbuf/rte_mbuf_version.map | 6 +++++ 3 files changed, 49 insertions(+), 32 deletions(-) diff --git a/lib/librte_mbuf/rte_mbuf.c b/lib/librte_mbuf/rte_mbuf.c index 37718d49c148..e2c661c97522 100644 --- a/lib/librte_mbuf/rte_mbuf.c +++ b/lib/librte_mbuf/rte_mbuf.c @@ -245,6 +245,43 @@ int rte_mbuf_check(const struct rte_mbuf *m, int is_header, return 0; } +/* convert multi-segment mbuf to single mbuf */ +int +__rte_pktmbuf_linearize(struct rte_mbuf *mbuf) +{ + size_t seg_len, copy_len; + struct rte_mbuf *m; + struct rte_mbuf *m_next; + char *buffer; + + /* Extend first segment to the total packet length */ + copy_len = rte_pktmbuf_pkt_len(mbuf) - rte_pktmbuf_data_len(mbuf); + + if (unlikely(copy_len > rte_pktmbuf_tailroom(mbuf))) + return -1; + + buffer = rte_pktmbuf_mtod_offset(mbuf, char *, mbuf->data_len); + mbuf->data_len = (uint16_t)(mbuf->pkt_len); + + /* Append data from next segments to the first one */ + m = mbuf->next; + while (m != NULL) { + m_next = m->next; + + seg_len = rte_pktmbuf_data_len(m); + rte_memcpy(buffer, rte_pktmbuf_mtod(m, char *), seg_len); + buffer += seg_len; + + rte_pktmbuf_free_seg(m); + m = m_next; + } + + mbuf->next = NULL; + mbuf->nb_segs = 1; + + return 0; +} + /* dump a mbuf on console */ void rte_pktmbuf_dump(FILE *f, const struct rte_mbuf *m, unsigned dump_len) diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index 98225ec80bf1..bffda1c81fbd 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -2400,6 +2400,11 @@ rte_validate_tx_offload(const struct rte_mbuf *m) return 0; } +/** + * @internal used by rte_pktmbuf_linearize(). + */ +int __rte_pktmbuf_linearize(struct rte_mbuf *mbuf); + /** * Linearize data in mbuf. * @@ -2415,40 +2420,9 @@ rte_validate_tx_offload(const struct rte_mbuf *m) static inline int rte_pktmbuf_linearize(struct rte_mbuf *mbuf) { - size_t seg_len, copy_len; - struct rte_mbuf *m; - struct rte_mbuf *m_next; - char *buffer; - if (rte_pktmbuf_is_contiguous(mbuf)) return 0; - - /* Extend first segment to the total packet length */ - copy_len = rte_pktmbuf_pkt_len(mbuf) - rte_pktmbuf_data_len(mbuf); - - if (unlikely(copy_len > rte_pktmbuf_tailroom(mbuf))) - return -1; - - buffer = rte_pktmbuf_mtod_offset(mbuf, char *, mbuf->data_len); - mbuf->data_len = (uint16_t)(mbuf->pkt_len); - - /* Append data from next segments to the first one */ - m = mbuf->next; - while (m != NULL) { - m_next = m->next; - - seg_len = rte_pktmbuf_data_len(m); - rte_memcpy(buffer, rte_pktmbuf_mtod(m, char *), seg_len); - buffer += seg_len; - - rte_pktmbuf_free_seg(m); - m = m_next; - } - - mbuf->next = NULL; - mbuf->nb_segs = 1; - - return 0; + return __rte_pktmbuf_linearize(mbuf); } /** diff --git a/lib/librte_mbuf/rte_mbuf_version.map b/lib/librte_mbuf/rte_mbuf_version.map index 2662a37bf674..4d0bc9772769 100644 --- a/lib/librte_mbuf/rte_mbuf_version.map +++ b/lib/librte_mbuf/rte_mbuf_version.map @@ -46,6 +46,12 @@ DPDK_18.08 { rte_pktmbuf_pool_create_by_ops; } DPDK_16.11; +DPDK_19.11 { + global: + + __rte_pktmbuf_linearize; +} DPDK_18.08; + EXPERIMENTAL { global: From patchwork Mon Sep 30 19:20:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 60251 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 903171BE96; Mon, 30 Sep 2019 21:21:10 +0200 (CEST) Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by dpdk.org (Postfix) with ESMTP id C4DDF8F96 for ; Mon, 30 Sep 2019 21:21:04 +0200 (CEST) Received: by mail-pg1-f193.google.com with SMTP id y35so7931047pgl.1 for ; Mon, 30 Sep 2019 12:21:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KpzPqcTLgFfQHsFswOqlQ5Y4gmJb1270gFhqcWJieus=; b=WMDvMlfTuMr8upsL6SbqbsZA4E4bzjZ7WOZxxekejejFvqLpdv9haz41ZU0cCJ5nRt 0xQP+jHjQjQJkj+fYdqfSRZYWB1ZluIMzpq+YOsccfZgJ5UkUVczNzJvKaak5Nvm5HPf 1oOyLzAF3qBtVilpSfwurdzWF2YEQTgTw/QQhQZuoLH1D3UCxGfWNvCInZ9RSqS6dHIR xFplqAA3H6LwBddBsNAxA5qy8zhFZ3ehl9rqHxdUJgVKgwrsrl/R91s0XEJKIlqMpDDb grmecFoqPG+JiapWDNTT3cmwBry0Jg76l7dQapB9KVknfZsm5tT8633/SDVFi0BkbEz2 WCYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KpzPqcTLgFfQHsFswOqlQ5Y4gmJb1270gFhqcWJieus=; b=ufA5sb9tC8JWAXpjz+Bhr0cHymzD101tl5CamckWI4IkSwpwc6FgerSbyHnk/ss/oX 6k9DXI2N/CWUfewvVdHOjieig/rxgy5Z1Hf3s/TAXkioYizCyCL3NI1ApLusZd23Jm32 SCBitvXqujhY/vh81fqfK29X7s/UL2qg7mGJce6UcGMkwEUuibLZtIGuoGf5jNV6Q4Me 3H4MutDILYON2cKT2MLM5PpldgK5yAzTH00M5th+58LVQ7XTzfJyR61tigbIEmZC2uuY aRN/ldOtVdsfv/FPwLQJZcevwYRIFn5jgBQJKXBBb5oAEbb3GlrmYTbQ8rBEOt5kE+fg /x6Q== X-Gm-Message-State: APjAAAX2SPMkwmBcZ1GHc5Ssxt6snTuisiCNBllKpqJXEbb0chxjoLla 7mOR655zBPI8EDOOBtdizJm9St/ftyICUQ== X-Google-Smtp-Source: APXvYqy5KEmCLHRxt0AP32Rz0A8/wvjvj4Ddex8iY21gb6gVT4BWEtMoo/pry1TFX7f9HWUWrcmW5Q== X-Received: by 2002:a63:6c89:: with SMTP id h131mr26508762pgc.322.1569871263644; Mon, 30 Sep 2019 12:21:03 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id c64sm14788304pfc.19.2019.09.30.12.21.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2019 12:21:02 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Mon, 30 Sep 2019 12:20:53 -0700 Message-Id: <20190930192056.26828-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190930192056.26828-1-stephen@networkplumber.org> References: <20190928003758.18489-1-stephen@networkplumber.org> <20190930192056.26828-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 3/6] mbuf: deinline rte_pktmbuf_clone X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Cloning mbufs requires allocations and iteration and therefore should not be an inline. Signed-off-by: Stephen Hemminger Acked-by: Andrew Rybchenko --- lib/librte_mbuf/rte_mbuf.c | 39 ++++++++++++++++++++++++++++ lib/librte_mbuf/rte_mbuf.h | 38 ++------------------------- lib/librte_mbuf/rte_mbuf_version.map | 1 + 3 files changed, 42 insertions(+), 36 deletions(-) diff --git a/lib/librte_mbuf/rte_mbuf.c b/lib/librte_mbuf/rte_mbuf.c index e2c661c97522..9a1a1b5f9468 100644 --- a/lib/librte_mbuf/rte_mbuf.c +++ b/lib/librte_mbuf/rte_mbuf.c @@ -245,6 +245,45 @@ int rte_mbuf_check(const struct rte_mbuf *m, int is_header, return 0; } +/* Creates a shallow copy of mbuf */ +struct rte_mbuf * +rte_pktmbuf_clone(struct rte_mbuf *md, struct rte_mempool *mp) +{ + struct rte_mbuf *mc, *mi, **prev; + uint32_t pktlen; + uint16_t nseg; + + mc = rte_pktmbuf_alloc(mp); + if (unlikely(mc == NULL)) + return NULL; + + mi = mc; + prev = &mi->next; + pktlen = md->pkt_len; + nseg = 0; + + do { + nseg++; + rte_pktmbuf_attach(mi, md); + *prev = mi; + prev = &mi->next; + } while ((md = md->next) != NULL && + (mi = rte_pktmbuf_alloc(mp)) != NULL); + + *prev = NULL; + mc->nb_segs = nseg; + mc->pkt_len = pktlen; + + /* Allocation of new indirect segment failed */ + if (unlikely(mi == NULL)) { + rte_pktmbuf_free(mc); + return NULL; + } + + __rte_mbuf_sanity_check(mc, 1); + return mc; +} + /* convert multi-segment mbuf to single mbuf */ int __rte_pktmbuf_linearize(struct rte_mbuf *mbuf) diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index bffda1c81fbd..6133f12172ae 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -1924,42 +1924,8 @@ static inline void rte_pktmbuf_free(struct rte_mbuf *m) * - The pointer to the new "clone" mbuf on success. * - NULL if allocation fails. */ -static inline struct rte_mbuf *rte_pktmbuf_clone(struct rte_mbuf *md, - struct rte_mempool *mp) -{ - struct rte_mbuf *mc, *mi, **prev; - uint32_t pktlen; - uint16_t nseg; - - if (unlikely ((mc = rte_pktmbuf_alloc(mp)) == NULL)) - return NULL; - - mi = mc; - prev = &mi->next; - pktlen = md->pkt_len; - nseg = 0; - - do { - nseg++; - rte_pktmbuf_attach(mi, md); - *prev = mi; - prev = &mi->next; - } while ((md = md->next) != NULL && - (mi = rte_pktmbuf_alloc(mp)) != NULL); - - *prev = NULL; - mc->nb_segs = nseg; - mc->pkt_len = pktlen; - - /* Allocation of new indirect segment failed */ - if (unlikely (mi == NULL)) { - rte_pktmbuf_free(mc); - return NULL; - } - - __rte_mbuf_sanity_check(mc, 1); - return mc; -} +struct rte_mbuf * +rte_pktmbuf_clone(struct rte_mbuf *md, struct rte_mempool *mp); /** * Adds given value to the refcnt of all packet mbuf segments. diff --git a/lib/librte_mbuf/rte_mbuf_version.map b/lib/librte_mbuf/rte_mbuf_version.map index 4d0bc9772769..ff5c18a5559b 100644 --- a/lib/librte_mbuf/rte_mbuf_version.map +++ b/lib/librte_mbuf/rte_mbuf_version.map @@ -50,6 +50,7 @@ DPDK_19.11 { global: __rte_pktmbuf_linearize; + rte_pktmbuf_clone; } DPDK_18.08; EXPERIMENTAL { From patchwork Mon Sep 30 19:20:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 60252 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id BD5DA1BEA5; Mon, 30 Sep 2019 21:21:13 +0200 (CEST) Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by dpdk.org (Postfix) with ESMTP id 460BC1BE81 for ; Mon, 30 Sep 2019 21:21:06 +0200 (CEST) Received: by mail-pf1-f194.google.com with SMTP id 205so6156766pfw.2 for ; Mon, 30 Sep 2019 12:21:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Gtm1zzy1GlSRdxte2W0/vd1Jy7ccpq73UopKgcsU4nI=; b=TPYehffRMmWBHFn1Ypvvc9RTZ7wtmK9EYCLaLZNcNo+IfaZE7C3rmo0H1epvUI2hWj S9MXV6WjS7owUtFfGK9cdmn/Wxvb2uAVCsE748XHMscnJ/9zU96Z4BTjNttspx5SnDY8 16KArChiBA6xdcFbzC4qG0Ea7vJ5HEebwU/q/zCB0bbmr8ZjGy8fxKZljH3QGMvDXkFy d71R5HLrK1kgA8It56t9us0lcyN5hPBIUD/s+ngMuB6+WoCAwq4H6JKu/9YZx3V+Hd31 9u2bYyNeN5prymrOT2GjyormY4UsM3gRKrfScPc3CIfgo7ZBPpxPjkWtV27zS3VfWogI sTNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Gtm1zzy1GlSRdxte2W0/vd1Jy7ccpq73UopKgcsU4nI=; b=sjFadNF2gjkZcOJtGq+37INeCtfmE0Mwty6WE+HiNIZhkowVR2+9Kv0RgHFyFHqmNk jKhGYvfw6SsJM9k8u06ug8LnCY9koyZs8kBRE5aGzkbvLMhtMocoPmF9cy8ecGfqMXHZ /WmGkVBGk8YmeLkvpOxhMM7VoPvamEKz/MR3lSqvxFLCRit+HtWim1FTIGWVMtGLCmsI N9TVszfOO21kdbs85scZFbB6Wnrq0r8PIRHigdtK4BrIQHDgIQRZ5o13kgZTMPl2F/cg 4PAeNlMRV0HwtDY0N3jAsjW1tSpPjcEIZufLZf4aEh5JN6otj4B0xkIhvG/FHIi+hi3E 5eMg== X-Gm-Message-State: APjAAAU5G8FtdtU2y/oRrhCw2ibEih8FBdQAlKIKL83aY8ibuJsGUx7T TR6uA00AOEXZ+zpY4K8Ns9tj7MGvprAUtw== X-Google-Smtp-Source: APXvYqy+lFFTtLxoA5PaHZr443gCeMjfts95owjFwtc/V/CDvOyHsdICJvDT/nzE5M8HLgLksvJ++w== X-Received: by 2002:a62:aa0f:: with SMTP id e15mr22580834pff.160.1569871265033; Mon, 30 Sep 2019 12:21:05 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id c64sm14788304pfc.19.2019.09.30.12.21.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2019 12:21:03 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Mon, 30 Sep 2019 12:20:54 -0700 Message-Id: <20190930192056.26828-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190930192056.26828-1-stephen@networkplumber.org> References: <20190928003758.18489-1-stephen@networkplumber.org> <20190930192056.26828-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 4/6] 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This is a commonly used operation that surprisingly the DPDK has not supported. The new rte_pktmbuf_copy does a deep copy of packet. This is a complete copy including meta-data. It handles the case where the source mbuf comes from a pool with larger data area than the destination pool. The routine also has options for skipping data, or truncating at a fixed length. Signed-off-by: Stephen Hemminger --- lib/librte_mbuf/rte_mbuf.c | 74 ++++++++++++++++++++++++++++ lib/librte_mbuf/rte_mbuf.h | 26 ++++++++++ lib/librte_mbuf/rte_mbuf_version.map | 1 + 3 files changed, 101 insertions(+) diff --git a/lib/librte_mbuf/rte_mbuf.c b/lib/librte_mbuf/rte_mbuf.c index 9a1a1b5f9468..901df0192d2e 100644 --- a/lib/librte_mbuf/rte_mbuf.c +++ b/lib/librte_mbuf/rte_mbuf.c @@ -321,6 +321,80 @@ __rte_pktmbuf_linearize(struct rte_mbuf *mbuf) return 0; } +/* Create a deep copy of mbuf */ +struct rte_mbuf * +rte_pktmbuf_copy(const struct rte_mbuf *m, struct rte_mempool *mp, + uint32_t off, uint32_t len) +{ + const struct rte_mbuf *seg = m; + struct rte_mbuf *mc, *m_last, **prev; + + if (unlikely(off >= m->pkt_len)) + return NULL; + + mc = rte_pktmbuf_alloc(mp); + if (unlikely(mc == NULL)) + return NULL; + + if (len > m->pkt_len - off) + len = m->pkt_len - off; + + /* clone meta data from original */ + mc->port = m->port; + mc->vlan_tci = m->vlan_tci; + mc->vlan_tci_outer = m->vlan_tci_outer; + mc->tx_offload = m->tx_offload; + mc->hash = m->hash; + mc->packet_type = m->packet_type; + mc->timestamp = m->timestamp; + + /* copy private data (if any) */ + rte_memcpy(mc + 1, m + 1, + rte_pktmbuf_priv_size(mp)); + + prev = &mc->next; + m_last = mc; + while (len > 0) { + uint32_t copy_len; + + while (off >= seg->data_len) { + off -= seg->data_len; + seg = seg->next; + } + + /* current buffer is full, chain a new one */ + if (rte_pktmbuf_tailroom(m_last) == 0) { + m_last = rte_pktmbuf_alloc(mp); + if (unlikely(m_last == NULL)) { + rte_pktmbuf_free(mc); + return NULL; + } + ++mc->nb_segs; + *prev = m_last; + prev = &m_last->next; + } + + copy_len = RTE_MIN(seg->data_len - off, len); + if (copy_len > rte_pktmbuf_tailroom(m_last)) + copy_len = rte_pktmbuf_tailroom(m_last); + + /* append from seg to m_last */ + rte_memcpy(rte_pktmbuf_mtod_offset(m_last, char *, + m_last->data_len), + rte_pktmbuf_mtod_offset(seg, char *, + off), + copy_len); + + m_last->data_len += copy_len; + mc->pkt_len += copy_len; + off += copy_len; + len -= copy_len; + } + + __rte_mbuf_sanity_check(mc, 1); + return mc; +} + /* dump a mbuf on console */ void rte_pktmbuf_dump(FILE *f, const struct rte_mbuf *m, unsigned dump_len) diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index 6133f12172ae..b860d570ef20 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -1927,6 +1927,32 @@ static inline void rte_pktmbuf_free(struct rte_mbuf *m) struct rte_mbuf * rte_pktmbuf_clone(struct rte_mbuf *md, struct rte_mempool *mp); +/** + * Creates a full copy of a given packet mbuf. + * + * Copies all the data from a given packet mbuf to a newly allocated + * set of mbufs. + * + * @param m + * The packet mbuf to be cloned. + * @param mp + * The mempool from which the "clone" mbufs are allocated. + * @param offset + * The number of bytes to skip before copying. + * If the mbuf does not have that many bytes, it is an error + * and NULL is returned. + * @param length + * The upper limit on bytes to copy. Passing UINT32_MAX + * means all data (after offset). + * @return + * - The pointer to the new "clone" mbuf on success. + * - NULL if allocation fails. + */ +__rte_experimental +struct rte_mbuf * +rte_pktmbuf_copy(const struct rte_mbuf *m, struct rte_mempool *mp, + uint32_t offset, uint32_t length); + /** * Adds given value to the refcnt of all packet mbuf segments. * diff --git a/lib/librte_mbuf/rte_mbuf_version.map b/lib/librte_mbuf/rte_mbuf_version.map index ff5c18a5559b..a50dcb6db9ec 100644 --- a/lib/librte_mbuf/rte_mbuf_version.map +++ b/lib/librte_mbuf/rte_mbuf_version.map @@ -57,4 +57,5 @@ EXPERIMENTAL { global: rte_mbuf_check; + rte_pktmbuf_copy; } DPDK_18.08; From patchwork Mon Sep 30 19:20:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 60253 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 829341BEB1; Mon, 30 Sep 2019 21:21:15 +0200 (CEST) Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by dpdk.org (Postfix) with ESMTP id 4A52F1BE86 for ; Mon, 30 Sep 2019 21:21:07 +0200 (CEST) Received: by mail-pf1-f196.google.com with SMTP id y22so6155217pfr.3 for ; Mon, 30 Sep 2019 12:21:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hnJVNme230AHorC9MqsxxOvVRW7V8JTUGHH+CXxU7nQ=; b=D6P+wCZihyOn1VlIF75MM3gIDohT0H5WXbsWLCcg8rMakd3dRBr/d0FLGXRFD0BA/0 wuKTcDOtF5qWWU2sB2b37CHXjGP5jFsFF4b7b12I5m7hf9uYPkBMoRkocI817NTC3fFH EkO9mjYSxgLX2pZOgc5Ew0Ugh7FWcKKWLItVVC701LxV3LtddIU/u4ccrcoZidnMrG4c tGdKvLHcQkd+Rs9mRQWWetysCN2G4ZYWb89q8IH4SDtZhHNFuGiDYuiyWy35I/1BwEOm ptXECgXs2Nk/CVLPPQySS7NgPdSB/2gxOw0+q08X2Eef7phEtG6/FsQ5iJsv7KS08Xs5 gruA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hnJVNme230AHorC9MqsxxOvVRW7V8JTUGHH+CXxU7nQ=; b=Le5YJ8/EdQPWVgRenjYx0YVYiZvbw74pa8+7rTkIOPCZ3AuPZssXNNFPweLfdFx5Za bxePzpHNscnbk74OHMNP2dHiJJQzqUi/HoEhyUCUVtR+GfSJ72zqQ8WxUck5pQXvIztI zsfETHKNQufarS9A0jGm7HdfsaubLztAOjNthoHmEDJoc2FCboM8FtHP+fKugWT4sOlL Fp5WLiY646fBDbDxLXViZHhTqppEne2hqU0s907IBS/yemC2sZCDhoz3SjGbnF89eTnS akgd/S5TTCX9h56wdxnqnH3whSyNJt4YwfJAvouo3uPpXoLexxIjEqpF/+HvPTvwJU1H HtYA== X-Gm-Message-State: APjAAAWLrBzmS6+UgyfwpbXq43f/eUgXLUT0aGZ2FQzVg98ci4moM+j5 HQGa+NInF1EgamLXCORA02rNzmCwcIk9EA== X-Google-Smtp-Source: APXvYqzWzOPkUUX3QhvkvxRTQren4vbhL/ijBOV/r++8Y02nUvmgP7RV0fpFk67invRndMiA1AFZWg== X-Received: by 2002:a62:2b4d:: with SMTP id r74mr23404586pfr.30.1569871266261; Mon, 30 Sep 2019 12:21:06 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id c64sm14788304pfc.19.2019.09.30.12.21.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2019 12:21:05 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Mon, 30 Sep 2019 12:20:55 -0700 Message-Id: <20190930192056.26828-6-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190930192056.26828-1-stephen@networkplumber.org> References: <20190928003758.18489-1-stephen@networkplumber.org> <20190930192056.26828-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 5/6] mbuf: add pktmbuf copy test X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" New test for rte_pktmbuf_copy based of the clone tests. Signed-off-by: Stephen Hemminger --- app/test/test_mbuf.c | 126 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) diff --git a/app/test/test_mbuf.c b/app/test/test_mbuf.c index aafad0cf6206..49c3a5f7893c 100644 --- a/app/test/test_mbuf.c +++ b/app/test/test_mbuf.c @@ -399,6 +399,127 @@ testclone_testupdate_testdetach(struct rte_mempool *pktmbuf_pool) return -1; } +static int +test_pktmbuf_copy(struct rte_mempool *pktmbuf_pool) +{ + struct rte_mbuf *m = NULL; + struct rte_mbuf *copy = NULL; + struct rte_mbuf *copy2 = NULL; + unaligned_uint32_t *data; + + /* alloc a mbuf */ + m = rte_pktmbuf_alloc(pktmbuf_pool); + if (m == NULL) + GOTO_FAIL("ooops not allocating mbuf"); + + if (rte_pktmbuf_pkt_len(m) != 0) + GOTO_FAIL("Bad length"); + + rte_pktmbuf_append(m, sizeof(uint32_t)); + data = rte_pktmbuf_mtod(m, unaligned_uint32_t *); + *data = MAGIC_DATA; + + /* copy the allocated mbuf */ + copy = rte_pktmbuf_copy(m, pktmbuf_pool, 0, UINT32_MAX); + if (copy == NULL) + GOTO_FAIL("cannot copy data\n"); + + if (rte_pktmbuf_pkt_len(copy) != sizeof(uint32_t)) + GOTO_FAIL("copy length incorrect\n"); + + if (rte_pktmbuf_data_len(copy) != sizeof(uint32_t)) + GOTO_FAIL("copy data length incorrect\n"); + + data = rte_pktmbuf_mtod(copy, unaligned_uint32_t *); + if (*data != MAGIC_DATA) + GOTO_FAIL("invalid data in copy\n"); + + /* free the copy */ + rte_pktmbuf_free(copy); + copy = NULL; + + /* same test with a chained mbuf */ + m->next = rte_pktmbuf_alloc(pktmbuf_pool); + if (m->next == NULL) + GOTO_FAIL("Next Pkt Null\n"); + m->nb_segs = 2; + + rte_pktmbuf_append(m->next, sizeof(uint32_t)); + m->pkt_len = 2 * sizeof(uint32_t); + data = rte_pktmbuf_mtod(m->next, unaligned_uint32_t *); + *data = MAGIC_DATA + 1; + + copy = rte_pktmbuf_copy(m, pktmbuf_pool, 0, UINT32_MAX); + if (copy == NULL) + GOTO_FAIL("cannot copy data\n"); + + if (rte_pktmbuf_pkt_len(copy) != 2 * sizeof(uint32_t)) + GOTO_FAIL("chain copy length incorrect\n"); + + if (rte_pktmbuf_data_len(copy) != 2 * sizeof(uint32_t)) + GOTO_FAIL("chain copy data length incorrect\n"); + + data = rte_pktmbuf_mtod(copy, unaligned_uint32_t *); + if (data[0] != MAGIC_DATA || data[1] != MAGIC_DATA + 1) + GOTO_FAIL("invalid data in copy\n"); + + rte_pktmbuf_free(copy2); + + /* test offset copy */ + copy2 = rte_pktmbuf_copy(copy, pktmbuf_pool, + sizeof(uint32_t), UINT32_MAX); + if (copy2 == NULL) + GOTO_FAIL("cannot copy the copy\n"); + + if (rte_pktmbuf_pkt_len(copy2) != sizeof(uint32_t)) + GOTO_FAIL("copy with offset, length incorrect\n"); + + if (rte_pktmbuf_data_len(copy2) != sizeof(uint32_t)) + GOTO_FAIL("copy with offset, data length incorrect\n"); + + data = rte_pktmbuf_mtod(copy2, unaligned_uint32_t *); + if (data[0] != MAGIC_DATA + 1) + GOTO_FAIL("copy with offset, invalid data\n"); + + rte_pktmbuf_free(copy2); + + /* test truncation copy */ + copy2 = rte_pktmbuf_copy(copy, pktmbuf_pool, + 0, sizeof(uint32_t)); + if (copy2 == NULL) + GOTO_FAIL("cannot copy the copy\n"); + + if (rte_pktmbuf_pkt_len(copy2) != sizeof(uint32_t)) + GOTO_FAIL("copy with truncate, length incorrect\n"); + + if (rte_pktmbuf_data_len(copy2) != sizeof(uint32_t)) + GOTO_FAIL("copy with truncate, data length incorrect\n"); + + data = rte_pktmbuf_mtod(copy2, unaligned_uint32_t *); + if (data[0] != MAGIC_DATA) + GOTO_FAIL("copy with truncate, invalid data\n"); + + /* free mbuf */ + rte_pktmbuf_free(m); + rte_pktmbuf_free(copy); + rte_pktmbuf_free(copy2); + + m = NULL; + copy = NULL; + copy2 = NULL; + printf("%s ok\n", __func__); + return 0; + +fail: + if (m) + rte_pktmbuf_free(m); + if (copy) + rte_pktmbuf_free(copy); + if (copy2) + rte_pktmbuf_free(copy2); + return -1; +} + static int test_attach_from_different_pool(struct rte_mempool *pktmbuf_pool, struct rte_mempool *pktmbuf_pool2) @@ -1203,6 +1324,11 @@ test_mbuf(void) goto err; } + if (test_pktmbuf_copy(pktmbuf_pool) < 0) { + printf("test_pktmbuf_copy() failed.\n"); + goto err; + } + if (test_attach_from_different_pool(pktmbuf_pool, pktmbuf_pool2) < 0) { printf("test_attach_from_different_pool() failed\n"); goto err; From patchwork Mon Sep 30 19:20:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 60254 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 166C61BEB7; Mon, 30 Sep 2019 21:21:18 +0200 (CEST) Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by dpdk.org (Postfix) with ESMTP id 76FF837A2 for ; Mon, 30 Sep 2019 21:21:08 +0200 (CEST) Received: by mail-pg1-f195.google.com with SMTP id e1so2387522pgj.6 for ; Mon, 30 Sep 2019 12:21:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zdsVTY0D8zVTp25c2Ag/LpUnnCKhJ2sj1djQsUGrXUo=; b=OlUzL+qQFhKQjYreMu1UeCD03JkZCZ7uVrqYHGdY2EufwKgxrdGXaTqrt4C3CPwD27 YxVVH9v5y4Nat4g8FGKrHbeFAoafO15PiKvCyOidxGb00xsG9/NewyO4UqTxt2684zwZ xK8Gq24c7COe/fM/sFDR35ih/3nvC0NI57g5PEV8cn1PgtDh0OpmAsjEpflMu3YTFboW fiaLxO9XVtAgoq1m4CizYL+7k1dQELwY6YiOXb0iwzc2H2CCmXE0xwY1FbWX0dVDx+uz /Yq/W3y/tO4fZnbNPW4PDtZVw0TosJkBJQfv0tewYaDlElNub3MkUfhz4Z593cApOBe/ IEew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zdsVTY0D8zVTp25c2Ag/LpUnnCKhJ2sj1djQsUGrXUo=; b=Dmp0sklCHyBSPgOHYNxnvKwxMjkr/B+eKNVBXhpg0Doftfm1vUmwijdb9TL13n2ZUl iZi/dinfS6C8bHsEeyk2uD12VTMTg5wq0NqnEeE1mGjxBO+WbvhPueQI+vThelFG0mwo E+CKYtCNkLjWMXzpKJ1m5f93QY30+F24WWUZ4k+zy392GS6jahs+N2ANhb522WQ4vopu 9LisSyyebUVihKTdSi+6KVzE/uapqZ+XFd0ePcx0tF1enRKS5ztzjU4TCf04mEN6ag2r bBdeSgfu5bXD3UD1yxEs0z9iXMwxj2s3LwQjVnrkgbiupISj+sR0L2/i9ft7wluj8f2k TN4A== X-Gm-Message-State: APjAAAWrfpBItcUG52t69ELA/Cy/O9+Quv1Af8Z0sbOGFhP3yosn4dyJ ZxRv1KN7rbZ99qtUYq/Sj/k3Cyc6gR8Jfg== X-Google-Smtp-Source: APXvYqyL2AiicPF5R57ZqGXj0bcq4QYOuvIeUa0MfLyniRfm51RMHRbLC7m48PO5Z34hNOMdCL+zGQ== X-Received: by 2002:aa7:9216:: with SMTP id 22mr23747381pfo.214.1569871267400; Mon, 30 Sep 2019 12:21:07 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id c64sm14788304pfc.19.2019.09.30.12.21.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2019 12:21:06 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Mon, 30 Sep 2019 12:20:56 -0700 Message-Id: <20190930192056.26828-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190930192056.26828-1-stephen@networkplumber.org> References: <20190928003758.18489-1-stephen@networkplumber.org> <20190930192056.26828-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 6/6] pdump: use new pktmbuf copy function X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The rte_pktmbuf_copy handles varying size mbuf pools correctly. Signed-off-by: Stephen Hemminger --- lib/librte_pdump/rte_pdump.c | 69 +----------------------------------- 1 file changed, 1 insertion(+), 68 deletions(-) diff --git a/lib/librte_pdump/rte_pdump.c b/lib/librte_pdump/rte_pdump.c index cd24dd010951..c665cf237f65 100644 --- a/lib/librte_pdump/rte_pdump.c +++ b/lib/librte_pdump/rte_pdump.c @@ -64,73 +64,6 @@ static struct pdump_rxtx_cbs { } rx_cbs[RTE_MAX_ETHPORTS][RTE_MAX_QUEUES_PER_PORT], tx_cbs[RTE_MAX_ETHPORTS][RTE_MAX_QUEUES_PER_PORT]; -static inline int -pdump_pktmbuf_copy_data(struct rte_mbuf *seg, const struct rte_mbuf *m) -{ - if (rte_pktmbuf_tailroom(seg) < m->data_len) { - RTE_LOG(ERR, PDUMP, - "User mempool: insufficient data_len of mbuf\n"); - return -EINVAL; - } - - seg->port = m->port; - seg->vlan_tci = m->vlan_tci; - seg->hash = m->hash; - seg->tx_offload = m->tx_offload; - seg->ol_flags = m->ol_flags; - seg->packet_type = m->packet_type; - seg->vlan_tci_outer = m->vlan_tci_outer; - seg->data_len = m->data_len; - seg->pkt_len = seg->data_len; - rte_memcpy(rte_pktmbuf_mtod(seg, void *), - rte_pktmbuf_mtod(m, void *), - rte_pktmbuf_data_len(seg)); - - return 0; -} - -static inline struct rte_mbuf * -pdump_pktmbuf_copy(struct rte_mbuf *m, struct rte_mempool *mp) -{ - struct rte_mbuf *m_dup, *seg, **prev; - uint32_t pktlen; - uint16_t nseg; - - m_dup = rte_pktmbuf_alloc(mp); - if (unlikely(m_dup == NULL)) - return NULL; - - seg = m_dup; - prev = &seg->next; - pktlen = m->pkt_len; - nseg = 0; - - do { - nseg++; - if (pdump_pktmbuf_copy_data(seg, m) < 0) { - if (seg != m_dup) - rte_pktmbuf_free_seg(seg); - rte_pktmbuf_free(m_dup); - return NULL; - } - *prev = seg; - prev = &seg->next; - } while ((m = m->next) != NULL && - (seg = rte_pktmbuf_alloc(mp)) != NULL); - - *prev = NULL; - m_dup->nb_segs = nseg; - m_dup->pkt_len = pktlen; - - /* Allocation of new indirect segment failed */ - if (unlikely(seg == NULL)) { - rte_pktmbuf_free(m_dup); - return NULL; - } - - __rte_mbuf_sanity_check(m_dup, 1); - return m_dup; -} static inline void pdump_copy(struct rte_mbuf **pkts, uint16_t nb_pkts, void *user_params) @@ -148,7 +81,7 @@ pdump_copy(struct rte_mbuf **pkts, uint16_t nb_pkts, void *user_params) ring = cbs->ring; mp = cbs->mp; for (i = 0; i < nb_pkts; i++) { - p = pdump_pktmbuf_copy(pkts[i], mp); + p = rte_pktmbuf_copy(pkts[i], mp, 0, UINT32_MAX); if (p) dup_bufs[d_pkts++] = p; }