From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by dpdk.org (Postfix) with ESMTP id 49BDA2B9B for ; Fri, 20 Jan 2017 17:17:56 +0100 (CET) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP; 20 Jan 2017 08:17:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,259,1477983600"; d="scan'208";a="811316099" Received: from silpixa00397515.ir.intel.com (HELO silpixa00397515.ger.corp.intel.com) ([10.237.223.14]) by FMSMGA003.fm.intel.com with ESMTP; 20 Jan 2017 08:17:54 -0800 From: David Hunt To: dev@dpdk.org Cc: bruce.richardson@intel.com, David Hunt Date: Fri, 20 Jan 2017 09:18:49 +0000 Message-Id: <1484903933-127190-3-git-send-email-david.hunt@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1484903933-127190-1-git-send-email-david.hunt@intel.com> References: <1483948248-91364-2-git-send-email-david.hunt@intel.com> <1484903933-127190-1-git-send-email-david.hunt@intel.com> Subject: [dpdk-dev] [PATCH v5 2/6] lib: add distributor vector flow matching X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Jan 2017 16:17:57 -0000 Signed-off-by: David Hunt --- lib/librte_distributor/Makefile | 7 ++ lib/librte_distributor/rte_distributor_burst.c | 12 ++- lib/librte_distributor/rte_distributor_burst.h | 6 +- .../rte_distributor_match_generic.c | 43 ++++++++ lib/librte_distributor/rte_distributor_match_sse.c | 113 +++++++++++++++++++++ lib/librte_distributor/rte_distributor_priv.h | 15 ++- 6 files changed, 191 insertions(+), 5 deletions(-) create mode 100644 lib/librte_distributor/rte_distributor_match_generic.c create mode 100644 lib/librte_distributor/rte_distributor_match_sse.c diff --git a/lib/librte_distributor/Makefile b/lib/librte_distributor/Makefile index 2acc54d..4baaa0c 100644 --- a/lib/librte_distributor/Makefile +++ b/lib/librte_distributor/Makefile @@ -44,6 +44,13 @@ LIBABIVER := 1 # all source are stored in SRCS-y SRCS-$(CONFIG_RTE_LIBRTE_DISTRIBUTOR) := rte_distributor.c SRCS-$(CONFIG_RTE_LIBRTE_DISTRIBUTOR) += rte_distributor_burst.c +ifeq ($(CONFIG_RTE_ARCH_X86),y) +SRCS-$(CONFIG_RTE_LIBRTE_DISTRIBUTOR) += rte_distributor_match_sse.c +CFLAGS_rte_distributor_match_sse.o += -msse4.2 +else +SRCS-$(CONFIG_RTE_LIBRTE_DISTRIBUTOR) += rte_distributor_match_generic.c +endif + # install this header file SYMLINK-$(CONFIG_RTE_LIBRTE_DISTRIBUTOR)-include := rte_distributor.h diff --git a/lib/librte_distributor/rte_distributor_burst.c b/lib/librte_distributor/rte_distributor_burst.c index 2cbf635..a629c73 100644 --- a/lib/librte_distributor/rte_distributor_burst.c +++ b/lib/librte_distributor/rte_distributor_burst.c @@ -190,7 +190,7 @@ store_return(uintptr_t oldbuf, struct rte_distributor_burst *d, * backlog). This will then allow us to pin those packets to the relevant * workers to give us our atomic flow pinning. */ -static inline void +void find_match_scalar(struct rte_distributor_burst *d, uint16_t *data_ptr, uint16_t *output_ptr) @@ -351,6 +351,9 @@ rte_distributor_process_burst(struct rte_distributor_burst *d, } switch (d->dist_match_fn) { + case RTE_DIST_MATCH_VECTOR: + find_match_vec(d, &flows[0], &matches[0]); + break; default: find_match_scalar(d, &flows[0], &matches[0]); } @@ -543,7 +546,12 @@ rte_distributor_create_burst(const char *name, snprintf(d->name, sizeof(d->name), "%s", name); d->num_workers = num_workers; - d->dist_match_fn = RTE_DIST_MATCH_SCALAR; +#if defined(RTE_ARCH_X86) + if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_SSE4_2)) { + d->dist_match_fn = RTE_DIST_MATCH_VECTOR; + } else +#endif + d->dist_match_fn = RTE_DIST_MATCH_SCALAR; /* * Set up the backog tags so they're pointing at the second cache diff --git a/lib/librte_distributor/rte_distributor_burst.h b/lib/librte_distributor/rte_distributor_burst.h index 0b65518..b0b41ec 100644 --- a/lib/librte_distributor/rte_distributor_burst.h +++ b/lib/librte_distributor/rte_distributor_burst.h @@ -192,8 +192,10 @@ rte_distributor_get_pkt_burst(struct rte_distributor_burst *d, * @param worker_id * The worker instance number to use - must be less that num_workers passed * at distributor creation time. - * @param mbuf - * The previous packet being processed by the worker + * @param oldpkt + * The previous packets being processed by the worker + * @param num + * The number of packets in the oldpkt array */ int rte_distributor_return_pkt_burst(struct rte_distributor_burst *d, diff --git a/lib/librte_distributor/rte_distributor_match_generic.c b/lib/librte_distributor/rte_distributor_match_generic.c new file mode 100644 index 0000000..6a1ff7f --- /dev/null +++ b/lib/librte_distributor/rte_distributor_match_generic.c @@ -0,0 +1,43 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2017 Intel 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 Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 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 "rte_distributor_priv.h" +#include "rte_distributor_burst.h" + +void +find_match_vec(struct rte_distributor_burst *d, + uint16_t *data_ptr, + uint16_t *output_ptr) +{ + find_match_scalar(d, data_ptr, output_ptr); +} diff --git a/lib/librte_distributor/rte_distributor_match_sse.c b/lib/librte_distributor/rte_distributor_match_sse.c new file mode 100644 index 0000000..383f12e --- /dev/null +++ b/lib/librte_distributor/rte_distributor_match_sse.c @@ -0,0 +1,113 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2017 Intel 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 Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 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 "rte_distributor_priv.h" +#include "rte_distributor_burst.h" +#include "smmintrin.h" + + +void +find_match_vec(struct rte_distributor_burst *d, + uint16_t *data_ptr, + uint16_t *output_ptr) +{ + /* Setup */ + __m128i incoming_fids; + __m128i inflight_fids; + __m128i preflight_fids; + __m128i wkr; + __m128i mask1; + __m128i mask2; + __m128i output; + struct rte_distributor_backlog *bl; + uint16_t i; + + /* + * Function overview: + * 2. Loop through all worker ID's + * 2a. Load the current inflights for that worker into an xmm reg + * 2b. Load the current backlog for that worker into an xmm reg + * 2c. use cmpestrm to intersect flow_ids with backlog and inflights + * 2d. Add any matches to the output + * 3. Write the output xmm (matching worker ids). + */ + + + output = _mm_set1_epi16(0); + incoming_fids = _mm_load_si128((__m128i *)data_ptr); + + for (i = 0; i < d->num_workers; i++) { + bl = &d->backlog[i]; + + inflight_fids = + _mm_load_si128((__m128i *)&(d->in_flight_tags[i])); + preflight_fids = + _mm_load_si128((__m128i *)(bl->tags)); + + /* + * Any incoming_fid that exists anywhere in inflight_fids will + * have 0xffff in same position of the mask as the incoming fid + * Example (shortened to bytes for brevity): + * incoming_fids 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 + * inflight_fids 0x03 0x05 0x07 0x00 0x00 0x00 0x00 0x00 + * mask 0x00 0x00 0xff 0x00 0xff 0x00 0xff 0x00 + */ + + mask1 = _mm_cmpestrm(inflight_fids, 8, incoming_fids, 8, + _SIDD_UWORD_OPS | + _SIDD_CMP_EQUAL_ANY | + _SIDD_UNIT_MASK); + mask2 = _mm_cmpestrm(preflight_fids, 8, incoming_fids, 8, + _SIDD_UWORD_OPS | + _SIDD_CMP_EQUAL_ANY | + _SIDD_UNIT_MASK); + + mask1 = _mm_or_si128(mask1, mask2); + /* + * Now mask contains 0xffff where there's a match. + * Next we need to store the worker_id in the relevant position + * in the output. + */ + + wkr = _mm_set1_epi16(i+1); + mask1 = _mm_and_si128(mask1, wkr); + output = _mm_or_si128(mask1, output); + } + + /* + * At this stage, the output 128-bit contains 8 16-bit values, with + * each non-zero value containing the worker ID on which the + * corresponding flow is pinned to. + */ + _mm_store_si128((__m128i *)output_ptr, output); +} diff --git a/lib/librte_distributor/rte_distributor_priv.h b/lib/librte_distributor/rte_distributor_priv.h index ae48d86..1d73d92 100644 --- a/lib/librte_distributor/rte_distributor_priv.h +++ b/lib/librte_distributor/rte_distributor_priv.h @@ -33,6 +33,8 @@ #ifndef _RTE_DIST_PRIV_H_ #define _RTE_DIST_PRIV_H_ +#include + /** * @file * RTE distributor @@ -70,7 +72,7 @@ extern "C" { /** * Maximum number of workers allowed. * Be aware of increasing the limit, becaus it is limited by how we track - * in-flight tags. See @in_flight_bitmask and @rte_distributor_process + * in-flight tags. See in_flight_bitmask and rte_distributor_process */ #define RTE_DISTRIB_MAX_WORKERS 64 @@ -155,6 +157,7 @@ struct rte_distributor { /* All different signature compare functions */ enum rte_distributor_match_function { RTE_DIST_MATCH_SCALAR = 0, + RTE_DIST_MATCH_VECTOR, RTE_DIST_NUM_MATCH_FNS }; @@ -182,6 +185,16 @@ struct rte_distributor_burst { enum rte_distributor_match_function dist_match_fn; }; +void +find_match_scalar(struct rte_distributor_burst *d, + uint16_t *data_ptr, + uint16_t *output_ptr); + +void +find_match_vec(struct rte_distributor_burst *d, + uint16_t *data_ptr, + uint16_t *output_ptr); + #ifdef __cplusplus } #endif -- 2.7.4