From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 40F81A0547; Thu, 21 Oct 2021 11:42:53 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C6ACE410E2; Thu, 21 Oct 2021 11:42:52 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mails.dpdk.org (Postfix) with ESMTP id BAED840142 for ; Thu, 21 Oct 2021 11:42:50 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10143"; a="229260955" X-IronPort-AV: E=Sophos;i="5.87,169,1631602800"; d="scan'208";a="229260955" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2021 02:42:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,169,1631602800"; d="scan'208";a="445274298" Received: from orsmsx605.amr.corp.intel.com ([10.22.229.18]) by orsmga003.jf.intel.com with ESMTP; 21 Oct 2021 02:42:42 -0700 Received: from orsmsx607.amr.corp.intel.com (10.22.229.20) by ORSMSX605.amr.corp.intel.com (10.22.229.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.12; Thu, 21 Oct 2021 02:42:41 -0700 Received: from orsmsx603.amr.corp.intel.com (10.22.229.16) by ORSMSX607.amr.corp.intel.com (10.22.229.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.12; Thu, 21 Oct 2021 02:42:41 -0700 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.12 via Frontend Transport; Thu, 21 Oct 2021 02:42:41 -0700 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (104.47.58.102) by edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2242.12; Thu, 21 Oct 2021 02:42:41 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cOPcWYettKEvlhv0L2ITCylvz3n2yDbg/BdXr/VFzFYk2wDEC1jkJu08y49lF7JhhJKuvSEWhnBrTTCx2LYheVnw/dlcuPtqCOfIBEmn6EoGSug682Q9pq2rbVHZu6t1XOoK54YSy2YFAz38Sx9fRjbRt2BMS09MnpfNv2KgiA46YAnj8gup5lHEdUQv6s6WE0sCSrbxsLyTMvkspE/YV0zzI/75Hf8A0RLBJxS5er+ndaOiKz5IlrDsEWGtgvWXikc/pbiRktm6NIV0Ql6agCJU58aJhqzPK5BoXELHlXfnCnINRZD5Toa2Taz+L6g/pjESh/CQhm52odWl/L25jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=DIdlDhYTS+dijTGsl+XL34rDyl8wM72qZnPlR0Di78E=; b=N+OFil56+I7bbOr/miDhY2OYsMweHXQTMH9JOJRKBiEGPuQhLW+UMW2ZJ0SM4DsE0/MqI0SK/K3Qo8Sbp2bnDhUiiHUGZkKLFR+G0NZVFsfQZFavn6r2J9+KMH+2JtpS07slYXTSoAt8htJFGKsL8xTkP/PTU6SjXrSbpo5iKW7it0I+CVj7uqnpm1iNgLsyLPkNioDL4yXvpQn2fMAxEpx9fLxmMJm4uFvSqYSFg0pVWipRuprRgyxpIy+pnkZcvSqXmUq0xDgtuWsSHi0hGMqtqhNd9of6H+CuSx6UUlHOCHv+mAzBuhrKKc6lMWk3Sa26pfQrSD2DYEHEzHiUYg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=DIdlDhYTS+dijTGsl+XL34rDyl8wM72qZnPlR0Di78E=; b=p4EjgHUJqzaf6UCD5AyPpPSj/pLzpNIgJ+UXWKC2oQhs9voGE3JoWOYh0R39sG47xi5IH0VYdaGFxnukWKRtT02m1Kix0ac7whjvR8mPjVjqq7LbTs1056lUTs1fzKggWjj9VwSLYNDnearvQ+lHBVr7hDg26tPikPrWgqHtrmQ= Received: from DM6PR11MB4491.namprd11.prod.outlook.com (2603:10b6:5:204::19) by DM6PR11MB4516.namprd11.prod.outlook.com (2603:10b6:5:2a5::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.16; Thu, 21 Oct 2021 09:42:37 +0000 Received: from DM6PR11MB4491.namprd11.prod.outlook.com ([fe80::2c0c:5383:f814:3b4e]) by DM6PR11MB4491.namprd11.prod.outlook.com ([fe80::2c0c:5383:f814:3b4e%6]) with mapi id 15.20.4628.018; Thu, 21 Oct 2021 09:42:37 +0000 From: "Ananyev, Konstantin" To: "Medvedkin, Vladimir" , "dev@dpdk.org" CC: "Wang, Yipeng1" , "Gobriel, Sameh" , "Richardson, Bruce" , "stephen@networkplumber.org" Thread-Topic: [PATCH v3 1/5] hash: add new toeplitz hash implementation Thread-Index: AQHXxd8yGjcCh6x8vEyg82Pmrduq76vdM6fQ Date: Thu, 21 Oct 2021 09:42:37 +0000 Message-ID: References: <1634290206-251913-1-git-send-email-vladimir.medvedkin@intel.com> <1634754016-367978-2-git-send-email-vladimir.medvedkin@intel.com> In-Reply-To: <1634754016-367978-2-git-send-email-vladimir.medvedkin@intel.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.6.200.16 authentication-results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: e295ee0f-fbee-49d7-4e99-08d994771e2f x-ms-traffictypediagnostic: DM6PR11MB4516: x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:64; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: NZMIaTdzT7at3DEpsig4T15MBp4QEsiXjxh4LFdFWNkY4y9D2I4c8qy/lyHdeFFu+znLXQNIxgftVknRVdpV0fdjDOZ5mPgyjIEzm5lj713HqbXfxbcfAc/GlCX0yO3gbdZGLVhGjZeZ/Au/7haQSfRn/aLEXyuKSYl6FB/cQ8M4WM6m/kkpRBz0rhUsv3IDhrbOOcV7ibk3PfIW6esJUz9auDU6LPBIByqfPqZt8mofJRBhjrOtdVxXZvJKlmm5ZqdO9AK+Ffeq3Mpglpcrg+3yJe73yYKtCprs7P7TUvVzH3Tln+0lhaTzP3sgkYvLvOWr4KzmVcBu3tRPEi9IVdvevG83Tma/bIoZQyw3lwHoFhWb/kS78yZ2GgD5/3r17A6/nFbI12IWGqeF/6nKOHI+VIKx/qe4UPXydsKSeXKFYtAA+9/UeYUUOrwEIa3bo0Y+xViaXgNenrUCeYWxOOx4LlVZlvMHXLfYGbK9GrMOz+TOZIJ9WoVYON4qgOuWc2M663qqWNGyy6Fta1Wq6WXfkw25nSYu8+Jc7MnvF620mBrRrW8OjSqjA1fyoUHp4gnKFXzNFxNIDGsTiEFAB9ccQjo11B/sg6sPCLLkHzdT/wTGrvn0VXh+x6CVZbOaskJFa9FewSgawcXozmw4DgxM4ZJbnwLfWBQVp0Fo9yNN0dYm32akxNlc6podA68I0eacDLHq+0lmGcgj9izTig== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR11MB4491.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(33656002)(86362001)(30864003)(5660300002)(26005)(9686003)(52536014)(186003)(7696005)(110136005)(2906002)(54906003)(82960400001)(55016002)(38070700005)(64756008)(66446008)(55236004)(38100700002)(122000001)(83380400001)(4326008)(66556008)(8936002)(66946007)(66476007)(71200400001)(8676002)(316002)(508600001)(6506007)(76116006); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?niHMs1PVgubUDqKhn0N+e5OVLxcuP4+Ir18wh2YJH6Y2Kpcon2Mljmm2ewhL?= =?us-ascii?Q?G1t8I+8Hov/17sEBLcKlIzXtjeNxgJKkASqM9KY076gd0oQM41hrcMGeEwty?= =?us-ascii?Q?P7rEZCSjhphzISAQUdmqhNRzrz2MUv5/4HVXILRRrlUDexeQNccO8RUXK6FM?= =?us-ascii?Q?Ub6f+ZzTXx2UyxbjhwFLgvwv/7xWHfx+bjASegflN5UbrlApZygbDLY5jzea?= =?us-ascii?Q?neKbwsDSFtNfNqul6Lp/Ay5OcEU5BcvssQpKgp4lVKLklCf7MyrsNO+4Lhno?= =?us-ascii?Q?RVFZmOA/e/o4b/kLMWeBcyiB8a3S6OJfH/y+OJ0eNt1Qfhfo7i4zdVtZuHNt?= =?us-ascii?Q?XqJgM5QbW9RdT3PbJHiRBd07trryAlRgLgvfF3mcN4V5Gvc/njjBQt+r3sGJ?= =?us-ascii?Q?xwwYvzeR964GgI21lYCbkX9E947AiDwoyfpEx2aKO0qJ21LDq+rIiyDrw/Mb?= =?us-ascii?Q?0fLF9rZGukgCkrFskDcLeh/Nac3WfF2ri1hBHYaZvmWKR04yEgNKVue65s/b?= =?us-ascii?Q?o4tjTWFifRuV1MzLJ6GqgJjQnCr15ZSoBjOiGDDBmD38dpoBpgfJaaEPy8g3?= =?us-ascii?Q?DFwYiZGGyPtx+vFELl5FK8/LVBDsJWmZ+zVbtjgMFTlohdKd/rlfye8LTe5d?= =?us-ascii?Q?xPSwsxK7vU8awZDk9DrnLg144JHDw1kkofND4aLzTasDoNHkPNAAXbCzlJnC?= =?us-ascii?Q?vfgA2eCT52rEZ07/CJ473AnSqv9Xe4qdoHe9CS42X+rAVEwDUclay5G7uC+v?= =?us-ascii?Q?A40DT96KztcE2xU4rvN7E2yEMnm3HqvQhBFaGej2yJIeT1bAcEro133zPSEU?= =?us-ascii?Q?3PeGvKLn+UdQVLaVJxuqf5CsnLJ/tzUmmeh5SYxeB3FkO0zkqksTOy3Ca5Ao?= =?us-ascii?Q?Qvvkzrhy71/Rv6vd0TPclwNHHMNT+XDEAAllSaDVOHXsbNDvf8rn88JKZbm4?= =?us-ascii?Q?JAtFIc7YEap+Etnlgb9x3m//ZoMIrpMaC84dJNfxV4e07r2Mrk/ysWBLhdgz?= =?us-ascii?Q?v3KrktW2YKoJuK4tzdOLxlQmlGxdKlp0zhN4ztIa8fuPThHavWjVQsOrqD1/?= =?us-ascii?Q?v38D9RWrSbq74RrgFvdNKWyMXve/2ZisO722LZ3ZztRev1TB0uZ19NTM9w0j?= =?us-ascii?Q?RL/duUo5ytWKe04/L7yeB7mTLyt4EcyE/Z8T22LxrrbmKmMLhlSupGdkrqSA?= =?us-ascii?Q?hkKt4y+2VcnCB/KIWwYmmoIdDGWzd2z2yWX3wfCmlGHyjmHVwUbcA/oLpLH1?= =?us-ascii?Q?xFHrPB2rsgwD8iZHqikBRrSwxyqT04+IpgzeDk3rC/FuhXlXD5TWrwW8DbX1?= =?us-ascii?Q?y7BlvpzXln4W+dE/+QI0H/u9hx2Zl2Jd7sUCpKMKGSA0Es69ljvayLOdP+hQ?= =?us-ascii?Q?fRjJU7JMHIVKtu/EKQ/4Z0aJrz+JTVuqgWUkMxLzvmASjpU7+3iU1oUB8/t0?= =?us-ascii?Q?OuDRfJtNOVKWJEpFjtjbjYdwvu4fPsgv?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM6PR11MB4491.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: e295ee0f-fbee-49d7-4e99-08d994771e2f X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Oct 2021 09:42:37.6052 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: konstantin.ananyev@intel.com X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR11MB4516 X-OriginatorOrg: intel.com Subject: Re: [dpdk-dev] [PATCH v3 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). >=20 > Signed-off-by: Vladimir Medvedkin > --- > doc/api/doxy-api-index.md | 1 + > lib/hash/meson.build | 1 + > lib/hash/rte_thash.c | 29 ++++++ > lib/hash/rte_thash.h | 35 +++++++ > lib/hash/rte_thash_gfni.h | 85 ++++++++++++++++ > lib/hash/rte_thash_x86_gfni.h | 221 ++++++++++++++++++++++++++++++++++++= ++++++ > lib/hash/version.map | 2 + > 7 files changed, 374 insertions(+) > create mode 100644 lib/hash/rte_thash_gfni.h > create mode 100644 lib/hash/rte_thash_x86_gfni.h >=20 > 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) >=20 > 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 =3D files( > 'rte_hash.h', > 'rte_jhash.h', > 'rte_thash.h', > + 'rte_thash_gfni.h', > ) > indirect_headers +=3D files('rte_crc_arm64.h') >=20 > diff --git a/lib/hash/rte_thash.c b/lib/hash/rte_thash.c > index 696a112..e605a6f 100644 > --- a/lib/hash/rte_thash.c > +++ b/lib/hash/rte_thash.c > @@ -90,6 +90,35 @@ struct rte_thash_ctx { > uint8_t hash_key[0]; > }; >=20 > +int > +rte_thash_gfni_supported(void) > +{ > +#ifdef RTE_THASH_GFNI_DEFINED > + if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_GFNI) && > + (rte_vect_get_max_simd_bitwidth() >=3D > + RTE_VECT_SIMD_512)) > + return 1; > +#endif > + > + return 0; > +}; > + > +void > +rte_thash_complete_matrix(uint64_t *matrixes, const uint8_t *rss_key, in= t size) > +{ > + int i, j; > + uint8_t *m =3D (uint8_t *)matrixes; > + uint8_t left_part, right_part; > + > + for (i =3D 0; i < size; i++) { > + for (j =3D 0; j < 8; j++) { > + left_part =3D rss_key[i] << j; > + right_part =3D (uint16_t)(rss_key[i + 1]) >> (8 - j); > + m[i * 8 + j] =3D left_part|right_part; > + } > + } > +} > + > static inline uint32_t > get_bit_lfsr(struct thash_lfsr *lfsr) > { > diff --git a/lib/hash/rte_thash.h b/lib/hash/rte_thash.h > index 76109fc..a406be0 100644 > --- a/lib/hash/rte_thash.h > +++ b/lib/hash/rte_thash.h > @@ -28,6 +28,7 @@ extern "C" { > #include > #include > #include > +#include >=20 > #if defined(RTE_ARCH_X86) || defined(__ARM_NEON) > #include > @@ -223,6 +224,40 @@ rte_softrss_be(uint32_t *input_tuple, uint32_t input= _len, > return ret; > } >=20 > +/** > + * Indicates if GFNI implementations of the Toeplitz hash are supported. > + * > + * @warning > + * @b EXPERIMENTAL: this API may change without prior notice. > + * > + * @return > + * 1 if GFNI is supported > + * 0 otherwise > + */ > +__rte_experimental > +int > +rte_thash_gfni_supported(void); > + > +/** > + * 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 matrices will be written. > + * 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, const 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..f59587f > --- /dev/null > +++ b/lib/hash/rte_thash_gfni.h > @@ -0,0 +1,85 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(c) 2021 Intel Corporation > + */ > + > +#ifndef _RTE_THASH_GFNI_H_ > +#define _RTE_THASH_GFNI_H_ > + > +#ifdef __cplusplus > +extern "C" { > +#endif > + > +#ifdef RTE_ARCH_X86 > + > +#include > + > +#endif > + > +#ifndef RTE_THASH_GFNI_DEFINED > + > +/** > + * Calculate Toeplitz hash. > + * Dummy implementation. > + * > + * @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(const uint64_t *mtrx __rte_unused, > + const uint8_t *key __rte_unused, int len __rte_unused) > +{ > + RTE_LOG(ERR, HASH, "%s is undefined under given arch\n", __func__); One nit: as I can see from test report some compilation fails. Probably we need to add #include to that file. Apart from that, LGTM. Acked-by: Konstantin Ananyev > + return 0; > +} > + > +/** > + * Bulk implementation for Toeplitz hash. > + * Dummy implementation. > + * > + * @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 > + * Array of the pointers on data to be hashed. > + * Data must be in network byte order. > + * @param len > + * Length of the largest data buffer to be hashed. > + * @param val > + * Array of uint32_t where to put calculated Toeplitz hash values > + * @param num > + * Number of tuples to hash. > + */ > +__rte_experimental > +static inline void > +rte_thash_gfni_bulk(const uint64_t *mtrx __rte_unused, > + int len __rte_unused, uint8_t *tuple[] __rte_unused, > + uint32_t val[], uint32_t num) > +{ > + unsigned int i; > + > + RTE_LOG(ERR, HASH, "%s is undefined under given arch\n", __func__); > + for (i =3D 0; i < num; i++) > + val[i] =3D 0; > +} > + > +#endif /* RTE_THASH_GFNI_DEFINED */ > + > +#ifdef __cplusplus > +} > +#endif > + > +#endif /* _RTE_THASH_GFNI_H_ */ > diff --git a/lib/hash/rte_thash_x86_gfni.h b/lib/hash/rte_thash_x86_gfni.= h > new file mode 100644 > index 0000000..faa340a > --- /dev/null > +++ b/lib/hash/rte_thash_x86_gfni.h > @@ -0,0 +1,221 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(c) 2021 Intel Corporation > + */ > + > +#ifndef _RTE_THASH_X86_GFNI_H_ > +#define _RTE_THASH_X86_GFNI_H_ > + > +/** > + * @file > + * > + * Optimized Toeplitz hash functions implementation > + * using Galois Fields New Instructions. > + */ > + > +#include > + > +#ifdef __cplusplus > +extern "C" { > +#endif > + > +#ifdef __GFNI__ > +#define RTE_THASH_GFNI_DEFINED > + > +#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 =3D _mm512_castsi512_si256(xor_acc); > + tmp_256_2 =3D _mm512_extracti32x8_epi32(xor_acc, 1); > + tmp_256_1 =3D _mm256_xor_si256(tmp_256_1, tmp_256_2); > + > + tmp128_1 =3D _mm256_castsi256_si128(tmp_256_1); > + tmp128_2 =3D _mm256_extracti32x4_epi32(tmp_256_1, 1); > + tmp128_1 =3D _mm_xor_si128(tmp128_1, tmp128_2); > + > + tmp_1 =3D _mm_extract_epi64(tmp128_1, 0); > + tmp_2 =3D _mm_extract_epi64(tmp128_1, 1); > + tmp_1 ^=3D tmp_2; > + > + *val_1 =3D (uint32_t)tmp_1; > + *val_2 =3D (uint32_t)(tmp_1 >> 32); > +} > + > +__rte_internal > +static inline __m512i > +__rte_thash_gfni(const uint64_t *mtrx, const uint8_t *tuple, > + const uint8_t *secondary_tuple, int len) > +{ > + __m512i permute_idx =3D _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 =3D _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 =3D RTE_THASH_REWIND_MSK; > + const __m512i shift_8 =3D _mm512_set1_epi8(8); > + __m512i xor_acc =3D _mm512_setzero_si512(); > + __m512i perm_bytes =3D _mm512_setzero_si512(); > + __m512i vals, matrixes, tuple_bytes, tuple_bytes_2; > + __mmask64 load_mask, permute_mask, permute_mask_2; > + int chunk_len =3D 0, i =3D 0; > + uint8_t mtrx_msk; > + const int prepend =3D 3; > + > + for (; len > 0; len -=3D 64, tuple +=3D 64) { > + if (i =3D=3D 8) > + perm_bytes =3D _mm512_maskz_permutexvar_epi8(rewind_mask, > + rewind_idx, perm_bytes); > + > + permute_mask =3D RTE_THASH_FIRST_ITER_MSK; > + load_mask =3D (len >=3D 64) ? UINT64_MAX : ((1ULL << len) - 1); > + tuple_bytes =3D _mm512_maskz_loadu_epi8(load_mask, tuple); > + if (secondary_tuple) { > + permute_mask_2 =3D RTE_THASH_FIRST_ITER_MSK_2; > + tuple_bytes_2 =3D _mm512_maskz_loadu_epi8(load_mask, > + secondary_tuple); > + } > + > + chunk_len =3D __builtin_popcountll(load_mask); > + for (i =3D 0; i < ((chunk_len + prepend) / 8); i++, mtrx +=3D 8) { > + perm_bytes =3D _mm512_mask_permutexvar_epi8(perm_bytes, > + permute_mask, permute_idx, tuple_bytes); > + > + if (secondary_tuple) > + perm_bytes =3D > + _mm512_mask_permutexvar_epi8(perm_bytes, > + permute_mask_2, permute_idx, > + tuple_bytes_2); > + > + matrixes =3D _mm512_maskz_loadu_epi64(UINT8_MAX, mtrx); > + vals =3D _mm512_gf2p8affine_epi64_epi8(perm_bytes, > + matrixes, 0); > + > + xor_acc =3D _mm512_xor_si512(xor_acc, vals); > + permute_idx =3D _mm512_add_epi8(permute_idx, shift_8); > + permute_mask =3D RTE_THASH_PERM_MSK; > + if (secondary_tuple) > + permute_mask_2 =3D RTE_THASH_PERM_MSK_2; > + } > + } > + > + int rest_len =3D (chunk_len + prepend) % 8; > + if (rest_len !=3D 0) { > + mtrx_msk =3D (1 << (rest_len % 8)) - 1; > + matrixes =3D _mm512_maskz_loadu_epi64(mtrx_msk, mtrx); > + if (i =3D=3D 8) { > + perm_bytes =3D _mm512_maskz_permutexvar_epi8(rewind_mask, > + rewind_idx, perm_bytes); > + } else { > + perm_bytes =3D _mm512_mask_permutexvar_epi8(perm_bytes, > + permute_mask, permute_idx, tuple_bytes); > + > + if (secondary_tuple) > + perm_bytes =3D > + _mm512_mask_permutexvar_epi8( > + perm_bytes, permute_mask_2, > + permute_idx, tuple_bytes_2); > + } > + > + vals =3D _mm512_gf2p8affine_epi64_epi8(perm_bytes, matrixes, 0); > + xor_acc =3D _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(const uint64_t *m, const uint8_t *tuple, int len) > +{ > + uint32_t val, val_zero; > + > + __m512i xor_acc =3D __rte_thash_gfni(m, tuple, NULL, len); > + __rte_thash_xor_reduce(xor_acc, &val, &val_zero); > + > + return val; > +} > + > +/** > + * Bulk implementation for 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 > + * Array of the pointers on data to be hashed. > + * Data must be in network byte order. > + * @param len > + * Length of the largest data buffer to be hashed. > + * @param val > + * Array of uint32_t where to put calculated Toeplitz hash values > + * @param num > + * Number of tuples to hash. > + */ > +__rte_experimental > +static inline void > +rte_thash_gfni_bulk(const uint64_t *mtrx, int len, uint8_t *tuple[], > + uint32_t val[], uint32_t num) > +{ > + uint32_t i; > + uint32_t val_zero; > + __m512i xor_acc; > + > + for (i =3D 0; i !=3D (num & ~1); i +=3D 2) { > + xor_acc =3D __rte_thash_gfni(mtrx, tuple[i], tuple[i + 1], len); > + __rte_thash_xor_reduce(xor_acc, val + i, val + i + 1); > + } > + > + if (num & 1) { > + xor_acc =3D __rte_thash_gfni(mtrx, tuple[i], NULL, len); > + __rte_thash_xor_reduce(xor_acc, val + i, &val_zero); > + } > +} > + > +#endif /* _GFNI_ */ > + > +#ifdef __cplusplus > +} > +#endif > + > +#endif /* _RTE_THASH_X86_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; > }; > -- > 2.7.4