DPDK patches and discussions
 help / color / mirror / Atom feed
From: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
To: dev@dpdk.org
Cc: "Kamalakannan R ." <kamalakannan.r@intel.com>
Subject: [PATCH 2/6] table: add key comparison functions
Date: Thu, 18 Aug 2022 11:44:45 +0000	[thread overview]
Message-ID: <20220818114449.1408226-3-cristian.dumitrescu@intel.com> (raw)
In-Reply-To: <20220818114449.1408226-1-cristian.dumitrescu@intel.com>

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

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
-- 
2.34.1


  parent reply	other threads:[~2022-08-18 11:45 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-18 11:44 [PATCH 0/6] pipeline: make the hash function configurable per table Cristian Dumitrescu
2022-08-18 11:44 ` [PATCH 1/6] table: add hash function prototype Cristian Dumitrescu
2022-08-18 11:44 ` Cristian Dumitrescu [this message]
2022-08-18 11:44 ` [PATCH 3/6] table: configure the hash function for regular tables Cristian Dumitrescu
2022-08-18 11:44 ` [PATCH 4/6] pipeline: " Cristian Dumitrescu
2022-08-18 11:44 ` [PATCH 5/6] table: configure the hash function for learner tables Cristian Dumitrescu
2022-08-18 11:44 ` [PATCH 6/6] pipeline: " Cristian Dumitrescu
2022-08-19 19:52 ` [PATCH V2 0/6] pipeline: make the hash function configurable per table Cristian Dumitrescu
2022-08-19 19:52   ` [PATCH V2 1/6] table: add hash function prototype Cristian Dumitrescu
2022-08-19 19:52   ` [PATCH V2 2/6] table: add key comparison functions Cristian Dumitrescu
2022-08-19 19:52   ` [PATCH V2 3/6] table: configure the hash function for regular tables Cristian Dumitrescu
2022-08-19 19:52   ` [PATCH V2 4/6] pipeline: " Cristian Dumitrescu
2022-08-19 19:52   ` [PATCH V2 5/6] table: configure the hash function for learner tables Cristian Dumitrescu
2022-08-19 19:52   ` [PATCH V2 6/6] pipeline: " Cristian Dumitrescu
2022-08-31 16:23   ` [PATCH V2 0/6] pipeline: make the hash function configurable per table Stephen Hemminger
2022-09-01  8:11     ` Morten Brørup
2022-09-23 15:58   ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220818114449.1408226-3-cristian.dumitrescu@intel.com \
    --to=cristian.dumitrescu@intel.com \
    --cc=dev@dpdk.org \
    --cc=kamalakannan.r@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).