[2/6] table: add key comparison functions

Message ID 20220818114449.1408226-3-cristian.dumitrescu@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series pipeline: make the hash function configurable per table |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Cristian Dumitrescu Aug. 18, 2022, 11:44 a.m. UTC
  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 <cristian.dumitrescu@intel.com>
Signed-off-by: Kamalakannan R. <kamalakannan.r@intel.com>
---
 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
  

Patch

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 <rte_common.h>
+
+#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 <stdint.h>
+#include <string.h>
+
+/**
+ * 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