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 24B18A04FD; Fri, 19 Aug 2022 21:52:41 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 85BD441611; Fri, 19 Aug 2022 21:52:31 +0200 (CEST) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mails.dpdk.org (Postfix) with ESMTP id 740A240689 for ; Fri, 19 Aug 2022 21:52:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660938749; x=1692474749; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JImFg1pj8CbyTJKD9nQP6/R4kN5yz0YnqiUeN+C3MeI=; b=e1gjg/9NunOZnPBL+U0jLs1d6z5FfNSs/DjV2Q2IUGum1ahs5tilatOi ZoRjnM/CLBsUa+3yTQMB5UKiGdcjkDdtZQ5e4roN2Zq6Y9okj+R9XmydH f1GRJytkoAgRWBtqrPGO+/NC2S8FwXAxYvW0KWjnGEZkUIUTXAFYnjr0c av4vsAtoGdWCCsEG6cqeiTi9RHS7Umq1a/Qkpb1O8zB+DY1/K1C5NV0Bx WfLeD00TlsT2Q5o+7wMuJAx1/6pn8aQobNbjyaRmEokHcBLO/Ingy1jaf mrMMTW+lXpbiUwoVq3mZmbpYP5DM71ep0Iq/UHUzFAlvs3dadGBGxS6Lf A==; X-IronPort-AV: E=McAfee;i="6500,9779,10444"; a="280047521" X-IronPort-AV: E=Sophos;i="5.93,249,1654585200"; d="scan'208";a="280047521" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Aug 2022 12:52:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,248,1654585200"; d="scan'208";a="604695948" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com.) ([10.237.223.157]) by orsmga007.jf.intel.com with ESMTP; 19 Aug 2022 12:52:28 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Cc: "Kamalakannan R ." Subject: [PATCH V2 2/6] table: add key comparison functions Date: Fri, 19 Aug 2022 19:52:21 +0000 Message-Id: <20220819195225.1483020-3-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220819195225.1483020-1-cristian.dumitrescu@intel.com> References: <20220818114449.1408226-1-cristian.dumitrescu@intel.com> <20220819195225.1483020-1-cristian.dumitrescu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Add key comparison functions to be used by the exact match and the learner table types as part of the performance critical lookup operation. Since the key size is fixed, it is possible to select a specialized memory copy function as opposed to using the variable size version, resulting in a performance improvement of around 5%. Signed-off-by: Cristian Dumitrescu Signed-off-by: Kamalakannan R. --- lib/table/meson.build | 1 + lib/table/rte_swx_keycmp.c | 166 +++++++++++++++++++++++++++++++++++++ lib/table/rte_swx_keycmp.h | 49 +++++++++++ 3 files changed, 216 insertions(+) create mode 100644 lib/table/rte_swx_keycmp.c create mode 100644 lib/table/rte_swx_keycmp.h diff --git a/lib/table/meson.build b/lib/table/meson.build index 6d4272c4ef..af749e4007 100644 --- a/lib/table/meson.build +++ b/lib/table/meson.build @@ -8,6 +8,7 @@ if is_windows endif sources = files( + 'rte_swx_keycmp.c', 'rte_swx_table_em.c', 'rte_swx_table_learner.c', 'rte_swx_table_selector.c', diff --git a/lib/table/rte_swx_keycmp.c b/lib/table/rte_swx_keycmp.c new file mode 100644 index 0000000000..ec65f5c822 --- /dev/null +++ b/lib/table/rte_swx_keycmp.c @@ -0,0 +1,166 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2022 Intel Corporation + */ +#include + +#include "rte_swx_keycmp.h" + +static uint32_t +keycmp_generic(void *key1, void *key2, uint32_t key_size) +{ + return memcmp(key1, key2, key_size) ? 0 : 1; +} + +#define KEYCMP(N) \ +static uint32_t \ +keycmp##N(void *key1, void *key2, uint32_t key_size __rte_unused) \ +{ \ + return memcmp(key1, key2, N) ? 0 : 1; \ +} + +KEYCMP(1) +KEYCMP(2) +KEYCMP(3) +KEYCMP(4) +KEYCMP(5) +KEYCMP(6) +KEYCMP(7) +KEYCMP(8) +KEYCMP(9) + +KEYCMP(10) +KEYCMP(11) +KEYCMP(12) +KEYCMP(13) +KEYCMP(14) +KEYCMP(15) +KEYCMP(16) +KEYCMP(17) +KEYCMP(18) +KEYCMP(19) + +KEYCMP(20) +KEYCMP(21) +KEYCMP(22) +KEYCMP(23) +KEYCMP(24) +KEYCMP(25) +KEYCMP(26) +KEYCMP(27) +KEYCMP(28) +KEYCMP(29) + +KEYCMP(30) +KEYCMP(31) +KEYCMP(32) +KEYCMP(33) +KEYCMP(34) +KEYCMP(35) +KEYCMP(36) +KEYCMP(37) +KEYCMP(38) +KEYCMP(39) + +KEYCMP(40) +KEYCMP(41) +KEYCMP(42) +KEYCMP(43) +KEYCMP(44) +KEYCMP(45) +KEYCMP(46) +KEYCMP(47) +KEYCMP(48) +KEYCMP(49) + +KEYCMP(50) +KEYCMP(51) +KEYCMP(52) +KEYCMP(53) +KEYCMP(54) +KEYCMP(55) +KEYCMP(56) +KEYCMP(57) +KEYCMP(58) +KEYCMP(59) + +KEYCMP(60) +KEYCMP(61) +KEYCMP(62) +KEYCMP(63) +KEYCMP(64) + +static rte_swx_keycmp_func_t keycmp_funcs[] = { + keycmp1, + keycmp2, + keycmp3, + keycmp4, + keycmp5, + keycmp6, + keycmp7, + keycmp8, + keycmp9, + keycmp10, + keycmp11, + keycmp12, + keycmp13, + keycmp14, + keycmp15, + keycmp16, + keycmp17, + keycmp18, + keycmp19, + keycmp20, + keycmp21, + keycmp22, + keycmp23, + keycmp24, + keycmp25, + keycmp26, + keycmp27, + keycmp28, + keycmp29, + keycmp30, + keycmp31, + keycmp32, + keycmp33, + keycmp34, + keycmp35, + keycmp36, + keycmp37, + keycmp38, + keycmp39, + keycmp40, + keycmp41, + keycmp42, + keycmp43, + keycmp44, + keycmp45, + keycmp46, + keycmp47, + keycmp48, + keycmp49, + keycmp50, + keycmp51, + keycmp52, + keycmp53, + keycmp54, + keycmp55, + keycmp56, + keycmp57, + keycmp58, + keycmp59, + keycmp60, + keycmp61, + keycmp62, + keycmp63, + keycmp64, +}; + +rte_swx_keycmp_func_t +rte_swx_keycmp_func_get(uint32_t key_size) +{ + if (key_size && key_size <= 64) + return keycmp_funcs[key_size - 1]; + + return keycmp_generic; +} diff --git a/lib/table/rte_swx_keycmp.h b/lib/table/rte_swx_keycmp.h new file mode 100644 index 0000000000..09fb1be869 --- /dev/null +++ b/lib/table/rte_swx_keycmp.h @@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2022 Intel Corporation + */ +#ifndef __INCLUDE_RTE_SWX_KEYCMP_H__ +#define __INCLUDE_RTE_SWX_KEYCMP_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file + * RTE SWX Key Comparison Functions + */ + +#include +#include + +/** + * Key comparison function prototype + * + * @param[in] key1 + * First key to compare. Must be non-NULL. + * @param[in] key2 + * Second key to compare. Must be non-NULL. + * @param[in] key_size + * Key size in bytes. + * @return + * 0 when keys are different, 1 when keys are equal. + */ +typedef uint32_t +(*rte_swx_keycmp_func_t)(void *key1, void *key2, uint32_t key_size); + +/** + * Key comparison function get + * + * @param[in] key_size + * Key size in bytes. + * @return + * Key comparison function for the given key size + */ +rte_swx_keycmp_func_t +rte_swx_keycmp_func_get(uint32_t key_size); + +#ifdef __cplusplus +} +#endif + +#endif -- 2.34.1