From patchwork Mon Sep 6 16:03:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Medvedkin X-Patchwork-Id: 98094 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 130B7A0C55; Mon, 6 Sep 2021 18:04:11 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AA38D41100; Mon, 6 Sep 2021 18:04:07 +0200 (CEST) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mails.dpdk.org (Postfix) with ESMTP id 3299C410ED for ; Mon, 6 Sep 2021 18:04:06 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10099"; a="281011520" X-IronPort-AV: E=Sophos;i="5.85,272,1624345200"; d="scan'208";a="281011520" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Sep 2021 09:04:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,272,1624345200"; d="scan'208";a="464093084" Received: from silpixa00400072.ir.intel.com ([10.237.222.213]) by fmsmga007.fm.intel.com with ESMTP; 06 Sep 2021 09:04:03 -0700 From: Vladimir Medvedkin To: dev@dpdk.org Cc: konstantin.ananyev@intel.com, andrey.chilikin@intel.com, yipeng1.wang@intel.com, sameh.gobriel@intel.com, bruce.richardson@intel.com, john.mcnamara@intel.com Date: Mon, 6 Sep 2021 17:03:55 +0100 Message-Id: <1630944239-363648-2-git-send-email-vladimir.medvedkin@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1630944239-363648-1-git-send-email-vladimir.medvedkin@intel.com> References: <1630944239-363648-1-git-send-email-vladimir.medvedkin@intel.com> Subject: [dpdk-dev] [PATCH 1/5] hash: add new toeplitz hash implementation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch add a new Toeplitz hash implementation using Galios Fields New Instructions (GFNI). Signed-off-by: Vladimir Medvedkin --- doc/api/doxy-api-index.md | 1 + lib/hash/meson.build | 1 + lib/hash/rte_thash.c | 26 ++++++ lib/hash/rte_thash.h | 22 +++++ lib/hash/rte_thash_gfni.h | 229 ++++++++++++++++++++++++++++++++++++++++++++++ lib/hash/version.map | 2 + 6 files changed, 281 insertions(+) create mode 100644 lib/hash/rte_thash_gfni.h diff --git a/doc/api/doxy-api-index.md b/doc/api/doxy-api-index.md index 1992107..7549477 100644 --- a/doc/api/doxy-api-index.md +++ b/doc/api/doxy-api-index.md @@ -139,6 +139,7 @@ The public API headers are grouped by topics: [hash] (@ref rte_hash.h), [jhash] (@ref rte_jhash.h), [thash] (@ref rte_thash.h), + [thash_gfni] (@ref rte_thash_gfni.h), [FBK hash] (@ref rte_fbk_hash.h), [CRC hash] (@ref rte_hash_crc.h) diff --git a/lib/hash/meson.build b/lib/hash/meson.build index 9bc5ef9..40444ac 100644 --- a/lib/hash/meson.build +++ b/lib/hash/meson.build @@ -7,6 +7,7 @@ headers = files( 'rte_hash.h', 'rte_jhash.h', 'rte_thash.h', + 'rte_thash_gfni.h', ) indirect_headers += files('rte_crc_arm64.h') diff --git a/lib/hash/rte_thash.c b/lib/hash/rte_thash.c index d5a95a6..07447f7 100644 --- a/lib/hash/rte_thash.c +++ b/lib/hash/rte_thash.c @@ -11,6 +11,7 @@ #include #include #include +#include #define THASH_NAME_LEN 64 #define TOEPLITZ_HASH_LEN 32 @@ -88,6 +89,23 @@ struct rte_thash_ctx { uint8_t hash_key[0]; }; +uint8_t rte_thash_gfni_supported; + +void +rte_thash_complete_matrix(uint64_t *matrixes, uint8_t *rss_key, int size) +{ + int i, j; + uint8_t *m = (uint8_t *)matrixes; + + for (i = 0; i < size; i++) { + for (j = 0; j < 8; j++) { + m[i * 8 + j] = (rss_key[i] << j)| + (uint8_t)((uint16_t)(rss_key[i + 1]) >> + (8 - j)); + } + } +} + static inline uint32_t get_bit_lfsr(struct thash_lfsr *lfsr) { @@ -759,3 +777,11 @@ rte_thash_adjust_tuple(struct rte_thash_ctx *ctx, return ret; } + +RTE_INIT(rte_thash_gfni_init) +{ +#ifdef __GFNI__ + if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_GFNI)) + rte_thash_gfni_supported = 1; +#endif +} diff --git a/lib/hash/rte_thash.h b/lib/hash/rte_thash.h index 76109fc..e3f1fc6 100644 --- a/lib/hash/rte_thash.h +++ b/lib/hash/rte_thash.h @@ -28,6 +28,7 @@ extern "C" { #include #include #include +#include #if defined(RTE_ARCH_X86) || defined(__ARM_NEON) #include @@ -113,6 +114,8 @@ union rte_thash_tuple { }; #endif +extern uint8_t rte_thash_gfni_supported; + /** * Prepare special converted key to use with rte_softrss_be() * @param orig @@ -223,6 +226,25 @@ rte_softrss_be(uint32_t *input_tuple, uint32_t input_len, return ret; } +/** + * Converts Toeplitz hash key (RSS key) into matrixes required + * for GFNI implementation + * + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * @param matrixes + * pointer to the memory where matrixes will be writen. + * Note: the size of this memory must be equal to size * 8 + * @param rss_key + * pointer to the Toeplitz hash key + * @param size + * Size of the rss_key in bytes. + */ +__rte_experimental +void +rte_thash_complete_matrix(uint64_t *matrixes, uint8_t *rss_key, int size); + /** @internal Logarithm of minimum size of the RSS ReTa */ #define RTE_THASH_RETA_SZ_MIN 2U /** @internal Logarithm of maximum size of the RSS ReTa */ diff --git a/lib/hash/rte_thash_gfni.h b/lib/hash/rte_thash_gfni.h new file mode 100644 index 0000000..8f89d7d --- /dev/null +++ b/lib/hash/rte_thash_gfni.h @@ -0,0 +1,229 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2021 Intel Corporation + */ + +#ifndef _RTE_THASH_GFNI_H_ +#define _RTE_THASH_GFNI_H_ + +/** + * @file + * + * Optimized Toeplitz hash functions implementation + * using Galois Fields New Instructions. + */ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __GFNI__ + +#define RTE_THASH_FIRST_ITER_MSK 0x0f0f0f0f0f0e0c08 +#define RTE_THASH_PERM_MSK 0x0f0f0f0f0f0f0f0f +#define RTE_THASH_FIRST_ITER_MSK_2 0xf0f0f0f0f0e0c080 +#define RTE_THASH_PERM_MSK_2 0xf0f0f0f0f0f0f0f0 +#define RTE_THASH_REWIND_MSK 0x0000000000113377 + +__rte_internal +static inline void +__rte_thash_xor_reduce(__m512i xor_acc, uint32_t *val_1, uint32_t *val_2) +{ + __m256i tmp_256_1, tmp_256_2; + __m128i tmp128_1, tmp128_2; + uint64_t tmp_1, tmp_2; + + tmp_256_1 = _mm512_castsi512_si256(xor_acc); + tmp_256_2 = _mm512_extracti32x8_epi32(xor_acc, 1); + tmp_256_1 = _mm256_xor_si256(tmp_256_1, tmp_256_2); + + tmp128_1 = _mm256_castsi256_si128(tmp_256_1); + tmp128_2 = _mm256_extracti32x4_epi32(tmp_256_1, 1); + tmp128_1 = _mm_xor_si128(tmp128_1, tmp128_2); + + tmp_1 = _mm_extract_epi64(tmp128_1, 0); + tmp_2 = _mm_extract_epi64(tmp128_1, 1); + tmp_1 ^= tmp_2; + + *val_1 = (uint32_t)tmp_1; + *val_2 = (uint32_t)(tmp_1 >> 32); +} + +__rte_internal +static inline __m512i +__rte_thash_gfni(uint64_t *mtrx, uint8_t *tuple, uint8_t *secondary_tuple, + int len) +{ + __m512i permute_idx = _mm512_set_epi8(7, 6, 5, 4, 7, 6, 5, 4, + 6, 5, 4, 3, 6, 5, 4, 3, + 5, 4, 3, 2, 5, 4, 3, 2, + 4, 3, 2, 1, 4, 3, 2, 1, + 3, 2, 1, 0, 3, 2, 1, 0, + 2, 1, 0, -1, 2, 1, 0, -1, + 1, 0, -1, -2, 1, 0, -1, -2, + 0, -1, -2, -3, 0, -1, -2, -3); + + const __m512i rewind_idx = _mm512_set_epi8(0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 59, 0, 0, 0, 59, + 0, 0, 59, 58, 0, 0, 59, 58, + 0, 59, 58, 57, 0, 59, 58, 57); + const __mmask64 rewind_mask = RTE_THASH_REWIND_MSK; + const __m512i shift_8 = _mm512_set1_epi8(8); + __m512i xor_acc = _mm512_setzero_si512(); + __m512i perm_bytes = _mm512_setzero_si512(); + __m512i vals, matrixes, tuple_bytes, tuple_bytes_2; + __mmask64 load_mask, permute_mask, permute_mask_2; + int chunk_len = 0, i = 0; + uint8_t mtrx_msk; + const int prepend = 3; + + for (; len > 0; len -= 64, tuple += 64) { + if (i == 8) + perm_bytes = _mm512_maskz_permutexvar_epi8(rewind_mask, + rewind_idx, perm_bytes); + + permute_mask = RTE_THASH_FIRST_ITER_MSK; + load_mask = (len >= 64) ? UINT64_MAX : ((1ULL << len) - 1); + tuple_bytes = _mm512_maskz_loadu_epi8(load_mask, tuple); + if (secondary_tuple) { + permute_mask_2 = RTE_THASH_FIRST_ITER_MSK_2; + tuple_bytes_2 = _mm512_maskz_loadu_epi8(load_mask, + secondary_tuple); + } + + chunk_len = __builtin_popcountll(load_mask); + for (i = 0; i < ((chunk_len + prepend) / 8); i++, mtrx += 8) { + perm_bytes = _mm512_mask_permutexvar_epi8(perm_bytes, + permute_mask, permute_idx, tuple_bytes); + + if (secondary_tuple) + perm_bytes = + _mm512_mask_permutexvar_epi8(perm_bytes, + permute_mask_2, permute_idx, + tuple_bytes_2); + + matrixes = _mm512_maskz_loadu_epi64(UINT8_MAX, mtrx); + vals = _mm512_gf2p8affine_epi64_epi8(perm_bytes, + matrixes, 0); + + xor_acc = _mm512_xor_si512(xor_acc, vals); + permute_idx = _mm512_add_epi8(permute_idx, shift_8); + permute_mask = RTE_THASH_PERM_MSK; + if (secondary_tuple) + permute_mask_2 = RTE_THASH_PERM_MSK_2; + } + } + + int rest_len = (chunk_len + prepend) % 8; + if (rest_len != 0) { + mtrx_msk = (1 << (rest_len % 8)) - 1; + matrixes = _mm512_maskz_loadu_epi64(mtrx_msk, mtrx); + if (i == 8) { + perm_bytes = _mm512_maskz_permutexvar_epi8(rewind_mask, + rewind_idx, perm_bytes); + } else { + perm_bytes = _mm512_mask_permutexvar_epi8(perm_bytes, + permute_mask, permute_idx, tuple_bytes); + + if (secondary_tuple) + perm_bytes = + _mm512_mask_permutexvar_epi8( + perm_bytes, permute_mask_2, + permute_idx, tuple_bytes_2); + } + + vals = _mm512_gf2p8affine_epi64_epi8(perm_bytes, matrixes, 0); + xor_acc = _mm512_xor_si512(xor_acc, vals); + } + + return xor_acc; +} + +/** + * Calculate Toeplitz hash. + * + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * @param m + * Pointer to the matrices generated from the corresponding + * RSS hash key using rte_thash_complete_matrix(). + * @param tuple + * Pointer to the data to be hashed. Data must be in network byte order. + * @param len + * Length of the data to be hashed. + * @return + * Calculated Toeplitz hash value. + */ +__rte_experimental +static inline uint32_t +rte_thash_gfni(uint64_t *m, uint8_t *tuple, int len) +{ + uint32_t val, val_zero; + + __m512i xor_acc = __rte_thash_gfni(m, tuple, NULL, len); + __rte_thash_xor_reduce(xor_acc, &val, &val_zero); + + return val; +} + +/** + * Calculate Toeplitz hash for two independent data buffers. + * + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * @param m + * Pointer to the matrices generated from the corresponding + * RSS hash key using rte_thash_complete_matrix(). + * @param tuple_1 + * Pointer to the data to be hashed. Data must be in network byte order. + * @param tuple_2 + * Pointer to the data to be hashed. Data must be in network byte order. + * @param len + * Length of the largest data buffer to be hashed. + * @param val_1 + * Pointer to uint32_t where to put calculated Toeplitz hash value for + * the first tuple. + * @param val_2 + * Pointer to uint32_t where to put calculated Toeplitz hash value for + * the second tuple. + */ +__rte_experimental +static inline void +rte_thash_gfni_x2(uint64_t *mtrx, uint8_t *tuple_1, uint8_t *tuple_2, int len, + uint32_t *val_1, uint32_t *val_2) +{ + __m512i xor_acc = __rte_thash_gfni(mtrx, tuple_1, tuple_2, len); + __rte_thash_xor_reduce(xor_acc, val_1, val_2); +} + +#else /* __GFNI__ */ + +static inline uint32_t +rte_thash_gfni(uint64_t *mtrx __rte_unused, uint8_t *key __rte_unused, + int len __rte_unused) +{ + return 0; +} + +static inline void +rte_thash_gfni_x2(uint64_t *mtrx __rte_unused, uint8_t *tuple_1 __rte_unused, + uint8_t *tuple_2 __rte_unused, int len __rte_unused, + uint32_t *val_1 __rte_unused, uint32_t *val_2 __rte_unused) +{ + +} + +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_THASH_GFNI_H_ */ diff --git a/lib/hash/version.map b/lib/hash/version.map index ce4309a..cecf922 100644 --- a/lib/hash/version.map +++ b/lib/hash/version.map @@ -39,10 +39,12 @@ EXPERIMENTAL { rte_hash_rcu_qsbr_add; rte_thash_add_helper; rte_thash_adjust_tuple; + rte_thash_complete_matrix; rte_thash_find_existing; rte_thash_free_ctx; rte_thash_get_complement; rte_thash_get_helper; rte_thash_get_key; + rte_thash_gfni_supported; rte_thash_init_ctx; }; From patchwork Mon Sep 6 16:03:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Medvedkin X-Patchwork-Id: 98095 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5D189A0C55; Mon, 6 Sep 2021 18:04:17 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B6E0B41123; Mon, 6 Sep 2021 18:04:09 +0200 (CEST) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mails.dpdk.org (Postfix) with ESMTP id B03A241102 for ; Mon, 6 Sep 2021 18:04:07 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10099"; a="281011522" X-IronPort-AV: E=Sophos;i="5.85,272,1624345200"; d="scan'208";a="281011522" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Sep 2021 09:04:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,272,1624345200"; d="scan'208";a="464093134" Received: from silpixa00400072.ir.intel.com ([10.237.222.213]) by fmsmga007.fm.intel.com with ESMTP; 06 Sep 2021 09:04:05 -0700 From: Vladimir Medvedkin To: dev@dpdk.org Cc: konstantin.ananyev@intel.com, andrey.chilikin@intel.com, yipeng1.wang@intel.com, sameh.gobriel@intel.com, bruce.richardson@intel.com Date: Mon, 6 Sep 2021 17:03:56 +0100 Message-Id: <1630944239-363648-3-git-send-email-vladimir.medvedkin@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1630944239-363648-1-git-send-email-vladimir.medvedkin@intel.com> References: <1630944239-363648-1-git-send-email-vladimir.medvedkin@intel.com> Subject: [dpdk-dev] [PATCH 2/5] hash: enable gfni thash implementation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch enables new GFNI Toeplitz hash in predictable RSS library. Signed-off-by: Vladimir Medvedkin --- lib/hash/rte_thash.c | 43 +++++++++++++++++++++++++++++++++++++++---- lib/hash/rte_thash.h | 19 +++++++++++++++++++ lib/hash/version.map | 1 + 3 files changed, 59 insertions(+), 4 deletions(-) diff --git a/lib/hash/rte_thash.c b/lib/hash/rte_thash.c index 07447f7..86a0e96 100644 --- a/lib/hash/rte_thash.c +++ b/lib/hash/rte_thash.c @@ -86,6 +86,8 @@ struct rte_thash_ctx { uint32_t reta_sz_log; /** < size of the RSS ReTa in bits */ uint32_t subtuples_nb; /** < number of subtuples */ uint32_t flags; + uint64_t *matrices; + /**< rte_thash_complete_matrix generated matrices */ uint8_t hash_key[0]; }; @@ -253,12 +255,25 @@ rte_thash_init_ctx(const char *name, uint32_t key_len, uint32_t reta_sz, ctx->hash_key[i] = rte_rand(); } + if (rte_thash_gfni_supported) { + ctx->matrices = rte_zmalloc(NULL, key_len * sizeof(uint64_t), + RTE_CACHE_LINE_SIZE); + if (ctx->matrices == NULL) + goto free_ctx; + + rte_thash_complete_matrix(ctx->matrices, ctx->hash_key, + key_len); + } + te->data = (void *)ctx; TAILQ_INSERT_TAIL(thash_list, te, next); rte_mcfg_tailq_write_unlock(); return ctx; + +free_ctx: + rte_free(ctx); free_te: rte_free(te); exit: @@ -372,6 +387,10 @@ generate_subkey(struct rte_thash_ctx *ctx, struct thash_lfsr *lfsr, set_bit(ctx->hash_key, get_rev_bit_lfsr(lfsr), i); } + if (rte_thash_gfni_supported) + rte_thash_complete_matrix(ctx->matrices, ctx->hash_key, + ctx->key_len); + return 0; } @@ -628,6 +647,16 @@ rte_thash_get_key(struct rte_thash_ctx *ctx) return ctx->hash_key; } +const uint64_t * +rte_thash_get_gfni_matrices(struct rte_thash_ctx *ctx) +{ + if (rte_thash_gfni_supported) + return ctx->matrices; + + rte_errno = ENOTSUP; + return NULL; +} + static inline uint8_t read_unaligned_byte(uint8_t *ptr, unsigned int len, unsigned int offset) { @@ -739,11 +768,17 @@ rte_thash_adjust_tuple(struct rte_thash_ctx *ctx, attempts = RTE_MIN(attempts, 1U << (h->tuple_len - ctx->reta_sz_log)); for (i = 0; i < attempts; i++) { - for (j = 0; j < (tuple_len / 4); j++) - tmp_tuple[j] = - rte_be_to_cpu_32(*(uint32_t *)&tuple[j * 4]); + if (rte_thash_gfni_supported) + hash = rte_thash_gfni(ctx->matrices, tuple, tuple_len); + else { + for (j = 0; j < (tuple_len / 4); j++) + tmp_tuple[j] = + rte_be_to_cpu_32( + *(uint32_t *)&tuple[j * 4]); + + hash = rte_softrss(tmp_tuple, tuple_len / 4, hash_key); + } - hash = rte_softrss(tmp_tuple, tuple_len / 4, hash_key); adj_bits = rte_thash_get_complement(h, hash, desired_value); /* diff --git a/lib/hash/rte_thash.h b/lib/hash/rte_thash.h index e3f1fc6..6e6861c 100644 --- a/lib/hash/rte_thash.h +++ b/lib/hash/rte_thash.h @@ -410,6 +410,25 @@ const uint8_t * rte_thash_get_key(struct rte_thash_ctx *ctx); /** + * Get a pointer to the toeplitz hash matrices contained in the context. + * These matrices could be used with fast toeplitz hash implementation if + * CPU supports GFNI. + * Matrices changes after each addition of a helper. + * + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * @param ctx + * Thash context + * @return + * A pointer to the toeplitz hash key matrices on success + * NULL if GFNI is not supported. + */ +__rte_experimental +const uint64_t * +rte_thash_get_gfni_matrices(struct rte_thash_ctx *ctx); + +/** * Function prototype for the rte_thash_adjust_tuple * to check if adjusted tuple could be used. * Generally it is some kind of lookup function to check diff --git a/lib/hash/version.map b/lib/hash/version.map index cecf922..3eda695 100644 --- a/lib/hash/version.map +++ b/lib/hash/version.map @@ -43,6 +43,7 @@ EXPERIMENTAL { rte_thash_find_existing; rte_thash_free_ctx; rte_thash_get_complement; + rte_thash_get_gfni_matrices; rte_thash_get_helper; rte_thash_get_key; rte_thash_gfni_supported; From patchwork Mon Sep 6 16:03:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Medvedkin X-Patchwork-Id: 98096 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id CB809A0C55; Mon, 6 Sep 2021 18:04:23 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DE85041134; Mon, 6 Sep 2021 18:04:10 +0200 (CEST) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mails.dpdk.org (Postfix) with ESMTP id 6BA8441120 for ; Mon, 6 Sep 2021 18:04:09 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10099"; a="281011527" X-IronPort-AV: E=Sophos;i="5.85,272,1624345200"; d="scan'208";a="281011527" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Sep 2021 09:04:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,272,1624345200"; d="scan'208";a="464093154" Received: from silpixa00400072.ir.intel.com ([10.237.222.213]) by fmsmga007.fm.intel.com with ESMTP; 06 Sep 2021 09:04:07 -0700 From: Vladimir Medvedkin To: dev@dpdk.org Cc: konstantin.ananyev@intel.com, andrey.chilikin@intel.com, yipeng1.wang@intel.com, sameh.gobriel@intel.com, bruce.richardson@intel.com, john.mcnamara@intel.com Date: Mon, 6 Sep 2021 17:03:57 +0100 Message-Id: <1630944239-363648-4-git-send-email-vladimir.medvedkin@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1630944239-363648-1-git-send-email-vladimir.medvedkin@intel.com> References: <1630944239-363648-1-git-send-email-vladimir.medvedkin@intel.com> Subject: [dpdk-dev] [PATCH 3/5] doc/hash: update documentation for the thash library X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch adds documentation for the new optimized Toeplitz hash implementation using GFNI. Signed-off-by: Vladimir Medvedkin --- doc/guides/prog_guide/toeplitz_hash_lib.rst | 37 +++++++++++++++++++++++++---- doc/guides/rel_notes/release_21_11.rst | 4 ++++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/doc/guides/prog_guide/toeplitz_hash_lib.rst b/doc/guides/prog_guide/toeplitz_hash_lib.rst index f916857..6f50a18 100644 --- a/doc/guides/prog_guide/toeplitz_hash_lib.rst +++ b/doc/guides/prog_guide/toeplitz_hash_lib.rst @@ -19,24 +19,53 @@ to calculate the RSS hash sum to spread the traffic among the queues. Toeplitz hash function API -------------------------- -There are two functions that provide calculation of the Toeplitz hash sum: +There are four functions that provide calculation of the Toeplitz hash sum: * ``rte_softrss()`` * ``rte_softrss_be()`` +* ``rte_thash_gfni()`` +* ``rte_thash_gfni_x2()`` -Both of these functions take the parameters: +First two functions are scalar implementation and take the parameters: * A pointer to the tuple, containing fields extracted from the packet. * A length of this tuple counted in double words. * A pointer to the RSS hash key corresponding to the one installed on the NIC. -Both functions expect the tuple to be in "host" byte order -and a multiple of 4 bytes in length. +Both of abovementioned _softrss_ functions expect the tuple to be in +"host" byte order and a multiple of 4 bytes in length. The ``rte_softrss()`` function expects the ``rss_key`` to be exactly the same as the one installed on the NIC. The ``rte_softrss_be`` function is a faster implementation, but it expects ``rss_key`` to be converted to the host byte order. +The last two functions are vectorized implementations using +Galois Fields New Instructions. Could be used if ``rte_thash_gfni_supported`` is true. +They expect the tuple to be in network byte order. + +``rte_thash_gfni()`` calculates the hash value for a single tuple, and +``rte_thash_gfni_x2()`` calculates for a two independent tuples in one go. + +``rte_thash_gfni()`` takes the parameters: + +* A pointer to the matrixes derived from the RSS hash key using ``rte_thash_complete_matrix()``. +* A pointer to the tuple. +* A length of the tuple in bytes. + +``rte_thash_gfni_x2()`` takes the parameters: + +* A pointer to the matrices derived from the RSS hash key using ``rte_thash_complete_matrix()``. +* Two tuple pointers. +* A length of the longest tuple in bytes. +* Two pointers on the ``uint32_t`` to write results to. + +``rte_thash_complete_matrix()`` is a function that calculates matrices required by +GFNI implementations from the RSS hash key. It takes the parameters: + +* A pointer to the memory where the matrices will be written. +* A pointer to the RSS hash key. +* Length of the RSS hash key in bytes. + Predictable RSS --------------- diff --git a/doc/guides/rel_notes/release_21_11.rst b/doc/guides/rel_notes/release_21_11.rst index d707a55..df28642 100644 --- a/doc/guides/rel_notes/release_21_11.rst +++ b/doc/guides/rel_notes/release_21_11.rst @@ -55,6 +55,10 @@ New Features Also, make sure to start the actual text at the margin. ======================================================= +* **Added optimized Toeplitz hash implementation.** + + Added optimized Toeplitz hash implementation using Galois Fields New Instructions. + Removed Items ------------- From patchwork Mon Sep 6 16:03:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Medvedkin X-Patchwork-Id: 98097 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 90473A0C55; Mon, 6 Sep 2021 18:04:31 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5E99E41141; Mon, 6 Sep 2021 18:04:13 +0200 (CEST) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mails.dpdk.org (Postfix) with ESMTP id 07DD541137 for ; Mon, 6 Sep 2021 18:04:10 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10099"; a="281011530" X-IronPort-AV: E=Sophos;i="5.85,272,1624345200"; d="scan'208";a="281011530" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Sep 2021 09:04:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,272,1624345200"; d="scan'208";a="464093165" Received: from silpixa00400072.ir.intel.com ([10.237.222.213]) by fmsmga007.fm.intel.com with ESMTP; 06 Sep 2021 09:04:09 -0700 From: Vladimir Medvedkin To: dev@dpdk.org Cc: konstantin.ananyev@intel.com, andrey.chilikin@intel.com, yipeng1.wang@intel.com, sameh.gobriel@intel.com, bruce.richardson@intel.com Date: Mon, 6 Sep 2021 17:03:58 +0100 Message-Id: <1630944239-363648-5-git-send-email-vladimir.medvedkin@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1630944239-363648-1-git-send-email-vladimir.medvedkin@intel.com> References: <1630944239-363648-1-git-send-email-vladimir.medvedkin@intel.com> Subject: [dpdk-dev] [PATCH 4/5] test/thash: add tests for a new Toeplitz hash function X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch provides a set of tests for verifying the new implementation of Toeplitz hash function using GFNI. Signed-off-by: Vladimir Medvedkin --- app/test/test_thash.c | 231 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) diff --git a/app/test/test_thash.c b/app/test/test_thash.c index d8981fb..5327a02 100644 --- a/app/test/test_thash.c +++ b/app/test/test_thash.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "test.h" @@ -78,6 +79,34 @@ uint8_t default_rss_key[] = { 0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa, }; +uint8_t big_rss_key[] = { +0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2, +0x41, 0x67, 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0, +0xd0, 0xca, 0x2b, 0xcb, 0xae, 0x7b, 0x30, 0xb4, +0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, 0xf2, 0x0c, +0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa, +0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2, +0x41, 0x67, 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0, +0xd0, 0xca, 0x2b, 0xcb, 0xae, 0x7b, 0x30, 0xb4, +0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, 0xf2, 0x0c, +0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa, +0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2, +0x41, 0x67, 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0, +0xd0, 0xca, 0x2b, 0xcb, 0xae, 0x7b, 0x30, 0xb4, +0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, 0xf2, 0x0c, +0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa, +0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2, +0x41, 0x67, 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0, +0xd0, 0xca, 0x2b, 0xcb, 0xae, 0x7b, 0x30, 0xb4, +0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, 0xf2, 0x0c, +0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa, +0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2, +0x41, 0x67, 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0, +0xd0, 0xca, 0x2b, 0xcb, 0xae, 0x7b, 0x30, 0xb4, +0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, 0xf2, 0x0c, +0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa, +}; + static int test_toeplitz_hash_calc(void) { @@ -145,6 +174,204 @@ test_toeplitz_hash_calc(void) } static int +test_toeplitz_hash_gfni(void) +{ + uint32_t i, j; + union rte_thash_tuple tuple; + uint32_t rss_l3, rss_l3l4; + uint64_t rss_key_matrixes[RTE_DIM(default_rss_key)]; + + if (!rte_thash_gfni_supported) + return TEST_SKIPPED; + + /* Convert RSS key into matrixes */ + rte_thash_complete_matrix(rss_key_matrixes, default_rss_key, + RTE_DIM(default_rss_key)); + + for (i = 0; i < RTE_DIM(v4_tbl); i++) { + tuple.v4.src_addr = rte_cpu_to_be_32(v4_tbl[i].src_ip); + tuple.v4.dst_addr = rte_cpu_to_be_32(v4_tbl[i].dst_ip); + tuple.v4.sport = rte_cpu_to_be_16(v4_tbl[i].dst_port); + tuple.v4.dport = rte_cpu_to_be_16(v4_tbl[i].src_port); + + rss_l3 = rte_thash_gfni(rss_key_matrixes, (uint8_t *)&tuple, + RTE_THASH_V4_L3_LEN * 4); + rss_l3l4 = rte_thash_gfni(rss_key_matrixes, (uint8_t *)&tuple, + RTE_THASH_V4_L4_LEN * 4); + if ((rss_l3 != v4_tbl[i].hash_l3) || + (rss_l3l4 != v4_tbl[i].hash_l3l4)) + return -TEST_FAILED; + } + + for (i = 0; i < RTE_DIM(v6_tbl); i++) { + for (j = 0; j < RTE_DIM(tuple.v6.src_addr); j++) + tuple.v6.src_addr[j] = v6_tbl[i].src_ip[j]; + for (j = 0; j < RTE_DIM(tuple.v6.dst_addr); j++) + tuple.v6.dst_addr[j] = v6_tbl[i].dst_ip[j]; + tuple.v6.sport = rte_cpu_to_be_16(v6_tbl[i].dst_port); + tuple.v6.dport = rte_cpu_to_be_16(v6_tbl[i].src_port); + rss_l3 = rte_thash_gfni(rss_key_matrixes, (uint8_t *)&tuple, + RTE_THASH_V6_L3_LEN * 4); + rss_l3l4 = rte_thash_gfni(rss_key_matrixes, (uint8_t *)&tuple, + RTE_THASH_V6_L4_LEN * 4); + if ((rss_l3 != v6_tbl[i].hash_l3) || + (rss_l3l4 != v6_tbl[i].hash_l3l4)) + return -TEST_FAILED; + } + + return TEST_SUCCESS; +} + +#define DATA_SZ 4 +#define ITER 1000 + +enum { + SCALAR_DATA_BUF_1_HASH_IDX = 0, + SCALAR_DATA_BUF_2_HASH_IDX, + GFNI_DATA_BUF_1_HASH_IDX, + GFNI_DATA_BUF_2_HASH_IDX, + GFNI_X2_DATA_BUF_1_HASH_IDX, + GFNI_X2_DATA_BUF_2_HASH_IDX, + HASH_IDXES +}; + +static int +test_toeplitz_hash_rand_data(void) +{ + uint32_t data[2][DATA_SZ]; + uint32_t scalar_data[2][DATA_SZ]; + uint32_t hash[HASH_IDXES] = { 0 }; + uint64_t rss_key_matrixes[RTE_DIM(default_rss_key)]; + int i, j; + + if (!rte_thash_gfni_supported) + return TEST_SKIPPED; + + rte_thash_complete_matrix(rss_key_matrixes, default_rss_key, + RTE_DIM(default_rss_key)); + + for (i = 0; i < ITER; i++) { + for (j = 0; j < DATA_SZ; j++) { + data[0][j] = rte_rand(); + data[1][j] = rte_rand(); + scalar_data[0][j] = rte_cpu_to_be_32(data[0][j]); + scalar_data[1][j] = rte_cpu_to_be_32(data[1][j]); + } + + hash[SCALAR_DATA_BUF_1_HASH_IDX] = rte_softrss(scalar_data[0], + DATA_SZ, default_rss_key); + hash[SCALAR_DATA_BUF_2_HASH_IDX] = rte_softrss(scalar_data[1], + DATA_SZ, default_rss_key); + hash[GFNI_DATA_BUF_1_HASH_IDX] = rte_thash_gfni( + rss_key_matrixes, (uint8_t *)data[0], + DATA_SZ * sizeof(uint32_t)); + hash[GFNI_DATA_BUF_2_HASH_IDX] = rte_thash_gfni( + rss_key_matrixes, (uint8_t *)data[1], + DATA_SZ * sizeof(uint32_t)); + rte_thash_gfni_x2(rss_key_matrixes, + (uint8_t *)data[0], (uint8_t *)data[1], + DATA_SZ * sizeof(uint32_t), + &hash[GFNI_X2_DATA_BUF_1_HASH_IDX], + &hash[GFNI_X2_DATA_BUF_2_HASH_IDX]); + + if ((hash[SCALAR_DATA_BUF_1_HASH_IDX] != + hash[GFNI_DATA_BUF_1_HASH_IDX]) || + (hash[SCALAR_DATA_BUF_1_HASH_IDX] != + hash[GFNI_X2_DATA_BUF_1_HASH_IDX]) || + (hash[SCALAR_DATA_BUF_2_HASH_IDX] != + hash[GFNI_DATA_BUF_2_HASH_IDX]) || + (hash[SCALAR_DATA_BUF_2_HASH_IDX] != + hash[GFNI_X2_DATA_BUF_2_HASH_IDX])) + + return -TEST_FAILED; + } + + return TEST_SUCCESS; +} + +static int +test_toeplitz_hash_gfni_x2(void) +{ + uint32_t i, j; + union rte_thash_tuple tuple[2]; + uint8_t *tuples[2]; + uint32_t rss_v4 = 0; + uint32_t rss_v6 = 0; + uint64_t rss_key_matrixes[RTE_DIM(default_rss_key)]; + + if (!rte_thash_gfni_supported) + return TEST_SKIPPED; + + /* Convert RSS key into matrixes */ + rte_thash_complete_matrix(rss_key_matrixes, default_rss_key, + RTE_DIM(default_rss_key)); + + for (i = 0; i < RTE_DIM(tuples); i++) { + /* allocate memory enough for a biggest tuple */ + tuples[i] = rte_zmalloc(NULL, RTE_THASH_V6_L4_LEN * 4, 0); + if (tuples[i] == NULL) + return -TEST_FAILED; + } + + for (i = 0; i < RTE_MIN(RTE_DIM(v4_tbl), RTE_DIM(v6_tbl)); i++) { + /*Load IPv4 headers and copy it into the corresponding tuple*/ + tuple[0].v4.src_addr = rte_cpu_to_be_32(v4_tbl[i].src_ip); + tuple[0].v4.dst_addr = rte_cpu_to_be_32(v4_tbl[i].dst_ip); + tuple[0].v4.sport = rte_cpu_to_be_16(v4_tbl[i].dst_port); + tuple[0].v4.dport = rte_cpu_to_be_16(v4_tbl[i].src_port); + rte_memcpy(tuples[0], &tuple[0], RTE_THASH_V4_L4_LEN * 4); + + /*Load IPv6 headers and copy it into the corresponding tuple*/ + for (j = 0; j < RTE_DIM(tuple[1].v6.src_addr); j++) + tuple[1].v6.src_addr[j] = v6_tbl[i].src_ip[j]; + for (j = 0; j < RTE_DIM(tuple[1].v6.dst_addr); j++) + tuple[1].v6.dst_addr[j] = v6_tbl[i].dst_ip[j]; + tuple[1].v6.sport = rte_cpu_to_be_16(v6_tbl[i].dst_port); + tuple[1].v6.dport = rte_cpu_to_be_16(v6_tbl[i].src_port); + rte_memcpy(tuples[1], &tuple[1], RTE_THASH_V6_L4_LEN * 4); + + rte_thash_gfni_x2(rss_key_matrixes, tuples[0], tuples[1], + RTE_THASH_V6_L4_LEN * 4, &rss_v4, &rss_v6); + + if ((rss_v4 != v4_tbl[i].hash_l3l4) || + (rss_v6 != v6_tbl[i].hash_l3l4)) + return -TEST_FAILED; + } + + return TEST_SUCCESS; +} + +static int +test_big_tuple_gfni(void) +{ + uint32_t arr[16]; + uint32_t arr_softrss[16]; + uint32_t hash_1, hash_2; + uint64_t rss_key_matrixes[RTE_DIM(big_rss_key)]; + unsigned int i, size = RTE_DIM(arr) * sizeof(uint32_t); + + if (!rte_thash_gfni_supported) + return TEST_SKIPPED; + + /* Convert RSS key into matrixes */ + rte_thash_complete_matrix(rss_key_matrixes, big_rss_key, + RTE_DIM(big_rss_key)); + + for (i = 0; i < RTE_DIM(arr); i++) { + arr[i] = rte_rand(); + arr_softrss[i] = rte_be_to_cpu_32(arr[i]); + } + + hash_1 = rte_softrss(arr_softrss, RTE_DIM(arr), big_rss_key); + hash_2 = rte_thash_gfni(rss_key_matrixes, (uint8_t *)arr, size); + + if (hash_1 != hash_2) + return -TEST_FAILED; + + return TEST_SUCCESS; +} + +static int test_create_invalid(void) { struct rte_thash_ctx *ctx; @@ -577,6 +804,10 @@ static struct unit_test_suite thash_tests = { .teardown = NULL, .unit_test_cases = { TEST_CASE(test_toeplitz_hash_calc), + TEST_CASE(test_toeplitz_hash_gfni), + TEST_CASE(test_toeplitz_hash_rand_data), + TEST_CASE(test_toeplitz_hash_gfni_x2), + TEST_CASE(test_big_tuple_gfni), TEST_CASE(test_create_invalid), TEST_CASE(test_multiple_create), TEST_CASE(test_free_null), From patchwork Mon Sep 6 16:03:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Medvedkin X-Patchwork-Id: 98098 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id CA42AA0C55; Mon, 6 Sep 2021 18:04:37 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7649641147; Mon, 6 Sep 2021 18:04:14 +0200 (CEST) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mails.dpdk.org (Postfix) with ESMTP id 8A1F341140 for ; Mon, 6 Sep 2021 18:04:12 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10099"; a="281011534" X-IronPort-AV: E=Sophos;i="5.85,272,1624345200"; d="scan'208";a="281011534" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Sep 2021 09:04:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,272,1624345200"; d="scan'208";a="464093183" Received: from silpixa00400072.ir.intel.com ([10.237.222.213]) by fmsmga007.fm.intel.com with ESMTP; 06 Sep 2021 09:04:10 -0700 From: Vladimir Medvedkin To: dev@dpdk.org Cc: konstantin.ananyev@intel.com, andrey.chilikin@intel.com, yipeng1.wang@intel.com, sameh.gobriel@intel.com, bruce.richardson@intel.com Date: Mon, 6 Sep 2021 17:03:59 +0100 Message-Id: <1630944239-363648-6-git-send-email-vladimir.medvedkin@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1630944239-363648-1-git-send-email-vladimir.medvedkin@intel.com> References: <1630944239-363648-1-git-send-email-vladimir.medvedkin@intel.com> Subject: [dpdk-dev] [PATCH 5/5] test/thash: add performance tests for the Toeplitz hash X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch adds performance tests for different implementations of the Toeplitz hash function. Signed-off-by: Vladimir Medvedkin --- app/test/meson.build | 2 + app/test/test_thash_perf.c | 125 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 app/test/test_thash_perf.c diff --git a/app/test/meson.build b/app/test/meson.build index a761168..be5df32 100644 --- a/app/test/meson.build +++ b/app/test/meson.build @@ -140,6 +140,7 @@ test_sources = files( 'test_table_tables.c', 'test_tailq.c', 'test_thash.c', + 'test_thash_perf.c', 'test_timer.c', 'test_timer_perf.c', 'test_timer_racecond.c', @@ -314,6 +315,7 @@ perf_test_names = [ 'hash_readwrite_lf_perf_autotest', 'trace_perf_autotest', 'ipsec_perf_autotest', + 'thash_perf_autotest', ] driver_test_names = [ diff --git a/app/test/test_thash_perf.c b/app/test/test_thash_perf.c new file mode 100644 index 0000000..ccc4710 --- /dev/null +++ b/app/test/test_thash_perf.c @@ -0,0 +1,125 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2021 Intel Corporation + */ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "test.h" + +#define ITERATIONS (1 << 15) +#define BATCH_SZ (1 << 10) + +#define IPV4_2_TUPLE_LEN (8) +#define IPV4_4_TUPLE_LEN (12) +#define IPV6_2_TUPLE_LEN (32) +#define IPV6_4_TUPLE_LEN (36) + + +static uint8_t default_rss_key[] = { + 0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2, + 0x41, 0x67, 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0, + 0xd0, 0xca, 0x2b, 0xcb, 0xae, 0x7b, 0x30, 0xb4, + 0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, 0xf2, 0x0c, + 0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa, +}; + +static void +run_thash_test(unsigned int tuple_len) +{ + uint32_t *tuples[BATCH_SZ]; + unsigned int i, j; + uint64_t start_tsc, end_tsc; + uint32_t len = RTE_ALIGN_CEIL(tuple_len, sizeof(uint32_t)); + volatile uint32_t hash = 0; + uint32_t hash_1 = 0; + uint32_t hash_2 = 0; + + for (i = 0; i < BATCH_SZ; i++) { + tuples[i] = rte_zmalloc(NULL, len, 0); + for (j = 0; j < len / sizeof(uint32_t); j++) + tuples[i][j] = rte_rand(); + } + + start_tsc = rte_rdtsc_precise(); + for (i = 0; i < ITERATIONS; i++) { + for (j = 0; j < BATCH_SZ; j++) { + hash ^= rte_softrss(tuples[j], len / sizeof(uint32_t), + default_rss_key); + } + } + end_tsc = rte_rdtsc_precise(); + + printf("Average rte_softrss() takes \t\t%.1f cycles for key len %d\n", + (double)(end_tsc - start_tsc) / (double)(ITERATIONS * + BATCH_SZ), len); + + start_tsc = rte_rdtsc_precise(); + for (i = 0; i < ITERATIONS; i++) { + for (j = 0; j < BATCH_SZ; j++) { + hash ^= rte_softrss_be(tuples[j], len / + sizeof(uint32_t), default_rss_key); + } + } + end_tsc = rte_rdtsc_precise(); + + printf("Average rte_softrss_be() takes \t\t%.1f cycles for key len %d\n", + (double)(end_tsc - start_tsc) / (double)(ITERATIONS * + BATCH_SZ), len); + + if (!rte_thash_gfni_supported) + return; + + uint64_t rss_key_matrixes[RTE_DIM(default_rss_key)]; + + rte_thash_complete_matrix(rss_key_matrixes, default_rss_key, + RTE_DIM(default_rss_key)); + + start_tsc = rte_rdtsc_precise(); + for (i = 0; i < ITERATIONS; i++) { + for (j = 0; j < BATCH_SZ; j++) + hash ^= rte_thash_gfni(rss_key_matrixes, + (uint8_t *)tuples[j], len); + } + end_tsc = rte_rdtsc_precise(); + + printf("Average rte_thash_gfni takes \t\t%.1f cycles for key len %d\n", + (double)(end_tsc - start_tsc) / (double)(ITERATIONS * + BATCH_SZ), len); + + start_tsc = rte_rdtsc_precise(); + for (i = 0; i < ITERATIONS; i++) { + for (j = 0; j < BATCH_SZ; j += 2) { + rte_thash_gfni_x2(rss_key_matrixes, + (uint8_t *)tuples[j], (uint8_t *)tuples[j + 1], + len, &hash_1, &hash_2); + + hash ^= hash_1 ^ hash_2; + } + } + end_tsc = rte_rdtsc_precise(); + + printf("Average rte_thash_gfni_x2 takes \t%.1f cycles for key len %d\n", + (double)(end_tsc - start_tsc) / (double)(ITERATIONS * + BATCH_SZ), len); +} + +static int +test_thash_perf(void) +{ + run_thash_test(IPV4_2_TUPLE_LEN); + run_thash_test(IPV4_4_TUPLE_LEN); + run_thash_test(IPV6_2_TUPLE_LEN); + run_thash_test(IPV6_4_TUPLE_LEN); + + return 0; +} + +REGISTER_TEST_COMMAND(thash_perf_autotest, test_thash_perf);