From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Ananyev, Konstantin" Subject: Re: [PATCH 1/5] lib: add Generic Segmentation Offload API framework Date: Wed, 30 Aug 2017 01:38:02 +0000 Message-ID: <2601191342CEEE43887BDE71AB9772584F23E089@IRSMSX103.ger.corp.intel.com> References: <1503584144-63181-1-git-send-email-jiayu.hu@intel.com> <1503584144-63181-2-git-send-email-jiayu.hu@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Cc: "Kavanagh, Mark B" , "Tan, Jianfeng" To: "Hu, Jiayu" , "dev@dpdk.org" Return-path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 7ADF02BAF for ; Wed, 30 Aug 2017 03:38:05 +0200 (CEST) In-Reply-To: <1503584144-63181-2-git-send-email-jiayu.hu@intel.com> Content-Language: en-US List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Hi Jiayu, >=20 > Generic Segmentation Offload (GSO) is a SW technique to split large > packets into small ones. Akin to TSO, GSO enables applications to > operate on large packets, thus reducing per-packet processing overhead. >=20 > To enable more flexibility to applications, DPDK GSO is implemented > as a standalone library. Applications explicitly use the GSO library > to segment packets. This patch introduces the GSO API framework to DPDK. >=20 > The GSO library provides a segmentation API, rte_gso_segment(), for > applications. It splits an input packet into small ones in each > invocation. The GSO library refers to these small packets generated > by rte_gso_segment() as GSO segments. When all GSO segments are freed, > the input packet is freed automatically. >=20 > Signed-off-by: Jiayu Hu > Signed-off-by: Mark Kavanagh > --- > config/common_base | 5 ++ > lib/Makefile | 2 + > lib/librte_gso/Makefile | 49 ++++++++++++++++ > lib/librte_gso/rte_gso.c | 47 ++++++++++++++++ > lib/librte_gso/rte_gso.h | 111 +++++++++++++++++++++++++++++++= ++++++ > lib/librte_gso/rte_gso_version.map | 7 +++ > mk/rte.app.mk | 1 + > 7 files changed, 222 insertions(+) > create mode 100644 lib/librte_gso/Makefile > create mode 100644 lib/librte_gso/rte_gso.c > create mode 100644 lib/librte_gso/rte_gso.h > create mode 100644 lib/librte_gso/rte_gso_version.map >=20 > diff --git a/config/common_base b/config/common_base > index 5e97a08..603e340 100644 > --- a/config/common_base > +++ b/config/common_base > @@ -652,6 +652,11 @@ CONFIG_RTE_LIBRTE_IP_FRAG_TBL_STAT=3Dn > CONFIG_RTE_LIBRTE_GRO=3Dy >=20 > # > +# Compile GSO library > +# > +CONFIG_RTE_LIBRTE_GSO=3Dy > + > +# > # Compile librte_meter > # > CONFIG_RTE_LIBRTE_METER=3Dy > diff --git a/lib/Makefile b/lib/Makefile > index 86caba1..3d123f4 100644 > --- a/lib/Makefile > +++ b/lib/Makefile > @@ -108,6 +108,8 @@ DIRS-$(CONFIG_RTE_LIBRTE_REORDER) +=3D librte_reorder > DEPDIRS-librte_reorder :=3D librte_eal librte_mempool librte_mbuf > DIRS-$(CONFIG_RTE_LIBRTE_PDUMP) +=3D librte_pdump > DEPDIRS-librte_pdump :=3D librte_eal librte_mempool librte_mbuf librte_e= ther > +DIRS-$(CONFIG_RTE_LIBRTE_GSO) +=3D librte_gso > +DEPDIRS-librte_gso :=3D librte_eal librte_mbuf librte_ether librte_net >=20 > ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP),y) > DIRS-$(CONFIG_RTE_LIBRTE_KNI) +=3D librte_kni > diff --git a/lib/librte_gso/Makefile b/lib/librte_gso/Makefile > new file mode 100644 > index 0000000..aeaacbc > --- /dev/null > +++ b/lib/librte_gso/Makefile > @@ -0,0 +1,49 @@ > +# BSD LICENSE > +# > +# Copyright(c) 2017 Intel Corporation. All rights reserved. > +# All rights reserved. > +# > +# Redistribution and use in source and binary forms, with or without > +# modification, are permitted provided that the following conditions > +# are met: > +# > +# * Redistributions of source code must retain the above copyright > +# notice, this list of conditions and the following disclaimer. > +# * Redistributions in binary form must reproduce the above copyrigh= t > +# notice, this list of conditions and the following disclaimer in > +# the documentation and/or other materials provided with the > +# distribution. > +# * Neither the name of Intel Corporation nor the names of its > +# contributors may be used to endorse or promote products derived > +# from this software without specific prior written permission. > +# > +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT > +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FO= R > +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT > +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL= , > +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT > +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE= , > +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON AN= Y > +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT > +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE US= E > +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + > +include $(RTE_SDK)/mk/rte.vars.mk > + > +# library name > +LIB =3D librte_gso.a > + > +CFLAGS +=3D $(WERROR_FLAGS) -I$(SRCDIR) -O3 > + > +EXPORT_MAP :=3D rte_gso_version.map > + > +LIBABIVER :=3D 1 > + > +#source files > +SRCS-$(CONFIG_RTE_LIBRTE_GSO) +=3D rte_gso.c > + > +# install this header file > +SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include +=3D rte_gso.h > + > +include $(RTE_SDK)/mk/rte.lib.mk > diff --git a/lib/librte_gso/rte_gso.c b/lib/librte_gso/rte_gso.c > new file mode 100644 > index 0000000..b81afce > --- /dev/null > +++ b/lib/librte_gso/rte_gso.c > @@ -0,0 +1,47 @@ > +/*- > + * BSD LICENSE > + * > + * Copyright(c) 2017 Intel Corporation. All rights reserved. > + * All rights reserved. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * > + * * Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * * Redistributions in binary form must reproduce the above copyrig= ht > + * notice, this list of conditions and the following disclaimer in > + * the documentation and/or other materials provided with the > + * distribution. > + * * Neither the name of Intel Corporation nor the names of its > + * contributors may be used to endorse or promote products derived > + * from this software without specific prior written permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT > + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS F= OR > + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGH= T > + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTA= L, > + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT > + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF US= E, > + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON A= NY > + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT > + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE U= SE > + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE= . > + */ > + > +#include "rte_gso.h" > + > +int > +rte_gso_segment(struct rte_mbuf *pkt, > + struct rte_gso_ctx gso_ctx, > + struct rte_mbuf **pkts_out, > + uint16_t nb_pkts_out __rte_unused) > +{ > + if (pkt =3D=3D NULL || pkts_out =3D=3D NULL || gso_ctx.direct_pool =3D= =3D > + NULL || gso_ctx.indirect_pool =3D=3D NULL) > + return -EINVAL; > + > + return 1; > +} > diff --git a/lib/librte_gso/rte_gso.h b/lib/librte_gso/rte_gso.h > new file mode 100644 > index 0000000..5a8389a > --- /dev/null > +++ b/lib/librte_gso/rte_gso.h > @@ -0,0 +1,111 @@ > +/*- > + * BSD LICENSE > + * > + * Copyright(c) 2017 Intel Corporation. All rights reserved. > + * All rights reserved. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * > + * * Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * * Redistributions in binary form must reproduce the above copyrig= ht > + * notice, this list of conditions and the following disclaimer in > + * the documentation and/or other materials provided with the > + * distribution. > + * * Neither the name of Intel Corporation nor the names of its > + * contributors may be used to endorse or promote products derived > + * from this software without specific prior written permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT > + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS F= OR > + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGH= T > + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTA= L, > + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT > + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF US= E, > + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON A= NY > + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT > + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE U= SE > + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE= . > + */ > + > +#ifndef _RTE_GSO_H_ > +#define _RTE_GSO_H_ > + > +/** > + * @file > + * Interface to GSO library > + */ > + > +#ifdef __cplusplus > +extern "C" { > +#endif > + > +#include > +#include > + > +/** > + * GSO context structure. > + */ > +struct rte_gso_ctx { > + struct rte_mempool *direct_pool; > + /**< MBUF pool for allocating direct buffers, which are used > + * to store packet headers for GSO segments. > + */ > + struct rte_mempool *indirect_pool; > + /**< MBUF pool for allocating indirect buffers, which are used > + * to locate packet payloads for GSO segments. The indirect > + * buffer doesn't contain any data, but simply points to an > + * offset within the packet to segment. > + */ > + uint64_t gso_types; > + /**< GSO types to perform */ Looking at the way it is used right now - there seems not much value in it.= .. Why not to make it a mask of ptypes for which GSO should be perfomed? Let say for gso_ctx that supports only ip4/tcp it would be: gso_types =3D (RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_TCP) and then in rte_gso_segment() we can perfom gso only on packets of requeste= d ptype: if ((pkt->packet_type & gso_ctx->gso_types) =3D=3D pkt->packet_type) { /* do segmentation */ } else { /* skip segmentation for that packet */ } > + uint16_t gso_size; > + /**< maximum size of a GSO segment, measured in bytes */ Is that MSS or MTU? > +}; > + > +/** > + * Segmentation function, which supports processing of both single- and > + * multi- segment packets. rte_gso_segment() assumes the input packet > + * has correct checksums, and it doesn't process IP fragment packets. > + * Additionally, it assumes that 'pkts_out' is large enough to hold all = GSO > + * segments. > + * > + * We refer to the packets that are segmented from the input packet as '= GSO > + * segments'. If the input packet is GSOed, its mbuf refcnt reduces by 1= . > + * Therefore, when all GSO segments are freed, the input packet is freed > + * automatically. If the input packet doesn't match the criteria for GSO > + * (e.g. 'pkt's length is small and doesn't need segmentation), the pack= et > + * is skipped and this function returns 1. If the available memory space > + * in MBUF pools is insufficient, the packet is skipped and return -ENOM= EM. > + * > + * @param pkt > + * The packet mbuf to segment. > + * @param ctx > + * GSO context object. > + * @param pkts_out > + * Pointer array used to stores the mbuf addresses of GSO segments. > + * Applications must ensure pkts_out is large enough to hold all GSO > + * segments. If the memory space in pkts_out is insufficient, the input > + * packet is skipped and return -EINVAL. > + * @param nb_pkts_out > + * The max number of items that pkts_out can keep. > + * > + * @return > + * - The number of GSO segments created on success. > + * - Return 1 if no GSO is performed. Wouldn't it be better to return number of elems filled in pkts_out[] on suc= cess? > + * - Return -ENOMEM if run out of memory in MBUF pools. > + * - Return -EINVAL for invalid parameters. > + */ > +int rte_gso_segment(struct rte_mbuf *pkt, > + struct rte_gso_ctx ctx, > + struct rte_mbuf **pkts_out, > + uint16_t nb_pkts_out); > + > +#ifdef __cplusplus > +} > +#endif > + > +#endif /* _RTE_GSO_H_ */ > diff --git a/lib/librte_gso/rte_gso_version.map b/lib/librte_gso/rte_gso_= version.map > new file mode 100644 > index 0000000..e1fd453 > --- /dev/null > +++ b/lib/librte_gso/rte_gso_version.map > @@ -0,0 +1,7 @@ > +DPDK_17.11 { > + global: > + > + rte_gso_segment; > + > + local: *; > +}; > diff --git a/mk/rte.app.mk b/mk/rte.app.mk > index c25fdd9..d4c9873 100644 > --- a/mk/rte.app.mk > +++ b/mk/rte.app.mk > @@ -66,6 +66,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_PDUMP) +=3D -lrte_= pdump > _LDLIBS-$(CONFIG_RTE_LIBRTE_DISTRIBUTOR) +=3D -lrte_distributor > _LDLIBS-$(CONFIG_RTE_LIBRTE_IP_FRAG) +=3D -lrte_ip_frag > _LDLIBS-$(CONFIG_RTE_LIBRTE_GRO) +=3D -lrte_gro > +_LDLIBS-$(CONFIG_RTE_LIBRTE_GSO) +=3D -lrte_gso > _LDLIBS-$(CONFIG_RTE_LIBRTE_METER) +=3D -lrte_meter > _LDLIBS-$(CONFIG_RTE_LIBRTE_SCHED) +=3D -lrte_sched > _LDLIBS-$(CONFIG_RTE_LIBRTE_LPM) +=3D -lrte_lpm > -- > 2.7.4