From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 62107A0032; Fri, 22 Jul 2022 16:42:33 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 04E8E4021E; Fri, 22 Jul 2022 16:42:33 +0200 (CEST) Received: from smartserver.smartsharesystems.com (smartserver.smartsharesystems.com [77.243.40.215]) by mails.dpdk.org (Postfix) with ESMTP id 0E0EE40156 for ; Fri, 22 Jul 2022 16:42:32 +0200 (CEST) X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: RE: [PATCH v3] ip_frag: add IPv4 fragment copy packet API Date: Fri, 22 Jul 2022 16:42:30 +0200 Message-ID: <98CBD80474FA8B44BF855DF32C47DC35D871DD@smartserver.smartshare.dk> In-Reply-To: <1658494910-7869-1-git-send-email-chcchc88@163.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PATCH v3] ip_frag: add IPv4 fragment copy packet API Thread-Index: Adidy0ZPcryFMQwwSU+RUVocY8V6/gADJT/A References: <1654784398-11315-1-git-send-email-chcchc88@163.com> <1658494910-7869-1-git-send-email-chcchc88@163.com> From: =?iso-8859-1?Q?Morten_Br=F8rup?= To: "Huichao Cai" , , Cc: "Olivier Matz" X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org > From: Huichao Cai [mailto:chcchc88@163.com] > Sent: Friday, 22 July 2022 15.02 > To: dev@dpdk.org > Cc: konstantin.v.ananyev@yandex.ru > Subject: [PATCH v3] ip_frag: add IPv4 fragment copy packet API >=20 > Some NIC drivers support MBUF_FAST_FREE(Device supports optimization > for fast release of mbufs. When set application must guarantee that > per-queue all mbufs comes from the same mempool and has refcnt =3D 1) > offload. In order to adapt to this offload function, add this API. > Add some test data for this API. >=20 > Signed-off-by: Huichao Cai > --- > app/test/test_ipfrag.c | 8 +- > lib/ip_frag/rte_ip_frag.h | 27 +++++ > lib/ip_frag/rte_ipv4_fragmentation.c | 208 > +++++++++++++++++++++++++++++++++++ > lib/ip_frag/version.map | 1 + > 4 files changed, 243 insertions(+), 1 deletion(-) >=20 > diff --git a/app/test/test_ipfrag.c b/app/test/test_ipfrag.c > index ba0ffd0..bb7c4d3 100644 > --- a/app/test/test_ipfrag.c > +++ b/app/test/test_ipfrag.c > @@ -418,10 +418,16 @@ static void ut_teardown(void) > } >=20 > if (tests[i].ipv =3D=3D 4) > - len =3D rte_ipv4_fragment_packet(b, pkts_out, BURST, > + if (i % 2) > + len =3D rte_ipv4_fragment_packet(b, pkts_out, > BURST, > tests[i].mtu_size, > direct_pool, > indirect_pool); > + else > + len =3D rte_ipv4_fragment_copy_packet(b, > pkts_out, > + BURST, > + tests[i].mtu_size, > + pkt_pool); > else if (tests[i].ipv =3D=3D 6) > len =3D rte_ipv6_fragment_packet(b, pkts_out, BURST, > tests[i].mtu_size, > diff --git a/lib/ip_frag/rte_ip_frag.h b/lib/ip_frag/rte_ip_frag.h > index 7d2abe1..c2a7e1e 100644 > --- a/lib/ip_frag/rte_ip_frag.h > +++ b/lib/ip_frag/rte_ip_frag.h > @@ -179,6 +179,33 @@ int32_t rte_ipv4_fragment_packet(struct rte_mbuf > *pkt_in, > struct rte_mempool *pool_indirect); >=20 > /** > + * IPv4 fragmentation by copy. > + * > + * This function implements the fragmentation of IPv4 packets by = copy. > + * > + * @param pkt_in > + * The input packet. > + * @param pkts_out > + * Array storing the output fragments. > + * @param mtu_size > + * Size in bytes of the Maximum Transfer Unit (MTU) for the = outgoing > IPv4 > + * datagrams. This value includes the size of the IPv4 header. > + * @param pool_direct > + * MBUF pool used for allocating direct buffers for the output > fragments. > + * @return > + * Upon successful completion - number of output fragments placed > + * in the pkts_out array. > + * Otherwise - (-1) * errno. > + */ > +__rte_experimental > +int32_t > +rte_ipv4_fragment_copy_packet(struct rte_mbuf *pkt_in, > + struct rte_mbuf **pkts_out, > + uint16_t nb_pkts_out, > + uint16_t mtu_size, > + struct rte_mempool *pool_direct); > + > +/** > * This function implements reassembly of fragmented IPv4 packets. > * Incoming mbufs should have its l2_len/l3_len fields setup > correctly. > * > diff --git a/lib/ip_frag/rte_ipv4_fragmentation.c > b/lib/ip_frag/rte_ipv4_fragmentation.c > index 27a8ad2..cb15781 100644 > --- a/lib/ip_frag/rte_ipv4_fragmentation.c > +++ b/lib/ip_frag/rte_ipv4_fragmentation.c > @@ -83,6 +83,48 @@ static inline uint16_t > __create_ipopt_frag_hdr(uint8_t *iph, > return ipopt_len; > } >=20 > +static struct rte_mbuf * > +__copy_to_pktmbuf(char *src, struct rte_mbuf *m_head, > + struct rte_mbuf *m_tail, struct rte_mempool *mp, uint32_t len) > +{ > + struct rte_mbuf *m_last, **prev; > + > + m_last =3D m_tail; > + prev =3D &m_last->next; > + while (len > 0) { > + uint32_t copy_len; > + > + /* current buffer is full, chain a new one */ > + if (unlikely(rte_pktmbuf_tailroom(m_last) =3D=3D 0)) { > + m_last =3D rte_pktmbuf_alloc(mp); > + if (unlikely(m_last =3D=3D NULL)) > + return NULL; > + > + ++m_head->nb_segs; > + *prev =3D m_last; > + prev =3D &m_last->next; > + } I think that MBUF_FAST_FREE also requires non-segmented packets, = although this requirement is missing in the documentation. I have asked = Olivier (as MBUF maintainer) to confirm this requirement [1]. [1] = http://inbox.dpdk.org/dev/98CBD80474FA8B44BF855DF32C47DC35D871C5@smartser= ver.smartshare.dk/ > + > + /* > + * copy the min of data in len > + * vs space available in output (m_last) > + */ > + copy_len =3D RTE_MIN(rte_pktmbuf_tailroom(m_last), len); > + > + /* append from seg to m_last */ > + memcpy(rte_pktmbuf_mtod_offset(m_last, char *, m_last- > >data_len), > + src, copy_len); > + > + /* update offsets and lengths */ > + m_last->data_len +=3D copy_len; > + m_head->pkt_len +=3D copy_len; > + src +=3D copy_len; > + len -=3D copy_len; > + } > + > + return m_last; > +} > + > /** > * IPv4 fragmentation. > *