* [dpdk-dev] [PATCH] hash: add rte_hash_set_cmp_func() function.
@ 2015-11-13 6:28 kamasamikon
2015-11-13 10:00 ` Bruce Richardson
0 siblings, 1 reply; 6+ messages in thread
From: kamasamikon @ 2015-11-13 6:28 UTC (permalink / raw)
To: dev; +Cc: Yu Nemo Wenbin
Give user a chance to costomize the hash key compare function.
The default rte_hash_cmp_eq function is set in the rte_hash_create
function, but these builtin ones may not good enough, so the user
may call this to override the default one.
Signed-off-by: Yu Nemo Wenbin <yuwb_bjy@ctbri.com.cn>
---
lib/librte_hash/rte_cuckoo_hash.c | 7 +++++--
lib/librte_hash/rte_hash.h | 12 ++++++++++++
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c
index 1e970de..71e2419 100644
--- a/lib/librte_hash/rte_cuckoo_hash.c
+++ b/lib/librte_hash/rte_cuckoo_hash.c
@@ -98,8 +98,6 @@ EAL_REGISTER_TAILQ(rte_hash_tailq)
#define LCORE_CACHE_SIZE 8
-typedef int (*rte_hash_cmp_eq_t)(const void *key1, const void *key2, size_t key_len);
-
struct lcore_cache {
unsigned len; /**< Cache len */
void *objs[LCORE_CACHE_SIZE]; /**< Cache objects */
@@ -183,6 +181,11 @@ rte_hash_find_existing(const char *name)
return h;
}
+void rte_hash_set_cmp_func(struct rte_hash *h, rte_hash_cmp_eq_t func)
+{
+ h->rte_hash_cmp_eq = func;
+}
+
struct rte_hash *
rte_hash_create(const struct rte_hash_parameters *params)
{
diff --git a/lib/librte_hash/rte_hash.h b/lib/librte_hash/rte_hash.h
index b678766..d626d1c 100644
--- a/lib/librte_hash/rte_hash.h
+++ b/lib/librte_hash/rte_hash.h
@@ -66,6 +66,9 @@ typedef uint32_t hash_sig_t;
typedef uint32_t (*rte_hash_function)(const void *key, uint32_t key_len,
uint32_t init_val);
+/** Type of function used to compare the key. It works like the memcmp() */
+typedef int (*rte_hash_cmp_eq_t)(const void *key1, const void *key2, size_t key_len);
+
/**
* Parameters used when creating the hash table.
*/
@@ -104,6 +107,15 @@ struct rte_hash *
rte_hash_create(const struct rte_hash_parameters *params);
/**
+ * Set the rte_hash_set_cmp_func.
+ * Set the new hash compare function if the default one is not suitable enough.
+ *
+ * @param h
+ * Hash table to reset
+ */
+void rte_hash_set_cmp_func(struct rte_hash *h, rte_hash_cmp_eq_t func);
+
+/**
* Find an existing hash table object and return a pointer to it.
*
* @param name
--
1.9.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [dpdk-dev] [PATCH] hash: add rte_hash_set_cmp_func() function.
2015-11-13 6:28 [dpdk-dev] [PATCH] hash: add rte_hash_set_cmp_func() function kamasamikon
@ 2015-11-13 10:00 ` Bruce Richardson
0 siblings, 0 replies; 6+ messages in thread
From: Bruce Richardson @ 2015-11-13 10:00 UTC (permalink / raw)
To: kamasamikon; +Cc: dev, Yu Nemo Wenbin
On Fri, Nov 13, 2015 at 02:28:13PM +0800, kamasamikon wrote:
> Give user a chance to costomize the hash key compare function.
> The default rte_hash_cmp_eq function is set in the rte_hash_create
> function, but these builtin ones may not good enough, so the user
> may call this to override the default one.
>
> Signed-off-by: Yu Nemo Wenbin <yuwb_bjy@ctbri.com.cn>
> ---
Hi,
Just a few small comments:
When adding a new function, you'll need to update the map file for the library
with the new API so it can be correctly versionned.
Also, using function pointers does not work with DPDK multi-process, so, at
minimum, you need to add to the doxygen documentation that your new function cannot
be used in multi-process mode.
/Bruce
^ permalink raw reply [flat|nested] 6+ messages in thread
* [dpdk-dev] [PATCH] hash: add rte_hash_set_cmp_func() function.
@ 2015-11-19 1:15 Yu Nemo Wenbin
2015-11-24 14:06 ` De Lara Guarch, Pablo
0 siblings, 1 reply; 6+ messages in thread
From: Yu Nemo Wenbin @ 2015-11-19 1:15 UTC (permalink / raw)
To: dev
Give user a chance to costomize the hash key compare function.
The default rte_hash_cmp_eq function is set in the rte_hash_create
function, but these builtin ones may not good enough, so the user
may call this to override the default one.
Signed-off-by: Yu Nemo Wenbin <yuwb_bjy@ctbri.com.cn>
---
lib/librte_hash/rte_cuckoo_hash.c | 7 +++++--
lib/librte_hash/rte_hash.h | 15 +++++++++++++++
lib/librte_hash/rte_hash_version.map | 1 +
3 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c
index 1e970de..71e2419 100644
--- a/lib/librte_hash/rte_cuckoo_hash.c
+++ b/lib/librte_hash/rte_cuckoo_hash.c
@@ -98,8 +98,6 @@ EAL_REGISTER_TAILQ(rte_hash_tailq)
#define LCORE_CACHE_SIZE 8
-typedef int (*rte_hash_cmp_eq_t)(const void *key1, const void *key2, size_t key_len);
-
struct lcore_cache {
unsigned len; /**< Cache len */
void *objs[LCORE_CACHE_SIZE]; /**< Cache objects */
@@ -183,6 +181,11 @@ rte_hash_find_existing(const char *name)
return h;
}
+void rte_hash_set_cmp_func(struct rte_hash *h, rte_hash_cmp_eq_t func)
+{
+ h->rte_hash_cmp_eq = func;
+}
+
struct rte_hash *
rte_hash_create(const struct rte_hash_parameters *params)
{
diff --git a/lib/librte_hash/rte_hash.h b/lib/librte_hash/rte_hash.h
index b678766..8378a42 100644
--- a/lib/librte_hash/rte_hash.h
+++ b/lib/librte_hash/rte_hash.h
@@ -66,6 +66,9 @@ typedef uint32_t hash_sig_t;
typedef uint32_t (*rte_hash_function)(const void *key, uint32_t key_len,
uint32_t init_val);
+/** Type of function used to compare the key. It works like the memcmp() */
+typedef int (*rte_hash_cmp_eq_t)(const void *key1, const void *key2, size_t key_len);
+
/**
* Parameters used when creating the hash table.
*/
@@ -104,6 +107,18 @@ struct rte_hash *
rte_hash_create(const struct rte_hash_parameters *params);
/**
+ * Set the rte_hash_set_cmp_func.
+ * Set the new hash compare function if the default one is not suitable enough.
+ *
+ * @note Function pointer does not work with multi-process, so don't use it
+ * in multi-process mode.
+ *
+ * @param h
+ * Hash table to reset
+ */
+void rte_hash_set_cmp_func(struct rte_hash *h, rte_hash_cmp_eq_t func);
+
+/**
* Find an existing hash table object and return a pointer to it.
*
* @param name
diff --git a/lib/librte_hash/rte_hash_version.map b/lib/librte_hash/rte_hash_version.map
index 906c8ad..3bc1e2c 100644
--- a/lib/librte_hash/rte_hash_version.map
+++ b/lib/librte_hash/rte_hash_version.map
@@ -30,5 +30,6 @@ DPDK_2.1 {
rte_hash_lookup_data;
rte_hash_lookup_with_hash_data;
rte_hash_reset;
+ rte_hash_set_cmp_func;
} DPDK_2.0;
--
1.9.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [dpdk-dev] [PATCH] hash: add rte_hash_set_cmp_func() function.
2015-11-19 1:15 Yu Nemo Wenbin
@ 2015-11-24 14:06 ` De Lara Guarch, Pablo
0 siblings, 0 replies; 6+ messages in thread
From: De Lara Guarch, Pablo @ 2015-11-24 14:06 UTC (permalink / raw)
To: Yu Nemo Wenbin, dev
Hi,
> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Yu Nemo Wenbin
> Sent: Thursday, November 19, 2015 1:15 AM
> To: dev@dpdk.org
> Subject: [dpdk-dev] [PATCH] hash: add rte_hash_set_cmp_func() function.
>
> Give user a chance to costomize the hash key compare function.
> The default rte_hash_cmp_eq function is set in the rte_hash_create
> function, but these builtin ones may not good enough, so the user
> may call this to override the default one.
Typos in "costomize" and "may not good" (may not be good)
>
> Signed-off-by: Yu Nemo Wenbin <yuwb_bjy@ctbri.com.cn>
> ---
> lib/librte_hash/rte_cuckoo_hash.c | 7 +++++--
> lib/librte_hash/rte_hash.h | 15 +++++++++++++++
> lib/librte_hash/rte_hash_version.map | 1 +
> 3 files changed, 21 insertions(+), 2 deletions(-)
>
> diff --git a/lib/librte_hash/rte_cuckoo_hash.c
> b/lib/librte_hash/rte_cuckoo_hash.c
> index 1e970de..71e2419 100644
> --- a/lib/librte_hash/rte_cuckoo_hash.c
> +++ b/lib/librte_hash/rte_cuckoo_hash.c
> @@ -98,8 +98,6 @@ EAL_REGISTER_TAILQ(rte_hash_tailq)
>
> #define LCORE_CACHE_SIZE 8
>
> -typedef int (*rte_hash_cmp_eq_t)(const void *key1, const void *key2,
> size_t key_len);
> -
> struct lcore_cache {
> unsigned len; /**< Cache len */
> void *objs[LCORE_CACHE_SIZE]; /**< Cache objects */
> @@ -183,6 +181,11 @@ rte_hash_find_existing(const char *name)
> return h;
> }
>
> +void rte_hash_set_cmp_func(struct rte_hash *h, rte_hash_cmp_eq_t
> func)
> +{
> + h->rte_hash_cmp_eq = func;
> +}
> +
> struct rte_hash *
> rte_hash_create(const struct rte_hash_parameters *params)
> {
> diff --git a/lib/librte_hash/rte_hash.h b/lib/librte_hash/rte_hash.h
> index b678766..8378a42 100644
> --- a/lib/librte_hash/rte_hash.h
> +++ b/lib/librte_hash/rte_hash.h
> @@ -66,6 +66,9 @@ typedef uint32_t hash_sig_t;
> typedef uint32_t (*rte_hash_function)(const void *key, uint32_t key_len,
> uint32_t init_val);
>
> +/** Type of function used to compare the key. It works like the memcmp()
> */
Remove "the".
> +typedef int (*rte_hash_cmp_eq_t)(const void *key1, const void *key2,
> size_t key_len);
> +
> /**
> * Parameters used when creating the hash table.
> */
> @@ -104,6 +107,18 @@ struct rte_hash *
> rte_hash_create(const struct rte_hash_parameters *params);
>
> /**
> + * Set the rte_hash_set_cmp_func.
> + * Set the new hash compare function if the default one is not suitable
> enough.
> + *
> + * @note Function pointer does not work with multi-process, so don't use
> it
> + * in multi-process mode.
> + *
> + * @param h
> + * Hash table to reset
> + */
> +void rte_hash_set_cmp_func(struct rte_hash *h, rte_hash_cmp_eq_t
> func);
> +
> +/**
> * Find an existing hash table object and return a pointer to it.
> *
> * @param name
> diff --git a/lib/librte_hash/rte_hash_version.map
> b/lib/librte_hash/rte_hash_version.map
> index 906c8ad..3bc1e2c 100644
> --- a/lib/librte_hash/rte_hash_version.map
> +++ b/lib/librte_hash/rte_hash_version.map
> @@ -30,5 +30,6 @@ DPDK_2.1 {
> rte_hash_lookup_data;
> rte_hash_lookup_with_hash_data;
> rte_hash_reset;
> + rte_hash_set_cmp_func;
>
> } DPDK_2.0;
> --
> 1.9.1
You have to add the new function in a different set (create a new one for 2.2).
Thanks,
Pablo
^ permalink raw reply [flat|nested] 6+ messages in thread
* [dpdk-dev] [PATCH] hash: add rte_hash_set_cmp_func() function.
@ 2015-11-27 2:11 Yu Nemo Wenbin
2015-11-30 8:34 ` De Lara Guarch, Pablo
0 siblings, 1 reply; 6+ messages in thread
From: Yu Nemo Wenbin @ 2015-11-27 2:11 UTC (permalink / raw)
To: dev
Give user a chance to customize the hash key compare function.
The default rte_hash_cmp_eq function is set in the rte_hash_create
function, but these builtin ones may not be good enough, so the user
may call this to override the default one.
Signed-off-by: Yu Nemo Wenbin <yuwb_bjy@ctbri.com.cn>
---
lib/librte_hash/rte_cuckoo_hash.c | 7 +++++--
lib/librte_hash/rte_hash.h | 15 +++++++++++++++
lib/librte_hash/rte_hash_version.map | 7 +++++++
3 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c
index 88f77c3..2ccb81c 100644
--- a/lib/librte_hash/rte_cuckoo_hash.c
+++ b/lib/librte_hash/rte_cuckoo_hash.c
@@ -102,8 +102,6 @@ EAL_REGISTER_TAILQ(rte_hash_tailq)
#define LCORE_CACHE_SIZE 8
-typedef int (*rte_hash_cmp_eq_t)(const void *key1, const void *key2, size_t key_len);
-
struct lcore_cache {
unsigned len; /**< Cache len */
void *objs[LCORE_CACHE_SIZE]; /**< Cache objects */
@@ -187,6 +185,11 @@ rte_hash_find_existing(const char *name)
return h;
}
+void rte_hash_set_cmp_func(struct rte_hash *h, rte_hash_cmp_eq_t func)
+{
+ h->rte_hash_cmp_eq = func;
+}
+
struct rte_hash *
rte_hash_create(const struct rte_hash_parameters *params)
{
diff --git a/lib/librte_hash/rte_hash.h b/lib/librte_hash/rte_hash.h
index b678766..dfca5ef 100644
--- a/lib/librte_hash/rte_hash.h
+++ b/lib/librte_hash/rte_hash.h
@@ -66,6 +66,9 @@ typedef uint32_t hash_sig_t;
typedef uint32_t (*rte_hash_function)(const void *key, uint32_t key_len,
uint32_t init_val);
+/** Type of function used to compare the hash key. */
+typedef int (*rte_hash_cmp_eq_t)(const void *key1, const void *key2, size_t key_len);
+
/**
* Parameters used when creating the hash table.
*/
@@ -104,6 +107,18 @@ struct rte_hash *
rte_hash_create(const struct rte_hash_parameters *params);
/**
+ * Set the rte_hash_set_cmp_func.
+ * Set a new hash compare function other than the default one.
+ *
+ * @note Function pointer does not work with multi-process, so don't use it
+ * in multi-process mode.
+ *
+ * @param h
+ * Hash table to reset
+ */
+void rte_hash_set_cmp_func(struct rte_hash *h, rte_hash_cmp_eq_t func);
+
+/**
* Find an existing hash table object and return a pointer to it.
*
* @param name
diff --git a/lib/librte_hash/rte_hash_version.map b/lib/librte_hash/rte_hash_version.map
index 906c8ad..1aa94f9 100644
--- a/lib/librte_hash/rte_hash_version.map
+++ b/lib/librte_hash/rte_hash_version.map
@@ -32,3 +32,10 @@ DPDK_2.1 {
rte_hash_reset;
} DPDK_2.0;
+
+DPDK_2.2 {
+ global:
+
+ rte_hash_set_cmp_func;
+
+} DPDK_2.1;
--
1.9.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [dpdk-dev] [PATCH] hash: add rte_hash_set_cmp_func() function.
2015-11-27 2:11 Yu Nemo Wenbin
@ 2015-11-30 8:34 ` De Lara Guarch, Pablo
0 siblings, 0 replies; 6+ messages in thread
From: De Lara Guarch, Pablo @ 2015-11-30 8:34 UTC (permalink / raw)
To: Yu Nemo Wenbin, dev
Hi,
> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Yu Nemo Wenbin
> Sent: Friday, November 27, 2015 2:11 AM
> To: dev@dpdk.org
> Subject: [dpdk-dev] [PATCH] hash: add rte_hash_set_cmp_func() function.
>
> Give user a chance to customize the hash key compare function.
> The default rte_hash_cmp_eq function is set in the rte_hash_create
> function, but these builtin ones may not be good enough, so the user
> may call this to override the default one.
>
> Signed-off-by: Yu Nemo Wenbin <yuwb_bjy@ctbri.com.cn>
> ---
> lib/librte_hash/rte_cuckoo_hash.c | 7 +++++--
> lib/librte_hash/rte_hash.h | 15 +++++++++++++++
> lib/librte_hash/rte_hash_version.map | 7 +++++++
> 3 files changed, 27 insertions(+), 2 deletions(-)
>
> diff --git a/lib/librte_hash/rte_cuckoo_hash.c
> b/lib/librte_hash/rte_cuckoo_hash.c
> index 88f77c3..2ccb81c 100644
> --- a/lib/librte_hash/rte_cuckoo_hash.c
> +++ b/lib/librte_hash/rte_cuckoo_hash.c
> @@ -102,8 +102,6 @@ EAL_REGISTER_TAILQ(rte_hash_tailq)
>
> #define LCORE_CACHE_SIZE 8
>
> -typedef int (*rte_hash_cmp_eq_t)(const void *key1, const void *key2,
> size_t key_len);
> -
> struct lcore_cache {
> unsigned len; /**< Cache len */
> void *objs[LCORE_CACHE_SIZE]; /**< Cache objects */
> @@ -187,6 +185,11 @@ rte_hash_find_existing(const char *name)
> return h;
> }
>
> +void rte_hash_set_cmp_func(struct rte_hash *h, rte_hash_cmp_eq_t
> func)
> +{
> + h->rte_hash_cmp_eq = func;
> +}
> +
> struct rte_hash *
> rte_hash_create(const struct rte_hash_parameters *params)
> {
> diff --git a/lib/librte_hash/rte_hash.h b/lib/librte_hash/rte_hash.h
> index b678766..dfca5ef 100644
> --- a/lib/librte_hash/rte_hash.h
> +++ b/lib/librte_hash/rte_hash.h
> @@ -66,6 +66,9 @@ typedef uint32_t hash_sig_t;
> typedef uint32_t (*rte_hash_function)(const void *key, uint32_t key_len,
> uint32_t init_val);
>
> +/** Type of function used to compare the hash key. */
> +typedef int (*rte_hash_cmp_eq_t)(const void *key1, const void *key2,
> size_t key_len);
> +
> /**
> * Parameters used when creating the hash table.
> */
> @@ -104,6 +107,18 @@ struct rte_hash *
> rte_hash_create(const struct rte_hash_parameters *params);
>
> /**
> + * Set the rte_hash_set_cmp_func.
> + * Set a new hash compare function other than the default one.
> + *
> + * @note Function pointer does not work with multi-process, so don't use
> it
> + * in multi-process mode.
> + *
> + * @param h
> + * Hash table to reset
> + */
> +void rte_hash_set_cmp_func(struct rte_hash *h, rte_hash_cmp_eq_t
> func);
> +
> +/**
> * Find an existing hash table object and return a pointer to it.
> *
> * @param name
> diff --git a/lib/librte_hash/rte_hash_version.map
> b/lib/librte_hash/rte_hash_version.map
> index 906c8ad..1aa94f9 100644
> --- a/lib/librte_hash/rte_hash_version.map
> +++ b/lib/librte_hash/rte_hash_version.map
> @@ -32,3 +32,10 @@ DPDK_2.1 {
> rte_hash_reset;
>
> } DPDK_2.0;
> +
> +DPDK_2.2 {
> + global:
> +
> + rte_hash_set_cmp_func;
> +
> +} DPDK_2.1;
> --
> 1.9.1
Acked-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
Although, you needed to send this as a v2 (or v3?)!
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-11-30 8:34 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-13 6:28 [dpdk-dev] [PATCH] hash: add rte_hash_set_cmp_func() function kamasamikon
2015-11-13 10:00 ` Bruce Richardson
2015-11-19 1:15 Yu Nemo Wenbin
2015-11-24 14:06 ` De Lara Guarch, Pablo
2015-11-27 2:11 Yu Nemo Wenbin
2015-11-30 8:34 ` De Lara Guarch, Pablo
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).