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 38915A034C; Thu, 18 Aug 2022 13:45:23 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 35BBD4280B; Thu, 18 Aug 2022 13:45:07 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mails.dpdk.org (Postfix) with ESMTP id 82B1E40156 for ; Thu, 18 Aug 2022 13:45:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660823103; x=1692359103; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JImFg1pj8CbyTJKD9nQP6/R4kN5yz0YnqiUeN+C3MeI=; b=HAcL9wgWKmdnKs50qbSbfpQ2PRBGyly+wYirum2IaccX/FBWWsnRFvvA G7AAaLXMBGZUpgU2TGSmhvEGdlXcBboy15xGou8k5D4ZDn6sO0ZurjRtr mJxeeQqqnVjkFuV96odYZ0crImeoz0g1mOB8praNMJci/6ucIWv7MhXSz KLY8+7k1eTuokVu5GviQaF2BtilitZo01xvRyg8cF0hwKn6PrOjlEAgO1 izkeWWfY+vktHeJqrXwHBCu8S65TBn0Qerjgb7ZCkviEDJLXPCK6M6I6T +fS6bfYwRU12V3nVgVGnE1GWkZh3xhgD7jMXorqhwdbQofqvyVARjjZp1 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10442"; a="292735208" X-IronPort-AV: E=Sophos;i="5.93,246,1654585200"; d="scan'208";a="292735208" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Aug 2022 04:44:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,246,1654585200"; d="scan'208";a="668069701" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com.) ([10.237.223.157]) by fmsmga008.fm.intel.com with ESMTP; 18 Aug 2022 04:44:51 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Cc: "Kamalakannan R ." Subject: [PATCH 2/6] table: add key comparison functions Date: Thu, 18 Aug 2022 11:44:45 +0000 Message-Id: <20220818114449.1408226-3-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220818114449.1408226-1-cristian.dumitrescu@intel.com> References: <20220818114449.1408226-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