From: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
To: dev@dpdk.org
Cc: "Kamalakannan R ." <kamalakannan.r@intel.com>
Subject: [PATCH 4/6] pipeline: configure the hash function for regular tables
Date: Thu, 18 Aug 2022 11:44:47 +0000 [thread overview]
Message-ID: <20220818114449.1408226-5-cristian.dumitrescu@intel.com> (raw)
In-Reply-To: <20220818114449.1408226-1-cristian.dumitrescu@intel.com>
Make the hash function configurable for the regular pipeline tables.
Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
Signed-off-by: Kamalakannan R. <kamalakannan.r@intel.com>
---
lib/pipeline/rte_swx_ctl.c | 1 +
lib/pipeline/rte_swx_ctl.h | 3 ++
lib/pipeline/rte_swx_pipeline.c | 10 +++++++
lib/pipeline/rte_swx_pipeline.h | 24 +++++-----------
lib/pipeline/rte_swx_pipeline_internal.h | 1 +
lib/pipeline/rte_swx_pipeline_spec.c | 35 +++++++++++++++++++++++-
lib/pipeline/rte_swx_pipeline_spec.h | 1 +
7 files changed, 57 insertions(+), 18 deletions(-)
diff --git a/lib/pipeline/rte_swx_ctl.c b/lib/pipeline/rte_swx_ctl.c
index bdbcd8f50a..b6449f5f0c 100644
--- a/lib/pipeline/rte_swx_ctl.c
+++ b/lib/pipeline/rte_swx_ctl.c
@@ -272,6 +272,7 @@ table_params_get(struct rte_swx_ctl_pipeline *ctl, uint32_t table_id)
table->params.key_offset = key_offset;
table->params.key_mask0 = key_mask;
table->params.action_data_size = action_data_size;
+ table->params.hash_func = table->info.hash_func;
table->params.n_keys_max = table->info.size;
table->mf_first = first;
diff --git a/lib/pipeline/rte_swx_ctl.h b/lib/pipeline/rte_swx_ctl.h
index 63ee479e47..0694df557a 100644
--- a/lib/pipeline/rte_swx_ctl.h
+++ b/lib/pipeline/rte_swx_ctl.h
@@ -236,6 +236,9 @@ struct rte_swx_ctl_table_info {
*/
int default_action_is_const;
+ /** Hash function. */
+ rte_swx_hash_func_t hash_func;
+
/** Table size parameter. */
uint32_t size;
};
diff --git a/lib/pipeline/rte_swx_pipeline.c b/lib/pipeline/rte_swx_pipeline.c
index 2cac4caa95..e1227cbfcc 100644
--- a/lib/pipeline/rte_swx_pipeline.c
+++ b/lib/pipeline/rte_swx_pipeline.c
@@ -7986,6 +7986,7 @@ rte_swx_pipeline_table_config(struct rte_swx_pipeline *p,
struct table *t = NULL;
struct action *default_action;
struct header *header = NULL;
+ struct hash_func *hf = NULL;
uint32_t action_data_size_max = 0, i;
int status = 0;
@@ -8042,6 +8043,12 @@ rte_swx_pipeline_table_config(struct rte_swx_pipeline *p,
CHECK((default_action->st && params->default_action_args) || !params->default_action_args,
EINVAL);
+ /* Hash function checks. */
+ if (params->hash_func_name) {
+ hf = hash_func_find(p, params->hash_func_name);
+ CHECK(hf, EINVAL);
+ }
+
/* Table type checks. */
if (recommended_table_type_name)
CHECK_NAME(recommended_table_type_name, EINVAL);
@@ -8141,6 +8148,7 @@ rte_swx_pipeline_table_config(struct rte_swx_pipeline *p,
t->default_action_is_const = params->default_action_is_const;
t->action_data_size_max = action_data_size_max;
+ t->hf = hf;
t->size = size;
t->id = p->n_tables;
@@ -8227,6 +8235,7 @@ table_params_get(struct table *table)
params->key_offset = key_offset;
params->key_mask0 = key_mask;
params->action_data_size = action_data_size;
+ params->hash_func = table->hf ? table->hf->func : NULL;
params->n_keys_max = table->size;
return params;
@@ -10265,6 +10274,7 @@ rte_swx_ctl_table_info_get(struct rte_swx_pipeline *p,
table->n_match_fields = t->n_fields;
table->n_actions = t->n_actions;
table->default_action_is_const = t->default_action_is_const;
+ table->hash_func = t->hf ? t->hf->func : NULL;
table->size = t->size;
return 0;
}
diff --git a/lib/pipeline/rte_swx_pipeline.h b/lib/pipeline/rte_swx_pipeline.h
index 9c629d4118..09c75180f8 100644
--- a/lib/pipeline/rte_swx_pipeline.h
+++ b/lib/pipeline/rte_swx_pipeline.h
@@ -331,23 +331,6 @@ rte_swx_pipeline_extern_func_register(struct rte_swx_pipeline *p,
* Hash function.
*/
-/**
- * Hash function prototype
- *
- * @param[in] key
- * Key to hash. Must be non-NULL.
- * @param[in] length
- * Key length in bytes.
- * @param[in] seed
- * Hash seed.
- * @return
- * Hash value.
- */
-typedef uint32_t
-(*rte_swx_hash_func_t)(const void *key,
- uint32_t length,
- uint32_t seed);
-
/**
* Pipeline hash function register
*
@@ -699,6 +682,13 @@ struct rte_swx_pipeline_table_params {
* list.
*/
int default_action_is_const;
+
+ /** Hash function name. When not set to NULL, it must point to one of
+ * the hash functions that were registered for the current pipeline.
+ * Ignored by the table implementation when not needed. When needed but
+ * NULL, the table implementation will select the hash function to use.
+ */
+ const char *hash_func_name;
};
/**
diff --git a/lib/pipeline/rte_swx_pipeline_internal.h b/lib/pipeline/rte_swx_pipeline_internal.h
index 6d65b635c6..ee579c6656 100644
--- a/lib/pipeline/rte_swx_pipeline_internal.h
+++ b/lib/pipeline/rte_swx_pipeline_internal.h
@@ -828,6 +828,7 @@ struct table {
int *action_is_for_table_entries;
int *action_is_for_default_entry;
+ struct hash_func *hf;
uint32_t size;
uint32_t id;
};
diff --git a/lib/pipeline/rte_swx_pipeline_spec.c b/lib/pipeline/rte_swx_pipeline_spec.c
index 1b4183ef55..c0ca7335ff 100644
--- a/lib/pipeline/rte_swx_pipeline_spec.c
+++ b/lib/pipeline/rte_swx_pipeline_spec.c
@@ -509,7 +509,7 @@ action_block_parse(struct action_spec *s,
static void
table_spec_free(struct table_spec *s)
{
- uintptr_t default_action_name, default_action_args;
+ uintptr_t default_action_name, default_action_args, hash_func_name;
uint32_t i;
if (!s)
@@ -556,6 +556,10 @@ table_spec_free(struct table_spec *s)
s->params.default_action_is_const = 0;
+ hash_func_name = (uintptr_t)s->params.hash_func_name;
+ free((void *)hash_func_name);
+ s->params.hash_func_name = NULL;
+
free(s->recommended_table_type_name);
s->recommended_table_type_name = NULL;
@@ -935,6 +939,35 @@ table_block_parse(struct table_spec *s,
err_line,
err_msg);
+ if (!strcmp(tokens[0], "hash")) {
+ if (n_tokens != 2) {
+ if (err_line)
+ *err_line = n_lines;
+ if (err_msg)
+ *err_msg = "Invalid hash statement.";
+ return -EINVAL;
+ }
+
+ if (s->params.hash_func_name) {
+ if (err_line)
+ *err_line = n_lines;
+ if (err_msg)
+ *err_msg = "Duplicate hash statement.";
+ return -EINVAL;
+ }
+
+ s->params.hash_func_name = strdup(tokens[1]);
+ if (!s->params.hash_func_name) {
+ if (err_line)
+ *err_line = n_lines;
+ if (err_msg)
+ *err_msg = "Memory allocation failed.";
+ return -ENOMEM;
+ }
+
+ return 0;
+ }
+
if (!strcmp(tokens[0], "instanceof")) {
if (n_tokens != 2) {
if (err_line)
diff --git a/lib/pipeline/rte_swx_pipeline_spec.h b/lib/pipeline/rte_swx_pipeline_spec.h
index 62ac4ecfc4..dbe1b40adc 100644
--- a/lib/pipeline/rte_swx_pipeline_spec.h
+++ b/lib/pipeline/rte_swx_pipeline_spec.h
@@ -88,6 +88,7 @@ struct action_spec {
* ...
* }
* default_action ACTION_NAME args none | ARG0_NAME ARG0_VALUE ... [ const ]
+ * hash HASH_FUNCTION_NAME
* instanceof TABLE_TYPE_NAME
* pragma ARGS
* size SIZE
--
2.34.1
next prev 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 ` [PATCH 2/6] table: add key comparison functions Cristian Dumitrescu
2022-08-18 11:44 ` [PATCH 3/6] table: configure the hash function for regular tables Cristian Dumitrescu
2022-08-18 11:44 ` Cristian Dumitrescu [this message]
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-5-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).