[dpdk-dev] [PATCH v2 00/12] Introducing the TILE-Gx platform
On Mon, 22 Jun 2015 11:58:32 -0700 Cyril Chemparathy wrote: > This series adds support for the EZchip TILE-Gx family of SoCs. The > architecture port in itself is fairly straight forward due to its > reliance on generics for the most part. > > In addition to adding TILE-Gx architecture specific code, this series > includes a few cross-platform fixes for DPDK (cpuflags, SSE related, > etc.), as well as minor extensions to to accomodate a wider range of > hugepage sizes and configurable mempool element alignment boundaries. > > Changes in this series: > v2: Removed RTE_LIBNAME per Thomas' feedback. > [...] Thomas, Any feedback on this series? Thanks -- Cyril.
[dpdk-dev] [PATCH v2 08/12] mempool: allow config override on element alignment
On Tue, 23 Jun 2015 00:31:06 + "Ananyev, Konstantin" wrote: > > +#define RTE_MEMPOOL_ALIGN_MASK (RTE_MEMPOOL_ALIGN - 1) > > I am probably a bit late with my comments, but why not make it a > runtime decision then? I know we can't add a new parameter to > mempool_xmem_create() without ABI breakage, but we can make some > global variable for now, that could be setup at init time or > something similar. But then, a global variable that is modified by an application _is_ a part of the ABI, and a bad one at that. I agree with the desire to make it runtime configurable, but I think we should do so in the right spirit, with the appropriate interfaces, and when we're open to changing the ABI accordingly. Thanks -- Cyril.
[dpdk-dev] [PATCH v4 0/9] Improve cast alignment for strict aligned machines
On Tue, 23 Jun 2015 17:36:40 +0200 Olivier MATZ wrote: > Series > Acked-by: Olivier Matz > Thanks Olivier.
[dpdk-dev] [PATCH] lib: fix RTE_MBUF_METADATA macros
On Mon, 22 Jun 2015 22:16:59 +0200 Thomas Monjalon wrote: > 2015-06-05 15:31, Dumitrescu, Cristian: > > > Fix RTE_MBUF_METADATA macros to allow for unaligned accesses to > > > meta-data fields. > > > Forcing aligned accesses is not really required, so this is > > > removing an unneeded constraint. > > > This issue was met during testing of the new version of the > > > ip_pipeline application. There is no performance impact. > > > This change has no ABI impact, as the previous code that uses > > > aligned accesses continues to run without any issues. > > > > > > Signed-off-by: Daniel Mrzyglod > > > > Ack-ed by: Cristian Dumitrescu > > Applied, thanks > > Cyril, feel free to fix it if it breaks with Tile arch. Also, in the code, doesn't the following break when mbuf_priv_size != 0? > #define RTE_MBUF_METADATA_UINT8_PTR(mbuf, offset) \ > (&((uint8_t *) &(mbuf)[1])[offset]) Thanks -- Cyril.
[dpdk-dev] [PATCH] lib: fix RTE_MBUF_METADATA macros
On Mon, 22 Jun 2015 22:16:59 +0200 Thomas Monjalon wrote: > 2015-06-05 15:31, Dumitrescu, Cristian: > > > Fix RTE_MBUF_METADATA macros to allow for unaligned accesses to > > > meta-data fields. > > > Forcing aligned accesses is not really required, so this is > > > removing an unneeded constraint. > > > This issue was met during testing of the new version of the > > > ip_pipeline application. There is no performance impact. > > > This change has no ABI impact, as the previous code that uses > > > aligned accesses continues to run without any issues. > > > > > > Signed-off-by: Daniel Mrzyglod > > > > Ack-ed by: Cristian Dumitrescu > > Applied, thanks > > Cyril, feel free to fix it if it breaks with Tile arch. Why define these locally within rte_port.h? Shouldn't these macros really be in rte_mbuf.h?
[dpdk-dev] [PATCH v2 12/12] maintainers: claim responsibility for TILE-Gx platform
Change-Id: I6491108ff86c1249bf4ffa4d4624c01b4594805e Signed-off-by: Cyril Chemparathy --- MAINTAINERS | 4 1 file changed, 4 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 9362c19..bffc1e6 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -113,6 +113,10 @@ M: Bruce Richardson M: Konstantin Ananyev F: lib/librte_eal/common/include/arch/x86/ +EZchip TILE-Gx +M: Zhigang Lu +F: lib/librte_eal/common/include/arch/tile/ + Linux EAL (with overlaps) M: David Marchand F: lib/librte_eal/linuxapp/Makefile -- 2.1.2
[dpdk-dev] [PATCH v2 11/12] tile: Add TILE-Gx mPIPE poll mode driver.
This commit adds a poll mode driver for the mPIPE hardware present on TILE-Gx SoCs. Change-Id: I1b9a9ef2c9f1c96810ec58b4d2ae77b870a6ec94 Signed-off-by: Cyril Chemparathy --- config/defconfig_tile-tilegx-linuxapp-gcc |1 + drivers/net/Makefile |1 + drivers/net/mpipe/Makefile| 46 + drivers/net/mpipe/mpipe_tilegx.c | 1637 + mk/rte.app.mk |1 + 5 files changed, 1686 insertions(+) create mode 100644 drivers/net/mpipe/Makefile create mode 100644 drivers/net/mpipe/mpipe_tilegx.c diff --git a/config/defconfig_tile-tilegx-linuxapp-gcc b/config/defconfig_tile-tilegx-linuxapp-gcc index 4023878..e603d1b 100644 --- a/config/defconfig_tile-tilegx-linuxapp-gcc +++ b/config/defconfig_tile-tilegx-linuxapp-gcc @@ -66,4 +66,5 @@ CONFIG_RTE_LIBRTE_TABLE=n CONFIG_RTE_LIBRTE_PIPELINE=n # Enable and override things that we need +CONFIG_RTE_LIBRTE_MPIPE_PMD=y CONFIG_RTE_MEMPOOL_ALIGN=128 diff --git a/drivers/net/Makefile b/drivers/net/Makefile index 1e6648a..f11b64b 100644 --- a/drivers/net/Makefile +++ b/drivers/net/Makefile @@ -35,6 +35,7 @@ DIRS-$(CONFIG_RTE_LIBRTE_PMD_AF_PACKET) += af_packet DIRS-$(CONFIG_RTE_LIBRTE_PMD_BOND) += bonding DIRS-$(CONFIG_RTE_LIBRTE_E1000_PMD) += e1000 DIRS-$(CONFIG_RTE_LIBRTE_ENIC_PMD) += enic +DIRS-$(CONFIG_RTE_LIBRTE_MPIPE_PMD) += mpipe DIRS-$(CONFIG_RTE_LIBRTE_FM10K_PMD) += fm10k DIRS-$(CONFIG_RTE_LIBRTE_I40E_PMD) += i40e DIRS-$(CONFIG_RTE_LIBRTE_IXGBE_PMD) += ixgbe diff --git a/drivers/net/mpipe/Makefile b/drivers/net/mpipe/Makefile new file mode 100644 index 000..552b303 --- /dev/null +++ b/drivers/net/mpipe/Makefile @@ -0,0 +1,46 @@ +# +# Copyright 2015 EZchip Semiconductor Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# +# 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 +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT HOLDER 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 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +include $(RTE_SDK)/mk/rte.vars.mk + +# library name +LIB = librte_pmd_mpipe.a + +CFLAGS += $(WERROR_FLAGS) -O3 + +EXPORT_MAP := rte_pmd_mpipe_version.map + +LIBABIVER := 1 + +SRCS-$(CONFIG_RTE_LIBRTE_MPIPE_PMD) += mpipe_tilegx.c + +DEPDIRS-$(CONFIG_RTE_LIBRTE_MPIPE_PMD) += lib/librte_eal lib/librte_ether +DEPDIRS-$(CONFIG_RTE_LIBRTE_MPIPE_PMD) += lib/librte_mempool lib/librte_mbuf +DEPDIRS-$(CONFIG_RTE_LIBRTE_MPIPE_PMD) += lib/librte_net lib/librte_malloc + +include $(RTE_SDK)/mk/rte.lib.mk diff --git a/drivers/net/mpipe/mpipe_tilegx.c b/drivers/net/mpipe/mpipe_tilegx.c new file mode 100644 index 000..e222443 --- /dev/null +++ b/drivers/net/mpipe/mpipe_tilegx.c @@ -0,0 +1,1637 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2015 EZchip Semiconductor Ltd. 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 copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of EZchip Semiconductor 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 FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * O
[dpdk-dev] [PATCH v2 10/12] tile: initial TILE-Gx support.
This commit adds support for the TILE-Gx platform, as well as the TILE CPU architecture. This architecture port is fairly simple due to its reliance on generics for most arch stuff. Change-Id: I809fcf740e25ba5976a6b7736c1673515338cf80 Signed-off-by: Cyril Chemparathy --- config/defconfig_tile-tilegx-linuxapp-gcc | 69 .../common/include/arch/tile/rte_atomic.h | 86 .../common/include/arch/tile/rte_byteorder.h | 91 + .../common/include/arch/tile/rte_cpuflags.h| 85 .../common/include/arch/tile/rte_cycles.h | 70 .../common/include/arch/tile/rte_memcpy.h | 93 ++ .../common/include/arch/tile/rte_prefetch.h| 61 ++ .../common/include/arch/tile/rte_rwlock.h | 70 .../common/include/arch/tile/rte_spinlock.h| 92 + mk/arch/tile/rte.vars.mk | 39 + mk/machine/tilegx/rte.vars.mk | 57 + 11 files changed, 813 insertions(+) create mode 100644 config/defconfig_tile-tilegx-linuxapp-gcc create mode 100644 lib/librte_eal/common/include/arch/tile/rte_atomic.h create mode 100644 lib/librte_eal/common/include/arch/tile/rte_byteorder.h create mode 100644 lib/librte_eal/common/include/arch/tile/rte_cpuflags.h create mode 100644 lib/librte_eal/common/include/arch/tile/rte_cycles.h create mode 100644 lib/librte_eal/common/include/arch/tile/rte_memcpy.h create mode 100644 lib/librte_eal/common/include/arch/tile/rte_prefetch.h create mode 100644 lib/librte_eal/common/include/arch/tile/rte_rwlock.h create mode 100644 lib/librte_eal/common/include/arch/tile/rte_spinlock.h create mode 100644 mk/arch/tile/rte.vars.mk create mode 100644 mk/machine/tilegx/rte.vars.mk diff --git a/config/defconfig_tile-tilegx-linuxapp-gcc b/config/defconfig_tile-tilegx-linuxapp-gcc new file mode 100644 index 000..4023878 --- /dev/null +++ b/config/defconfig_tile-tilegx-linuxapp-gcc @@ -0,0 +1,69 @@ +# BSD LICENSE +# +# Copyright (C) EZchip Semiconductor 2015. +# +# 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 copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of EZchip Semiconductor 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 FOR +# 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 ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include "common_linuxapp" + +CONFIG_RTE_MACHINE="tilegx" + +CONFIG_RTE_ARCH="tile" +CONFIG_RTE_ARCH_TILE=y +CONFIG_RTE_ARCH_64=y +CONFIG_RTE_ARCH_STRICT_ALIGN=y +CONFIG_RTE_FORCE_INTRINSICS=y + +CONFIG_RTE_TOOLCHAIN="gcc" +CONFIG_RTE_TOOLCHAIN_GCC=y + +# Disable things that we don't support or need +CONFIG_RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT=n +CONFIG_RTE_EAL_IGB_UIO=n +CONFIG_RTE_EAL_VFIO=n +CONFIG_RTE_LIBRTE_KNI=n +CONFIG_RTE_LIBRTE_XEN_DOM0=n +CONFIG_RTE_LIBRTE_IGB_PMD=n +CONFIG_RTE_LIBRTE_EM_PMD=n +CONFIG_RTE_LIBRTE_IXGBE_PMD=n +CONFIG_RTE_LIBRTE_I40E_PMD=n +CONFIG_RTE_LIBRTE_FM10K_PMD=n +CONFIG_RTE_LIBRTE_VIRTIO_PMD=n +CONFIG_RTE_LIBRTE_VMXNET3_PMD=n +CONFIG_RTE_LIBRTE_ENIC_PMD=n + +# This following libraries are not available on the tile architecture. So +# they're turned off. +CONFIG_RTE_LIBRTE_LPM=n +CONFIG_RTE_LIBRTE_ACL=n +CONFIG_RTE_LIBRTE_SCHED=n +CONFIG_RTE_LIBRTE_PORT=n +CONFIG_RTE_LIBRTE_TABLE=n +CONFIG_RTE_LIBRTE_PIPELINE=n + +# Enable and override things that we need +CONFIG_RTE_MEMPOOL_ALIGN=128 diff --git a/lib/librte_eal/common/include/arch/tile/rte_atomic.h b/lib/librte_eal/common/include/arch/tile/rte_atomic.h new file mode 100644 index 000.
[dpdk-dev] [PATCH v2 09/12] tile: add page sizes for TILE-Gx/Mx platforms
This patch adds a few new page sizes that are supported on the TILE-Gx and TILE-Mx platforms. Change-Id: I7da783703149c4f96b84d0017fa4f1191fc029c6 Signed-off-by: Cyril Chemparathy --- lib/librte_eal/common/eal_common_memzone.c | 8 + lib/librte_eal/common/include/rte_memory.h | 16 + lib/librte_eal/common/include/rte_memzone.h | 50 +++-- 3 files changed, 51 insertions(+), 23 deletions(-) diff --git a/lib/librte_eal/common/eal_common_memzone.c b/lib/librte_eal/common/eal_common_memzone.c index 84b773c..53f6040 100644 --- a/lib/librte_eal/common/eal_common_memzone.c +++ b/lib/librte_eal/common/eal_common_memzone.c @@ -284,12 +284,20 @@ rte_memzone_reserve_thread_safe(const char *name, size_t len, const struct rte_memzone *mz = NULL; uint64_t size_mask = 0; + if (flags & RTE_MEMZONE_256KB) + size_mask |= RTE_PGSIZE_256K; if (flags & RTE_MEMZONE_2MB) size_mask |= RTE_PGSIZE_2M; if (flags & RTE_MEMZONE_16MB) size_mask |= RTE_PGSIZE_16M; + if (flags & RTE_MEMZONE_256MB) + size_mask |= RTE_PGSIZE_256M; + if (flags & RTE_MEMZONE_512MB) + size_mask |= RTE_PGSIZE_512M; if (flags & RTE_MEMZONE_1GB) size_mask |= RTE_PGSIZE_1G; + if (flags & RTE_MEMZONE_4GB) + size_mask |= RTE_PGSIZE_4G; if (flags & RTE_MEMZONE_16GB) size_mask |= RTE_PGSIZE_16G; if (!size_mask) diff --git a/lib/librte_eal/common/include/rte_memory.h b/lib/librte_eal/common/include/rte_memory.h index d948c0b..1bed415 100644 --- a/lib/librte_eal/common/include/rte_memory.h +++ b/lib/librte_eal/common/include/rte_memory.h @@ -53,12 +53,16 @@ extern "C" { #endif enum rte_page_sizes { - RTE_PGSIZE_4K = 1ULL << 12, - RTE_PGSIZE_2M = 1ULL << 21, - RTE_PGSIZE_1G = 1ULL << 30, - RTE_PGSIZE_64K = 1ULL << 16, - RTE_PGSIZE_16M = 1ULL << 24, - RTE_PGSIZE_16G = 1ULL << 34 + RTE_PGSIZE_4K= 1ULL << 12, + RTE_PGSIZE_64K = 1ULL << 16, + RTE_PGSIZE_256K = 1ULL << 18, + RTE_PGSIZE_2M= 1ULL << 21, + RTE_PGSIZE_16M = 1ULL << 24, + RTE_PGSIZE_256M = 1ULL << 28, + RTE_PGSIZE_512M = 1ULL << 29, + RTE_PGSIZE_1G= 1ULL << 30, + RTE_PGSIZE_4G= 1ULL << 32, + RTE_PGSIZE_16G = 1ULL << 34, }; #define SOCKET_ID_ANY -1/**< Any NUMA socket. */ diff --git a/lib/librte_eal/common/include/rte_memzone.h b/lib/librte_eal/common/include/rte_memzone.h index ee62680..de5ae55 100644 --- a/lib/librte_eal/common/include/rte_memzone.h +++ b/lib/librte_eal/common/include/rte_memzone.h @@ -60,8 +60,12 @@ extern "C" { #define RTE_MEMZONE_2MB0x0001 /**< Use 2MB pages. */ #define RTE_MEMZONE_1GB0x0002 /**< Use 1GB pages. */ -#define RTE_MEMZONE_16MB0x0100 /**< Use 16MB pages. */ -#define RTE_MEMZONE_16GB0x0200 /**< Use 16GB pages. */ +#define RTE_MEMZONE_16MB 0x0100 /**< Use 16MB pages. */ +#define RTE_MEMZONE_16GB 0x0200 /**< Use 16GB pages. */ +#define RTE_MEMZONE_256KB 0x0001 /**< Use 256KB pages. */ +#define RTE_MEMZONE_256MB 0x0002 /**< Use 256MB pages. */ +#define RTE_MEMZONE_512MB 0x0004 /**< Use 512MB pages. */ +#define RTE_MEMZONE_4GB0x0008 /**< Use 4GB pages. */ #define RTE_MEMZONE_SIZE_HINT_ONLY 0x0004 /**< Use available page size */ /** @@ -110,11 +114,15 @@ struct rte_memzone { * constraint for the reserved zone. * @param flags * The flags parameter is used to request memzones to be - * taken from 1GB or 2MB hugepages. - * - RTE_MEMZONE_2MB - Reserve from 2MB pages - * - RTE_MEMZONE_1GB - Reserve from 1GB pages - * - RTE_MEMZONE_16MB - Reserve from 16MB pages - * - RTE_MEMZONE_16GB - Reserve from 16GB pages + * taken from specifically sized hugepages. + * - RTE_MEMZONE_2MB - Reserved from 2MB pages + * - RTE_MEMZONE_1GB - Reserved from 1GB pages + * - RTE_MEMZONE_16MB - Reserved from 16MB pages + * - RTE_MEMZONE_16GB - Reserved from 16GB pages + * - RTE_MEMZONE_256KB - Reserved from 256KB pages + * - RTE_MEMZONE_256MB - Reserved from 256MB pages + * - RTE_MEMZONE_512MB - Reserved from 512MB pages + * - RTE_MEMZONE_4GB - Reserved from 4GB pages * - RTE_MEMZONE_SIZE_HINT_ONLY - Allow alternative page size to be used if * the requested page size is unavailable. * If this flag is not set, the function @@ -157,11 +165,15 @@ const struct rte_memzone *rte_memzone_reserve(const char *name, * constraint for the reserved zone. * @param fla
[dpdk-dev] [PATCH v2 08/12] mempool: allow config override on element alignment
On TILE-Gx and TILE-Mx platforms, the buffers fed into the hardware buffer manager require a 128-byte alignment. With this change, we allow configuration based override of the element alignment, and default to RTE_CACHE_LINE_SIZE if left unspecified. Change-Id: I9cd789d92b0bc9c8f44a633de59bb04d45d927a7 Signed-off-by: Cyril Chemparathy --- lib/librte_mempool/rte_mempool.c | 16 +--- lib/librte_mempool/rte_mempool.h | 6 ++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c index 002d3a8..7656b0f 100644 --- a/lib/librte_mempool/rte_mempool.c +++ b/lib/librte_mempool/rte_mempool.c @@ -120,10 +120,10 @@ static unsigned optimize_object_size(unsigned obj_size) nrank = 1; /* process new object size */ - new_obj_size = (obj_size + RTE_CACHE_LINE_MASK) / RTE_CACHE_LINE_SIZE; + new_obj_size = (obj_size + RTE_MEMPOOL_ALIGN_MASK) / RTE_MEMPOOL_ALIGN; while (get_gcd(new_obj_size, nrank * nchan) != 1) new_obj_size++; - return new_obj_size * RTE_CACHE_LINE_SIZE; + return new_obj_size * RTE_MEMPOOL_ALIGN; } static void @@ -267,7 +267,7 @@ rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags, #endif if ((flags & MEMPOOL_F_NO_CACHE_ALIGN) == 0) sz->header_size = RTE_ALIGN_CEIL(sz->header_size, - RTE_CACHE_LINE_SIZE); + RTE_MEMPOOL_ALIGN); /* trailer contains the cookie in debug mode */ sz->trailer_size = 0; @@ -281,9 +281,9 @@ rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags, if ((flags & MEMPOOL_F_NO_CACHE_ALIGN) == 0) { sz->total_size = sz->header_size + sz->elt_size + sz->trailer_size; - sz->trailer_size += ((RTE_CACHE_LINE_SIZE - - (sz->total_size & RTE_CACHE_LINE_MASK)) & -RTE_CACHE_LINE_MASK); + sz->trailer_size += ((RTE_MEMPOOL_ALIGN - + (sz->total_size & RTE_MEMPOOL_ALIGN_MASK)) & +RTE_MEMPOOL_ALIGN_MASK); } /* @@ -498,7 +498,7 @@ rte_mempool_xmem_create(const char *name, unsigned n, unsigned elt_size, * cache-aligned */ private_data_size = (private_data_size + -RTE_CACHE_LINE_MASK) & (~RTE_CACHE_LINE_MASK); +RTE_MEMPOOL_ALIGN_MASK) & (~RTE_MEMPOOL_ALIGN_MASK); if (! rte_eal_has_hugepages()) { /* @@ -525,6 +525,7 @@ rte_mempool_xmem_create(const char *name, unsigned n, unsigned elt_size, * enough to hold mempool header and metadata plus mempool objects. */ mempool_size = MEMPOOL_HEADER_SIZE(mp, pg_num) + private_data_size; + mempool_size = RTE_ALIGN_CEIL(mempool_size, RTE_MEMPOOL_ALIGN); if (vaddr == NULL) mempool_size += (size_t)objsz.total_size * n; @@ -580,6 +581,7 @@ rte_mempool_xmem_create(const char *name, unsigned n, unsigned elt_size, /* calculate address of the first element for continuous mempool. */ obj = (char *)mp + MEMPOOL_HEADER_SIZE(mp, pg_num) + private_data_size; + obj = RTE_PTR_ALIGN_CEIL(obj, RTE_MEMPOOL_ALIGN); /* populate address translation fields. */ mp->pg_num = pg_num; diff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h index 380d60b..9321b86 100644 --- a/lib/librte_mempool/rte_mempool.h +++ b/lib/librte_mempool/rte_mempool.h @@ -142,6 +142,12 @@ struct rte_mempool_objsz { /** Mempool over one chunk of physically continuous memory */ #defineMEMPOOL_PG_NUM_DEFAULT 1 +#ifndef RTE_MEMPOOL_ALIGN +#define RTE_MEMPOOL_ALIGN RTE_CACHE_LINE_SIZE +#endif + +#define RTE_MEMPOOL_ALIGN_MASK (RTE_MEMPOOL_ALIGN - 1) + /** * Mempool object header structure * -- 2.1.2
[dpdk-dev] [PATCH v2 07/12] memzone: allow multiple pagesizes to be requested
This patch extends the memzone allocator to remove the restriction that prevented callers from specifying multiple page sizes in the flags argument. In doing so, we also sanitize the free segment matching logic to get rid of architecture specific disjunctions (2MB vs 1GB on x86, and 16MB vs 16GB on PPC), thereby allowing for a broader range of hugepages on architectures that support it. Change-Id: Ic3713f61da49629a570fe4de34a8aaf5e2e0a19b Signed-off-by: Cyril Chemparathy --- lib/librte_eal/common/eal_common_memzone.c | 58 ++ 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/lib/librte_eal/common/eal_common_memzone.c b/lib/librte_eal/common/eal_common_memzone.c index 87057d4..84b773c 100644 --- a/lib/librte_eal/common/eal_common_memzone.c +++ b/lib/librte_eal/common/eal_common_memzone.c @@ -113,7 +113,8 @@ align_phys_boundary(const struct rte_memseg *ms, size_t len, size_t align, static const struct rte_memzone * memzone_reserve_aligned_thread_unsafe(const char *name, size_t len, - int socket_id, unsigned flags, unsigned align, unsigned bound) + int socket_id, uint64_t size_mask, unsigned align, + unsigned bound) { struct rte_mem_config *mcfg; unsigned i = 0; @@ -201,18 +202,7 @@ memzone_reserve_aligned_thread_unsafe(const char *name, size_t len, if ((requested_len + addr_offset) > free_memseg[i].len) continue; - /* check flags for hugepage sizes */ - if ((flags & RTE_MEMZONE_2MB) && - free_memseg[i].hugepage_sz == RTE_PGSIZE_1G) - continue; - if ((flags & RTE_MEMZONE_1GB) && - free_memseg[i].hugepage_sz == RTE_PGSIZE_2M) - continue; - if ((flags & RTE_MEMZONE_16MB) && - free_memseg[i].hugepage_sz == RTE_PGSIZE_16G) - continue; - if ((flags & RTE_MEMZONE_16GB) && - free_memseg[i].hugepage_sz == RTE_PGSIZE_16M) + if ((size_mask & free_memseg[i].hugepage_sz) == 0) continue; /* this segment is the best until now */ @@ -244,16 +234,6 @@ memzone_reserve_aligned_thread_unsafe(const char *name, size_t len, /* no segment found */ if (memseg_idx == -1) { - /* -* If RTE_MEMZONE_SIZE_HINT_ONLY flag is specified, -* try allocating again without the size parameter otherwise -fail. -*/ - if ((flags & RTE_MEMZONE_SIZE_HINT_ONLY) && - ((flags & RTE_MEMZONE_1GB) || (flags & RTE_MEMZONE_2MB) - || (flags & RTE_MEMZONE_16MB) || (flags & RTE_MEMZONE_16GB))) - return memzone_reserve_aligned_thread_unsafe(name, - len, socket_id, 0, align, bound); - rte_errno = ENOMEM; return NULL; } @@ -302,13 +282,18 @@ rte_memzone_reserve_thread_safe(const char *name, size_t len, { struct rte_mem_config *mcfg; const struct rte_memzone *mz = NULL; - - /* both sizes cannot be explicitly called for */ - if (((flags & RTE_MEMZONE_1GB) && (flags & RTE_MEMZONE_2MB)) - || ((flags & RTE_MEMZONE_16MB) && (flags & RTE_MEMZONE_16GB))) { - rte_errno = EINVAL; - return NULL; - } + uint64_t size_mask = 0; + + if (flags & RTE_MEMZONE_2MB) + size_mask |= RTE_PGSIZE_2M; + if (flags & RTE_MEMZONE_16MB) + size_mask |= RTE_PGSIZE_16M; + if (flags & RTE_MEMZONE_1GB) + size_mask |= RTE_PGSIZE_1G; + if (flags & RTE_MEMZONE_16GB) + size_mask |= RTE_PGSIZE_16G; + if (!size_mask) + size_mask = UINT64_MAX; /* get pointer to global configuration */ mcfg = rte_eal_get_configuration()->mem_config; @@ -316,7 +301,18 @@ rte_memzone_reserve_thread_safe(const char *name, size_t len, rte_rwlock_write_lock(>mlock); mz = memzone_reserve_aligned_thread_unsafe( - name, len, socket_id, flags, align, bound); + name, len, socket_id, size_mask, align, bound); + + /* +* If we failed to allocate the requested page size, and the +* RTE_MEMZONE_SIZE_HINT_ONLY flag is specified, try allocating +* again. +*/ + if (!mz && rte_errno == ENOMEM && size_mask != UINT64_MAX && + flags & RTE_MEMZONE_SIZE_HINT_ONLY) { + mz = memzone_reserve_aligned_thread_unsafe( + name, len, socket_id, UINT64_MAX, align, bound); + } rte_rwlock_write_unlock(>mlock); -- 2.1.2
[dpdk-dev] [PATCH v2 06/12] memzone: refactor rte_memzone_reserve() variants
The definitions of rte_memzone_reserve_aligned() and rte_memzone_reserve_bounded() were identical with the exception of the bound argument passed into rte_memzone_reserve_thread_safe(). This patch removes this replication of code by unifying it into rte_memzone_reserve_thread_safe(), which is then called by all three variants of rte_memzone_reserve(). Change-Id: Id26c25b4dd3d07861eaf35e72aaa2de555916fa3 Signed-off-by: Cyril Chemparathy --- lib/librte_eal/common/eal_common_memzone.c | 77 +- 1 file changed, 33 insertions(+), 44 deletions(-) diff --git a/lib/librte_eal/common/eal_common_memzone.c b/lib/librte_eal/common/eal_common_memzone.c index 888f9e5..87057d4 100644 --- a/lib/librte_eal/common/eal_common_memzone.c +++ b/lib/librte_eal/common/eal_common_memzone.c @@ -77,18 +77,6 @@ memzone_lookup_thread_unsafe(const char *name) } /* - * Return a pointer to a correctly filled memzone descriptor. If the - * allocation cannot be done, return NULL. - */ -const struct rte_memzone * -rte_memzone_reserve(const char *name, size_t len, int socket_id, - unsigned flags) -{ - return rte_memzone_reserve_aligned(name, - len, socket_id, flags, RTE_CACHE_LINE_SIZE); -} - -/* * Helper function for memzone_reserve_aligned_thread_unsafe(). * Calculate address offset from the start of the segment. * Align offset in that way that it satisfy istart alignmnet and @@ -307,13 +295,10 @@ memzone_reserve_aligned_thread_unsafe(const char *name, size_t len, return mz; } -/* - * Return a pointer to a correctly filled memzone descriptor (with a - * specified alignment). If the allocation cannot be done, return NULL. - */ -const struct rte_memzone * -rte_memzone_reserve_aligned(const char *name, size_t len, - int socket_id, unsigned flags, unsigned align) +static const struct rte_memzone * +rte_memzone_reserve_thread_safe(const char *name, size_t len, + int socket_id, unsigned flags, unsigned align, + unsigned bound) { struct rte_mem_config *mcfg; const struct rte_memzone *mz = NULL; @@ -331,7 +316,7 @@ rte_memzone_reserve_aligned(const char *name, size_t len, rte_rwlock_write_lock(>mlock); mz = memzone_reserve_aligned_thread_unsafe( - name, len, socket_id, flags, align, 0); + name, len, socket_id, flags, align, bound); rte_rwlock_write_unlock(>mlock); @@ -340,36 +325,40 @@ rte_memzone_reserve_aligned(const char *name, size_t len, /* * Return a pointer to a correctly filled memzone descriptor (with a - * specified alignment and boundary). - * If the allocation cannot be done, return NULL. + * specified alignment and boundary). If the allocation cannot be done, + * return NULL. */ const struct rte_memzone * -rte_memzone_reserve_bounded(const char *name, size_t len, - int socket_id, unsigned flags, unsigned align, unsigned bound) +rte_memzone_reserve_bounded(const char *name, size_t len, int socket_id, + unsigned flags, unsigned align, unsigned bound) { - struct rte_mem_config *mcfg; - const struct rte_memzone *mz = NULL; - - /* both sizes cannot be explicitly called for */ - if (((flags & RTE_MEMZONE_1GB) && (flags & RTE_MEMZONE_2MB)) - || ((flags & RTE_MEMZONE_16MB) && (flags & RTE_MEMZONE_16GB))) { - rte_errno = EINVAL; - return NULL; - } - - /* get pointer to global configuration */ - mcfg = rte_eal_get_configuration()->mem_config; - - rte_rwlock_write_lock(>mlock); - - mz = memzone_reserve_aligned_thread_unsafe( - name, len, socket_id, flags, align, bound); - - rte_rwlock_write_unlock(>mlock); + return rte_memzone_reserve_thread_safe(name, len, socket_id, flags, + align, bound); +} - return mz; +/* + * Return a pointer to a correctly filled memzone descriptor (with a + * specified alignment). If the allocation cannot be done, return NULL. + */ +const struct rte_memzone * +rte_memzone_reserve_aligned(const char *name, size_t len, int socket_id, + unsigned flags, unsigned align) +{ + return rte_memzone_reserve_thread_safe(name, len, socket_id, flags, + align, 0); } +/* + * Return a pointer to a correctly filled memzone descriptor. If the + * allocation cannot be done, return NULL. + */ +const struct rte_memzone * +rte_memzone_reserve(const char *name, size_t len, int socket_id, + unsigned flags) +{ + return rte_memzone_reserve_thread_safe(name, len, socket_id, + flags, RTE_CACHE_LINE_SIZE, 0); +} /* * Lookup for the memzone identified by the given name -- 2.1.2
[dpdk-dev] [PATCH v2 05/12] config: remove RTE_LIBNAME definition.
The library name is now being pinned to "dpdk" instead of intel_dpdk, powerpc_dpdk, etc. As a result, we no longer need this config item. This patch removes it. Change-Id: I36f7cf6c18c3563c6f5ccdf01bb70579c7ccaa16 Signed-off-by: Cyril Chemparathy --- config/common_bsdapp| 1 - config/common_linuxapp | 1 - config/defconfig_ppc_64-power8-linuxapp-gcc | 2 -- mk/rte.vars.mk | 5 + 4 files changed, 1 insertion(+), 8 deletions(-) diff --git a/config/common_bsdapp b/config/common_bsdapp index 3af59d9..6100fa9 100644 --- a/config/common_bsdapp +++ b/config/common_bsdapp @@ -87,7 +87,6 @@ CONFIG_RTE_BUILD_SHARED_LIB=n # Combine to one single library # CONFIG_RTE_BUILD_COMBINE_LIBS=n -CONFIG_RTE_LIBNAME=intel_dpdk # # Compile Environment Abstraction Layer diff --git a/config/common_linuxapp b/config/common_linuxapp index a0b37d8..2b13723 100644 --- a/config/common_linuxapp +++ b/config/common_linuxapp @@ -87,7 +87,6 @@ CONFIG_RTE_BUILD_SHARED_LIB=n # Combine to one single library # CONFIG_RTE_BUILD_COMBINE_LIBS=n -CONFIG_RTE_LIBNAME="intel_dpdk" # # Compile Environment Abstraction Layer diff --git a/config/defconfig_ppc_64-power8-linuxapp-gcc b/config/defconfig_ppc_64-power8-linuxapp-gcc index d97a885..f1af518 100644 --- a/config/defconfig_ppc_64-power8-linuxapp-gcc +++ b/config/defconfig_ppc_64-power8-linuxapp-gcc @@ -39,8 +39,6 @@ CONFIG_RTE_ARCH_64=y CONFIG_RTE_TOOLCHAIN="gcc" CONFIG_RTE_TOOLCHAIN_GCC=y -CONFIG_RTE_LIBNAME="powerpc_dpdk" - # Note: Power doesn't have this support CONFIG_RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT=n diff --git a/mk/rte.vars.mk b/mk/rte.vars.mk index d2f01b6..bb82395 100644 --- a/mk/rte.vars.mk +++ b/mk/rte.vars.mk @@ -73,10 +73,7 @@ ifneq ($(BUILDING_RTE_SDK),) endif endif -RTE_LIBNAME := $(CONFIG_RTE_LIBNAME:"%"=%) -ifeq ($(RTE_LIBNAME),) -RTE_LIBNAME := intel_dpdk -endif +RTE_LIBNAME := dpdk # RTE_TARGET is deducted from config when we are building the SDK. # Else, when building an external app, RTE_TARGET must be specified -- 2.1.2
[dpdk-dev] [PATCH v2 04/12] eal: allow empty compile time flags
The rte_cpu_check_supported() code breaks with a "comparison is always false due to limited range of data type" when the compile_time_flags[] array is empty. Assigning the array dimension to a local variable apparently solves this. Change-Id: I0ae21f529cf7b6dd9cf0f4532dce9198f4bf4230 Signed-off-by: Cyril Chemparathy --- lib/librte_eal/common/eal_common_cpuflags.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/librte_eal/common/eal_common_cpuflags.c b/lib/librte_eal/common/eal_common_cpuflags.c index 6fd360c..8ba7b30 100644 --- a/lib/librte_eal/common/eal_common_cpuflags.c +++ b/lib/librte_eal/common/eal_common_cpuflags.c @@ -30,6 +30,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include /* @@ -62,10 +63,10 @@ rte_cpu_check_supported(void) static const enum rte_cpu_flag_t compile_time_flags[] = { RTE_COMPILE_TIME_CPUFLAGS }; - unsigned i; + unsigned count = RTE_DIM(compile_time_flags), i; int ret; - for (i = 0; i < sizeof(compile_time_flags)/sizeof(compile_time_flags[0]); i++) { + for (i = 0; i < count; i++) { ret = rte_cpu_get_flag_enabled(compile_time_flags[i]); if (ret < 0) { -- 2.1.2
[dpdk-dev] [PATCH v2 03/12] hash: check SSE flags only on x86 builds
This is necessary because the required CPU flags may not be defined on other architectures. Change-Id: I14d3f9f625b2e7567123f1c97095f8d06abd674b Signed-off-by: Cyril Chemparathy --- lib/librte_hash/rte_hash_crc.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/librte_hash/rte_hash_crc.h b/lib/librte_hash/rte_hash_crc.h index abdbd9a..1f6f5bf 100644 --- a/lib/librte_hash/rte_hash_crc.h +++ b/lib/librte_hash/rte_hash_crc.h @@ -425,12 +425,14 @@ static inline void rte_hash_crc_set_alg(uint8_t alg) { switch (alg) { +#if defined(RTE_ARCH_I686) || defined(RTE_ARCH_X86_64) case CRC32_SSE42_x64: if (! rte_cpu_get_flag_enabled(RTE_CPUFLAG_EM64T)) alg = CRC32_SSE42; case CRC32_SSE42: if (! rte_cpu_get_flag_enabled(RTE_CPUFLAG_SSE4_2)) alg = CRC32_SW; +#endif case CRC32_SW: crc32_alg = alg; default: -- 2.1.2
[dpdk-dev] [PATCH v2 02/12] hash: fix compilation on non-X86 platforms
The "hash: remove duplicated code" change unfortunately broke the build for non-X86 platforms. This patch fixes this breakage. Change-Id: Ie109d67e681b75b45320fab1bf9de4eb9c9701bf Signed-off-by: Cyril Chemparathy --- lib/librte_hash/rte_jhash.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/librte_hash/rte_jhash.h b/lib/librte_hash/rte_jhash.h index e230449..d1b6cf3 100644 --- a/lib/librte_hash/rte_jhash.h +++ b/lib/librte_hash/rte_jhash.h @@ -44,6 +44,7 @@ extern "C" { #endif +#include #include #include @@ -122,7 +123,7 @@ __rte_jhash_2hashes(const void *key, uint32_t length, uint32_t *pc, const uint32_t *k = key; const uint32_t s = 0; #else - const uint32_t *k = (uint32_t *)(uintptr_t)key & (uintptr_t)~3); + const uint32_t *k = (uint32_t *)((uintptr_t)key & (uintptr_t)~3); const uint32_t s = ((uintptr_t)key & 3) * CHAR_BIT; #endif if (!check_align || s == 0) { -- 2.1.2
[dpdk-dev] [PATCH v2 01/12] test: limit x86 cpuflags checks to x86 builds
The original code mistakenly defaulted to X86 when RTE_ARCH_PPC_64 was left undefined. This did not accomodate other non-PPC/non-X86 architectures. This patch fixes this issue. Change-Id: I5e8cf33c2eb917f7f6583dc95ed0f336066a285e Signed-off-by: Cyril Chemparathy --- app/test/test_cpuflags.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/test/test_cpuflags.c b/app/test/test_cpuflags.c index 5aeba5d..5b92061 100644 --- a/app/test/test_cpuflags.c +++ b/app/test/test_cpuflags.c @@ -113,7 +113,9 @@ test_cpuflags(void) printf("Check for ICACHE_SNOOP:\t\t"); CHECK_FOR_FLAG(RTE_CPUFLAG_ICACHE_SNOOP); -#else +#endif + +#if defined(RTE_ARCH_X86_64) || defined(RTE_ARCH_I686) printf("Check for SSE:\t\t"); CHECK_FOR_FLAG(RTE_CPUFLAG_SSE); @@ -149,8 +151,6 @@ test_cpuflags(void) printf("Check for INVTSC:\t"); CHECK_FOR_FLAG(RTE_CPUFLAG_INVTSC); - - #endif /* -- 2.1.2
[dpdk-dev] [PATCH v2 00/12] Introducing the TILE-Gx platform
This series adds support for the EZchip TILE-Gx family of SoCs. The architecture port in itself is fairly straight forward due to its reliance on generics for the most part. In addition to adding TILE-Gx architecture specific code, this series includes a few cross-platform fixes for DPDK (cpuflags, SSE related, etc.), as well as minor extensions to to accomodate a wider range of hugepage sizes and configurable mempool element alignment boundaries. Changes in this series: v2: Removed RTE_LIBNAME per Thomas' feedback. Cyril Chemparathy (12): test: limit x86 cpuflags checks to x86 builds hash: fix compilation on non-X86 platforms hash: check SSE flags only on x86 builds eal: allow empty compile time flags config: remove RTE_LIBNAME definition. memzone: refactor rte_memzone_reserve() variants memzone: allow multiple pagesizes to be requested mempool: allow config override on element alignment tile: add page sizes for TILE-Gx/Mx platforms tile: initial TILE-Gx support. tile: Add TILE-Gx mPIPE poll mode driver. maintainers: claim responsibility for TILE-Gx platform MAINTAINERS|4 + app/test/test_cpuflags.c |6 +- config/common_bsdapp |1 - config/common_linuxapp |1 - config/defconfig_ppc_64-power8-linuxapp-gcc|2 - config/defconfig_tile-tilegx-linuxapp-gcc | 70 + drivers/net/Makefile |1 + drivers/net/mpipe/Makefile | 46 + drivers/net/mpipe/mpipe_tilegx.c | 1637 lib/librte_eal/common/eal_common_cpuflags.c|5 +- lib/librte_eal/common/eal_common_memzone.c | 141 +- .../common/include/arch/tile/rte_atomic.h | 86 + .../common/include/arch/tile/rte_byteorder.h | 91 ++ .../common/include/arch/tile/rte_cpuflags.h| 85 + .../common/include/arch/tile/rte_cycles.h | 70 + .../common/include/arch/tile/rte_memcpy.h | 93 ++ .../common/include/arch/tile/rte_prefetch.h| 61 + .../common/include/arch/tile/rte_rwlock.h | 70 + .../common/include/arch/tile/rte_spinlock.h| 92 ++ lib/librte_eal/common/include/rte_memory.h | 16 +- lib/librte_eal/common/include/rte_memzone.h| 50 +- lib/librte_hash/rte_hash_crc.h |2 + lib/librte_hash/rte_jhash.h|3 +- lib/librte_mempool/rte_mempool.c | 16 +- lib/librte_mempool/rte_mempool.h |6 + mk/arch/tile/rte.vars.mk | 39 + mk/machine/tilegx/rte.vars.mk | 57 + mk/rte.app.mk |1 + mk/rte.vars.mk |5 +- 29 files changed, 2639 insertions(+), 118 deletions(-) create mode 100644 config/defconfig_tile-tilegx-linuxapp-gcc create mode 100644 drivers/net/mpipe/Makefile create mode 100644 drivers/net/mpipe/mpipe_tilegx.c create mode 100644 lib/librte_eal/common/include/arch/tile/rte_atomic.h create mode 100644 lib/librte_eal/common/include/arch/tile/rte_byteorder.h create mode 100644 lib/librte_eal/common/include/arch/tile/rte_cpuflags.h create mode 100644 lib/librte_eal/common/include/arch/tile/rte_cycles.h create mode 100644 lib/librte_eal/common/include/arch/tile/rte_memcpy.h create mode 100644 lib/librte_eal/common/include/arch/tile/rte_prefetch.h create mode 100644 lib/librte_eal/common/include/arch/tile/rte_rwlock.h create mode 100644 lib/librte_eal/common/include/arch/tile/rte_spinlock.h create mode 100644 mk/arch/tile/rte.vars.mk create mode 100644 mk/machine/tilegx/rte.vars.mk -- 2.1.2
[dpdk-dev] [PATCH v4 9/9] librte_mbuf: Apply mtod-offset.cocci transform
This patch simply applies the transform previously committed in scripts/cocci/mtod-offset.cocci. No other modifications have been made here. This patch applies on commit 960e8a22fc6d9373e37dd1454131e91f082bb8bc. This patch may need to be regenerated by rerunning scripts/cocci.sh instead of simply merging in the change. Acked-by: Olivier Matz Change-Id: I1cdc4fe6f7954cebb520e495a9454cb586cace54 Signed-off-by: Cyril Chemparathy --- app/test-pmd/ieee1588fwd.c | 4 +- app/test-pmd/rxonly.c| 21 ++ app/test-pmd/txonly.c| 4 +- app/test/packet_burst_generator.c| 5 ++- drivers/net/mlx4/mlx4.c | 9 ++-- examples/dpdk_qat/crypto.c | 8 ++-- examples/dpdk_qat/main.c | 5 ++- examples/l3fwd-acl/main.c| 20 - examples/l3fwd-power/main.c | 8 ++-- examples/l3fwd-vf/main.c | 4 +- examples/l3fwd/main.c| 71 ++-- examples/load_balancer/runtime.c | 4 +- examples/vhost_xen/main.c| 4 +- lib/librte_ip_frag/rte_ipv4_reassembly.c | 3 +- lib/librte_ip_frag/rte_ipv6_reassembly.c | 5 +-- lib/librte_port/rte_port_ras.c | 6 +-- lib/librte_vhost/vhost_rxtx.c| 6 +-- 17 files changed, 90 insertions(+), 97 deletions(-) diff --git a/app/test-pmd/ieee1588fwd.c b/app/test-pmd/ieee1588fwd.c index 84237c1..dfbb185 100644 --- a/app/test-pmd/ieee1588fwd.c +++ b/app/test-pmd/ieee1588fwd.c @@ -573,8 +573,8 @@ ieee1588_packet_fwd(struct fwd_stream *fs) * Check that the received PTP packet is a PTP V2 packet of type * PTP_SYNC_MESSAGE. */ - ptp_hdr = (struct ptpv2_msg *) (rte_pktmbuf_mtod(mb, char *) + - sizeof(struct ether_hdr)); + ptp_hdr = rte_pktmbuf_mtod_offset(mb, struct ptpv2_msg *, + sizeof(struct ether_hdr)); if (ptp_hdr->version != 0x02) { printf("Port %u Received PTP V2 Ethernet frame with wrong PTP" " protocol version 0x%x (should be 0x02)\n", diff --git a/app/test-pmd/rxonly.c b/app/test-pmd/rxonly.c index ac56090..b8e35ab 100644 --- a/app/test-pmd/rxonly.c +++ b/app/test-pmd/rxonly.c @@ -175,22 +175,25 @@ pkt_burst_receive(struct fwd_stream *fs) /* Do not support ipv4 option field */ if (ol_flags & PKT_RX_TUNNEL_IPV4_HDR) { l3_len = sizeof(struct ipv4_hdr); - ipv4_hdr = (struct ipv4_hdr *) (rte_pktmbuf_mtod(mb, - unsigned char *) + l2_len); + ipv4_hdr = rte_pktmbuf_mtod_offset(mb, + struct ipv4_hdr *, + l2_len); l4_proto = ipv4_hdr->next_proto_id; } else { l3_len = sizeof(struct ipv6_hdr); - ipv6_hdr = (struct ipv6_hdr *) (rte_pktmbuf_mtod(mb, - unsigned char *) + l2_len); + ipv6_hdr = rte_pktmbuf_mtod_offset(mb, + struct ipv6_hdr *, + l2_len); l4_proto = ipv6_hdr->proto; } if (l4_proto == IPPROTO_UDP) { - udp_hdr = (struct udp_hdr *) (rte_pktmbuf_mtod(mb, - unsigned char *) + l2_len + l3_len); + udp_hdr = rte_pktmbuf_mtod_offset(mb, + struct udp_hdr *, + l2_len + l3_len); l4_len = sizeof(struct udp_hdr); - vxlan_hdr = (struct vxlan_hdr *) (rte_pktmbuf_mtod(mb, - unsigned char *) + l2_len + l3_len -+ l4_len); + vxlan_hdr = rte_pktmbuf_mtod_offset(mb, + struct vxlan_hdr *, + l2_len + l3_len + l4_len); printf(" - VXLAN packet: packet type =%d, " "Destination UDP port =%d, VNI = %d", diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c index 9e66552..f8027f1 100644 --- a/app/test-pmd/
[dpdk-dev] [PATCH v4 8/9] librte_mbuf: Add transform for rte_pktmbuf_mtod_offset()
This patch adds a coccinelle (see http://coccinelle.lip6.fr/) transform to use the newly added rte_pktmbuf_mtod_offset() helper. In addition, we add a simple script to apply all available transforms to a codebase. Acked-by: Olivier Matz Change-Id: Ie1a82c48210098dd7bece81cc77cd5ea2da4148d Signed-off-by: Cyril Chemparathy --- scripts/cocci.sh| 64 ++ scripts/cocci/mtod-offset.cocci | 76 + 2 files changed, 140 insertions(+) create mode 100755 scripts/cocci.sh create mode 100644 scripts/cocci/mtod-offset.cocci diff --git a/scripts/cocci.sh b/scripts/cocci.sh new file mode 100755 index 000..7acc256 --- /dev/null +++ b/scripts/cocci.sh @@ -0,0 +1,64 @@ +#! /bin/sh + +# BSD LICENSE +# +# Copyright 2015 EZchip Semiconductor Ltd. +# +# 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 copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of EZchip Semiconductor 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 FOR +# 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 ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# Apply coccinelle transforms. + +SRCTREE=$(readlink -f $(dirname $0)/..) +COCCI=$SRCTREE/scripts/cocci +[ -n "$SPATCH" ] || SPATCH=$(which spatch) + +PATCH_LIST="$@" +[ -n "$PATCH_LIST" ] || PATCH_LIST=$(echo $COCCI/*.cocci) + +[ -x "$SPATCH" ] || ( + echo "Coccinelle tools not installed." + exit 1 +) + +tmp=$(mktemp) + +for c in $PATCH_LIST; do + while true; do + echo -n "Applying $c..." + $SPATCH --sp-file $c -c --linux-spacing --very-quiet\ + --include-headers --preprocess \ + --in-place --dir $SRCTREE > $tmp + if [ -s $tmp ]; then + echo " changes applied, retrying." + else + echo " no change." + break; + fi + done +done + +rm -f $tmp diff --git a/scripts/cocci/mtod-offset.cocci b/scripts/cocci/mtod-offset.cocci new file mode 100644 index 000..13134e9 --- /dev/null +++ b/scripts/cocci/mtod-offset.cocci @@ -0,0 +1,76 @@ +// +// Replace explicit packet offset computations with rte_pktmbuf_mtod_offset(). +// + at disable paren@ +typedef uint8_t; +expression M, O; +@@ +( +- rte_pktmbuf_mtod(M, char *) + O ++ rte_pktmbuf_mtod_offset(M, char *, O) +| +- rte_pktmbuf_mtod(M, char *) - O ++ rte_pktmbuf_mtod_offset(M, char *, -O) +| +- rte_pktmbuf_mtod(M, unsigned char *) + O ++ rte_pktmbuf_mtod_offset(M, unsigned char *, O) +| +- rte_pktmbuf_mtod(M, unsigned char *) - O ++ rte_pktmbuf_mtod_offset(M, unsigned char *, -O) +| +- rte_pktmbuf_mtod(M, uint8_t *) + O ++ rte_pktmbuf_mtod_offset(M, uint8_t *, O) +| +- rte_pktmbuf_mtod(M, uint8_t *) - O ++ rte_pktmbuf_mtod_offset(M, uint8_t *, -O) +) + + +// +// Fold subsequent offset terms into pre-existing offset used in +// rte_pktmbuf_mtod_offset(). +// + at disable paren@ +expression M, O1, O2; +@@ +( +- rte_pktmbuf_mtod_offset(M, char *, O1) + O2 ++ rte_pktmbuf_mtod_offset(M, char *, O1 + O2) +| +- rte_pktmbuf_mtod_offset(M, char *, O1) - O2 ++ rte_pktmbuf_mtod_offset(M, char *, O1 - O2) +| +- rte_pktmbuf_mtod_offset(M, unsigned char *, O1) + O2 ++ rte_pktmbuf_mtod_offset(M, unsigned char *, O1 + O2) +| +- rte_pktmbuf_mtod_offset(M, unsigned char *, O1) - O2 ++ rte_pktmbuf_mtod_offset(M, unsigned char *, O1 - O2) +| +- rte_pktmbuf_mtod_offset(M, uint8_t *, O1) + O2 ++ rte_pktmbuf_mtod_offset(M, uint8_t *, O1 + O2) +| +- rte_pktmbuf_mtod_offset(M, uint8_t *, O1) - O2 ++ rte_pktmbuf_mtod_offset(M, uint8_t *, O1 - O2) +) + + +// +/
[dpdk-dev] [PATCH v4 7/9] librte_mbuf: Add rte_pktmbuf_mtod_offset()
There are a number of instances in the code where rte_pktmbuf_mtod() is used to get the mbuf data pointer, only to add an offset before casting the result to some other header type. This patch adds a new rte_pktmbuf_mtod_offset() macro to eliminate these awful double cast situations. Change-Id: I4dec35a15e44a7b8c767559a8d3b294177f39552 Signed-off-by: Cyril Chemparathy --- lib/librte_mbuf/rte_mbuf.h | 24 +--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index 6efd2b5..396963c 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -54,6 +54,7 @@ */ #include +#include #include #include #include @@ -1080,18 +1081,35 @@ static inline struct rte_mbuf *rte_pktmbuf_lastseg(struct rte_mbuf *m) } /** + * A macro that points to an offset into the data in the mbuf. + * + * The returned pointer is cast to type t. Before using this + * function, the user must ensure that the first segment is large + * enough to accomodate its data. + * + * @param m + * The packet mbuf. + * @param o + * The offset into the mbuf data. + * @param t + * The type to cast the result into. + */ +#define rte_pktmbuf_mtod_offset(m, t, o) \ + ((t)((char *)(m)->buf_addr + (m)->data_off + (o))) + +/** * A macro that points to the start of the data in the mbuf. * * The returned pointer is cast to type t. Before using this - * function, the user must ensure that m_headlen(m) is large enough to - * read its data. + * function, the user must ensure that the first segment is large + * enough to accomodate its data. * * @param m * The packet mbuf. * @param t * The type to cast the result into. */ -#define rte_pktmbuf_mtod(m, t) ((t)((char *)(m)->buf_addr + (m)->data_off)) +#define rte_pktmbuf_mtod(m, t) rte_pktmbuf_mtod_offset(m, t, 0) /** * A macro that returns the length of the packet. -- 2.1.2
[dpdk-dev] [PATCH v4 6/9] app/test-pmd: pack simple_gre_hdr
Not packing this causes -Wcast-align breakage on machines that are strict on alignment. This patch fixes this bug. Acked-by: Olivier Matz Change-Id: I7feab9ea4fc33c4ebdf3503ca67477ca0809bb7e Signed-off-by: Cyril Chemparathy --- app/test-pmd/csumonly.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c index 950ea82..4287940 100644 --- a/app/test-pmd/csumonly.c +++ b/app/test-pmd/csumonly.c @@ -108,7 +108,7 @@ struct testpmd_offload_info { struct simple_gre_hdr { uint16_t flags; uint16_t proto; -}; +} __attribute__((__packed__)); static uint16_t get_psd_sum(void *l3_hdr, uint16_t ethertype, uint64_t ol_flags) -- 2.1.2
[dpdk-dev] [PATCH v4 5/9] eal: add and use unaligned integer types
On machines that are strict on pointer alignment, current code breaks on GCC's -Wcast-align checks on casts from narrower to wider types. This patch introduces new unaligned_uint(16|32|64)_t types, which correctly retain alignment in such cases. Strict alignment architectures will need to define CONFIG_RTE_ARCH_STRICT_ALIGN in order to effect these new types. Change-Id: I6f7c429fc14233c991287d065ecf2a09dbd65ebb Signed-off-by: Cyril Chemparathy --- app/test-pmd/flowgen.c | 4 ++-- app/test-pmd/icmpecho.c| 2 +- app/test-pmd/txonly.c | 2 +- app/test/packet_burst_generator.c | 4 ++-- app/test/test_hash_functions.c | 2 +- app/test/test_mbuf.c | 16 config/common_bsdapp | 5 + config/common_linuxapp | 5 + drivers/net/bonding/rte_eth_bond_pmd.c | 12 lib/librte_eal/common/include/rte_common.h | 10 ++ lib/librte_ether/rte_ether.h | 2 +- lib/librte_ip_frag/rte_ipv4_reassembly.c | 4 ++-- 12 files changed, 46 insertions(+), 22 deletions(-) diff --git a/app/test-pmd/flowgen.c b/app/test-pmd/flowgen.c index 72016c9..174c003 100644 --- a/app/test-pmd/flowgen.c +++ b/app/test-pmd/flowgen.c @@ -101,7 +101,7 @@ tx_mbuf_alloc(struct rte_mempool *mp) static inline uint16_t -ip_sum(const uint16_t *hdr, int hdr_len) +ip_sum(const unaligned_uint16_t *hdr, int hdr_len) { uint32_t sum = 0; @@ -193,7 +193,7 @@ pkt_burst_flow_gen(struct fwd_stream *fs) next_flow); ip_hdr->total_length= RTE_CPU_TO_BE_16(pkt_size - sizeof(*eth_hdr)); - ip_hdr->hdr_checksum= ip_sum((uint16_t *)ip_hdr, + ip_hdr->hdr_checksum= ip_sum((unaligned_uint16_t *)ip_hdr, sizeof(*ip_hdr)); /* Initialize UDP header. */ diff --git a/app/test-pmd/icmpecho.c b/app/test-pmd/icmpecho.c index 29aef71..e510f9b 100644 --- a/app/test-pmd/icmpecho.c +++ b/app/test-pmd/icmpecho.c @@ -282,7 +282,7 @@ ipv4_hdr_cksum(struct ipv4_hdr *ip_h) * Compute the sum of successive 16-bit words of the IPv4 header, * skipping the checksum field of the header. */ - v16_h = (uint16_t *) ip_h; + v16_h = (unaligned_uint16_t *) ip_h; ip_cksum = v16_h[0] + v16_h[1] + v16_h[2] + v16_h[3] + v16_h[4] + v16_h[6] + v16_h[7] + v16_h[8] + v16_h[9]; diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c index ca32c85..9e66552 100644 --- a/app/test-pmd/txonly.c +++ b/app/test-pmd/txonly.c @@ -167,7 +167,7 @@ setup_pkt_udp_ip_headers(struct ipv4_hdr *ip_hdr, /* * Compute IP header checksum. */ - ptr16 = (uint16_t*) ip_hdr; + ptr16 = (unaligned_uint16_t*) ip_hdr; ip_cksum = 0; ip_cksum += ptr16[0]; ip_cksum += ptr16[1]; ip_cksum += ptr16[2]; ip_cksum += ptr16[3]; diff --git a/app/test/packet_burst_generator.c b/app/test/packet_burst_generator.c index b46eed7..06762c6 100644 --- a/app/test/packet_burst_generator.c +++ b/app/test/packet_burst_generator.c @@ -154,7 +154,7 @@ initialize_ipv4_header(struct ipv4_hdr *ip_hdr, uint32_t src_addr, uint32_t dst_addr, uint16_t pkt_data_len) { uint16_t pkt_len; - uint16_t *ptr16; + unaligned_uint16_t *ptr16; uint32_t ip_cksum; /* @@ -175,7 +175,7 @@ initialize_ipv4_header(struct ipv4_hdr *ip_hdr, uint32_t src_addr, /* * Compute IP header checksum. */ - ptr16 = (uint16_t *)ip_hdr; + ptr16 = (unaligned_uint16_t *)ip_hdr; ip_cksum = 0; ip_cksum += ptr16[0]; ip_cksum += ptr16[1]; ip_cksum += ptr16[2]; ip_cksum += ptr16[3]; diff --git a/app/test/test_hash_functions.c b/app/test/test_hash_functions.c index df7c909..8c7cf63 100644 --- a/app/test/test_hash_functions.c +++ b/app/test/test_hash_functions.c @@ -223,7 +223,7 @@ verify_jhash_32bits(void) hash = rte_jhash(key, hashtest_key_lens[i], hashtest_initvals[j]); /* Divide key length by 4 in rte_jhash for 32 bits */ - hash32 = rte_jhash_32b((const uint32_t *)key, + hash32 = rte_jhash_32b((const unaligned_uint32_t *)key, hashtest_key_lens[i] >> 2, hashtest_initvals[j]); if (hash != hash32) { diff --git a/app/test/test_mbuf.c b/app/test/test_mbuf.c index 5e8a377..d9beb29 100644 --- a/app/test/test_mbuf.c +++ b/app/test/test_mbuf.c @@ -333,7 +333,7 @@ testclone_testupdate_testdetach(void)
[dpdk-dev] [PATCH v4 4/9] hash: silence -Wcast-align on pointer arithmetic
Since sig_tbl_bucket_size and key_tbl_key_size are explicitly aligned at initialization, offset dereferences in the hash table code cannot possibly be unaligned. However, the compiler is unaware of this fact and complains on -Wcast-align. This patch modifies the code to use RTE_PTR_ADD(), thereby silencing the compiler by casting through (void *). Change-Id: Ia7102cf3f870752743cfe9f4443a3e53cd99bac1 Signed-off-by: Cyril Chemparathy --- lib/librte_hash/rte_hash.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/librte_hash/rte_hash.c b/lib/librte_hash/rte_hash.c index 9245716..67dff5b 100644 --- a/lib/librte_hash/rte_hash.c +++ b/lib/librte_hash/rte_hash.c @@ -96,23 +96,23 @@ EAL_REGISTER_TAILQ(rte_hash_tailq) static inline hash_sig_t * get_sig_tbl_bucket(const struct rte_hash *h, uint32_t bucket_index) { - return (hash_sig_t *) - &(h->sig_tbl[bucket_index * h->sig_tbl_bucket_size]); + return RTE_PTR_ADD(h->sig_tbl, (bucket_index * + h->sig_tbl_bucket_size)); } /* Returns a pointer to the first key in specified bucket. */ static inline uint8_t * get_key_tbl_bucket(const struct rte_hash *h, uint32_t bucket_index) { - return (uint8_t *) &(h->key_tbl[bucket_index * h->bucket_entries * -h->key_tbl_key_size]); + return RTE_PTR_ADD(h->key_tbl, (bucket_index * h->bucket_entries * + h->key_tbl_key_size)); } /* Returns a pointer to a key at a specific position in a specified bucket. */ static inline void * get_key_from_bucket(const struct rte_hash *h, uint8_t *bkt, uint32_t pos) { - return (void *) [pos * h->key_tbl_key_size]; + return RTE_PTR_ADD(bkt, pos * h->key_tbl_key_size); } /* Does integer division with rounding-up of result. */ -- 2.1.2
[dpdk-dev] [PATCH v4 3/9] ethdev: silence -Wcast-align on pointer arithmetic
Statistics offsets in the rte_stats_strings[] array are always 64-bit aligned. However, the compiler is unaware of this fact and complains on -Wcast-align. This patch modifies the code to use RTE_PTR_ADD(), thereby silencing the compiler by casting through (void *). Change-Id: I6460b4b84b89dce6ac0b7b20e7002d53bcbd22db Signed-off-by: Cyril Chemparathy --- lib/librte_ether/rte_ethdev.c | 24 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index e13fde5..02cd07f 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -1742,8 +1742,7 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats, struct rte_eth_stats eth_stats; struct rte_eth_dev *dev; unsigned count, i, q; - uint64_t val; - char *stats_ptr; + uint64_t val, *stats_ptr; if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); @@ -1770,8 +1769,9 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats, /* global stats */ for (i = 0; i < RTE_NB_STATS; i++) { - stats_ptr = (char *)_stats + rte_stats_strings[i].offset; - val = *(uint64_t *)stats_ptr; + stats_ptr = RTE_PTR_ADD(_stats, + rte_stats_strings[i].offset); + val = *stats_ptr; snprintf(xstats[count].name, sizeof(xstats[count].name), "%s", rte_stats_strings[i].name); xstats[count++].value = val; @@ -1780,10 +1780,10 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats, /* per-rxq stats */ for (q = 0; q < dev->data->nb_rx_queues; q++) { for (i = 0; i < RTE_NB_RXQ_STATS; i++) { - stats_ptr = (char *)_stats; - stats_ptr += rte_rxq_stats_strings[i].offset; - stats_ptr += q * sizeof(uint64_t); - val = *(uint64_t *)stats_ptr; + stats_ptr = RTE_PTR_ADD(_stats, + rte_rxq_stats_strings[i].offset + + q * sizeof(uint64_t)); + val = *stats_ptr; snprintf(xstats[count].name, sizeof(xstats[count].name), "rx_queue_%u_%s", q, rte_rxq_stats_strings[i].name); @@ -1794,10 +1794,10 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats, /* per-txq stats */ for (q = 0; q < dev->data->nb_tx_queues; q++) { for (i = 0; i < RTE_NB_TXQ_STATS; i++) { - stats_ptr = (char *)_stats; - stats_ptr += rte_txq_stats_strings[i].offset; - stats_ptr += q * sizeof(uint64_t); - val = *(uint64_t *)stats_ptr; + stats_ptr = RTE_PTR_ADD(_stats, + rte_txq_stats_strings[i].offset + + q * sizeof(uint64_t)); + val = *stats_ptr; snprintf(xstats[count].name, sizeof(xstats[count].name), "tx_queue_%u_%s", q, rte_txq_stats_strings[i].name); -- 2.1.2
[dpdk-dev] [PATCH v4 2/9] mbuf: silence -Wcast-align on pointer arithmetic
Translating from an mbuf element to the mbuf pointer does not break alignment constraints. However, the compiler is unaware of this fact and complains on -Wcast-align. This patch modifies the code to use RTE_PTR_SUB(), thereby silencing the compiler by casting through (void *). Change-Id: I60d9b7a9205ff0befb8dbb4cdcb1df6f9d9d0250 Signed-off-by: Cyril Chemparathy --- lib/librte_mbuf/rte_mbuf.h | 8 +--- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index 6c9cfd6..6efd2b5 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -347,13 +347,7 @@ static inline uint16_t rte_pktmbuf_priv_size(struct rte_mempool *mp); static inline struct rte_mbuf * rte_mbuf_from_indirect(struct rte_mbuf *mi) { - struct rte_mbuf *md; - - /* mi->buf_addr and mi->priv_size correspond to buffer and -* private size of the direct mbuf */ - md = (struct rte_mbuf *)((char *)mi->buf_addr - sizeof(*mi) - - mi->priv_size); - return md; + return RTE_PTR_SUB(mi->buf_addr, sizeof(*mi) + mi->priv_size); } /** -- 2.1.2
[dpdk-dev] [PATCH v4 1/9] mempool: silence -Wcast-align on pointer arithmetic
Translating from a mempool object to the mempool pointer does not break alignment constraints. However, the compiler is unaware of this fact and complains on -Wcast-align. This patch modifies the code to use RTE_PTR_SUB(), thereby silencing the compiler by casting through (void *). Change-Id: I4a67c9aa1bf012a0bf860d21bb8105db89062c76 Signed-off-by: Cyril Chemparathy --- lib/librte_mempool/rte_mempool.c | 2 +- lib/librte_mempool/rte_mempool.h | 6 ++ 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c index f592dc7..002d3a8 100644 --- a/lib/librte_mempool/rte_mempool.c +++ b/lib/librte_mempool/rte_mempool.c @@ -136,7 +136,7 @@ mempool_add_elem(struct rte_mempool *mp, void *obj, uint32_t obj_idx, obj = (char *)obj + mp->header_size; /* set mempool ptr in header */ - hdr = (struct rte_mempool_objhdr *)((char *)obj - sizeof(*hdr)); + hdr = RTE_PTR_SUB(obj, sizeof(*hdr)); hdr->mp = mp; #ifdef RTE_LIBRTE_MEMPOOL_DEBUG diff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h index a8054e1..380d60b 100644 --- a/lib/librte_mempool/rte_mempool.h +++ b/lib/librte_mempool/rte_mempool.h @@ -262,15 +262,13 @@ struct rte_mempool { /* return the header of a mempool object (internal) */ static inline struct rte_mempool_objhdr *__mempool_get_header(void *obj) { - return (struct rte_mempool_objhdr *)((char *)obj - - sizeof(struct rte_mempool_objhdr)); + return RTE_PTR_SUB(obj, sizeof(struct rte_mempool_objhdr)); } /* return the trailer of a mempool object (internal) */ static inline struct rte_mempool_objtlr *__mempool_get_trailer(void *obj) { - return (struct rte_mempool_objtlr *)((char *)obj - - sizeof(struct rte_mempool_objtlr)); + return RTE_PTR_SUB(obj, sizeof(struct rte_mempool_objtlr)); } /** -- 2.1.2
[dpdk-dev] [PATCH v4 0/9] Improve cast alignment for strict aligned machines
This series contains a few improvements that allow the DPDK code base to build properly on machines that enforce strict pointer cast alignment constraints. When dealing with packet data which could be arbitrarily aligned, we get the compiler to do the right thing by (a) making sure that header types are packed, and (b) introducing and using unaligned_uint(16|32|64)_t types when upcasting from byte pointers. In a few other instances, we know apriori that the pointer cast cannot possibly break alignment. This applies to the changes in mempool, hash, mbuf, and the ethdev stats code. Here, we simply silence the compiler by casting through (void *) using the RTE_PTR_(ADD|SUB) macros. Finally, we introduce a new rte_pktmbuf_mtod_offset() helper to return a type casted pointer to an offset within the packet data. This replaces the following commonly used pattern: (struct foo *)(rte_pktmbuf_mtod(m, char *) + offset) with: rte_pktmbuf_mtod_offset(m, struct foo *, offset) To ensure consistency, the above transform was applied throughout the code base using the coccinelle semantic patching tool. Changes in this series: v2: Fixes based on Olivier's comments. v3: Extends unaligned fixes to new code introduced on master. v4: Fixes based on Thomas' comments. Extends unaligned fixes to new code introduced on master. Cyril Chemparathy (9): mempool: silence -Wcast-align on pointer arithmetic mbuf: silence -Wcast-align on pointer arithmetic ethdev: silence -Wcast-align on pointer arithmetic hash: silence -Wcast-align on pointer arithmetic eal: add and use unaligned integer types app/test-pmd: pack simple_gre_hdr librte_mbuf: Add rte_pktmbuf_mtod_offset() librte_mbuf: Add transform for rte_pktmbuf_mtod_offset() librte_mbuf: Apply mtod-offset.cocci transform app/test-pmd/csumonly.c| 2 +- app/test-pmd/flowgen.c | 4 +- app/test-pmd/icmpecho.c| 2 +- app/test-pmd/ieee1588fwd.c | 4 +- app/test-pmd/rxonly.c | 21 + app/test-pmd/txonly.c | 6 +-- app/test/packet_burst_generator.c | 9 ++-- app/test/test_hash_functions.c | 2 +- app/test/test_mbuf.c | 16 +++ config/common_bsdapp | 5 ++ config/common_linuxapp | 5 ++ drivers/net/bonding/rte_eth_bond_pmd.c | 12 +++-- drivers/net/mlx4/mlx4.c| 9 ++-- examples/dpdk_qat/crypto.c | 8 ++-- examples/dpdk_qat/main.c | 5 +- examples/l3fwd-acl/main.c | 20 examples/l3fwd-power/main.c| 8 ++-- examples/l3fwd-vf/main.c | 4 +- examples/l3fwd/main.c | 71 examples/load_balancer/runtime.c | 4 +- examples/vhost_xen/main.c | 4 +- lib/librte_eal/common/include/rte_common.h | 10 lib/librte_ether/rte_ethdev.c | 24 +- lib/librte_ether/rte_ether.h | 2 +- lib/librte_hash/rte_hash.c | 10 ++-- lib/librte_ip_frag/rte_ipv4_reassembly.c | 7 ++- lib/librte_ip_frag/rte_ipv6_reassembly.c | 5 +- lib/librte_mbuf/rte_mbuf.h | 32 + lib/librte_mempool/rte_mempool.c | 2 +- lib/librte_mempool/rte_mempool.h | 6 +-- lib/librte_port/rte_port_ras.c | 6 +-- lib/librte_vhost/vhost_rxtx.c | 6 +-- scripts/cocci.sh | 64 + scripts/cocci/mtod-offset.cocci| 76 ++ 34 files changed, 319 insertions(+), 152 deletions(-) create mode 100755 scripts/cocci.sh create mode 100644 scripts/cocci/mtod-offset.cocci -- 2.1.2
[dpdk-dev] [PATCH 09/11] tile: initial TILE-Gx support.
On Mon, 22 Jun 2015 19:00:44 +0200 Thomas Monjalon wrote: > > > Not sure it makes sense to have different library names. > > > Why not renaming all to "dpdk"? > > > > This config doesn't seem to be getting used anywhere. Maybe just > > get rid of it globally? > > No it's used in mk/ directory: > git grep RTE_LIBNAME Right. But if all platforms are going to be defining these to the same thing "dpdk", do we need to retain the config?
[dpdk-dev] [PATCH 09/11] tile: initial TILE-Gx support.
On Mon, 22 Jun 2015 11:39:07 +0200 Thomas Monjalon wrote: > > +CONFIG_RTE_LIBNAME="tile_dpdk" > > Not sure it makes sense to have different library names. > Why not renaming all to "dpdk"? This config doesn't seem to be getting used anywhere. Maybe just get rid of it globally?
[dpdk-dev] [PATCH v2 05/10] eal: add and use unaligned integer types
On Mon, 22 Jun 2015 11:36:20 +0200 Thomas Monjalon wrote: > 2015-06-19 10:34, Cyril Chemparathy: > > On machines that are strict on pointer alignment, current code > > breaks on GCC's -Wcast-align checks on casts from narrower to wider > > types. This patch introduces new unaligned_uint(16|32|64)_t types, > > which correctly retain alignment in such cases. > [...] > > +#ifdef RTE_ARCH_STRICT_ALIGN > > +typedef uint64_t unaligned_uint64_t __attribute__ ((aligned(1))); > > +typedef uint32_t unaligned_uint32_t __attribute__ ((aligned(1))); > > +typedef uint16_t unaligned_uint16_t __attribute__ ((aligned(1))); > > +#else > > +typedef uint64_t unaligned_uint64_t; > > +typedef uint32_t unaligned_uint32_t; > > +typedef uint16_t unaligned_uint16_t; > > +#endif > > CONFIG_RTE_ARCH_STRICT_ALIGN should be declared (and disabled) in > config templates. Sure. Will include in v3. I'm assuming this goes into common_linuxapp and common_bsdapp, allowing specific architectures to override if necessary. Correct?
[dpdk-dev] [PATCH] mk: add support for gdb debug info generation
On Mon, 22 Jun 2015 08:44:41 +0100 "Gonzalez Monroy, Sergio" wrote: > I don't think you need to modify the makefiles and introduce a new > compile time option for this. > The same result can be easily achieved by setting EXTRA_CFLAGS in the > command line. ie: > $ make install T=x86_64-native-linuxapp-gcc EXTRA_CFLAGS='-g > -ggdb' Fair enough. Please ignore this patch then. Thanks!
[dpdk-dev] [PATCH v2 07/10] app/test: use struct ether_addr instead of a byte array cast
On Sun, 21 Jun 2015 21:56:24 -0400 Stephen Hemminger wrote: > On Fri, 19 Jun 2015 10:34:50 -0700 > Cyril Chemparathy wrote: > > > + static struct ether_addr src_mac = > > + { { 0x00, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF } }; > > + static struct ether_addr dst_mac = > > + { { 0x00, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA } }; > > > > Should have been const (in original code). Thanks. Fixed for v3. I'll be happy to resend the series unless you have comments on the rest of the patches.
[dpdk-dev] [PATCH] examples/l2fwd: Add forward count limit.
This commit adds a forward count argument, which is used to terminate the test once a certain number of packets have been forwarded. Change-Id: Ia3e7ff5d41c3e947509b0653d53271b882fc04de Signed-off-by: Cyril Chemparathy --- examples/l2fwd/main.c | 46 -- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/examples/l2fwd/main.c b/examples/l2fwd/main.c index 720fd5a..20c1dd2 100644 --- a/examples/l2fwd/main.c +++ b/examples/l2fwd/main.c @@ -137,7 +137,9 @@ struct l2fwd_port_statistics port_statistics[RTE_MAX_ETHPORTS]; /* A tsc-based timer responsible for triggering statistics printout */ #define TIMER_MILLISECOND 200ULL /* around 1ms at 2 Ghz */ #define MAX_TIMER_PERIOD 86400 /* 1 day max */ +#define MAX_FORWARD_COUNT 10 /* a cool billion :) */ static int64_t timer_period = 10 * TIMER_MILLISECOND * 1000; /* default period is 10 seconds */ +static int64_t forward_count; /* Print out statistics on packets dropped */ static void @@ -262,6 +264,7 @@ l2fwd_main_loop(void) unsigned i, j, portid, nb_rx; struct lcore_queue_conf *qconf; const uint64_t drain_tsc = (rte_get_tsc_hz() + US_PER_S - 1) / US_PER_S * BURST_TX_DRAIN_US; + uint64_t total_packets_tx; prev_tsc = 0; timer_tsc = 0; @@ -321,6 +324,17 @@ l2fwd_main_loop(void) } prev_tsc = cur_tsc; + + if (forward_count > 0) { + total_packets_tx = 0; + for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++) { + /* skip disabled ports */ + if ((l2fwd_enabled_port_mask & (1 << portid)) != 0) + total_packets_tx += port_statistics[portid].tx; + } + if (total_packets_tx >= forward_count) + break; + } } /* @@ -357,7 +371,8 @@ l2fwd_usage(const char *prgname) printf("%s [EAL options] -- -p PORTMASK [-q NQ]\n" " -p PORTMASK: hexadecimal bitmask of ports to configure\n" " -q NQ: number of queue (=ports) per lcore (default is 1)\n" - " -T PERIOD: statistics will be refreshed each PERIOD seconds (0 to disable, 10 default, 86400 maximum)\n", + " -T PERIOD: statistics will be refreshed each PERIOD seconds (0 to disable, 10 default, 86400 maximum)\n" + " -C COUNT: exit after transmitting COUNT packets\n", prgname); } @@ -412,6 +427,22 @@ l2fwd_parse_timer_period(const char *q_arg) return n; } +static int +l2fwd_parse_forward_count(const char *q_arg) +{ + char *end = NULL; + int n; + + /* parse number string */ + n = strtol(q_arg, , 10); + if ((q_arg[0] == '\0') || (end == NULL) || (*end != '\0')) + return -1; + if (n >= MAX_FORWARD_COUNT) + return -1; + + return n; +} + /* Parse the argument given in the command line of the application */ static int l2fwd_parse_args(int argc, char **argv) @@ -426,7 +457,7 @@ l2fwd_parse_args(int argc, char **argv) argvopt = argv; - while ((opt = getopt_long(argc, argvopt, "p:q:T:", + while ((opt = getopt_long(argc, argvopt, "p:q:T:C:", lgopts, _index)) != EOF) { switch (opt) { @@ -460,6 +491,16 @@ l2fwd_parse_args(int argc, char **argv) } break; + /* forward count */ + case 'C': + forward_count = l2fwd_parse_forward_count(optarg); + if (forward_count < 0) { + printf("invalid forward count\n"); + l2fwd_usage(prgname); + return -1; + } + break; + /* long options */ case 0: l2fwd_usage(prgname); @@ -702,6 +743,7 @@ main(int argc, char **argv) if (rte_eal_wait_lcore(lcore_id) < 0) return -1; } + print_stats(); return 0; } -- 2.1.2
[dpdk-dev] [PATCH] mk: add support for gdb debug info generation
From: Cyril Chemparathy <cchempara...@tilera.com> It is often useful to build with debug enabled, we add a config (CONFIG_RTE_TOOLCHAIN_DEBUG) to do so. Note: This patch does not include corresponding changes for ICC. The author pleads abject ignorance in this regard, and welcomes recommendations. :-) Change-Id: I499e591e1b7d71df751fd40d1fdcbe6975eeeb27 Signed-off-by: Cyril Chemparathy --- mk/toolchain/gcc/rte.vars.mk | 5 + 1 file changed, 5 insertions(+) diff --git a/mk/toolchain/gcc/rte.vars.mk b/mk/toolchain/gcc/rte.vars.mk index 0f51c66..22c4c1f 100644 --- a/mk/toolchain/gcc/rte.vars.mk +++ b/mk/toolchain/gcc/rte.vars.mk @@ -71,6 +71,11 @@ ifeq (,$(findstring -O0,$(EXTRA_CFLAGS))) endif endif +ifeq ($(CONFIG_RTE_TOOLCHAIN_DEBUG),y) +TOOLCHAIN_CFLAGS += -g -ggdb +TOOLCHAIN_LDFLAGS += -g -ggdb +endif + WERROR_FLAGS := -W -Wall -Werror -Wstrict-prototypes -Wmissing-prototypes WERROR_FLAGS += -Wmissing-declarations -Wold-style-definition -Wpointer-arith WERROR_FLAGS += -Wcast-align -Wnested-externs -Wcast-qual -- 2.1.2
[dpdk-dev] [PATCH 11/11] maintainers: claim responsibility for TILE-Gx platform
Change-Id: I6491108ff86c1249bf4ffa4d4624c01b4594805e Signed-off-by: Cyril Chemparathy --- MAINTAINERS | 4 1 file changed, 4 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 9362c19..bffc1e6 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -113,6 +113,10 @@ M: Bruce Richardson M: Konstantin Ananyev F: lib/librte_eal/common/include/arch/x86/ +EZchip TILE-Gx +M: Zhigang Lu +F: lib/librte_eal/common/include/arch/tile/ + Linux EAL (with overlaps) M: David Marchand F: lib/librte_eal/linuxapp/Makefile -- 2.1.2
[dpdk-dev] [PATCH 10/11] tile: Add TILE-Gx mPIPE poll mode driver.
This commit adds a poll mode driver for the mPIPE hardware present on TILE-Gx SoCs. Change-Id: I1b9a9ef2c9f1c96810ec58b4d2ae77b870a6ec94 Signed-off-by: Cyril Chemparathy --- config/defconfig_tile-tilegx-linuxapp-gcc |1 + drivers/net/Makefile |1 + drivers/net/mpipe/Makefile| 46 + drivers/net/mpipe/mpipe_tilegx.c | 1641 + mk/rte.app.mk |1 + 5 files changed, 1690 insertions(+) create mode 100644 drivers/net/mpipe/Makefile create mode 100644 drivers/net/mpipe/mpipe_tilegx.c diff --git a/config/defconfig_tile-tilegx-linuxapp-gcc b/config/defconfig_tile-tilegx-linuxapp-gcc index 835faed..d77fba2 100644 --- a/config/defconfig_tile-tilegx-linuxapp-gcc +++ b/config/defconfig_tile-tilegx-linuxapp-gcc @@ -69,4 +69,5 @@ CONFIG_RTE_LIBRTE_TABLE=n CONFIG_RTE_LIBRTE_PIPELINE=n # Enable and override things that we need +CONFIG_RTE_LIBRTE_MPIPE_PMD=y CONFIG_RTE_MEMPOOL_ALIGN=128 diff --git a/drivers/net/Makefile b/drivers/net/Makefile index 1e6648a..f11b64b 100644 --- a/drivers/net/Makefile +++ b/drivers/net/Makefile @@ -35,6 +35,7 @@ DIRS-$(CONFIG_RTE_LIBRTE_PMD_AF_PACKET) += af_packet DIRS-$(CONFIG_RTE_LIBRTE_PMD_BOND) += bonding DIRS-$(CONFIG_RTE_LIBRTE_E1000_PMD) += e1000 DIRS-$(CONFIG_RTE_LIBRTE_ENIC_PMD) += enic +DIRS-$(CONFIG_RTE_LIBRTE_MPIPE_PMD) += mpipe DIRS-$(CONFIG_RTE_LIBRTE_FM10K_PMD) += fm10k DIRS-$(CONFIG_RTE_LIBRTE_I40E_PMD) += i40e DIRS-$(CONFIG_RTE_LIBRTE_IXGBE_PMD) += ixgbe diff --git a/drivers/net/mpipe/Makefile b/drivers/net/mpipe/Makefile new file mode 100644 index 000..552b303 --- /dev/null +++ b/drivers/net/mpipe/Makefile @@ -0,0 +1,46 @@ +# +# Copyright 2015 EZchip Semiconductor Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# +# 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 +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT HOLDER 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 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +include $(RTE_SDK)/mk/rte.vars.mk + +# library name +LIB = librte_pmd_mpipe.a + +CFLAGS += $(WERROR_FLAGS) -O3 + +EXPORT_MAP := rte_pmd_mpipe_version.map + +LIBABIVER := 1 + +SRCS-$(CONFIG_RTE_LIBRTE_MPIPE_PMD) += mpipe_tilegx.c + +DEPDIRS-$(CONFIG_RTE_LIBRTE_MPIPE_PMD) += lib/librte_eal lib/librte_ether +DEPDIRS-$(CONFIG_RTE_LIBRTE_MPIPE_PMD) += lib/librte_mempool lib/librte_mbuf +DEPDIRS-$(CONFIG_RTE_LIBRTE_MPIPE_PMD) += lib/librte_net lib/librte_malloc + +include $(RTE_SDK)/mk/rte.lib.mk diff --git a/drivers/net/mpipe/mpipe_tilegx.c b/drivers/net/mpipe/mpipe_tilegx.c new file mode 100644 index 000..0998eb5 --- /dev/null +++ b/drivers/net/mpipe/mpipe_tilegx.c @@ -0,0 +1,1641 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2015 EZchip Semiconductor Ltd. 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 copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of EZchip Semiconductor 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 FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * O
[dpdk-dev] [PATCH 09/11] tile: initial TILE-Gx support.
This commit adds support for the TILE-Gx platform, as well as the TILE CPU architecture. This architecture port is fairly simple due to its reliance on generics for most arch stuff. Change-Id: I809fcf740e25ba5976a6b7736c1673515338cf80 Signed-off-by: Cyril Chemparathy --- config/defconfig_tile-tilegx-linuxapp-gcc | 72 + .../common/include/arch/tile/rte_atomic.h | 86 .../common/include/arch/tile/rte_byteorder.h | 91 + .../common/include/arch/tile/rte_cpuflags.h| 85 .../common/include/arch/tile/rte_cycles.h | 70 .../common/include/arch/tile/rte_memcpy.h | 93 ++ .../common/include/arch/tile/rte_prefetch.h| 61 ++ .../common/include/arch/tile/rte_rwlock.h | 70 .../common/include/arch/tile/rte_spinlock.h| 92 + mk/arch/tile/rte.vars.mk | 39 + mk/machine/tilegx/rte.vars.mk | 57 + 11 files changed, 816 insertions(+) create mode 100644 config/defconfig_tile-tilegx-linuxapp-gcc create mode 100644 lib/librte_eal/common/include/arch/tile/rte_atomic.h create mode 100644 lib/librte_eal/common/include/arch/tile/rte_byteorder.h create mode 100644 lib/librte_eal/common/include/arch/tile/rte_cpuflags.h create mode 100644 lib/librte_eal/common/include/arch/tile/rte_cycles.h create mode 100644 lib/librte_eal/common/include/arch/tile/rte_memcpy.h create mode 100644 lib/librte_eal/common/include/arch/tile/rte_prefetch.h create mode 100644 lib/librte_eal/common/include/arch/tile/rte_rwlock.h create mode 100644 lib/librte_eal/common/include/arch/tile/rte_spinlock.h create mode 100644 mk/arch/tile/rte.vars.mk create mode 100644 mk/machine/tilegx/rte.vars.mk diff --git a/config/defconfig_tile-tilegx-linuxapp-gcc b/config/defconfig_tile-tilegx-linuxapp-gcc new file mode 100644 index 000..835faed --- /dev/null +++ b/config/defconfig_tile-tilegx-linuxapp-gcc @@ -0,0 +1,72 @@ +# BSD LICENSE +# +# Copyright (C) EZchip Semiconductor 2015. +# +# 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 copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of EZchip Semiconductor 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 FOR +# 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 ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include "common_linuxapp" + +CONFIG_RTE_MACHINE="tilegx" + +CONFIG_RTE_ARCH="tile" +CONFIG_RTE_ARCH_TILE=y +CONFIG_RTE_ARCH_64=y +CONFIG_RTE_ARCH_STRICT_ALIGN=y +CONFIG_RTE_FORCE_INTRINSICS=y + +CONFIG_RTE_TOOLCHAIN="gcc" +CONFIG_RTE_TOOLCHAIN_GCC=y + +CONFIG_RTE_LIBNAME="tile_dpdk" + +# Disable things that we don't support or need +CONFIG_RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT=n +CONFIG_RTE_EAL_IGB_UIO=n +CONFIG_RTE_EAL_VFIO=n +CONFIG_RTE_LIBRTE_KNI=n +CONFIG_RTE_LIBRTE_XEN_DOM0=n +CONFIG_RTE_LIBRTE_IGB_PMD=n +CONFIG_RTE_LIBRTE_EM_PMD=n +CONFIG_RTE_LIBRTE_IXGBE_PMD=n +CONFIG_RTE_LIBRTE_I40E_PMD=n +CONFIG_RTE_LIBRTE_FM10K_PMD=n +CONFIG_RTE_LIBRTE_VIRTIO_PMD=n +CONFIG_RTE_LIBRTE_VMXNET3_PMD=n +CONFIG_RTE_LIBRTE_PMD_BOND=n +CONFIG_RTE_LIBRTE_ENIC_PMD=n + +# This following libraries are not available on the tile architecture. So +# they're turned off. +CONFIG_RTE_LIBRTE_LPM=n +CONFIG_RTE_LIBRTE_ACL=n +CONFIG_RTE_LIBRTE_SCHED=n +CONFIG_RTE_LIBRTE_PORT=n +CONFIG_RTE_LIBRTE_TABLE=n +CONFIG_RTE_LIBRTE_PIPELINE=n + +# Enable and override things that we need +CONFIG_RTE_MEMPOOL_ALIGN=128 diff --git a/lib/librte_eal/common/include/arch/tile/rte_atomic.h b/lib/librte_ea
[dpdk-dev] [PATCH 08/11] tile: add page sizes for TILE-Gx/Mx platforms
This patch adds a few new page sizes that are supported on the TILE-Gx and TILE-Mx platforms. Change-Id: I7da783703149c4f96b84d0017fa4f1191fc029c6 Signed-off-by: Cyril Chemparathy --- lib/librte_eal/common/eal_common_memzone.c | 8 + lib/librte_eal/common/include/rte_memory.h | 16 + lib/librte_eal/common/include/rte_memzone.h | 50 +++-- 3 files changed, 51 insertions(+), 23 deletions(-) diff --git a/lib/librte_eal/common/eal_common_memzone.c b/lib/librte_eal/common/eal_common_memzone.c index 84b773c..53f6040 100644 --- a/lib/librte_eal/common/eal_common_memzone.c +++ b/lib/librte_eal/common/eal_common_memzone.c @@ -284,12 +284,20 @@ rte_memzone_reserve_thread_safe(const char *name, size_t len, const struct rte_memzone *mz = NULL; uint64_t size_mask = 0; + if (flags & RTE_MEMZONE_256KB) + size_mask |= RTE_PGSIZE_256K; if (flags & RTE_MEMZONE_2MB) size_mask |= RTE_PGSIZE_2M; if (flags & RTE_MEMZONE_16MB) size_mask |= RTE_PGSIZE_16M; + if (flags & RTE_MEMZONE_256MB) + size_mask |= RTE_PGSIZE_256M; + if (flags & RTE_MEMZONE_512MB) + size_mask |= RTE_PGSIZE_512M; if (flags & RTE_MEMZONE_1GB) size_mask |= RTE_PGSIZE_1G; + if (flags & RTE_MEMZONE_4GB) + size_mask |= RTE_PGSIZE_4G; if (flags & RTE_MEMZONE_16GB) size_mask |= RTE_PGSIZE_16G; if (!size_mask) diff --git a/lib/librte_eal/common/include/rte_memory.h b/lib/librte_eal/common/include/rte_memory.h index d948c0b..1bed415 100644 --- a/lib/librte_eal/common/include/rte_memory.h +++ b/lib/librte_eal/common/include/rte_memory.h @@ -53,12 +53,16 @@ extern "C" { #endif enum rte_page_sizes { - RTE_PGSIZE_4K = 1ULL << 12, - RTE_PGSIZE_2M = 1ULL << 21, - RTE_PGSIZE_1G = 1ULL << 30, - RTE_PGSIZE_64K = 1ULL << 16, - RTE_PGSIZE_16M = 1ULL << 24, - RTE_PGSIZE_16G = 1ULL << 34 + RTE_PGSIZE_4K= 1ULL << 12, + RTE_PGSIZE_64K = 1ULL << 16, + RTE_PGSIZE_256K = 1ULL << 18, + RTE_PGSIZE_2M= 1ULL << 21, + RTE_PGSIZE_16M = 1ULL << 24, + RTE_PGSIZE_256M = 1ULL << 28, + RTE_PGSIZE_512M = 1ULL << 29, + RTE_PGSIZE_1G= 1ULL << 30, + RTE_PGSIZE_4G= 1ULL << 32, + RTE_PGSIZE_16G = 1ULL << 34, }; #define SOCKET_ID_ANY -1/**< Any NUMA socket. */ diff --git a/lib/librte_eal/common/include/rte_memzone.h b/lib/librte_eal/common/include/rte_memzone.h index ee62680..de5ae55 100644 --- a/lib/librte_eal/common/include/rte_memzone.h +++ b/lib/librte_eal/common/include/rte_memzone.h @@ -60,8 +60,12 @@ extern "C" { #define RTE_MEMZONE_2MB0x0001 /**< Use 2MB pages. */ #define RTE_MEMZONE_1GB0x0002 /**< Use 1GB pages. */ -#define RTE_MEMZONE_16MB0x0100 /**< Use 16MB pages. */ -#define RTE_MEMZONE_16GB0x0200 /**< Use 16GB pages. */ +#define RTE_MEMZONE_16MB 0x0100 /**< Use 16MB pages. */ +#define RTE_MEMZONE_16GB 0x0200 /**< Use 16GB pages. */ +#define RTE_MEMZONE_256KB 0x0001 /**< Use 256KB pages. */ +#define RTE_MEMZONE_256MB 0x0002 /**< Use 256MB pages. */ +#define RTE_MEMZONE_512MB 0x0004 /**< Use 512MB pages. */ +#define RTE_MEMZONE_4GB0x0008 /**< Use 4GB pages. */ #define RTE_MEMZONE_SIZE_HINT_ONLY 0x0004 /**< Use available page size */ /** @@ -110,11 +114,15 @@ struct rte_memzone { * constraint for the reserved zone. * @param flags * The flags parameter is used to request memzones to be - * taken from 1GB or 2MB hugepages. - * - RTE_MEMZONE_2MB - Reserve from 2MB pages - * - RTE_MEMZONE_1GB - Reserve from 1GB pages - * - RTE_MEMZONE_16MB - Reserve from 16MB pages - * - RTE_MEMZONE_16GB - Reserve from 16GB pages + * taken from specifically sized hugepages. + * - RTE_MEMZONE_2MB - Reserved from 2MB pages + * - RTE_MEMZONE_1GB - Reserved from 1GB pages + * - RTE_MEMZONE_16MB - Reserved from 16MB pages + * - RTE_MEMZONE_16GB - Reserved from 16GB pages + * - RTE_MEMZONE_256KB - Reserved from 256KB pages + * - RTE_MEMZONE_256MB - Reserved from 256MB pages + * - RTE_MEMZONE_512MB - Reserved from 512MB pages + * - RTE_MEMZONE_4GB - Reserved from 4GB pages * - RTE_MEMZONE_SIZE_HINT_ONLY - Allow alternative page size to be used if * the requested page size is unavailable. * If this flag is not set, the function @@ -157,11 +165,15 @@ const struct rte_memzone *rte_memzone_reserve(const char *name, * constraint for the reserved zone. * @param fla
[dpdk-dev] [PATCH 07/11] mempool: allow config override on element alignment
On TILE-Gx and TILE-Mx platforms, the buffers fed into the hardware buffer manager require a 128-byte alignment. With this change, we allow configuration based override of the element alignment, and default to RTE_CACHE_LINE_SIZE if left unspecified. Change-Id: I9cd789d92b0bc9c8f44a633de59bb04d45d927a7 Signed-off-by: Cyril Chemparathy --- lib/librte_mempool/rte_mempool.c | 16 +--- lib/librte_mempool/rte_mempool.h | 6 ++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c index 190cfd9..37823dc 100644 --- a/lib/librte_mempool/rte_mempool.c +++ b/lib/librte_mempool/rte_mempool.c @@ -120,10 +120,10 @@ static unsigned optimize_object_size(unsigned obj_size) nrank = 1; /* process new object size */ - new_obj_size = (obj_size + RTE_CACHE_LINE_MASK) / RTE_CACHE_LINE_SIZE; + new_obj_size = (obj_size + RTE_MEMPOOL_ALIGN_MASK) / RTE_MEMPOOL_ALIGN; while (get_gcd(new_obj_size, nrank * nchan) != 1) new_obj_size++; - return new_obj_size * RTE_CACHE_LINE_SIZE; + return new_obj_size * RTE_MEMPOOL_ALIGN; } static void @@ -265,7 +265,7 @@ rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags, #endif if ((flags & MEMPOOL_F_NO_CACHE_ALIGN) == 0) sz->header_size = RTE_ALIGN_CEIL(sz->header_size, - RTE_CACHE_LINE_SIZE); + RTE_MEMPOOL_ALIGN); /* trailer contains the cookie in debug mode */ sz->trailer_size = 0; @@ -279,9 +279,9 @@ rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags, if ((flags & MEMPOOL_F_NO_CACHE_ALIGN) == 0) { sz->total_size = sz->header_size + sz->elt_size + sz->trailer_size; - sz->trailer_size += ((RTE_CACHE_LINE_SIZE - - (sz->total_size & RTE_CACHE_LINE_MASK)) & -RTE_CACHE_LINE_MASK); + sz->trailer_size += ((RTE_MEMPOOL_ALIGN - + (sz->total_size & RTE_MEMPOOL_ALIGN_MASK)) & +RTE_MEMPOOL_ALIGN_MASK); } /* @@ -496,7 +496,7 @@ rte_mempool_xmem_create(const char *name, unsigned n, unsigned elt_size, * cache-aligned */ private_data_size = (private_data_size + -RTE_CACHE_LINE_MASK) & (~RTE_CACHE_LINE_MASK); +RTE_MEMPOOL_ALIGN_MASK) & (~RTE_MEMPOOL_ALIGN_MASK); if (! rte_eal_has_hugepages()) { /* @@ -523,6 +523,7 @@ rte_mempool_xmem_create(const char *name, unsigned n, unsigned elt_size, * hold mempool header and metadata plus mempool objects. */ mempool_size = MEMPOOL_HEADER_SIZE(mp, pg_num) + private_data_size; + mempool_size = RTE_ALIGN_CEIL(mempool_size, RTE_MEMPOOL_ALIGN); if (vaddr == NULL) mempool_size += (size_t)objsz.total_size * n; @@ -578,6 +579,7 @@ rte_mempool_xmem_create(const char *name, unsigned n, unsigned elt_size, /* calculate address of the first element for continuous mempool. */ obj = (char *)mp + MEMPOOL_HEADER_SIZE(mp, pg_num) + private_data_size; + obj = RTE_PTR_ALIGN_CEIL(obj, RTE_MEMPOOL_ALIGN); /* populate address translation fields. */ mp->pg_num = pg_num; diff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h index 8be040b..175a793 100644 --- a/lib/librte_mempool/rte_mempool.h +++ b/lib/librte_mempool/rte_mempool.h @@ -139,6 +139,12 @@ struct rte_mempool_objsz { /** Mempool over one chunk of physically continuous memory */ #defineMEMPOOL_PG_NUM_DEFAULT 1 +#ifndef RTE_MEMPOOL_ALIGN +#define RTE_MEMPOOL_ALIGN RTE_CACHE_LINE_SIZE +#endif + +#define RTE_MEMPOOL_ALIGN_MASK (RTE_MEMPOOL_ALIGN - 1) + /** * The RTE mempool structure. */ -- 2.1.2
[dpdk-dev] [PATCH 06/11] memzone: allow multiple pagesizes to be requested
This patch extends the memzone allocator to remove the restriction that prevented callers from specifying multiple page sizes in the flags argument. In doing so, we also sanitize the free segment matching logic to get rid of architecture specific disjunctions (2MB vs 1GB on x86, and 16MB vs 16GB on PPC), thereby allowing for a broader range of hugepages on architectures that support it. Change-Id: Ic3713f61da49629a570fe4de34a8aaf5e2e0a19b Signed-off-by: Cyril Chemparathy --- lib/librte_eal/common/eal_common_memzone.c | 58 ++ 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/lib/librte_eal/common/eal_common_memzone.c b/lib/librte_eal/common/eal_common_memzone.c index 87057d4..84b773c 100644 --- a/lib/librte_eal/common/eal_common_memzone.c +++ b/lib/librte_eal/common/eal_common_memzone.c @@ -113,7 +113,8 @@ align_phys_boundary(const struct rte_memseg *ms, size_t len, size_t align, static const struct rte_memzone * memzone_reserve_aligned_thread_unsafe(const char *name, size_t len, - int socket_id, unsigned flags, unsigned align, unsigned bound) + int socket_id, uint64_t size_mask, unsigned align, + unsigned bound) { struct rte_mem_config *mcfg; unsigned i = 0; @@ -201,18 +202,7 @@ memzone_reserve_aligned_thread_unsafe(const char *name, size_t len, if ((requested_len + addr_offset) > free_memseg[i].len) continue; - /* check flags for hugepage sizes */ - if ((flags & RTE_MEMZONE_2MB) && - free_memseg[i].hugepage_sz == RTE_PGSIZE_1G) - continue; - if ((flags & RTE_MEMZONE_1GB) && - free_memseg[i].hugepage_sz == RTE_PGSIZE_2M) - continue; - if ((flags & RTE_MEMZONE_16MB) && - free_memseg[i].hugepage_sz == RTE_PGSIZE_16G) - continue; - if ((flags & RTE_MEMZONE_16GB) && - free_memseg[i].hugepage_sz == RTE_PGSIZE_16M) + if ((size_mask & free_memseg[i].hugepage_sz) == 0) continue; /* this segment is the best until now */ @@ -244,16 +234,6 @@ memzone_reserve_aligned_thread_unsafe(const char *name, size_t len, /* no segment found */ if (memseg_idx == -1) { - /* -* If RTE_MEMZONE_SIZE_HINT_ONLY flag is specified, -* try allocating again without the size parameter otherwise -fail. -*/ - if ((flags & RTE_MEMZONE_SIZE_HINT_ONLY) && - ((flags & RTE_MEMZONE_1GB) || (flags & RTE_MEMZONE_2MB) - || (flags & RTE_MEMZONE_16MB) || (flags & RTE_MEMZONE_16GB))) - return memzone_reserve_aligned_thread_unsafe(name, - len, socket_id, 0, align, bound); - rte_errno = ENOMEM; return NULL; } @@ -302,13 +282,18 @@ rte_memzone_reserve_thread_safe(const char *name, size_t len, { struct rte_mem_config *mcfg; const struct rte_memzone *mz = NULL; - - /* both sizes cannot be explicitly called for */ - if (((flags & RTE_MEMZONE_1GB) && (flags & RTE_MEMZONE_2MB)) - || ((flags & RTE_MEMZONE_16MB) && (flags & RTE_MEMZONE_16GB))) { - rte_errno = EINVAL; - return NULL; - } + uint64_t size_mask = 0; + + if (flags & RTE_MEMZONE_2MB) + size_mask |= RTE_PGSIZE_2M; + if (flags & RTE_MEMZONE_16MB) + size_mask |= RTE_PGSIZE_16M; + if (flags & RTE_MEMZONE_1GB) + size_mask |= RTE_PGSIZE_1G; + if (flags & RTE_MEMZONE_16GB) + size_mask |= RTE_PGSIZE_16G; + if (!size_mask) + size_mask = UINT64_MAX; /* get pointer to global configuration */ mcfg = rte_eal_get_configuration()->mem_config; @@ -316,7 +301,18 @@ rte_memzone_reserve_thread_safe(const char *name, size_t len, rte_rwlock_write_lock(>mlock); mz = memzone_reserve_aligned_thread_unsafe( - name, len, socket_id, flags, align, bound); + name, len, socket_id, size_mask, align, bound); + + /* +* If we failed to allocate the requested page size, and the +* RTE_MEMZONE_SIZE_HINT_ONLY flag is specified, try allocating +* again. +*/ + if (!mz && rte_errno == ENOMEM && size_mask != UINT64_MAX && + flags & RTE_MEMZONE_SIZE_HINT_ONLY) { + mz = memzone_reserve_aligned_thread_unsafe( + name, len, socket_id, UINT64_MAX, align, bound); + } rte_rwlock_write_unlock(>mlock); -- 2.1.2
[dpdk-dev] [PATCH 05/11] memzone: refactor rte_memzone_reserve() variants
The definitions of rte_memzone_reserve_aligned() and rte_memzone_reserve_bounded() were identical with the exception of the bound argument passed into rte_memzone_reserve_thread_safe(). This patch removes this replication of code by unifying it into rte_memzone_reserve_thread_safe(), which is then called by all three variants of rte_memzone_reserve(). Change-Id: Id26c25b4dd3d07861eaf35e72aaa2de555916fa3 Signed-off-by: Cyril Chemparathy --- lib/librte_eal/common/eal_common_memzone.c | 77 +- 1 file changed, 33 insertions(+), 44 deletions(-) diff --git a/lib/librte_eal/common/eal_common_memzone.c b/lib/librte_eal/common/eal_common_memzone.c index 888f9e5..87057d4 100644 --- a/lib/librte_eal/common/eal_common_memzone.c +++ b/lib/librte_eal/common/eal_common_memzone.c @@ -77,18 +77,6 @@ memzone_lookup_thread_unsafe(const char *name) } /* - * Return a pointer to a correctly filled memzone descriptor. If the - * allocation cannot be done, return NULL. - */ -const struct rte_memzone * -rte_memzone_reserve(const char *name, size_t len, int socket_id, - unsigned flags) -{ - return rte_memzone_reserve_aligned(name, - len, socket_id, flags, RTE_CACHE_LINE_SIZE); -} - -/* * Helper function for memzone_reserve_aligned_thread_unsafe(). * Calculate address offset from the start of the segment. * Align offset in that way that it satisfy istart alignmnet and @@ -307,13 +295,10 @@ memzone_reserve_aligned_thread_unsafe(const char *name, size_t len, return mz; } -/* - * Return a pointer to a correctly filled memzone descriptor (with a - * specified alignment). If the allocation cannot be done, return NULL. - */ -const struct rte_memzone * -rte_memzone_reserve_aligned(const char *name, size_t len, - int socket_id, unsigned flags, unsigned align) +static const struct rte_memzone * +rte_memzone_reserve_thread_safe(const char *name, size_t len, + int socket_id, unsigned flags, unsigned align, + unsigned bound) { struct rte_mem_config *mcfg; const struct rte_memzone *mz = NULL; @@ -331,7 +316,7 @@ rte_memzone_reserve_aligned(const char *name, size_t len, rte_rwlock_write_lock(>mlock); mz = memzone_reserve_aligned_thread_unsafe( - name, len, socket_id, flags, align, 0); + name, len, socket_id, flags, align, bound); rte_rwlock_write_unlock(>mlock); @@ -340,36 +325,40 @@ rte_memzone_reserve_aligned(const char *name, size_t len, /* * Return a pointer to a correctly filled memzone descriptor (with a - * specified alignment and boundary). - * If the allocation cannot be done, return NULL. + * specified alignment and boundary). If the allocation cannot be done, + * return NULL. */ const struct rte_memzone * -rte_memzone_reserve_bounded(const char *name, size_t len, - int socket_id, unsigned flags, unsigned align, unsigned bound) +rte_memzone_reserve_bounded(const char *name, size_t len, int socket_id, + unsigned flags, unsigned align, unsigned bound) { - struct rte_mem_config *mcfg; - const struct rte_memzone *mz = NULL; - - /* both sizes cannot be explicitly called for */ - if (((flags & RTE_MEMZONE_1GB) && (flags & RTE_MEMZONE_2MB)) - || ((flags & RTE_MEMZONE_16MB) && (flags & RTE_MEMZONE_16GB))) { - rte_errno = EINVAL; - return NULL; - } - - /* get pointer to global configuration */ - mcfg = rte_eal_get_configuration()->mem_config; - - rte_rwlock_write_lock(>mlock); - - mz = memzone_reserve_aligned_thread_unsafe( - name, len, socket_id, flags, align, bound); - - rte_rwlock_write_unlock(>mlock); + return rte_memzone_reserve_thread_safe(name, len, socket_id, flags, + align, bound); +} - return mz; +/* + * Return a pointer to a correctly filled memzone descriptor (with a + * specified alignment). If the allocation cannot be done, return NULL. + */ +const struct rte_memzone * +rte_memzone_reserve_aligned(const char *name, size_t len, int socket_id, + unsigned flags, unsigned align) +{ + return rte_memzone_reserve_thread_safe(name, len, socket_id, flags, + align, 0); } +/* + * Return a pointer to a correctly filled memzone descriptor. If the + * allocation cannot be done, return NULL. + */ +const struct rte_memzone * +rte_memzone_reserve(const char *name, size_t len, int socket_id, + unsigned flags) +{ + return rte_memzone_reserve_thread_safe(name, len, socket_id, + flags, RTE_CACHE_LINE_SIZE, 0); +} /* * Lookup for the memzone identified by the given name -- 2.1.2
[dpdk-dev] [PATCH 04/11] eal: allow empty compile time flags
The rte_cpu_check_supported() code breaks with a "comparison is always false due to limited range of data type" when the compile_time_flags[] array is empty. Assigning the array dimension to a local variable apparently solves this. Change-Id: I0ae21f529cf7b6dd9cf0f4532dce9198f4bf4230 Signed-off-by: Cyril Chemparathy --- lib/librte_eal/common/eal_common_cpuflags.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/librte_eal/common/eal_common_cpuflags.c b/lib/librte_eal/common/eal_common_cpuflags.c index 6fd360c..8ba7b30 100644 --- a/lib/librte_eal/common/eal_common_cpuflags.c +++ b/lib/librte_eal/common/eal_common_cpuflags.c @@ -30,6 +30,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include /* @@ -62,10 +63,10 @@ rte_cpu_check_supported(void) static const enum rte_cpu_flag_t compile_time_flags[] = { RTE_COMPILE_TIME_CPUFLAGS }; - unsigned i; + unsigned count = RTE_DIM(compile_time_flags), i; int ret; - for (i = 0; i < sizeof(compile_time_flags)/sizeof(compile_time_flags[0]); i++) { + for (i = 0; i < count; i++) { ret = rte_cpu_get_flag_enabled(compile_time_flags[i]); if (ret < 0) { -- 2.1.2
[dpdk-dev] [PATCH 03/11] hash: check SSE flags only on x86 builds
This is necessary because the required CPU flags may not be defined on other architectures. Change-Id: I14d3f9f625b2e7567123f1c97095f8d06abd674b Signed-off-by: Cyril Chemparathy --- lib/librte_hash/rte_hash_crc.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/librte_hash/rte_hash_crc.h b/lib/librte_hash/rte_hash_crc.h index abdbd9a..1f6f5bf 100644 --- a/lib/librte_hash/rte_hash_crc.h +++ b/lib/librte_hash/rte_hash_crc.h @@ -425,12 +425,14 @@ static inline void rte_hash_crc_set_alg(uint8_t alg) { switch (alg) { +#if defined(RTE_ARCH_I686) || defined(RTE_ARCH_X86_64) case CRC32_SSE42_x64: if (! rte_cpu_get_flag_enabled(RTE_CPUFLAG_EM64T)) alg = CRC32_SSE42; case CRC32_SSE42: if (! rte_cpu_get_flag_enabled(RTE_CPUFLAG_SSE4_2)) alg = CRC32_SW; +#endif case CRC32_SW: crc32_alg = alg; default: -- 2.1.2
[dpdk-dev] [PATCH 02/11] hash: fix compilation on non-X86 platforms
The "hash: remove duplicated code" change unfortunately broke the build for non-X86 platforms. This patch fixes this breakage. Change-Id: Ie109d67e681b75b45320fab1bf9de4eb9c9701bf Signed-off-by: Cyril Chemparathy --- lib/librte_hash/rte_jhash.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/librte_hash/rte_jhash.h b/lib/librte_hash/rte_jhash.h index e230449..d1b6cf3 100644 --- a/lib/librte_hash/rte_jhash.h +++ b/lib/librte_hash/rte_jhash.h @@ -44,6 +44,7 @@ extern "C" { #endif +#include #include #include @@ -122,7 +123,7 @@ __rte_jhash_2hashes(const void *key, uint32_t length, uint32_t *pc, const uint32_t *k = key; const uint32_t s = 0; #else - const uint32_t *k = (uint32_t *)(uintptr_t)key & (uintptr_t)~3); + const uint32_t *k = (uint32_t *)((uintptr_t)key & (uintptr_t)~3); const uint32_t s = ((uintptr_t)key & 3) * CHAR_BIT; #endif if (!check_align || s == 0) { -- 2.1.2
[dpdk-dev] [PATCH 01/11] test: limit x86 cpuflags checks to x86 builds
The original code mistakenly defaulted to X86 when RTE_ARCH_PPC_64 was left undefined. This did not accomodate other non-PPC/non-X86 architectures. This patch fixes this issue. Change-Id: I5e8cf33c2eb917f7f6583dc95ed0f336066a285e Signed-off-by: Cyril Chemparathy --- app/test/test_cpuflags.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/test/test_cpuflags.c b/app/test/test_cpuflags.c index 5aeba5d..5b92061 100644 --- a/app/test/test_cpuflags.c +++ b/app/test/test_cpuflags.c @@ -113,7 +113,9 @@ test_cpuflags(void) printf("Check for ICACHE_SNOOP:\t\t"); CHECK_FOR_FLAG(RTE_CPUFLAG_ICACHE_SNOOP); -#else +#endif + +#if defined(RTE_ARCH_X86_64) || defined(RTE_ARCH_I686) printf("Check for SSE:\t\t"); CHECK_FOR_FLAG(RTE_CPUFLAG_SSE); @@ -149,8 +151,6 @@ test_cpuflags(void) printf("Check for INVTSC:\t"); CHECK_FOR_FLAG(RTE_CPUFLAG_INVTSC); - - #endif /* -- 2.1.2
[dpdk-dev] [PATCH 00/11] Introducing the TILE-Gx platform
This series adds support for the EZchip TILE-Gx family of SoCs. The architecture port in itself is fairly straight forward due to its reliance on generics for the most part. In addition to adding TILE-Gx architecture specific code, this series includes a few cross-platform fixes for DPDK (cpuflags, SSE related, etc.), as well as minor extensions to to accomodate a wider range of hugepage sizes and configurable mempool element alignment boundaries. Cyril Chemparathy (11): test: limit x86 cpuflags checks to x86 builds hash: fix compilation on non-X86 platforms hash: check SSE flags only on x86 builds eal: allow empty compile time flags memzone: refactor rte_memzone_reserve() variants memzone: allow multiple pagesizes to be requested mempool: allow config override on element alignment tile: add page sizes for TILE-Gx/Mx platforms tile: initial TILE-Gx support. tile: Add TILE-Gx mPIPE poll mode driver. maintainers: claim responsibility for TILE-Gx platform MAINTAINERS|4 + app/test/test_cpuflags.c |6 +- config/defconfig_tile-tilegx-linuxapp-gcc | 73 + drivers/net/Makefile |1 + drivers/net/mpipe/Makefile | 46 + drivers/net/mpipe/mpipe_tilegx.c | 1641 lib/librte_eal/common/eal_common_cpuflags.c|5 +- lib/librte_eal/common/eal_common_memzone.c | 141 +- .../common/include/arch/tile/rte_atomic.h | 86 + .../common/include/arch/tile/rte_byteorder.h | 91 ++ .../common/include/arch/tile/rte_cpuflags.h| 85 + .../common/include/arch/tile/rte_cycles.h | 70 + .../common/include/arch/tile/rte_memcpy.h | 93 ++ .../common/include/arch/tile/rte_prefetch.h| 61 + .../common/include/arch/tile/rte_rwlock.h | 70 + .../common/include/arch/tile/rte_spinlock.h| 92 ++ lib/librte_eal/common/include/rte_memory.h | 16 +- lib/librte_eal/common/include/rte_memzone.h| 50 +- lib/librte_hash/rte_hash_crc.h |2 + lib/librte_hash/rte_jhash.h|3 +- lib/librte_mempool/rte_mempool.c | 16 +- lib/librte_mempool/rte_mempool.h |6 + mk/arch/tile/rte.vars.mk | 39 + mk/machine/tilegx/rte.vars.mk | 57 + mk/rte.app.mk |1 + 25 files changed, 2645 insertions(+), 110 deletions(-) create mode 100644 config/defconfig_tile-tilegx-linuxapp-gcc create mode 100644 drivers/net/mpipe/Makefile create mode 100644 drivers/net/mpipe/mpipe_tilegx.c create mode 100644 lib/librte_eal/common/include/arch/tile/rte_atomic.h create mode 100644 lib/librte_eal/common/include/arch/tile/rte_byteorder.h create mode 100644 lib/librte_eal/common/include/arch/tile/rte_cpuflags.h create mode 100644 lib/librte_eal/common/include/arch/tile/rte_cycles.h create mode 100644 lib/librte_eal/common/include/arch/tile/rte_memcpy.h create mode 100644 lib/librte_eal/common/include/arch/tile/rte_prefetch.h create mode 100644 lib/librte_eal/common/include/arch/tile/rte_rwlock.h create mode 100644 lib/librte_eal/common/include/arch/tile/rte_spinlock.h create mode 100644 mk/arch/tile/rte.vars.mk create mode 100644 mk/machine/tilegx/rte.vars.mk -- 2.1.2
[dpdk-dev] [PATCH v3 10/10] librte_mbuf: Apply mtod-offset.cocci transform
This patch simply applies the transform previously committed in scripts/cocci/mtod-offset.cocci. No other modifications have been made here. This patch applies on commit 960e8a22fc6d9373e37dd1454131e91f082bb8bc. This patch may need to be regenerated by rerunning scripts/cocci.sh instead of simply merging in the change. Acked-by: Olivier Matz Signed-off-by: Cyril Chemparathy --- app/test-pmd/ieee1588fwd.c | 4 +- app/test-pmd/rxonly.c| 21 ++ app/test-pmd/txonly.c| 4 +- app/test/packet_burst_generator.c| 5 ++- drivers/net/mlx4/mlx4.c | 9 ++-- examples/dpdk_qat/crypto.c | 8 ++-- examples/dpdk_qat/main.c | 5 ++- examples/l3fwd-acl/main.c| 20 - examples/l3fwd-power/main.c | 8 ++-- examples/l3fwd-vf/main.c | 4 +- examples/l3fwd/main.c| 71 ++-- examples/load_balancer/runtime.c | 4 +- examples/vhost_xen/main.c| 4 +- lib/librte_ip_frag/rte_ipv4_reassembly.c | 3 +- lib/librte_ip_frag/rte_ipv6_reassembly.c | 5 +-- lib/librte_port/rte_port_ras.c | 6 +-- lib/librte_vhost/vhost_rxtx.c| 6 +-- 17 files changed, 90 insertions(+), 97 deletions(-) diff --git a/app/test-pmd/ieee1588fwd.c b/app/test-pmd/ieee1588fwd.c index 84237c1..dfbb185 100644 --- a/app/test-pmd/ieee1588fwd.c +++ b/app/test-pmd/ieee1588fwd.c @@ -573,8 +573,8 @@ ieee1588_packet_fwd(struct fwd_stream *fs) * Check that the received PTP packet is a PTP V2 packet of type * PTP_SYNC_MESSAGE. */ - ptp_hdr = (struct ptpv2_msg *) (rte_pktmbuf_mtod(mb, char *) + - sizeof(struct ether_hdr)); + ptp_hdr = rte_pktmbuf_mtod_offset(mb, struct ptpv2_msg *, + sizeof(struct ether_hdr)); if (ptp_hdr->version != 0x02) { printf("Port %u Received PTP V2 Ethernet frame with wrong PTP" " protocol version 0x%x (should be 0x02)\n", diff --git a/app/test-pmd/rxonly.c b/app/test-pmd/rxonly.c index ac56090..b8e35ab 100644 --- a/app/test-pmd/rxonly.c +++ b/app/test-pmd/rxonly.c @@ -175,22 +175,25 @@ pkt_burst_receive(struct fwd_stream *fs) /* Do not support ipv4 option field */ if (ol_flags & PKT_RX_TUNNEL_IPV4_HDR) { l3_len = sizeof(struct ipv4_hdr); - ipv4_hdr = (struct ipv4_hdr *) (rte_pktmbuf_mtod(mb, - unsigned char *) + l2_len); + ipv4_hdr = rte_pktmbuf_mtod_offset(mb, + struct ipv4_hdr *, + l2_len); l4_proto = ipv4_hdr->next_proto_id; } else { l3_len = sizeof(struct ipv6_hdr); - ipv6_hdr = (struct ipv6_hdr *) (rte_pktmbuf_mtod(mb, - unsigned char *) + l2_len); + ipv6_hdr = rte_pktmbuf_mtod_offset(mb, + struct ipv6_hdr *, + l2_len); l4_proto = ipv6_hdr->proto; } if (l4_proto == IPPROTO_UDP) { - udp_hdr = (struct udp_hdr *) (rte_pktmbuf_mtod(mb, - unsigned char *) + l2_len + l3_len); + udp_hdr = rte_pktmbuf_mtod_offset(mb, + struct udp_hdr *, + l2_len + l3_len); l4_len = sizeof(struct udp_hdr); - vxlan_hdr = (struct vxlan_hdr *) (rte_pktmbuf_mtod(mb, - unsigned char *) + l2_len + l3_len -+ l4_len); + vxlan_hdr = rte_pktmbuf_mtod_offset(mb, + struct vxlan_hdr *, + l2_len + l3_len + l4_len); printf(" - VXLAN packet: packet type =%d, " "Destination UDP port =%d, VNI = %d", diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c index 9e66552..f8027f1 100644 --- a/app/test-pmd/txonly.c +++ b/app/test-pmd/txonly.c @@ -110,7 +110,7 @@ copy_buf_
[dpdk-dev] [PATCH v3 09/10] librte_mbuf: Add transform for rte_pktmbuf_mtod_offset()
This patch adds a coccinelle (see http://coccinelle.lip6.fr/) transform to use the newly added rte_pktmbuf_mtod_offset() helper. In addition, we add a simple script to apply all available transforms to a codebase. Acked-by: Olivier Matz Signed-off-by: Cyril Chemparathy --- scripts/cocci.sh| 64 ++ scripts/cocci/mtod-offset.cocci | 76 + 2 files changed, 140 insertions(+) create mode 100755 scripts/cocci.sh create mode 100644 scripts/cocci/mtod-offset.cocci diff --git a/scripts/cocci.sh b/scripts/cocci.sh new file mode 100755 index 000..3a70223 --- /dev/null +++ b/scripts/cocci.sh @@ -0,0 +1,64 @@ +#! /bin/sh + +# BSD LICENSE +# +# Copyright 2015 EZchip Semiconductor. +# +# 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 copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of EZchip Semiconductor 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 FOR +# 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 ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# Apply coccinelle transforms. + +SRCTREE=$(readlink -f $(dirname $0)/..) +COCCI=$SRCTREE/scripts/cocci +[ -n "$SPATCH" ] || SPATCH=$(which spatch) + +PATCH_LIST="$@" +[ -n "$PATCH_LIST" ] || PATCH_LIST=$(echo $COCCI/*.cocci) + +[ -x "$SPATCH" ] || ( + echo "Coccinelle tools not installed." + exit 1 +) + +tmp=$(mktemp) + +for c in $PATCH_LIST; do + while true; do + echo -n "Applying $c..." + $SPATCH --sp-file $c -c --linux-spacing --very-quiet\ + --include-headers --preprocess \ + --in-place --dir $SRCTREE > $tmp + if [ -s $tmp ]; then + echo " changes applied, retrying." + else + echo " no change." + break; + fi + done +done + +rm -f $tmp diff --git a/scripts/cocci/mtod-offset.cocci b/scripts/cocci/mtod-offset.cocci new file mode 100644 index 000..13134e9 --- /dev/null +++ b/scripts/cocci/mtod-offset.cocci @@ -0,0 +1,76 @@ +// +// Replace explicit packet offset computations with rte_pktmbuf_mtod_offset(). +// + at disable paren@ +typedef uint8_t; +expression M, O; +@@ +( +- rte_pktmbuf_mtod(M, char *) + O ++ rte_pktmbuf_mtod_offset(M, char *, O) +| +- rte_pktmbuf_mtod(M, char *) - O ++ rte_pktmbuf_mtod_offset(M, char *, -O) +| +- rte_pktmbuf_mtod(M, unsigned char *) + O ++ rte_pktmbuf_mtod_offset(M, unsigned char *, O) +| +- rte_pktmbuf_mtod(M, unsigned char *) - O ++ rte_pktmbuf_mtod_offset(M, unsigned char *, -O) +| +- rte_pktmbuf_mtod(M, uint8_t *) + O ++ rte_pktmbuf_mtod_offset(M, uint8_t *, O) +| +- rte_pktmbuf_mtod(M, uint8_t *) - O ++ rte_pktmbuf_mtod_offset(M, uint8_t *, -O) +) + + +// +// Fold subsequent offset terms into pre-existing offset used in +// rte_pktmbuf_mtod_offset(). +// + at disable paren@ +expression M, O1, O2; +@@ +( +- rte_pktmbuf_mtod_offset(M, char *, O1) + O2 ++ rte_pktmbuf_mtod_offset(M, char *, O1 + O2) +| +- rte_pktmbuf_mtod_offset(M, char *, O1) - O2 ++ rte_pktmbuf_mtod_offset(M, char *, O1 - O2) +| +- rte_pktmbuf_mtod_offset(M, unsigned char *, O1) + O2 ++ rte_pktmbuf_mtod_offset(M, unsigned char *, O1 + O2) +| +- rte_pktmbuf_mtod_offset(M, unsigned char *, O1) - O2 ++ rte_pktmbuf_mtod_offset(M, unsigned char *, O1 - O2) +| +- rte_pktmbuf_mtod_offset(M, uint8_t *, O1) + O2 ++ rte_pktmbuf_mtod_offset(M, uint8_t *, O1 + O2) +| +- rte_pktmbuf_mtod_offset(M, uint8_t *, O1) - O2 ++ rte_pktmbuf_mtod_offset(M, uint8_t *, O1 - O2) +) + + +// +// Cleanup rules. Fold in double casts, remove unn
[dpdk-dev] [PATCH v3 08/10] librte_mbuf: Add rte_pktmbuf_mtod_offset()
There are a number of instances in the code where rte_pktmbuf_mtod() is used to get the mbuf data pointer, only to add an offset before casting the result to some other header type. This patch adds a new rte_pktmbuf_mtod_offset() macro to eliminate these awful double cast situations. Signed-off-by: Cyril Chemparathy --- lib/librte_mbuf/rte_mbuf.h | 24 +--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index 6efd2b5..396963c 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -54,6 +54,7 @@ */ #include +#include #include #include #include @@ -1080,18 +1081,35 @@ static inline struct rte_mbuf *rte_pktmbuf_lastseg(struct rte_mbuf *m) } /** + * A macro that points to an offset into the data in the mbuf. + * + * The returned pointer is cast to type t. Before using this + * function, the user must ensure that the first segment is large + * enough to accomodate its data. + * + * @param m + * The packet mbuf. + * @param o + * The offset into the mbuf data. + * @param t + * The type to cast the result into. + */ +#define rte_pktmbuf_mtod_offset(m, t, o) \ + ((t)((char *)(m)->buf_addr + (m)->data_off + (o))) + +/** * A macro that points to the start of the data in the mbuf. * * The returned pointer is cast to type t. Before using this - * function, the user must ensure that m_headlen(m) is large enough to - * read its data. + * function, the user must ensure that the first segment is large + * enough to accomodate its data. * * @param m * The packet mbuf. * @param t * The type to cast the result into. */ -#define rte_pktmbuf_mtod(m, t) ((t)((char *)(m)->buf_addr + (m)->data_off)) +#define rte_pktmbuf_mtod(m, t) rte_pktmbuf_mtod_offset(m, t, 0) /** * A macro that returns the length of the packet. -- 2.1.2
[dpdk-dev] [PATCH v3 07/10] app/test: use struct ether_addr instead of a byte array cast
This patch instantiates struct ether_addr instead of type casting a uint8_t pointer to the same structure. The type cast breaks on machines that enforce strict alignment. Acked-by: Olivier Matz Signed-off-by: Cyril Chemparathy --- app/test/test_pmd_perf.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/test/test_pmd_perf.c b/app/test/test_pmd_perf.c index 1fd6843..c5253d0 100644 --- a/app/test/test_pmd_perf.c +++ b/app/test/test_pmd_perf.c @@ -228,13 +228,13 @@ init_traffic(struct rte_mempool *mp, struct ipv4_hdr pkt_ipv4_hdr; struct udp_hdr pkt_udp_hdr; uint32_t pktlen; - static uint8_t src_mac[] = { 0x00, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF }; - static uint8_t dst_mac[] = { 0x00, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA }; - + static struct ether_addr src_mac = + { { 0x00, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF } }; + static struct ether_addr dst_mac = + { { 0x00, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA } }; initialize_eth_header(_eth_hdr, - (struct ether_addr *)src_mac, - (struct ether_addr *)dst_mac, ETHER_TYPE_IPv4, 0, 0); + _mac, _mac, ETHER_TYPE_IPv4, 0, 0); pktlen = initialize_ipv4_header(_ipv4_hdr, IPV4_ADDR(10, 0, 0, 1), -- 2.1.2
[dpdk-dev] [PATCH v3 06/10] app/test-pmd: pack simple_gre_hdr
Not packing this causes -Wcast-align breakage on machines that are strict on alignment. This patch fixes this bug. Acked-by: Olivier Matz Signed-off-by: Cyril Chemparathy --- app/test-pmd/csumonly.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c index 950ea82..4287940 100644 --- a/app/test-pmd/csumonly.c +++ b/app/test-pmd/csumonly.c @@ -108,7 +108,7 @@ struct testpmd_offload_info { struct simple_gre_hdr { uint16_t flags; uint16_t proto; -}; +} __attribute__((__packed__)); static uint16_t get_psd_sum(void *l3_hdr, uint16_t ethertype, uint64_t ol_flags) -- 2.1.2
[dpdk-dev] [PATCH v3 05/10] eal: add and use unaligned integer types
On machines that are strict on pointer alignment, current code breaks on GCC's -Wcast-align checks on casts from narrower to wider types. This patch introduces new unaligned_uint(16|32|64)_t types, which correctly retain alignment in such cases. Strict alignment architectures will need to define CONFIG_RTE_ARCH_STRICT_ALIGN in order to effect these new types. Signed-off-by: Cyril Chemparathy --- app/test-pmd/flowgen.c | 4 ++-- app/test-pmd/icmpecho.c| 2 +- app/test-pmd/txonly.c | 2 +- app/test/packet_burst_generator.c | 4 ++-- app/test/test_hash_functions.c | 2 +- app/test/test_mbuf.c | 16 lib/librte_eal/common/include/rte_common.h | 10 ++ lib/librte_ether/rte_ether.h | 2 +- lib/librte_ip_frag/rte_ipv4_reassembly.c | 4 ++-- 9 files changed, 28 insertions(+), 18 deletions(-) diff --git a/app/test-pmd/flowgen.c b/app/test-pmd/flowgen.c index 72016c9..174c003 100644 --- a/app/test-pmd/flowgen.c +++ b/app/test-pmd/flowgen.c @@ -101,7 +101,7 @@ tx_mbuf_alloc(struct rte_mempool *mp) static inline uint16_t -ip_sum(const uint16_t *hdr, int hdr_len) +ip_sum(const unaligned_uint16_t *hdr, int hdr_len) { uint32_t sum = 0; @@ -193,7 +193,7 @@ pkt_burst_flow_gen(struct fwd_stream *fs) next_flow); ip_hdr->total_length= RTE_CPU_TO_BE_16(pkt_size - sizeof(*eth_hdr)); - ip_hdr->hdr_checksum= ip_sum((uint16_t *)ip_hdr, + ip_hdr->hdr_checksum= ip_sum((unaligned_uint16_t *)ip_hdr, sizeof(*ip_hdr)); /* Initialize UDP header. */ diff --git a/app/test-pmd/icmpecho.c b/app/test-pmd/icmpecho.c index 29aef71..e510f9b 100644 --- a/app/test-pmd/icmpecho.c +++ b/app/test-pmd/icmpecho.c @@ -282,7 +282,7 @@ ipv4_hdr_cksum(struct ipv4_hdr *ip_h) * Compute the sum of successive 16-bit words of the IPv4 header, * skipping the checksum field of the header. */ - v16_h = (uint16_t *) ip_h; + v16_h = (unaligned_uint16_t *) ip_h; ip_cksum = v16_h[0] + v16_h[1] + v16_h[2] + v16_h[3] + v16_h[4] + v16_h[6] + v16_h[7] + v16_h[8] + v16_h[9]; diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c index ca32c85..9e66552 100644 --- a/app/test-pmd/txonly.c +++ b/app/test-pmd/txonly.c @@ -167,7 +167,7 @@ setup_pkt_udp_ip_headers(struct ipv4_hdr *ip_hdr, /* * Compute IP header checksum. */ - ptr16 = (uint16_t*) ip_hdr; + ptr16 = (unaligned_uint16_t*) ip_hdr; ip_cksum = 0; ip_cksum += ptr16[0]; ip_cksum += ptr16[1]; ip_cksum += ptr16[2]; ip_cksum += ptr16[3]; diff --git a/app/test/packet_burst_generator.c b/app/test/packet_burst_generator.c index b46eed7..06762c6 100644 --- a/app/test/packet_burst_generator.c +++ b/app/test/packet_burst_generator.c @@ -154,7 +154,7 @@ initialize_ipv4_header(struct ipv4_hdr *ip_hdr, uint32_t src_addr, uint32_t dst_addr, uint16_t pkt_data_len) { uint16_t pkt_len; - uint16_t *ptr16; + unaligned_uint16_t *ptr16; uint32_t ip_cksum; /* @@ -175,7 +175,7 @@ initialize_ipv4_header(struct ipv4_hdr *ip_hdr, uint32_t src_addr, /* * Compute IP header checksum. */ - ptr16 = (uint16_t *)ip_hdr; + ptr16 = (unaligned_uint16_t *)ip_hdr; ip_cksum = 0; ip_cksum += ptr16[0]; ip_cksum += ptr16[1]; ip_cksum += ptr16[2]; ip_cksum += ptr16[3]; diff --git a/app/test/test_hash_functions.c b/app/test/test_hash_functions.c index df7c909..8c7cf63 100644 --- a/app/test/test_hash_functions.c +++ b/app/test/test_hash_functions.c @@ -223,7 +223,7 @@ verify_jhash_32bits(void) hash = rte_jhash(key, hashtest_key_lens[i], hashtest_initvals[j]); /* Divide key length by 4 in rte_jhash for 32 bits */ - hash32 = rte_jhash_32b((const uint32_t *)key, + hash32 = rte_jhash_32b((const unaligned_uint32_t *)key, hashtest_key_lens[i] >> 2, hashtest_initvals[j]); if (hash != hash32) { diff --git a/app/test/test_mbuf.c b/app/test/test_mbuf.c index 5e8a377..d9beb29 100644 --- a/app/test/test_mbuf.c +++ b/app/test/test_mbuf.c @@ -333,7 +333,7 @@ testclone_testupdate_testdetach(void) struct rte_mbuf *m = NULL; struct rte_mbuf *clone = NULL; struct rte_mbuf *clone2 = NULL; - uint32_t *data; + unaligned_uint32_t *data; /* alloc a mbuf */ m = rte_pktmbuf_all
[dpdk-dev] [PATCH v3 04/10] hash: silence -Wcast-align on pointer arithmetic
Since sig_tbl_bucket_size and key_tbl_key_size are explicitly aligned at initialization, offset dereferences in the hash table code cannot possibly be unaligned. However, the compiler is unaware of this fact and complains on -Wcast-align. This patch modifies the code to use RTE_PTR_ADD(), thereby silencing the compiler by casting through (void *). Acked-by: Olivier Matz Signed-off-by: Cyril Chemparathy --- lib/librte_hash/rte_hash.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/librte_hash/rte_hash.c b/lib/librte_hash/rte_hash.c index 9245716..67dff5b 100644 --- a/lib/librte_hash/rte_hash.c +++ b/lib/librte_hash/rte_hash.c @@ -96,23 +96,23 @@ EAL_REGISTER_TAILQ(rte_hash_tailq) static inline hash_sig_t * get_sig_tbl_bucket(const struct rte_hash *h, uint32_t bucket_index) { - return (hash_sig_t *) - &(h->sig_tbl[bucket_index * h->sig_tbl_bucket_size]); + return RTE_PTR_ADD(h->sig_tbl, (bucket_index * + h->sig_tbl_bucket_size)); } /* Returns a pointer to the first key in specified bucket. */ static inline uint8_t * get_key_tbl_bucket(const struct rte_hash *h, uint32_t bucket_index) { - return (uint8_t *) &(h->key_tbl[bucket_index * h->bucket_entries * -h->key_tbl_key_size]); + return RTE_PTR_ADD(h->key_tbl, (bucket_index * h->bucket_entries * + h->key_tbl_key_size)); } /* Returns a pointer to a key at a specific position in a specified bucket. */ static inline void * get_key_from_bucket(const struct rte_hash *h, uint8_t *bkt, uint32_t pos) { - return (void *) [pos * h->key_tbl_key_size]; + return RTE_PTR_ADD(bkt, pos * h->key_tbl_key_size); } /* Does integer division with rounding-up of result. */ -- 2.1.2
[dpdk-dev] [PATCH v3 03/10] ethdev: silence -Wcast-align on pointer arithmetic
Statistics offsets in the rte_stats_strings[] array are always 64-bit aligned. However, the compiler is unaware of this fact and complains on -Wcast-align. This patch modifies the code to use RTE_PTR_ADD(), thereby silencing the compiler by casting through (void *). Acked-by: Olivier Matz Signed-off-by: Cyril Chemparathy --- lib/librte_ether/rte_ethdev.c | 24 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index e13fde5..02cd07f 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -1742,8 +1742,7 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats, struct rte_eth_stats eth_stats; struct rte_eth_dev *dev; unsigned count, i, q; - uint64_t val; - char *stats_ptr; + uint64_t val, *stats_ptr; if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); @@ -1770,8 +1769,9 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats, /* global stats */ for (i = 0; i < RTE_NB_STATS; i++) { - stats_ptr = (char *)_stats + rte_stats_strings[i].offset; - val = *(uint64_t *)stats_ptr; + stats_ptr = RTE_PTR_ADD(_stats, + rte_stats_strings[i].offset); + val = *stats_ptr; snprintf(xstats[count].name, sizeof(xstats[count].name), "%s", rte_stats_strings[i].name); xstats[count++].value = val; @@ -1780,10 +1780,10 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats, /* per-rxq stats */ for (q = 0; q < dev->data->nb_rx_queues; q++) { for (i = 0; i < RTE_NB_RXQ_STATS; i++) { - stats_ptr = (char *)_stats; - stats_ptr += rte_rxq_stats_strings[i].offset; - stats_ptr += q * sizeof(uint64_t); - val = *(uint64_t *)stats_ptr; + stats_ptr = RTE_PTR_ADD(_stats, + rte_rxq_stats_strings[i].offset + + q * sizeof(uint64_t)); + val = *stats_ptr; snprintf(xstats[count].name, sizeof(xstats[count].name), "rx_queue_%u_%s", q, rte_rxq_stats_strings[i].name); @@ -1794,10 +1794,10 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats, /* per-txq stats */ for (q = 0; q < dev->data->nb_tx_queues; q++) { for (i = 0; i < RTE_NB_TXQ_STATS; i++) { - stats_ptr = (char *)_stats; - stats_ptr += rte_txq_stats_strings[i].offset; - stats_ptr += q * sizeof(uint64_t); - val = *(uint64_t *)stats_ptr; + stats_ptr = RTE_PTR_ADD(_stats, + rte_txq_stats_strings[i].offset + + q * sizeof(uint64_t)); + val = *stats_ptr; snprintf(xstats[count].name, sizeof(xstats[count].name), "tx_queue_%u_%s", q, rte_txq_stats_strings[i].name); -- 2.1.2
[dpdk-dev] [PATCH v3 02/10] mbuf: silence -Wcast-align on pointer arithmetic
Translating from an mbuf element to the mbuf pointer does not break alignment constraints. However, the compiler is unaware of this fact and complains on -Wcast-align. This patch modifies the code to use RTE_PTR_SUB(), thereby silencing the compiler by casting through (void *). Acked-by: Olivier Matz Signed-off-by: Cyril Chemparathy --- lib/librte_mbuf/rte_mbuf.h | 8 +--- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index 6c9cfd6..6efd2b5 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -347,13 +347,7 @@ static inline uint16_t rte_pktmbuf_priv_size(struct rte_mempool *mp); static inline struct rte_mbuf * rte_mbuf_from_indirect(struct rte_mbuf *mi) { - struct rte_mbuf *md; - - /* mi->buf_addr and mi->priv_size correspond to buffer and -* private size of the direct mbuf */ - md = (struct rte_mbuf *)((char *)mi->buf_addr - sizeof(*mi) - - mi->priv_size); - return md; + return RTE_PTR_SUB(mi->buf_addr, sizeof(*mi) + mi->priv_size); } /** -- 2.1.2
[dpdk-dev] [PATCH v3 01/10] mempool: silence -Wcast-align on pointer arithmetic
Translating from a mempool object to the mempool pointer does not break alignment constraints. However, the compiler is unaware of this fact and complains on -Wcast-align. This patch modifies the code to use RTE_PTR_SUB(), thereby silencing the compiler by casting through (void *). Acked-by: Olivier Matz Signed-off-by: Cyril Chemparathy --- lib/librte_mempool/rte_mempool.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h index bc2bae0..8be040b 100644 --- a/lib/librte_mempool/rte_mempool.h +++ b/lib/librte_mempool/rte_mempool.h @@ -236,15 +236,13 @@ struct rte_mempool { */ static inline struct rte_mempool **__mempool_from_obj(void *obj) { - struct rte_mempool **mpp; unsigned off; off = sizeof(struct rte_mempool *); #ifdef RTE_LIBRTE_MEMPOOL_DEBUG off += sizeof(uint64_t); #endif - mpp = (struct rte_mempool **)((char *)obj - off); - return mpp; + return RTE_PTR_SUB(obj, off); } /** -- 2.1.2
[dpdk-dev] [PATCH v3 00/10] Improve cast alignment for strict aligned machines
This series contains a few improvements that allow the DPDK code base to build properly on machines that enforce strict pointer cast alignment constraints. When dealing with packet data which could be arbitrarily aligned, we get the compiler to do the right thing by (a) making sure that header types are packed, and (b) introducing and using unaligned_uint(16|32|64)_t types when upcasting from byte pointers. In a few other instances, we know apriori that the pointer cast cannot possibly break alignment. This applies to the changes in mempool, hash, mbuf, and the ethdev stats code. Here, we simply silence the compiler by casting through (void *) using the RTE_PTR_(ADD|SUB) macros. Finally, we introduce a new rte_pktmbuf_mtod_offset() helper to return a type casted pointer to an offset within the packet data. This replaces the following commonly used pattern: (struct foo *)(rte_pktmbuf_mtod(m, char *) + offset) with: rte_pktmbuf_mtod_offset(m, struct foo *, offset) To ensure consistency, the above transform was applied throughout the code base using the coccinelle semantic patching tool. Changes in this series: v2: Fixes based on Olivier's comments. v3: Extends unaligned fixes to new code introduced on master. Cyril Chemparathy (10): mempool: silence -Wcast-align on pointer arithmetic mbuf: silence -Wcast-align on pointer arithmetic ethdev: silence -Wcast-align on pointer arithmetic hash: silence -Wcast-align on pointer arithmetic eal: add and use unaligned integer types app/test-pmd: pack simple_gre_hdr app/test: use struct ether_addr instead of a byte array cast librte_mbuf: Add rte_pktmbuf_mtod_offset() librte_mbuf: Add transform for rte_pktmbuf_mtod_offset() librte_mbuf: Apply mtod-offset.cocci transform app/test-pmd/csumonly.c| 2 +- app/test-pmd/flowgen.c | 4 +- app/test-pmd/icmpecho.c| 2 +- app/test-pmd/ieee1588fwd.c | 4 +- app/test-pmd/rxonly.c | 21 + app/test-pmd/txonly.c | 6 +-- app/test/packet_burst_generator.c | 9 ++-- app/test/test_hash_functions.c | 2 +- app/test/test_mbuf.c | 16 +++ app/test/test_pmd_perf.c | 10 ++-- drivers/net/mlx4/mlx4.c| 9 ++-- examples/dpdk_qat/crypto.c | 8 ++-- examples/dpdk_qat/main.c | 5 +- examples/l3fwd-acl/main.c | 20 examples/l3fwd-power/main.c| 8 ++-- examples/l3fwd-vf/main.c | 4 +- examples/l3fwd/main.c | 71 examples/load_balancer/runtime.c | 4 +- examples/vhost_xen/main.c | 4 +- lib/librte_eal/common/include/rte_common.h | 10 lib/librte_ether/rte_ethdev.c | 24 +- lib/librte_ether/rte_ether.h | 2 +- lib/librte_hash/rte_hash.c | 10 ++-- lib/librte_ip_frag/rte_ipv4_reassembly.c | 7 ++- lib/librte_ip_frag/rte_ipv6_reassembly.c | 5 +- lib/librte_mbuf/rte_mbuf.h | 32 + lib/librte_mempool/rte_mempool.h | 4 +- lib/librte_port/rte_port_ras.c | 6 +-- lib/librte_vhost/vhost_rxtx.c | 6 +-- scripts/cocci.sh | 64 + scripts/cocci/mtod-offset.cocci| 76 ++ 31 files changed, 304 insertions(+), 151 deletions(-) create mode 100755 scripts/cocci.sh create mode 100644 scripts/cocci/mtod-offset.cocci -- 2.1.2
[dpdk-dev] [PATCH v2 10/10] librte_mbuf: Apply mtod-offset.cocci transform
This patch simply applies the transform previously committed in scripts/cocci/mtod-offset.cocci. No other modifications have been made here. This patch applies on commit 960e8a22fc6d9373e37dd1454131e91f082bb8bc. This patch may need to be regenerated by rerunning scripts/cocci.sh instead of simply merging in the change. Acked-by: Olivier Matz Signed-off-by: Cyril Chemparathy --- app/test-pmd/ieee1588fwd.c | 4 +- app/test-pmd/rxonly.c| 21 ++ app/test-pmd/txonly.c| 4 +- app/test/packet_burst_generator.c| 5 ++- drivers/net/mlx4/mlx4.c | 9 ++-- examples/dpdk_qat/crypto.c | 8 ++-- examples/dpdk_qat/main.c | 5 ++- examples/l3fwd-acl/main.c| 20 - examples/l3fwd-power/main.c | 8 ++-- examples/l3fwd-vf/main.c | 4 +- examples/l3fwd/main.c| 71 ++-- examples/load_balancer/runtime.c | 4 +- examples/vhost_xen/main.c| 4 +- lib/librte_ip_frag/rte_ipv4_reassembly.c | 3 +- lib/librte_ip_frag/rte_ipv6_reassembly.c | 5 +-- lib/librte_port/rte_port_ras.c | 6 +-- lib/librte_vhost/vhost_rxtx.c| 6 +-- 17 files changed, 90 insertions(+), 97 deletions(-) diff --git a/app/test-pmd/ieee1588fwd.c b/app/test-pmd/ieee1588fwd.c index 84237c1..dfbb185 100644 --- a/app/test-pmd/ieee1588fwd.c +++ b/app/test-pmd/ieee1588fwd.c @@ -573,8 +573,8 @@ ieee1588_packet_fwd(struct fwd_stream *fs) * Check that the received PTP packet is a PTP V2 packet of type * PTP_SYNC_MESSAGE. */ - ptp_hdr = (struct ptpv2_msg *) (rte_pktmbuf_mtod(mb, char *) + - sizeof(struct ether_hdr)); + ptp_hdr = rte_pktmbuf_mtod_offset(mb, struct ptpv2_msg *, + sizeof(struct ether_hdr)); if (ptp_hdr->version != 0x02) { printf("Port %u Received PTP V2 Ethernet frame with wrong PTP" " protocol version 0x%x (should be 0x02)\n", diff --git a/app/test-pmd/rxonly.c b/app/test-pmd/rxonly.c index ac56090..b8e35ab 100644 --- a/app/test-pmd/rxonly.c +++ b/app/test-pmd/rxonly.c @@ -175,22 +175,25 @@ pkt_burst_receive(struct fwd_stream *fs) /* Do not support ipv4 option field */ if (ol_flags & PKT_RX_TUNNEL_IPV4_HDR) { l3_len = sizeof(struct ipv4_hdr); - ipv4_hdr = (struct ipv4_hdr *) (rte_pktmbuf_mtod(mb, - unsigned char *) + l2_len); + ipv4_hdr = rte_pktmbuf_mtod_offset(mb, + struct ipv4_hdr *, + l2_len); l4_proto = ipv4_hdr->next_proto_id; } else { l3_len = sizeof(struct ipv6_hdr); - ipv6_hdr = (struct ipv6_hdr *) (rte_pktmbuf_mtod(mb, - unsigned char *) + l2_len); + ipv6_hdr = rte_pktmbuf_mtod_offset(mb, + struct ipv6_hdr *, + l2_len); l4_proto = ipv6_hdr->proto; } if (l4_proto == IPPROTO_UDP) { - udp_hdr = (struct udp_hdr *) (rte_pktmbuf_mtod(mb, - unsigned char *) + l2_len + l3_len); + udp_hdr = rte_pktmbuf_mtod_offset(mb, + struct udp_hdr *, + l2_len + l3_len); l4_len = sizeof(struct udp_hdr); - vxlan_hdr = (struct vxlan_hdr *) (rte_pktmbuf_mtod(mb, - unsigned char *) + l2_len + l3_len -+ l4_len); + vxlan_hdr = rte_pktmbuf_mtod_offset(mb, + struct vxlan_hdr *, + l2_len + l3_len + l4_len); printf(" - VXLAN packet: packet type =%d, " "Destination UDP port =%d, VNI = %d", diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c index 9e66552..f8027f1 100644 --- a/app/test-pmd/txonly.c +++ b/app/test-pmd/txonly.c @@ -110,7 +110,7 @@ copy_buf_
[dpdk-dev] [PATCH v2 09/10] librte_mbuf: Add transform for rte_pktmbuf_mtod_offset()
This patch adds a coccinelle (see http://coccinelle.lip6.fr/) transform to use the newly added rte_pktmbuf_mtod_offset() helper. In addition, we add a simple script to apply all available transforms to a codebase. Acked-by: Olivier Matz Signed-off-by: Cyril Chemparathy --- scripts/cocci.sh| 64 ++ scripts/cocci/mtod-offset.cocci | 76 + 2 files changed, 140 insertions(+) create mode 100755 scripts/cocci.sh create mode 100644 scripts/cocci/mtod-offset.cocci diff --git a/scripts/cocci.sh b/scripts/cocci.sh new file mode 100755 index 000..3a70223 --- /dev/null +++ b/scripts/cocci.sh @@ -0,0 +1,64 @@ +#! /bin/sh + +# BSD LICENSE +# +# Copyright 2015 EZchip Semiconductor. +# +# 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 copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of EZchip Semiconductor 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 FOR +# 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 ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# Apply coccinelle transforms. + +SRCTREE=$(readlink -f $(dirname $0)/..) +COCCI=$SRCTREE/scripts/cocci +[ -n "$SPATCH" ] || SPATCH=$(which spatch) + +PATCH_LIST="$@" +[ -n "$PATCH_LIST" ] || PATCH_LIST=$(echo $COCCI/*.cocci) + +[ -x "$SPATCH" ] || ( + echo "Coccinelle tools not installed." + exit 1 +) + +tmp=$(mktemp) + +for c in $PATCH_LIST; do + while true; do + echo -n "Applying $c..." + $SPATCH --sp-file $c -c --linux-spacing --very-quiet\ + --include-headers --preprocess \ + --in-place --dir $SRCTREE > $tmp + if [ -s $tmp ]; then + echo " changes applied, retrying." + else + echo " no change." + break; + fi + done +done + +rm -f $tmp diff --git a/scripts/cocci/mtod-offset.cocci b/scripts/cocci/mtod-offset.cocci new file mode 100644 index 000..13134e9 --- /dev/null +++ b/scripts/cocci/mtod-offset.cocci @@ -0,0 +1,76 @@ +// +// Replace explicit packet offset computations with rte_pktmbuf_mtod_offset(). +// + at disable paren@ +typedef uint8_t; +expression M, O; +@@ +( +- rte_pktmbuf_mtod(M, char *) + O ++ rte_pktmbuf_mtod_offset(M, char *, O) +| +- rte_pktmbuf_mtod(M, char *) - O ++ rte_pktmbuf_mtod_offset(M, char *, -O) +| +- rte_pktmbuf_mtod(M, unsigned char *) + O ++ rte_pktmbuf_mtod_offset(M, unsigned char *, O) +| +- rte_pktmbuf_mtod(M, unsigned char *) - O ++ rte_pktmbuf_mtod_offset(M, unsigned char *, -O) +| +- rte_pktmbuf_mtod(M, uint8_t *) + O ++ rte_pktmbuf_mtod_offset(M, uint8_t *, O) +| +- rte_pktmbuf_mtod(M, uint8_t *) - O ++ rte_pktmbuf_mtod_offset(M, uint8_t *, -O) +) + + +// +// Fold subsequent offset terms into pre-existing offset used in +// rte_pktmbuf_mtod_offset(). +// + at disable paren@ +expression M, O1, O2; +@@ +( +- rte_pktmbuf_mtod_offset(M, char *, O1) + O2 ++ rte_pktmbuf_mtod_offset(M, char *, O1 + O2) +| +- rte_pktmbuf_mtod_offset(M, char *, O1) - O2 ++ rte_pktmbuf_mtod_offset(M, char *, O1 - O2) +| +- rte_pktmbuf_mtod_offset(M, unsigned char *, O1) + O2 ++ rte_pktmbuf_mtod_offset(M, unsigned char *, O1 + O2) +| +- rte_pktmbuf_mtod_offset(M, unsigned char *, O1) - O2 ++ rte_pktmbuf_mtod_offset(M, unsigned char *, O1 - O2) +| +- rte_pktmbuf_mtod_offset(M, uint8_t *, O1) + O2 ++ rte_pktmbuf_mtod_offset(M, uint8_t *, O1 + O2) +| +- rte_pktmbuf_mtod_offset(M, uint8_t *, O1) - O2 ++ rte_pktmbuf_mtod_offset(M, uint8_t *, O1 - O2) +) + + +// +// Cleanup rules. Fold in double casts, remove unn
[dpdk-dev] [PATCH v2 08/10] librte_mbuf: Add rte_pktmbuf_mtod_offset()
There are a number of instances in the code where rte_pktmbuf_mtod() is used to get the mbuf data pointer, only to add an offset before casting the result to some other header type. This patch adds a new rte_pktmbuf_mtod_offset() macro to eliminate these awful double cast situations. Signed-off-by: Cyril Chemparathy --- lib/librte_mbuf/rte_mbuf.h | 24 +--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index 6efd2b5..396963c 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -54,6 +54,7 @@ */ #include +#include #include #include #include @@ -1080,18 +1081,35 @@ static inline struct rte_mbuf *rte_pktmbuf_lastseg(struct rte_mbuf *m) } /** + * A macro that points to an offset into the data in the mbuf. + * + * The returned pointer is cast to type t. Before using this + * function, the user must ensure that the first segment is large + * enough to accomodate its data. + * + * @param m + * The packet mbuf. + * @param o + * The offset into the mbuf data. + * @param t + * The type to cast the result into. + */ +#define rte_pktmbuf_mtod_offset(m, t, o) \ + ((t)((char *)(m)->buf_addr + (m)->data_off + (o))) + +/** * A macro that points to the start of the data in the mbuf. * * The returned pointer is cast to type t. Before using this - * function, the user must ensure that m_headlen(m) is large enough to - * read its data. + * function, the user must ensure that the first segment is large + * enough to accomodate its data. * * @param m * The packet mbuf. * @param t * The type to cast the result into. */ -#define rte_pktmbuf_mtod(m, t) ((t)((char *)(m)->buf_addr + (m)->data_off)) +#define rte_pktmbuf_mtod(m, t) rte_pktmbuf_mtod_offset(m, t, 0) /** * A macro that returns the length of the packet. -- 2.1.2
[dpdk-dev] [PATCH v2 07/10] app/test: use struct ether_addr instead of a byte array cast
This patch instantiates struct ether_addr instead of type casting a uint8_t pointer to the same structure. The type cast breaks on machines that enforce strict alignment. Acked-by: Olivier Matz Signed-off-by: Cyril Chemparathy --- app/test/test_pmd_perf.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/test/test_pmd_perf.c b/app/test/test_pmd_perf.c index 1fd6843..c5253d0 100644 --- a/app/test/test_pmd_perf.c +++ b/app/test/test_pmd_perf.c @@ -228,13 +228,13 @@ init_traffic(struct rte_mempool *mp, struct ipv4_hdr pkt_ipv4_hdr; struct udp_hdr pkt_udp_hdr; uint32_t pktlen; - static uint8_t src_mac[] = { 0x00, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF }; - static uint8_t dst_mac[] = { 0x00, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA }; - + static struct ether_addr src_mac = + { { 0x00, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF } }; + static struct ether_addr dst_mac = + { { 0x00, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA } }; initialize_eth_header(_eth_hdr, - (struct ether_addr *)src_mac, - (struct ether_addr *)dst_mac, ETHER_TYPE_IPv4, 0, 0); + _mac, _mac, ETHER_TYPE_IPv4, 0, 0); pktlen = initialize_ipv4_header(_ipv4_hdr, IPV4_ADDR(10, 0, 0, 1), -- 2.1.2
[dpdk-dev] [PATCH v2 06/10] app/test-pmd: pack simple_gre_hdr
Not packing this causes -Wcast-align breakage on machines that are strict on alignment. This patch fixes this bug. Acked-by: Olivier Matz Signed-off-by: Cyril Chemparathy --- app/test-pmd/csumonly.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c index 950ea82..4287940 100644 --- a/app/test-pmd/csumonly.c +++ b/app/test-pmd/csumonly.c @@ -108,7 +108,7 @@ struct testpmd_offload_info { struct simple_gre_hdr { uint16_t flags; uint16_t proto; -}; +} __attribute__((__packed__)); static uint16_t get_psd_sum(void *l3_hdr, uint16_t ethertype, uint64_t ol_flags) -- 2.1.2
[dpdk-dev] [PATCH v2 05/10] eal: add and use unaligned integer types
On machines that are strict on pointer alignment, current code breaks on GCC's -Wcast-align checks on casts from narrower to wider types. This patch introduces new unaligned_uint(16|32|64)_t types, which correctly retain alignment in such cases. This is currently unimplemented on ICC and clang, and equivalents will need to be plugged in. Signed-off-by: Cyril Chemparathy --- app/test-pmd/flowgen.c | 4 ++-- app/test-pmd/txonly.c | 2 +- app/test/packet_burst_generator.c | 4 ++-- app/test/test_mbuf.c | 16 lib/librte_eal/common/include/rte_common.h | 10 ++ lib/librte_ether/rte_ether.h | 2 +- lib/librte_ip_frag/rte_ipv4_reassembly.c | 4 ++-- 7 files changed, 26 insertions(+), 16 deletions(-) diff --git a/app/test-pmd/flowgen.c b/app/test-pmd/flowgen.c index 72016c9..174c003 100644 --- a/app/test-pmd/flowgen.c +++ b/app/test-pmd/flowgen.c @@ -101,7 +101,7 @@ tx_mbuf_alloc(struct rte_mempool *mp) static inline uint16_t -ip_sum(const uint16_t *hdr, int hdr_len) +ip_sum(const unaligned_uint16_t *hdr, int hdr_len) { uint32_t sum = 0; @@ -193,7 +193,7 @@ pkt_burst_flow_gen(struct fwd_stream *fs) next_flow); ip_hdr->total_length= RTE_CPU_TO_BE_16(pkt_size - sizeof(*eth_hdr)); - ip_hdr->hdr_checksum= ip_sum((uint16_t *)ip_hdr, + ip_hdr->hdr_checksum= ip_sum((unaligned_uint16_t *)ip_hdr, sizeof(*ip_hdr)); /* Initialize UDP header. */ diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c index ca32c85..9e66552 100644 --- a/app/test-pmd/txonly.c +++ b/app/test-pmd/txonly.c @@ -167,7 +167,7 @@ setup_pkt_udp_ip_headers(struct ipv4_hdr *ip_hdr, /* * Compute IP header checksum. */ - ptr16 = (uint16_t*) ip_hdr; + ptr16 = (unaligned_uint16_t*) ip_hdr; ip_cksum = 0; ip_cksum += ptr16[0]; ip_cksum += ptr16[1]; ip_cksum += ptr16[2]; ip_cksum += ptr16[3]; diff --git a/app/test/packet_burst_generator.c b/app/test/packet_burst_generator.c index b46eed7..06762c6 100644 --- a/app/test/packet_burst_generator.c +++ b/app/test/packet_burst_generator.c @@ -154,7 +154,7 @@ initialize_ipv4_header(struct ipv4_hdr *ip_hdr, uint32_t src_addr, uint32_t dst_addr, uint16_t pkt_data_len) { uint16_t pkt_len; - uint16_t *ptr16; + unaligned_uint16_t *ptr16; uint32_t ip_cksum; /* @@ -175,7 +175,7 @@ initialize_ipv4_header(struct ipv4_hdr *ip_hdr, uint32_t src_addr, /* * Compute IP header checksum. */ - ptr16 = (uint16_t *)ip_hdr; + ptr16 = (unaligned_uint16_t *)ip_hdr; ip_cksum = 0; ip_cksum += ptr16[0]; ip_cksum += ptr16[1]; ip_cksum += ptr16[2]; ip_cksum += ptr16[3]; diff --git a/app/test/test_mbuf.c b/app/test/test_mbuf.c index 5e8a377..d9beb29 100644 --- a/app/test/test_mbuf.c +++ b/app/test/test_mbuf.c @@ -333,7 +333,7 @@ testclone_testupdate_testdetach(void) struct rte_mbuf *m = NULL; struct rte_mbuf *clone = NULL; struct rte_mbuf *clone2 = NULL; - uint32_t *data; + unaligned_uint32_t *data; /* alloc a mbuf */ m = rte_pktmbuf_alloc(pktmbuf_pool); @@ -344,7 +344,7 @@ testclone_testupdate_testdetach(void) GOTO_FAIL("Bad length"); rte_pktmbuf_append(m, sizeof(uint32_t)); - data = rte_pktmbuf_mtod(m, uint32_t *); + data = rte_pktmbuf_mtod(m, unaligned_uint32_t *); *data = MAGIC_DATA; /* clone the allocated mbuf */ @@ -352,7 +352,7 @@ testclone_testupdate_testdetach(void) if (clone == NULL) GOTO_FAIL("cannot clone data\n"); - data = rte_pktmbuf_mtod(clone, uint32_t *); + data = rte_pktmbuf_mtod(clone, unaligned_uint32_t *); if (*data != MAGIC_DATA) GOTO_FAIL("invalid data in clone\n"); @@ -369,18 +369,18 @@ testclone_testupdate_testdetach(void) GOTO_FAIL("Next Pkt Null\n"); rte_pktmbuf_append(m->next, sizeof(uint32_t)); - data = rte_pktmbuf_mtod(m->next, uint32_t *); + data = rte_pktmbuf_mtod(m->next, unaligned_uint32_t *); *data = MAGIC_DATA; clone = rte_pktmbuf_clone(m, pktmbuf_pool); if (clone == NULL) GOTO_FAIL("cannot clone data\n"); - data = rte_pktmbuf_mtod(clone, uint32_t *); + data = rte_pktmbuf_mtod(clone, unaligned_uint32_t *); if (*data != MAGIC_DATA) GOTO_FAIL("invalid data in clone\n"); - data = rte_pktmbuf_mtod(clone->next, uint32_t *); + data = rte_pktmbuf_mtod(clone->next, unaligned_uint32_t *);
[dpdk-dev] [PATCH v2 03/10] ethdev: silence -Wcast-align on pointer arithmetic
Statistics offsets in the rte_stats_strings[] array are always 64-bit aligned. However, the compiler is unaware of this fact and complains on -Wcast-align. This patch modifies the code to use RTE_PTR_ADD(), thereby silencing the compiler by casting through (void *). Acked-by: Olivier Matz Signed-off-by: Cyril Chemparathy --- lib/librte_ether/rte_ethdev.c | 24 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index e13fde5..02cd07f 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -1742,8 +1742,7 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats, struct rte_eth_stats eth_stats; struct rte_eth_dev *dev; unsigned count, i, q; - uint64_t val; - char *stats_ptr; + uint64_t val, *stats_ptr; if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); @@ -1770,8 +1769,9 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats, /* global stats */ for (i = 0; i < RTE_NB_STATS; i++) { - stats_ptr = (char *)_stats + rte_stats_strings[i].offset; - val = *(uint64_t *)stats_ptr; + stats_ptr = RTE_PTR_ADD(_stats, + rte_stats_strings[i].offset); + val = *stats_ptr; snprintf(xstats[count].name, sizeof(xstats[count].name), "%s", rte_stats_strings[i].name); xstats[count++].value = val; @@ -1780,10 +1780,10 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats, /* per-rxq stats */ for (q = 0; q < dev->data->nb_rx_queues; q++) { for (i = 0; i < RTE_NB_RXQ_STATS; i++) { - stats_ptr = (char *)_stats; - stats_ptr += rte_rxq_stats_strings[i].offset; - stats_ptr += q * sizeof(uint64_t); - val = *(uint64_t *)stats_ptr; + stats_ptr = RTE_PTR_ADD(_stats, + rte_rxq_stats_strings[i].offset + + q * sizeof(uint64_t)); + val = *stats_ptr; snprintf(xstats[count].name, sizeof(xstats[count].name), "rx_queue_%u_%s", q, rte_rxq_stats_strings[i].name); @@ -1794,10 +1794,10 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats, /* per-txq stats */ for (q = 0; q < dev->data->nb_tx_queues; q++) { for (i = 0; i < RTE_NB_TXQ_STATS; i++) { - stats_ptr = (char *)_stats; - stats_ptr += rte_txq_stats_strings[i].offset; - stats_ptr += q * sizeof(uint64_t); - val = *(uint64_t *)stats_ptr; + stats_ptr = RTE_PTR_ADD(_stats, + rte_txq_stats_strings[i].offset + + q * sizeof(uint64_t)); + val = *stats_ptr; snprintf(xstats[count].name, sizeof(xstats[count].name), "tx_queue_%u_%s", q, rte_txq_stats_strings[i].name); -- 2.1.2
[dpdk-dev] [PATCH v2 02/10] mbuf: silence -Wcast-align on pointer arithmetic
Translating from an mbuf element to the mbuf pointer does not break alignment constraints. However, the compiler is unaware of this fact and complains on -Wcast-align. This patch modifies the code to use RTE_PTR_SUB(), thereby silencing the compiler by casting through (void *). Acked-by: Olivier Matz Signed-off-by: Cyril Chemparathy --- lib/librte_mbuf/rte_mbuf.h | 8 +--- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index 6c9cfd6..6efd2b5 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -347,13 +347,7 @@ static inline uint16_t rte_pktmbuf_priv_size(struct rte_mempool *mp); static inline struct rte_mbuf * rte_mbuf_from_indirect(struct rte_mbuf *mi) { - struct rte_mbuf *md; - - /* mi->buf_addr and mi->priv_size correspond to buffer and -* private size of the direct mbuf */ - md = (struct rte_mbuf *)((char *)mi->buf_addr - sizeof(*mi) - - mi->priv_size); - return md; + return RTE_PTR_SUB(mi->buf_addr, sizeof(*mi) + mi->priv_size); } /** -- 2.1.2
[dpdk-dev] [PATCH v2 01/10] mempool: silence -Wcast-align on pointer arithmetic
Translating from a mempool object to the mempool pointer does not break alignment constraints. However, the compiler is unaware of this fact and complains on -Wcast-align. This patch modifies the code to use RTE_PTR_SUB(), thereby silencing the compiler by casting through (void *). Acked-by: Olivier Matz Signed-off-by: Cyril Chemparathy --- lib/librte_mempool/rte_mempool.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h index bc2bae0..8be040b 100644 --- a/lib/librte_mempool/rte_mempool.h +++ b/lib/librte_mempool/rte_mempool.h @@ -236,15 +236,13 @@ struct rte_mempool { */ static inline struct rte_mempool **__mempool_from_obj(void *obj) { - struct rte_mempool **mpp; unsigned off; off = sizeof(struct rte_mempool *); #ifdef RTE_LIBRTE_MEMPOOL_DEBUG off += sizeof(uint64_t); #endif - mpp = (struct rte_mempool **)((char *)obj - off); - return mpp; + return RTE_PTR_SUB(obj, off); } /** -- 2.1.2
[dpdk-dev] [PATCH v2 00/10] Improve cast alignment for strict aligned machines
This series contains a few improvements that allow the DPDK code base to build properly on machines that enforce strict pointer cast alignment constraints. When dealing with packet data which could be arbitrarily aligned, we get the compiler to do the right thing by (a) making sure that header types are packed, and (b) introducing and using unaligned_uint(16|32|64)_t types when upcasting from byte pointers. In a few other instances, we know apriori that the pointer cast cannot possibly break alignment. This applies to the changes in mempool, hash, mbuf, and the ethdev stats code. Here, we simply silence the compiler by casting through (void *) using the RTE_PTR_(ADD|SUB) macros. Finally, we introduce a new rte_pktmbuf_mtod_offset() helper to return a type casted pointer to an offset within the packet data. This replaces the following commonly used pattern: (struct foo *)(rte_pktmbuf_mtod(m, char *) + offset) with: rte_pktmbuf_mtod_offset(m, struct foo *, offset) To ensure consistency, the above transform was applied throughout the code base using the coccinelle semantic patching tool. Cyril Chemparathy (10): mempool: silence -Wcast-align on pointer arithmetic mbuf: silence -Wcast-align on pointer arithmetic ethdev: silence -Wcast-align on pointer arithmetic hash: silence -Wcast-align on pointer arithmetic eal: add and use unaligned integer types app/test-pmd: pack simple_gre_hdr app/test: use struct ether_addr instead of a byte array cast librte_mbuf: Add rte_pktmbuf_mtod_offset() librte_mbuf: Add transform for rte_pktmbuf_mtod_offset() librte_mbuf: Apply mtod-offset.cocci transform app/test-pmd/csumonly.c| 2 +- app/test-pmd/flowgen.c | 4 +- app/test-pmd/ieee1588fwd.c | 4 +- app/test-pmd/rxonly.c | 21 + app/test-pmd/txonly.c | 6 +-- app/test/packet_burst_generator.c | 9 ++-- app/test/test_mbuf.c | 16 +++ app/test/test_pmd_perf.c | 10 ++-- drivers/net/mlx4/mlx4.c| 9 ++-- examples/dpdk_qat/crypto.c | 8 ++-- examples/dpdk_qat/main.c | 5 +- examples/l3fwd-acl/main.c | 20 examples/l3fwd-power/main.c| 8 ++-- examples/l3fwd-vf/main.c | 4 +- examples/l3fwd/main.c | 71 examples/load_balancer/runtime.c | 4 +- examples/vhost_xen/main.c | 4 +- lib/librte_eal/common/include/rte_common.h | 10 lib/librte_ether/rte_ethdev.c | 24 +- lib/librte_ether/rte_ether.h | 2 +- lib/librte_hash/rte_hash.c | 10 ++-- lib/librte_ip_frag/rte_ipv4_reassembly.c | 7 ++- lib/librte_ip_frag/rte_ipv6_reassembly.c | 5 +- lib/librte_mbuf/rte_mbuf.h | 32 + lib/librte_mempool/rte_mempool.h | 4 +- lib/librte_port/rte_port_ras.c | 6 +-- lib/librte_vhost/vhost_rxtx.c | 6 +-- scripts/cocci.sh | 64 + scripts/cocci/mtod-offset.cocci| 76 ++ 29 files changed, 302 insertions(+), 149 deletions(-) create mode 100755 scripts/cocci.sh create mode 100644 scripts/cocci/mtod-offset.cocci -- 2.1.2
[dpdk-dev] [PATCH 08/10] librte_mbuf: Add rte_pktmbuf_mtod_offset()
On Fri, 19 Jun 2015 17:58:59 +0200 Olivier MATZ wrote: > Small comment here: m_headlen(m) should be replaced by "the length of > the first segment". Indeed, there is no m_headlen() function (I see > that it is coming from a copy/paste of the mtod() comment). Could you > also fix it by the way? Will do. Thanks.
[dpdk-dev] [PATCH 01/10] eal: add and use unaligned integer types
On Fri, 19 Jun 2015 17:58:57 +0200 Olivier MATZ wrote: > Hello Cyril, > > First, sorry commenting that late. My first intent was to benchmark > with your modifications, but I did not find the time for it. > > So, please find some comments on your series below so it can be pushed > for 2.1. > > On 04/29/2015 06:15 PM, Cyril Chemparathy wrote: > > On machines that are strict on pointer alignment, current code > > breaks on GCC's -Wcast-align checks on casts from narrower to wider > > types. This patch introduces new unaligned_uint(16|32|64)_t types, > > which correctly retain alignment in such cases. > > > > This is currently unimplemented on ICC and clang, and equivalents > > will need to be plugged in. > > > > Signed-off-by: Cyril Chemparathy > > --- > > app/test-pmd/flowgen.c | 4 ++-- > > app/test-pmd/txonly.c | 2 +- > > app/test/packet_burst_generator.c | 4 ++-- > > app/test/test_mbuf.c | 16 > > lib/librte_eal/common/include/rte_common.h | 10 ++ > > lib/librte_ether/rte_ether.h | 2 +- > > lib/librte_ip_frag/rte_ipv4_reassembly.c | 4 ++-- > > 7 files changed, 26 insertions(+), 16 deletions(-) > > > > [...] > > diff --git a/lib/librte_eal/common/include/rte_common.h > > b/lib/librte_eal/common/include/rte_common.h index c0ab8b4..3bb97d1 > > 100644 --- a/lib/librte_eal/common/include/rte_common.h > > +++ b/lib/librte_eal/common/include/rte_common.h > > @@ -61,6 +61,16 @@ extern "C" { > > > > /*** Macros to eliminate unused variable warnings / > > > > +#if defined(__GNUC__) > > +typedef uint64_t unaligned_uint64_t __attribute__ ((aligned(1))); > > +typedef uint32_t unaligned_uint32_t __attribute__ ((aligned(1))); > > +typedef uint16_t unaligned_uint16_t __attribute__ ((aligned(1))); > > +#else > > +typedef uint64_t unaligned_uint64_t; > > +typedef uint32_t unaligned_uint32_t; > > +typedef uint16_t unaligned_uint16_t; > > +#endif > > + > > Shouldn't we only define these unaligned types for architectures that > have strict alignment constraints ? I am a bit puzzled by only > defining it when compiling with gcc: is it because only gcc triggers > a warning? If yes, I'm not sure it's a good reason. > > Maybe we could have a compile-time option to enable these types, and > this option would be set for architectures that require it only. The > advantage would be to ensure there's no modification on x86. > > What do you think? > Fair enough. I like that better than keying off of GCC or anything like that. I will change this patch accordingly for the next revision. > cosmetic: the definitions should go above the comment line that refers > to the macro below. > > For the rest of the series (except a small comment on patch 8/10, > see the other mail): > Acked-by: Olivier Matz > >
[dpdk-dev] mempool with custom alignment
On Wed, 3 Jun 2015 11:30:17 -0700 Hi Dax, Dax Rawal wrote: > Hi, > I use mempool APIs to allocate DMA-able descriptor ring and buffers > so that I get both physical and virtual addresses of allocated > memory. I buffers I get from the mempool APIs are 64 byte aligned. My > requirement is 256byte alignment. How to achieve this? mempool APIs > do not seem to take alignment parameters. > I have a patch that allows configuration override of mempool element alignment to allow for larger alignment limits (e.g. 128B on the TILE-Gx platform, 256B on yours). Would that suffice? If so, I'd be happy to post this patch on the mailing list. Thanks -- Cyril.
[dpdk-dev] [PATCH v2 12/12] mk: introduce Tilera Tile architecture
On Fri, 22 May 2015 18:03:04 +0200 Thomas Monjalon wrote: > Hi, > > 2015-01-06 14:53, Zhigang Lu: > > Add defconfig and rte.vars.mk files for Tile architecture. > > > > Signed-off-by: Zhigang Lu > > Signed-off-by: Cyril Chemparathy > > This series is pending without having any comments. > So it should be accepted and merged. > I'm working on a refresh to the latest master. In the process, I've simplified most of the patches down to bare essentials. Since the TILE-Gx platform is a strict alignment machine, we need alignment related fixes that have been submitted previously (see http://www.dpdk.org/ml/archives/dev/2015-April/017090.html). These are based on relatively recent contents of master, and therefore should be ready to merge once we go through the review cycle. Would you mind taking a look at these? > Do you accept to be the maintainer of Tile architecture? > If you agree, please respin this series with a cover letter (it was > missing in this v2) and update the MAINTAINERS file. > Sure. We'll internally figure out the appropriate maintainer and include this in the next round of patches. Thanks -- Cyril.
[dpdk-dev] [PATCH 00/10] Improve cast alignment for strict aligned machines
On Mon, 4 May 2015 11:50:09 +0200 Olivier MATZ wrote: > Hi Cyril, > > On 04/29/2015 06:15 PM, Cyril Chemparathy wrote: > > This series contains a few improvements that allow the DPDK code > > base to build properly on machines that enforce strict pointer cast > > alignment constraints. > > > > When dealing with packet data which could be arbitrarily aligned, > > we get the compiler to do the right thing by (a) making sure that > > header types are packed, and (b) introducing and using > > unaligned_uint(16|32|64)_t types when upcasting from byte pointers. > > > > In a few other instances, we know apriori that the pointer cast > > cannot possibly break alignment. This applies to the changes in > > mempool, hash, mbuf, and the ethdev stats code. Here, we simply > > silence the compiler by casting through (void *) using the > > RTE_PTR_(ADD|SUB) macros. > > > > Finally, we introduce a new rte_pktmbuf_mtod_offset() helper to > > return a type casted pointer to an offset within the packet data. > > This replaces the following commonly used pattern: > > (struct foo *)(rte_pktmbuf_mtod(m, char *) + offset) > > with: > > rte_pktmbuf_mtod_offset(m, struct foo *, offset) > > To ensure consistency, the above transform was applied throughout > > the code base using the coccinelle semantic patching tool. > > > > Before diving into the patches, I'm wondering if adding aligned(1) or > (packed) attribute at some places would have a performance impact on > supported architectures (Intel or IBM Power). Did you manage to test > it? > I don't expect to see a performance impact on x86. I don't really have a way of trying this out on PPC, and I could use some help here. Overall, I think that the few places where we've injected aligned(1) or packed really warrant the insertion for correctness. These are places where packet data of unknown alignment is being typecast and dereferenced. In such cases, _not_ representing the unaligned nature of these accesses breaks machines with strict alignment. Thanks -- Cyril.
[dpdk-dev] [PATCH 09/10] librte_mbuf: Add transform for rte_pktmbuf_mtod_offset()
This patch adds a coccinelle (see http://coccinelle.lip6.fr/) transform to use the newly added rte_pktmbuf_mtod_offset() helper. In addition, we add a simple script to apply all available transforms to a codebase. Signed-off-by: Cyril Chemparathy --- scripts/cocci.sh| 64 ++ scripts/cocci/mtod-offset.cocci | 76 + 2 files changed, 140 insertions(+) create mode 100755 scripts/cocci.sh create mode 100644 scripts/cocci/mtod-offset.cocci diff --git a/scripts/cocci.sh b/scripts/cocci.sh new file mode 100755 index 000..3a70223 --- /dev/null +++ b/scripts/cocci.sh @@ -0,0 +1,64 @@ +#! /bin/sh + +# BSD LICENSE +# +# Copyright 2015 EZchip Semiconductor. +# +# 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 copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of EZchip Semiconductor 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 FOR +# 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 ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# Apply coccinelle transforms. + +SRCTREE=$(readlink -f $(dirname $0)/..) +COCCI=$SRCTREE/scripts/cocci +[ -n "$SPATCH" ] || SPATCH=$(which spatch) + +PATCH_LIST="$@" +[ -n "$PATCH_LIST" ] || PATCH_LIST=$(echo $COCCI/*.cocci) + +[ -x "$SPATCH" ] || ( + echo "Coccinelle tools not installed." + exit 1 +) + +tmp=$(mktemp) + +for c in $PATCH_LIST; do + while true; do + echo -n "Applying $c..." + $SPATCH --sp-file $c -c --linux-spacing --very-quiet\ + --include-headers --preprocess \ + --in-place --dir $SRCTREE > $tmp + if [ -s $tmp ]; then + echo " changes applied, retrying." + else + echo " no change." + break; + fi + done +done + +rm -f $tmp diff --git a/scripts/cocci/mtod-offset.cocci b/scripts/cocci/mtod-offset.cocci new file mode 100644 index 000..13134e9 --- /dev/null +++ b/scripts/cocci/mtod-offset.cocci @@ -0,0 +1,76 @@ +// +// Replace explicit packet offset computations with rte_pktmbuf_mtod_offset(). +// + at disable paren@ +typedef uint8_t; +expression M, O; +@@ +( +- rte_pktmbuf_mtod(M, char *) + O ++ rte_pktmbuf_mtod_offset(M, char *, O) +| +- rte_pktmbuf_mtod(M, char *) - O ++ rte_pktmbuf_mtod_offset(M, char *, -O) +| +- rte_pktmbuf_mtod(M, unsigned char *) + O ++ rte_pktmbuf_mtod_offset(M, unsigned char *, O) +| +- rte_pktmbuf_mtod(M, unsigned char *) - O ++ rte_pktmbuf_mtod_offset(M, unsigned char *, -O) +| +- rte_pktmbuf_mtod(M, uint8_t *) + O ++ rte_pktmbuf_mtod_offset(M, uint8_t *, O) +| +- rte_pktmbuf_mtod(M, uint8_t *) - O ++ rte_pktmbuf_mtod_offset(M, uint8_t *, -O) +) + + +// +// Fold subsequent offset terms into pre-existing offset used in +// rte_pktmbuf_mtod_offset(). +// + at disable paren@ +expression M, O1, O2; +@@ +( +- rte_pktmbuf_mtod_offset(M, char *, O1) + O2 ++ rte_pktmbuf_mtod_offset(M, char *, O1 + O2) +| +- rte_pktmbuf_mtod_offset(M, char *, O1) - O2 ++ rte_pktmbuf_mtod_offset(M, char *, O1 - O2) +| +- rte_pktmbuf_mtod_offset(M, unsigned char *, O1) + O2 ++ rte_pktmbuf_mtod_offset(M, unsigned char *, O1 + O2) +| +- rte_pktmbuf_mtod_offset(M, unsigned char *, O1) - O2 ++ rte_pktmbuf_mtod_offset(M, unsigned char *, O1 - O2) +| +- rte_pktmbuf_mtod_offset(M, uint8_t *, O1) + O2 ++ rte_pktmbuf_mtod_offset(M, uint8_t *, O1 + O2) +| +- rte_pktmbuf_mtod_offset(M, uint8_t *, O1) - O2 ++ rte_pktmbuf_mtod_offset(M, uint8_t *, O1 - O2) +) + + +// +// Cleanup rules. Fold in double casts, remove unnecessary paranthesis, etc. +// +
[dpdk-dev] [PATCH 08/10] librte_mbuf: Add rte_pktmbuf_mtod_offset()
There are a number of instances in the code where rte_pktmbuf_mtod() is used to get the mbuf data pointer, only to add an offset before casting the result to some other header type. This patch adds a new rte_pktmbuf_mtod_offset() macro to eliminate these awful double cast situations. Signed-off-by: Cyril Chemparathy --- lib/librte_mbuf/rte_mbuf.h | 20 +++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index 5ddd8dd..e8f1bf4 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -54,6 +54,7 @@ */ #include +#include #include #include #include @@ -1071,6 +1072,23 @@ static inline struct rte_mbuf *rte_pktmbuf_lastseg(struct rte_mbuf *m) } /** + * A macro that points to an offset into the data in the mbuf. + * + * The returned pointer is cast to type t. Before using this + * function, the user must ensure that m_headlen(m) is large enough to + * read its data. + * + * @param m + * The packet mbuf. + * @param o + * The offset into the mbuf data. + * @param t + * The type to cast the result into. + */ +#define rte_pktmbuf_mtod_offset(m, t, o) \ + ((t)((char *)(m)->buf_addr + (m)->data_off + (o))) + +/** * A macro that points to the start of the data in the mbuf. * * The returned pointer is cast to type t. Before using this @@ -1082,7 +1100,7 @@ static inline struct rte_mbuf *rte_pktmbuf_lastseg(struct rte_mbuf *m) * @param t * The type to cast the result into. */ -#define rte_pktmbuf_mtod(m, t) ((t)((char *)(m)->buf_addr + (m)->data_off)) +#define rte_pktmbuf_mtod(m, t) rte_pktmbuf_mtod_offset(m, t, 0) /** * A macro that returns the length of the packet. -- 2.1.2
[dpdk-dev] [PATCH 07/10] app/test: use struct ether_addr instead of a byte array cast
This patch instantiates struct ether_addr instead of type casting a uint8_t pointer to the same structure. The type cast breaks on machines that enforce strict alignment. Signed-off-by: Cyril Chemparathy --- app/test/test_pmd_perf.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/test/test_pmd_perf.c b/app/test/test_pmd_perf.c index 49a494d..5810e7f 100644 --- a/app/test/test_pmd_perf.c +++ b/app/test/test_pmd_perf.c @@ -229,13 +229,13 @@ init_traffic(struct rte_mempool *mp, struct ipv4_hdr pkt_ipv4_hdr; struct udp_hdr pkt_udp_hdr; uint32_t pktlen; - static uint8_t src_mac[] = { 0x00, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF }; - static uint8_t dst_mac[] = { 0x00, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA }; - + static struct ether_addr src_mac = + { { 0x00, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF } }; + static struct ether_addr dst_mac = + { { 0x00, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA } }; initialize_eth_header(_eth_hdr, - (struct ether_addr *)src_mac, - (struct ether_addr *)dst_mac, ETHER_TYPE_IPv4, 0, 0); + _mac, _mac, ETHER_TYPE_IPv4, 0, 0); pktlen = initialize_ipv4_header(_ipv4_hdr, IPV4_ADDR(10, 0, 0, 1), -- 2.1.2
[dpdk-dev] [PATCH 06/10] app/test-pmd: pack simple_gre_hdr
Not packing this causes -Wcast-align breakage on machines that are strict on alignment. This patch fixes this bug. Signed-off-by: Cyril Chemparathy --- app/test-pmd/csumonly.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c index c180ff2..eadfd2b 100644 --- a/app/test-pmd/csumonly.c +++ b/app/test-pmd/csumonly.c @@ -108,7 +108,7 @@ struct testpmd_offload_info { struct simple_gre_hdr { uint16_t flags; uint16_t proto; -}; +} __attribute((packed)); static uint16_t get_psd_sum(void *l3_hdr, uint16_t ethertype, uint64_t ol_flags) -- 2.1.2
[dpdk-dev] [PATCH 03/10] hash: silence -Wcast-align on pointer arithmetic
Since sig_tbl_bucket_size and key_tbl_key_size are explicitly aligned at initialization, offset dereferences in the hash table code cannot possibly be unaligned. However, the compiler is unaware of this fact and complains on -Wcast-align. This patch modifies the code to use RTE_PTR_ADD(), thereby silencing the compiler by casting through (void *). Signed-off-by: Cyril Chemparathy --- lib/librte_hash/rte_hash.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/librte_hash/rte_hash.c b/lib/librte_hash/rte_hash.c index 9245716..67dff5b 100644 --- a/lib/librte_hash/rte_hash.c +++ b/lib/librte_hash/rte_hash.c @@ -96,23 +96,23 @@ EAL_REGISTER_TAILQ(rte_hash_tailq) static inline hash_sig_t * get_sig_tbl_bucket(const struct rte_hash *h, uint32_t bucket_index) { - return (hash_sig_t *) - &(h->sig_tbl[bucket_index * h->sig_tbl_bucket_size]); + return RTE_PTR_ADD(h->sig_tbl, (bucket_index * + h->sig_tbl_bucket_size)); } /* Returns a pointer to the first key in specified bucket. */ static inline uint8_t * get_key_tbl_bucket(const struct rte_hash *h, uint32_t bucket_index) { - return (uint8_t *) &(h->key_tbl[bucket_index * h->bucket_entries * -h->key_tbl_key_size]); + return RTE_PTR_ADD(h->key_tbl, (bucket_index * h->bucket_entries * + h->key_tbl_key_size)); } /* Returns a pointer to a key at a specific position in a specified bucket. */ static inline void * get_key_from_bucket(const struct rte_hash *h, uint8_t *bkt, uint32_t pos) { - return (void *) [pos * h->key_tbl_key_size]; + return RTE_PTR_ADD(bkt, pos * h->key_tbl_key_size); } /* Does integer division with rounding-up of result. */ -- 2.1.2
[dpdk-dev] [PATCH 02/10] mempool: silence -Wcast-align on pointer arithmetic
Translating from a mempool object to the mempool pointer does not break alignment constraints. However, the compiler is unaware of this fact and complains on -Wcast-align. This patch modifies the code to use RTE_PTR_SUB(), thereby silencing the compiler by casting through (void *). Signed-off-by: Cyril Chemparathy --- lib/librte_mempool/rte_mempool.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h index 9001312..1fb4184 100644 --- a/lib/librte_mempool/rte_mempool.h +++ b/lib/librte_mempool/rte_mempool.h @@ -236,15 +236,13 @@ struct rte_mempool { */ static inline struct rte_mempool **__mempool_from_obj(void *obj) { - struct rte_mempool **mpp; unsigned off; off = sizeof(struct rte_mempool *); #ifdef RTE_LIBRTE_MEMPOOL_DEBUG off += sizeof(uint64_t); #endif - mpp = (struct rte_mempool **)((char *)obj - off); - return mpp; + return RTE_PTR_SUB(obj, off); } /** -- 2.1.2
[dpdk-dev] [PATCH 01/10] eal: add and use unaligned integer types
On machines that are strict on pointer alignment, current code breaks on GCC's -Wcast-align checks on casts from narrower to wider types. This patch introduces new unaligned_uint(16|32|64)_t types, which correctly retain alignment in such cases. This is currently unimplemented on ICC and clang, and equivalents will need to be plugged in. Signed-off-by: Cyril Chemparathy --- app/test-pmd/flowgen.c | 4 ++-- app/test-pmd/txonly.c | 2 +- app/test/packet_burst_generator.c | 4 ++-- app/test/test_mbuf.c | 16 lib/librte_eal/common/include/rte_common.h | 10 ++ lib/librte_ether/rte_ether.h | 2 +- lib/librte_ip_frag/rte_ipv4_reassembly.c | 4 ++-- 7 files changed, 26 insertions(+), 16 deletions(-) diff --git a/app/test-pmd/flowgen.c b/app/test-pmd/flowgen.c index 72016c9..174c003 100644 --- a/app/test-pmd/flowgen.c +++ b/app/test-pmd/flowgen.c @@ -101,7 +101,7 @@ tx_mbuf_alloc(struct rte_mempool *mp) static inline uint16_t -ip_sum(const uint16_t *hdr, int hdr_len) +ip_sum(const unaligned_uint16_t *hdr, int hdr_len) { uint32_t sum = 0; @@ -193,7 +193,7 @@ pkt_burst_flow_gen(struct fwd_stream *fs) next_flow); ip_hdr->total_length= RTE_CPU_TO_BE_16(pkt_size - sizeof(*eth_hdr)); - ip_hdr->hdr_checksum= ip_sum((uint16_t *)ip_hdr, + ip_hdr->hdr_checksum= ip_sum((unaligned_uint16_t *)ip_hdr, sizeof(*ip_hdr)); /* Initialize UDP header. */ diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c index ca32c85..9e66552 100644 --- a/app/test-pmd/txonly.c +++ b/app/test-pmd/txonly.c @@ -167,7 +167,7 @@ setup_pkt_udp_ip_headers(struct ipv4_hdr *ip_hdr, /* * Compute IP header checksum. */ - ptr16 = (uint16_t*) ip_hdr; + ptr16 = (unaligned_uint16_t*) ip_hdr; ip_cksum = 0; ip_cksum += ptr16[0]; ip_cksum += ptr16[1]; ip_cksum += ptr16[2]; ip_cksum += ptr16[3]; diff --git a/app/test/packet_burst_generator.c b/app/test/packet_burst_generator.c index b46eed7..06762c6 100644 --- a/app/test/packet_burst_generator.c +++ b/app/test/packet_burst_generator.c @@ -154,7 +154,7 @@ initialize_ipv4_header(struct ipv4_hdr *ip_hdr, uint32_t src_addr, uint32_t dst_addr, uint16_t pkt_data_len) { uint16_t pkt_len; - uint16_t *ptr16; + unaligned_uint16_t *ptr16; uint32_t ip_cksum; /* @@ -175,7 +175,7 @@ initialize_ipv4_header(struct ipv4_hdr *ip_hdr, uint32_t src_addr, /* * Compute IP header checksum. */ - ptr16 = (uint16_t *)ip_hdr; + ptr16 = (unaligned_uint16_t *)ip_hdr; ip_cksum = 0; ip_cksum += ptr16[0]; ip_cksum += ptr16[1]; ip_cksum += ptr16[2]; ip_cksum += ptr16[3]; diff --git a/app/test/test_mbuf.c b/app/test/test_mbuf.c index 5e8a377..d9beb29 100644 --- a/app/test/test_mbuf.c +++ b/app/test/test_mbuf.c @@ -333,7 +333,7 @@ testclone_testupdate_testdetach(void) struct rte_mbuf *m = NULL; struct rte_mbuf *clone = NULL; struct rte_mbuf *clone2 = NULL; - uint32_t *data; + unaligned_uint32_t *data; /* alloc a mbuf */ m = rte_pktmbuf_alloc(pktmbuf_pool); @@ -344,7 +344,7 @@ testclone_testupdate_testdetach(void) GOTO_FAIL("Bad length"); rte_pktmbuf_append(m, sizeof(uint32_t)); - data = rte_pktmbuf_mtod(m, uint32_t *); + data = rte_pktmbuf_mtod(m, unaligned_uint32_t *); *data = MAGIC_DATA; /* clone the allocated mbuf */ @@ -352,7 +352,7 @@ testclone_testupdate_testdetach(void) if (clone == NULL) GOTO_FAIL("cannot clone data\n"); - data = rte_pktmbuf_mtod(clone, uint32_t *); + data = rte_pktmbuf_mtod(clone, unaligned_uint32_t *); if (*data != MAGIC_DATA) GOTO_FAIL("invalid data in clone\n"); @@ -369,18 +369,18 @@ testclone_testupdate_testdetach(void) GOTO_FAIL("Next Pkt Null\n"); rte_pktmbuf_append(m->next, sizeof(uint32_t)); - data = rte_pktmbuf_mtod(m->next, uint32_t *); + data = rte_pktmbuf_mtod(m->next, unaligned_uint32_t *); *data = MAGIC_DATA; clone = rte_pktmbuf_clone(m, pktmbuf_pool); if (clone == NULL) GOTO_FAIL("cannot clone data\n"); - data = rte_pktmbuf_mtod(clone, uint32_t *); + data = rte_pktmbuf_mtod(clone, unaligned_uint32_t *); if (*data != MAGIC_DATA) GOTO_FAIL("invalid data in clone\n"); - data = rte_pktmbuf_mtod(clone->next, uint32_t *); + data = rte_pktmbuf_mtod(clone->next, unaligned_uint32_t *);
[dpdk-dev] [PATCH 00/10] Improve cast alignment for strict aligned machines
This series contains a few improvements that allow the DPDK code base to build properly on machines that enforce strict pointer cast alignment constraints. When dealing with packet data which could be arbitrarily aligned, we get the compiler to do the right thing by (a) making sure that header types are packed, and (b) introducing and using unaligned_uint(16|32|64)_t types when upcasting from byte pointers. In a few other instances, we know apriori that the pointer cast cannot possibly break alignment. This applies to the changes in mempool, hash, mbuf, and the ethdev stats code. Here, we simply silence the compiler by casting through (void *) using the RTE_PTR_(ADD|SUB) macros. Finally, we introduce a new rte_pktmbuf_mtod_offset() helper to return a type casted pointer to an offset within the packet data. This replaces the following commonly used pattern: (struct foo *)(rte_pktmbuf_mtod(m, char *) + offset) with: rte_pktmbuf_mtod_offset(m, struct foo *, offset) To ensure consistency, the above transform was applied throughout the code base using the coccinelle semantic patching tool. Cyril Chemparathy (10): eal: add and use unaligned integer types mempool: silence -Wcast-align on pointer arithmetic hash: silence -Wcast-align on pointer arithmetic mbuf: silence -Wcast-align on pointer arithmetic ethdev: silence -Wcast-align on pointer arithmetic app/test-pmd: pack simple_gre_hdr app/test: use struct ether_addr instead of a byte array cast librte_mbuf: Add rte_pktmbuf_mtod_offset() librte_mbuf: Add transform for rte_pktmbuf_mtod_offset() librte_mbuf: Apply mtod-offset.cocci transform app/test-pmd/csumonly.c| 2 +- app/test-pmd/flowgen.c | 4 +- app/test-pmd/ieee1588fwd.c | 4 +- app/test-pmd/rxonly.c | 21 + app/test-pmd/txonly.c | 6 +-- app/test/packet_burst_generator.c | 9 ++-- app/test/test_mbuf.c | 16 +++ app/test/test_pmd_perf.c | 10 ++-- examples/dpdk_qat/crypto.c | 8 ++-- examples/dpdk_qat/main.c | 5 +- examples/l3fwd-acl/main.c | 20 examples/l3fwd-power/main.c| 8 ++-- examples/l3fwd-vf/main.c | 4 +- examples/l3fwd/main.c | 71 examples/load_balancer/runtime.c | 4 +- examples/vhost_xen/main.c | 4 +- lib/librte_eal/common/include/rte_common.h | 10 lib/librte_ether/rte_ethdev.c | 24 +- lib/librte_ether/rte_ether.h | 2 +- lib/librte_hash/rte_hash.c | 10 ++-- lib/librte_ip_frag/rte_ipv4_reassembly.c | 7 ++- lib/librte_ip_frag/rte_ipv6_reassembly.c | 5 +- lib/librte_mbuf/rte_mbuf.h | 28 +++ lib/librte_mempool/rte_mempool.h | 4 +- lib/librte_pmd_mlx4/mlx4.c | 9 ++-- lib/librte_port/rte_port_ras.c | 3 +- lib/librte_vhost/vhost_rxtx.c | 4 +- scripts/cocci.sh | 64 + scripts/cocci/mtod-offset.cocci| 76 ++ 29 files changed, 298 insertions(+), 144 deletions(-) create mode 100755 scripts/cocci.sh create mode 100644 scripts/cocci/mtod-offset.cocci -- 2.1.2
[dpdk-dev] [PATCH 11/15] eal/tile: add EAL support for global mPIPE initialization
Hi Neil, On 12/8/2014 12:03 PM, Neil Horman wrote: > On Mon, Dec 08, 2014 at 04:59:34PM +0800, Zhigang Lu wrote: >> The TileGx mPIPE hardware provides Ethernet connectivity, >> packet classification, and packet load balancing services. >> >> Signed-off-by: Zhigang Lu >> Signed-off-by: Cyril Chemparathy >> --- >> .../common/include/arch/tile/rte_mpipe.h | 67 ++ >> lib/librte_eal/linuxapp/eal/Makefile | 3 + >> lib/librte_eal/linuxapp/eal/eal.c | 9 ++ >> lib/librte_eal/linuxapp/eal/eal_mpipe_tile.c | 147 >> + >> mk/rte.app.mk | 4 + >> 5 files changed, 230 insertions(+) >> create mode 100644 lib/librte_eal/common/include/arch/tile/rte_mpipe.h >> create mode 100644 lib/librte_eal/linuxapp/eal/eal_mpipe_tile.c >> > This seems like the wrong way to implement mpip access. If you want to use it > for networking access, you should create a pmd to talk to it. If you just > want > raw gxio access, you already have a gxio library that applications can > interface > to. Theres no need to create addtional DPDK api services just to wrap it up, > especially given that those surfaces won't exist outside of the tile arch > (i.e. > this allows for the creation of very non-portable applications). Thanks for the taking a look. The mPIPE hardware block includes hardware managed buffer pools, which we've abstracted under the mempool interface in the very next patch in the series. As a result of this mempool dependency, mPIPE needs to be globally initialized on TileGX architecture. The alternative is to not include support for the hardware managed buffer pool, but that decision incurs a significant performance hit. Thanks -- Cyril.
[dpdk-dev] [PATCH 02/15] eal/tile: add atomic operations for TileGx
On 12/8/2014 6:28 AM, Neil Horman wrote: > On Mon, Dec 08, 2014 at 04:59:25PM +0800, Zhigang Lu wrote: >> This patch adds architecture specific memory barrier operations for >> TileGx. >> >> Signed-off-by: Zhigang Lu >> Signed-off-by: Cyril Chemparathy >> --- [...] >> +__sync_synchronize(); > I don't see __sync_synchronize defined anywhere. Is that an intrinsic for > gcc, > or a library call? That is a GCC primitive. -- Cyril.
[dpdk-dev] [PATCH 09/12] Remove iopl operation for IBM Power architecture
On 9/26/2014 2:36 AM, Chao Zhu wrote: > iopl() call is mostly for the i386 architecture. In Power architecture. > It doesn't exist. This patch modified rte_eal_iopl_init() and make it > return -1 on Power. This means rte_config.flags will not contain > EAL_FLG_HIGH_IOPL flag on IBM Power architecture. Since iopl() is an x86-only thing, shouldn't the code be conditional on defined(RTE_ARCH_X86_64) || defined(RTE_ARCH_I686) instead of below? Better still, should we maybe break out an architecture specific init function? This function could set iopl on x86, and possibly do other lowlevel init things on other architectures... > Signed-off-by: Chao Zhu > --- > lib/librte_eal/linuxapp/eal/eal.c | 11 +++ > 1 files changed, 11 insertions(+), 0 deletions(-) > > diff --git a/lib/librte_eal/linuxapp/eal/eal.c > b/lib/librte_eal/linuxapp/eal/eal.c > index 4869e7c..8cc1f21 100644 > --- a/lib/librte_eal/linuxapp/eal/eal.c > +++ b/lib/librte_eal/linuxapp/eal/eal.c > @@ -50,7 +50,10 @@ > #include > #include > #include > +/* Power architecture doesn't have this header file */ > +#ifndef RTE_ARCH_PPC_64 > #include > +#endif > > #include > #include > @@ -1019,11 +1022,19 @@ rte_eal_mcfg_complete(void) > > /* >* Request iopl privilege for all RPL, returns 0 on success > + * > + * Power architecture doesn't have iopl function, so this function > + * return -1 on Power architecture, because this function is only used > + * in rte_eal_init to add EAL_FLG_HIGH_IOPL to rte_config.flags. >*/ > static int > rte_eal_iopl_init(void) > { > +#ifndef RTE_ARCH_PPC_64 > return iopl(HIGHEST_RPL); > +#else > + return -1; > +#endif > } > > /* Launch threads, called at application init(). */
[dpdk-dev] [PATCH 0/6] Extensions to test-pmd
On 5/16/2014 7:22 AM, Thomas Monjalon wrote: > Hi Cyril, > > 2014-04-03 10:30, Cyril Chemparathy: >> This patch series contains a few minor extensions to test-pmd. These >> changes have been added primarily for convenience while testing out various >> scenarios with DPDK. >> >> Cyril Chemparathy (6): >>test-pmd: add support for single port loopback topology >>test-pmd: add support for auto-start when interactive >>test-pmd: allow command line selection of forwarding mode >>test-pmd: allow txpkts to be setup via command line >>test-pmd: add mac swap forwarding mode >>test-pmd: add flowgen forwarding engine > Thanks for these new features. > > This is not the first time a new engine is added by copy/pasting the most part > of an existing engine. For instance, the "mac-retry" engine was added by Intel > as a copy/paste of the original "mac" one. > This is acceptable but not the perfect way to implement engines. > To address this issue, a new engine function could be introduced to setup some > parameters to be used by "packet_fwd" function. This way, similar engines > could be removed. Agreed that it sucks to incessantly replicate code. Maybe some of the packet_fwd code is common enough to bump into run_pkt_fwd_on_lcore()? Most of these forwarding modes have similar looking code to receive/transmit bursts and free the failed remnants of the burst. Could this common code be bumped up into run_pkt_fwd_on_lcore() maybe? > Acked-by: Thomas Monjalon > > Applied for version 1.7.0. Thanks! Much appreciated. -- Cyril.
[dpdk-dev] [PATCH] mk: add support for gdb debug info generation
It is often useful to build with debug enabled, we add a config (CONFIG_RTE_TOOLCHAIN_DEBUG) to do so. Note: This patch does not include corresponding changes for ICC. The author pleads abject ignorance in this regard, and welcomes recommendations. :-) Signed-off-by: Cyril Chemparathy --- config/defconfig_x86_64-default-linuxapp-gcc | 1 + mk/toolchain/gcc/rte.vars.mk | 5 + 2 files changed, 6 insertions(+) diff --git a/config/defconfig_x86_64-default-linuxapp-gcc b/config/defconfig_x86_64-default-linuxapp-gcc index f11ffbf..3b36efd 100644 --- a/config/defconfig_x86_64-default-linuxapp-gcc +++ b/config/defconfig_x86_64-default-linuxapp-gcc @@ -67,6 +67,7 @@ CONFIG_RTE_ARCH_X86_64=y # CONFIG_RTE_TOOLCHAIN="gcc" CONFIG_RTE_TOOLCHAIN_GCC=y +CONFIG_RTE_TOOLCHAIN_DEBUG=n # # Use intrinsics or assembly code for key routines diff --git a/mk/toolchain/gcc/rte.vars.mk b/mk/toolchain/gcc/rte.vars.mk index 0edb93f..81ed3fa 100644 --- a/mk/toolchain/gcc/rte.vars.mk +++ b/mk/toolchain/gcc/rte.vars.mk @@ -68,6 +68,11 @@ ifeq (,$(findstring -O0,$(EXTRA_CFLAGS))) endif endif +ifeq ($(CONFIG_RTE_TOOLCHAIN_DEBUG),y) +TOOLCHAIN_CFLAGS += -g -ggdb +TOOLCHAIN_LDFLAGS += -g -ggdb +endif + WERROR_FLAGS := -W -Wall -Werror -Wstrict-prototypes -Wmissing-prototypes WERROR_FLAGS += -Wmissing-declarations -Wold-style-definition -Wpointer-arith WERROR_FLAGS += -Wcast-align -Wnested-externs -Wcast-qual -- 1.8.3.1
[dpdk-dev] [PATCH 6/6] test-pmd: add flowgen forwarding engine
This commit adds a multi-flow traffic generator forwarding engine. In effect, this forwarding mode functions very similar to the txonly mode, with the difference that it generates multiple L4 flows. Signed-off-by: Cyril Chemparathy --- app/test-pmd/Makefile | 1 + app/test-pmd/flowgen.c | 247 + app/test-pmd/testpmd.c | 1 + app/test-pmd/testpmd.h | 1 + 4 files changed, 250 insertions(+) create mode 100644 app/test-pmd/flowgen.c diff --git a/app/test-pmd/Makefile b/app/test-pmd/Makefile index f0d0262..6ed2634 100644 --- a/app/test-pmd/Makefile +++ b/app/test-pmd/Makefile @@ -52,6 +52,7 @@ SRCS-$(CONFIG_RTE_TEST_PMD) += iofwd.c SRCS-$(CONFIG_RTE_TEST_PMD) += macfwd.c SRCS-$(CONFIG_RTE_TEST_PMD) += macfwd-retry.c SRCS-$(CONFIG_RTE_TEST_PMD) += macswap.c +SRCS-$(CONFIG_RTE_TEST_PMD) += flowgen.c SRCS-$(CONFIG_RTE_TEST_PMD) += rxonly.c SRCS-$(CONFIG_RTE_TEST_PMD) += txonly.c SRCS-$(CONFIG_RTE_TEST_PMD) += csumonly.c diff --git a/app/test-pmd/flowgen.c b/app/test-pmd/flowgen.c new file mode 100644 index 000..04911ff --- /dev/null +++ b/app/test-pmd/flowgen.c @@ -0,0 +1,247 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2010-2013 Tilera 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 copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Tilera 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 FOR + * 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 ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "testpmd.h" + +/* hardcoded configuration (for now) */ +static unsigned cfg_n_flows= 1024; +static unsigned cfg_pkt_size = 300; +static uint32_t cfg_ip_src = IPv4(10, 254, 0, 0); +static uint32_t cfg_ip_dst = IPv4(10, 253, 0, 0); +static uint16_t cfg_udp_src= 1000; +static uint16_t cfg_udp_dst= 1001; +static struct ether_addr cfg_ether_src = + {{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x00 }}; +static struct ether_addr cfg_ether_dst = + {{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x01 }}; + +#define IP_DEFTTL 64 /* from RFC 1340. */ +#define IP_VERSION 0x40 +#define IP_HDRLEN 0x05 /* default IP header length == five 32-bits words. */ +#define IP_VHL_DEF (IP_VERSION | IP_HDRLEN) + +static inline struct rte_mbuf * +tx_mbuf_alloc(struct rte_mempool *mp) +{ + struct rte_mbuf *m; + + m = __rte_mbuf_raw_alloc(mp); + __rte_mbuf_sanity_check_raw(m, RTE_MBUF_PKT, 0); + return (m); +} + + +static inline uint16_t +ip_sum(const uint16_t *hdr, int hdr_len) +{ + uint32_t sum = 0; + + while (hdr_len > 1) + { + sum += *hdr++; + if (sum & 0x8000) + sum = (sum & 0x) + (sum >> 16); + hdr_len -= 2; + } + + while (sum >> 16) + sum = (sum & 0x) + (sum >> 16); + + return ~sum; +} + +/* + * Multi-flow generation mode. + * + * We originate a bunch of flows (varying destination IP addresses), and + * terminate receive traffic. Received traffic is simply discarded, but we + * still do so in order to maintain traffic statistics. + */ +static void +pkt_burst_flow_ge
[dpdk-dev] [PATCH 5/6] test-pmd: add mac swap forwarding mode
This commit adds a new forwarding mode, in which the source and destination MAC addresses of packets are swapped before forwarding according to the port-topology in effect. This has been designed for operation primarily with --port-topology=loopback. Signed-off-by: Cyril Chemparathy --- app/test-pmd/Makefile | 1 + app/test-pmd/macswap.c | 148 + app/test-pmd/testpmd.c | 1 + app/test-pmd/testpmd.h | 1 + 4 files changed, 151 insertions(+) create mode 100644 app/test-pmd/macswap.c diff --git a/app/test-pmd/Makefile b/app/test-pmd/Makefile index f0d4b4d..f0d0262 100644 --- a/app/test-pmd/Makefile +++ b/app/test-pmd/Makefile @@ -51,6 +51,7 @@ SRCS-$(CONFIG_RTE_TEST_PMD) += config.c SRCS-$(CONFIG_RTE_TEST_PMD) += iofwd.c SRCS-$(CONFIG_RTE_TEST_PMD) += macfwd.c SRCS-$(CONFIG_RTE_TEST_PMD) += macfwd-retry.c +SRCS-$(CONFIG_RTE_TEST_PMD) += macswap.c SRCS-$(CONFIG_RTE_TEST_PMD) += rxonly.c SRCS-$(CONFIG_RTE_TEST_PMD) += txonly.c SRCS-$(CONFIG_RTE_TEST_PMD) += csumonly.c diff --git a/app/test-pmd/macswap.c b/app/test-pmd/macswap.c new file mode 100644 index 000..4ed6096 --- /dev/null +++ b/app/test-pmd/macswap.c @@ -0,0 +1,148 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2014 Tilera Corporation. 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 copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Tilera 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 FOR + * 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 ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "testpmd.h" + +/* + * MAC swap forwarding mode: Swap the source and the destination Ethernet + * addresses of packets before forwarding them. + */ +static void +pkt_burst_mac_swap(struct fwd_stream *fs) +{ + struct rte_mbuf *pkts_burst[MAX_PKT_BURST]; + struct rte_port *txp; + struct rte_mbuf *mb; + struct ether_hdr *eth_hdr; + struct ether_addr addr; + uint16_t nb_rx; + uint16_t nb_tx; + uint16_t i; +#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES + uint64_t start_tsc; + uint64_t end_tsc; + uint64_t core_cycles; +#endif + +#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES + start_tsc = rte_rdtsc(); +#endif + + /* +* Receive a burst of packets and forward them. +*/ + nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst, +nb_pkt_per_burst); + if (unlikely(nb_rx == 0)) + return; + +#ifdef RTE_TEST_PMD_RECORD_BURST_STATS + fs->rx_burst_stats.pkt_burst_spread[nb_rx]++; +#endif + fs->rx_packets += nb_rx; + txp = [fs->tx_port]; + for (i = 0; i < nb_rx; i++) { + mb = pkts_burst[i]; + eth_hdr = (struct ether_hdr *) mb->pkt.data; + + /* Swap dest and src mac addresses. */ + ether_addr_copy(_hdr->d_addr, ); + ether_addr_copy(_hdr->s_addr, _hdr->d_addr); + ether_addr_copy(, _hdr->s_addr); + + mb->ol_flags = txp->tx_ol_flags; + mb->pkt.vlan_macip.f.l2_len = sizeof(struct ether_hdr); + mb->pkt.vlan_macip.f.l3_len = sizeof(stru
[dpdk-dev] [PATCH 4/6] test-pmd: allow txpkts to be setup via command line
We allow a new --txpkts command-line parameter to configure segment sizes when in txonly or flowgen forwarding modes. Signed-off-by: Cyril Chemparathy --- app/test-pmd/parameters.c | 57 +++ 1 file changed, 57 insertions(+) diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c index 67081d7..ce90399 100644 --- a/app/test-pmd/parameters.c +++ b/app/test-pmd/parameters.c @@ -476,6 +476,52 @@ parse_ringnuma_config(const char *q_arg) return 0; } +static unsigned int +parse_item_list(char* str, unsigned int max_items, unsigned int *parsed_items) +{ + unsigned int nb_item; + unsigned int value; + unsigned int i; + int value_ok; + char c; + + /* +* First parse all items in the list and store their value. +*/ + value = 0; + nb_item = 0; + value_ok = 0; + for (i = 0; i < strlen(str); i++) { + c = str[i]; + if ((c >= '0') && (c <= '9')) { + value = (unsigned int) (value * 10 + (c - '0')); + value_ok = 1; + continue; + } + if (c != ',') { + printf("character %c is not a decimal digit\n", c); + return (0); + } + if (! value_ok) { + printf("No valid value before comma\n"); + return (0); + } + if (nb_item < max_items) { + parsed_items[nb_item] = value; + value_ok = 0; + value = 0; + } + nb_item++; + } + + if (nb_item >= max_items) + rte_exit(EXIT_FAILURE, "too many txpkt segments!\n"); + + parsed_items[nb_item++] = value; + + return (nb_item); +} + void launch_args_parse(int argc, char** argv) { @@ -538,6 +584,7 @@ launch_args_parse(int argc, char** argv) { "tx-queue-stats-mapping", 1, 0, 0 }, { "rx-queue-stats-mapping", 1, 0, 0 }, { "no-flush-rx",0, 0, 0 }, + { "txpkts", 1, 0, 0 }, { 0, 0, 0, 0 }, }; @@ -983,6 +1030,16 @@ launch_args_parse(int argc, char** argv) "invalid RX queue statistics mapping config entered\n"); } } + if (!strcmp(lgopts[opt_idx].name, "txpkts")) { + unsigned seg_lengths[RTE_MAX_SEGS_PER_PKT]; + unsigned int nb_segs; + + nb_segs = parse_item_list(optarg, RTE_MAX_SEGS_PER_PKT, seg_lengths); + if (nb_segs > 0) + set_tx_pkt_segments(seg_lengths, nb_segs); + else + rte_exit(EXIT_FAILURE, "bad txpkts\n"); + } if (!strcmp(lgopts[opt_idx].name, "no-flush-rx")) no_flush_rx = 1; -- 1.8.3.1
[dpdk-dev] [PATCH 3/6] test-pmd: allow command line selection of forwarding mode
This commit allows testpmd forwarding mode selection through command line parameters instead of having to set this up in interactive mode. Signed-off-by: Cyril Chemparathy --- app/test-pmd/parameters.c | 4 1 file changed, 4 insertions(+) diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c index 18b52cc..67081d7 100644 --- a/app/test-pmd/parameters.c +++ b/app/test-pmd/parameters.c @@ -158,6 +158,7 @@ usage(char* progname) printf(" --disable-rss: disable rss.\n"); printf(" --port-topology=N: set port topology (N: paired (default) or " "chained).\n"); + printf(" --forward-mode=N: set forwarding mode.\n"); printf(" --rss-ip: set RSS functions to IPv4/IPv6 only .\n"); printf(" --rss-udp: set RSS functions to IPv4/IPv6 + UDP.\n"); printf(" --rxq=N: set the number of RX queues per port to N.\n"); @@ -515,6 +516,7 @@ launch_args_parse(int argc, char** argv) { "enable-drop-en",0, 0, 0 }, { "disable-rss",0, 0, 0 }, { "port-topology", 1, 0, 0 }, + { "forward-mode", 1, 0, 0 }, { "rss-ip", 0, 0, 0 }, { "rss-udp",0, 0, 0 }, { "rxq",1, 0, 0 }, @@ -775,6 +777,8 @@ launch_args_parse(int argc, char** argv) " must be: paired or chained \n", optarg); } + if (!strcmp(lgopts[opt_idx].name, "forward-mode")) + set_pkt_forwarding_mode(optarg); if (!strcmp(lgopts[opt_idx].name, "rss-ip")) rss_hf = ETH_RSS_IPV4 | ETH_RSS_IPV6; if (!strcmp(lgopts[opt_idx].name, "rss-udp")) -- 1.8.3.1
[dpdk-dev] [PATCH 2/6] test-pmd: add support for auto-start when interactive
This patch adds support for a command-line argument --auto-start (-a). When running in interactive mode, this allows us to start traffic without user intervention before dropping to the prompt. Signed-off-by: Cyril Chemparathy --- app/test-pmd/parameters.c | 20 app/test-pmd/testpmd.c| 9 +++-- app/test-pmd/testpmd.h| 1 + 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c index d47d020..18b52cc 100644 --- a/app/test-pmd/parameters.c +++ b/app/test-pmd/parameters.c @@ -85,7 +85,7 @@ usage(char* progname) #ifdef RTE_LIBRTE_CMDLINE "[--interactive|-i] " #endif - "[--help|-h] | [" + "[--help|-h] | [--auto-start|-a] | [" "--coremask=COREMASK --portmask=PORTMASK --numa " "--mbuf-size= | --total-num-mbufs= | " "--nb-cores= | --nb-ports= | " @@ -102,6 +102,8 @@ usage(char* progname) #ifdef RTE_LIBRTE_CMDLINE printf(" --interactive: run in interactive mode.\n"); #endif + printf(" --auto-start: start forwarding on init " + "[always when non-interactive].\n"); printf(" --help: display this message and quit.\n"); printf(" --nb-cores=N: set the number of forwarding cores " "(1 <= N <= %d).\n", nb_lcores); @@ -485,6 +487,7 @@ launch_args_parse(int argc, char** argv) { "help", 0, 0, 0 }, #ifdef RTE_LIBRTE_CMDLINE { "interactive",0, 0, 0 }, + { "auto-start", 0, 0, 0 }, { "eth-peers-configfile", 1, 0, 0 }, { "eth-peer", 1, 0, 0 }, #endif @@ -539,11 +542,11 @@ launch_args_parse(int argc, char** argv) argvopt = argv; #ifdef RTE_LIBRTE_CMDLINE -#define SHORTOPTS "ih" +#define SHORTOPTS "i" #else -#define SHORTOPTS "h" +#define SHORTOPTS "" #endif - while ((opt = getopt_long(argc, argvopt, SHORTOPTS, + while ((opt = getopt_long(argc, argvopt, SHORTOPTS "ah", lgopts, _idx)) != EOF) { switch (opt) { #ifdef RTE_LIBRTE_CMDLINE @@ -552,6 +555,11 @@ launch_args_parse(int argc, char** argv) interactive = 1; break; #endif + case 'a': + printf("Auto-start selected\n"); + auto_start = 1; + break; + case 0: /*long options */ if (!strcmp(lgopts[opt_idx].name, "help")) { usage(argv[0]); @@ -562,6 +570,10 @@ launch_args_parse(int argc, char** argv) printf("Interactive-mode selected\n"); interactive = 1; } + if (!strcmp(lgopts[opt_idx].name, "auto-start")) { + printf("Auto-start selected\n"); + auto_start = 1; + } if (!strcmp(lgopts[opt_idx].name, "eth-peers-configfile")) { if (init_peer_eth_addrs(optarg) != 0) diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index 04dca57..cde9c2b 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -83,6 +83,7 @@ uint16_t verbose_level = 0; /**< Silent by default. */ /* use master core for command line ? */ uint8_t interactive = 0; +uint8_t auto_start = 0; /* * NUMA support configuration. @@ -1794,9 +1795,13 @@ main(int argc, char** argv) rte_eth_promiscuous_enable(port_id); #ifdef RTE_LIBRTE_CMDLINE - if (interactive == 1) + if (interactive == 1) { + if (auto_start) { + printf("Start automatic packet forwarding\n"); + start_packet_forwarding(0); + } prompt(); - else + } else #endif { char c; diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index a4842ec..52d3543 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -270,6 +270,7 @@ extern uint16_t nb_rx_queue_stats_mappings; /* globals used for configuration */ extern uint16_t verbose_level; /**< Drives messages being displayed, if any. */ extern uint8_t interactive; +extern uint8_t auto_start; extern uint8_t numa_support; /**< set by "--numa" parameter */ extern uint16_t port_topology; /**< set by "--port-topology" parameter */ extern uint8_t no_flush_rx; /**
[dpdk-dev] [PATCH 1/6] test-pmd: add support for single port loopback topology
This commits adds a new "loop" option to the --port-topology argument. With the loop option specified, ingress traffic is simply transmitted back on the same interface. Signed-off-by: Cyril Chemparathy --- app/test-pmd/config.c | 16 ++-- app/test-pmd/parameters.c | 2 ++ app/test-pmd/testpmd.h| 3 ++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index 0816227..1d3cdba 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -733,7 +733,8 @@ simple_fwd_config_setup(void) portid_t j; portid_t inc = 2; - if (port_topology == PORT_TOPOLOGY_CHAINED) { + if (port_topology == PORT_TOPOLOGY_CHAINED || + port_topology == PORT_TOPOLOGY_LOOP) { inc = 1; } else if (nb_fwd_ports % 2) { printf("\nWarning! Cannot handle an odd number of ports " @@ -761,7 +762,10 @@ simple_fwd_config_setup(void) setup_fwd_config_of_each_lcore(_fwd_config); for (i = 0; i < cur_fwd_config.nb_fwd_ports; i = (portid_t) (i + inc)) { - j = (portid_t) ((i + 1) % cur_fwd_config.nb_fwd_ports); + if (port_topology != PORT_TOPOLOGY_LOOP) + j = (portid_t) ((i + 1) % cur_fwd_config.nb_fwd_ports); + else + j = i; fwd_streams[i]->rx_port = fwd_ports_ids[i]; fwd_streams[i]->rx_queue = 0; fwd_streams[i]->tx_port = fwd_ports_ids[j]; @@ -825,10 +829,18 @@ rss_fwd_config_setup(void) struct fwd_stream *fs; fs = fwd_streams[lc_id]; + if ((rxp & 0x1) == 0) txp = (portid_t) (rxp + 1); else txp = (portid_t) (rxp - 1); + /* +* if we are in loopback, simply send stuff out through the +* ingress port +*/ + if (port_topology == PORT_TOPOLOGY_LOOP) + txp = rxp; + fs->rx_port = fwd_ports_ids[rxp]; fs->rx_queue = rxq; fs->tx_port = fwd_ports_ids[txp]; diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c index f537e49..d47d020 100644 --- a/app/test-pmd/parameters.c +++ b/app/test-pmd/parameters.c @@ -756,6 +756,8 @@ launch_args_parse(int argc, char** argv) port_topology = PORT_TOPOLOGY_PAIRED; else if (!strcmp(optarg, "chained")) port_topology = PORT_TOPOLOGY_CHAINED; + else if (!strcmp(optarg, "loop")) + port_topology = PORT_TOPOLOGY_LOOP; else rte_exit(EXIT_FAILURE, "port-topology %s invalid -" " must be: paired or chained \n", diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index 5b4ee6f..a4842ec 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -80,7 +80,8 @@ typedef uint16_t streamid_t; enum { PORT_TOPOLOGY_PAIRED, - PORT_TOPOLOGY_CHAINED + PORT_TOPOLOGY_CHAINED, + PORT_TOPOLOGY_LOOP, }; #ifdef RTE_TEST_PMD_RECORD_BURST_STATS -- 1.8.3.1
[dpdk-dev] [PATCH 0/6] Extensions to test-pmd
Hi, This patch series contains a few minor extensions to test-pmd. These changes have been added primarily for convenience while testing out various scenarios with DPDK. Thanks -- Cyril. Cyril Chemparathy (6): test-pmd: add support for single port loopback topology test-pmd: add support for auto-start when interactive test-pmd: allow command line selection of forwarding mode test-pmd: allow txpkts to be setup via command line test-pmd: add mac swap forwarding mode test-pmd: add flowgen forwarding engine app/test-pmd/Makefile | 2 + app/test-pmd/config.c | 16 ++- app/test-pmd/flowgen.c| 247 ++ app/test-pmd/macswap.c| 148 +++ app/test-pmd/parameters.c | 83 +++- app/test-pmd/testpmd.c| 11 ++- app/test-pmd/testpmd.h| 6 +- 7 files changed, 504 insertions(+), 9 deletions(-) create mode 100644 app/test-pmd/flowgen.c create mode 100644 app/test-pmd/macswap.c -- 1.8.3.1