[dpdk-dev,v5,09/10] hash: rename rte_jhash2 to rte_jhash_32b

Message ID 1432289771-12799-10-git-send-email-pablo.de.lara.guarch@intel.com (mailing list archive)
State Superseded, archived
Headers

Commit Message

De Lara Guarch, Pablo May 22, 2015, 10:16 a.m. UTC
  Changed name to something more meaningful,
and mark rte_jhash2 as deprecated.

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
---
 app/test/test_func_reentrancy.c |    2 +-
 app/test/test_hash.c            |    4 ++--
 app/test/test_hash_functions.c  |    6 +++---
 lib/librte_hash/rte_jhash.h     |   17 +++++++++++++++--
 4 files changed, 21 insertions(+), 8 deletions(-)
  

Comments

Bruce Richardson June 10, 2015, 11:09 a.m. UTC | #1
On Fri, May 22, 2015 at 11:16:10AM +0100, Pablo de Lara wrote:
> Changed name to something more meaningful,
> and mark rte_jhash2 as deprecated.
> 
> Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
> ---
>  app/test/test_func_reentrancy.c |    2 +-
>  app/test/test_hash.c            |    4 ++--
>  app/test/test_hash_functions.c  |    6 +++---
>  lib/librte_hash/rte_jhash.h     |   17 +++++++++++++++--
>  4 files changed, 21 insertions(+), 8 deletions(-)
> 
<snip>
> @@ -278,7 +280,7 @@ rte_jhash_2hashes(const void *key, uint32_t length, uint32_t *pc, uint32_t *pb)
>   *   IN: second seed OUT: secondary hash value.
>   */
>  static inline void
> -rte_jhash2_2hashes(const uint32_t *k, uint32_t length, uint32_t *pc, uint32_t *pb)
> +rte_jhash_32b_2hashes(const uint32_t *k, uint32_t length, uint32_t *pc, uint32_t *pb)
>  {
>  	__rte_jhash_2hashes((const void *) k, (length << 2), pc, pb, 0);
>  }
> @@ -321,11 +323,22 @@ rte_jhash(const void *key, uint32_t length, uint32_t initval)
>   *   Calculated hash value.
>   */
>  static inline uint32_t
> +rte_jhash_32b(const uint32_t *k, uint32_t length, uint32_t initval)
> +{
> +	uint32_t initval2 = 0;
> +
> +	rte_jhash_32b_2hashes(k, length, &initval, &initval2);
> +
> +	return initval;
> +}
> +
> +static inline uint32_t
>  rte_jhash2(const uint32_t *k, uint32_t length, uint32_t initval)
>  {
>  	uint32_t initval2 = 0;
>  
> -	rte_jhash2_2hashes(k, length, &initval, &initval2);
> +	RTE_LOG(WARNING, HASH, "rte_jhash2 is deprecated\n");
> +	rte_jhash_32b_2hashes(k, length, &initval, &initval2);
>  
>  	return initval;
>  }

To deprecate this, rather than printing a message each time it is called, just
add "__attribute__((deprecated))" to the definition, and let the compiler do the
work of flagging this to the user.

/Bruce
  

Patch

diff --git a/app/test/test_func_reentrancy.c b/app/test/test_func_reentrancy.c
index dc070af..85504c0 100644
--- a/app/test/test_func_reentrancy.c
+++ b/app/test/test_func_reentrancy.c
@@ -228,7 +228,7 @@  hash_create_free(__attribute__((unused)) void *arg)
 		.entries = 16,
 		.bucket_entries = 4,
 		.key_len = 4,
-		.hash_func = (rte_hash_function)rte_jhash2,
+		.hash_func = (rte_hash_function)rte_jhash_32b,
 		.hash_func_init_val = 0,
 		.socket_id = 0,
 	};
diff --git a/app/test/test_hash.c b/app/test/test_hash.c
index 1da27c5..4ecb11b 100644
--- a/app/test/test_hash.c
+++ b/app/test/test_hash.c
@@ -1177,7 +1177,7 @@  test_hash_add_delete_jhash2(void)
 
 	hash_params_ex.name = "hash_test_jhash2";
 	hash_params_ex.key_len = 4;
-	hash_params_ex.hash_func = (rte_hash_function)rte_jhash2;
+	hash_params_ex.hash_func = (rte_hash_function)rte_jhash_32b;
 
 	handle = rte_hash_create(&hash_params_ex);
 	if (handle == NULL) {
@@ -1216,7 +1216,7 @@  test_hash_add_delete_2_jhash2(void)
 
 	hash_params_ex.name = "hash_test_2_jhash2";
 	hash_params_ex.key_len = 8;
-	hash_params_ex.hash_func = (rte_hash_function)rte_jhash2;
+	hash_params_ex.hash_func = (rte_hash_function)rte_jhash_32b;
 
 	handle = rte_hash_create(&hash_params_ex);
 	if (handle == NULL)
diff --git a/app/test/test_hash_functions.c b/app/test/test_hash_functions.c
index 976dd95..04b2862 100644
--- a/app/test/test_hash_functions.c
+++ b/app/test/test_hash_functions.c
@@ -208,7 +208,7 @@  verify_precalculated_hash_func_tests(void)
 }
 
 /*
- * Verify that rte_jhash and rte_jhash2 return the same
+ * Verify that rte_jhash and rte_jhash_32b return the same
  */
 static int
 verify_jhash_32bits(void)
@@ -226,10 +226,10 @@  verify_jhash_32bits(void)
 			if ((hashtest_key_lens[i] & 0x3) == 0) {
 				hash = rte_jhash(key, hashtest_key_lens[i], hashtest_initvals[j]);
 				/* Divide key length by 4 in rte_jhash for 32 bits */
-				hash32 = rte_jhash2((const uint32_t *)key, hashtest_key_lens[i] >> 2, hashtest_initvals[j]);
+				hash32 = rte_jhash_32b((const uint32_t *)key, hashtest_key_lens[i] >> 2, hashtest_initvals[j]);
 				if (hash != hash32) {
 					printf("rte_jhash returns different value (0x%x)"
-					       "than rte_jhash2 (0x%x)\n",
+					       "than rte_jhash_32b (0x%x)\n",
 					       hash, hash32);
 					return -1;
 				}
diff --git a/lib/librte_hash/rte_jhash.h b/lib/librte_hash/rte_jhash.h
index aa5bb2d..01b1795 100644
--- a/lib/librte_hash/rte_jhash.h
+++ b/lib/librte_hash/rte_jhash.h
@@ -46,6 +46,8 @@  extern "C" {
 
 #include <stdint.h>
 #include <string.h>
+
+#include <rte_log.h>
 #include <rte_byteorder.h>
 
 /* jhash.h: Jenkins hash support.
@@ -278,7 +280,7 @@  rte_jhash_2hashes(const void *key, uint32_t length, uint32_t *pc, uint32_t *pb)
  *   IN: second seed OUT: secondary hash value.
  */
 static inline void
-rte_jhash2_2hashes(const uint32_t *k, uint32_t length, uint32_t *pc, uint32_t *pb)
+rte_jhash_32b_2hashes(const uint32_t *k, uint32_t length, uint32_t *pc, uint32_t *pb)
 {
 	__rte_jhash_2hashes((const void *) k, (length << 2), pc, pb, 0);
 }
@@ -321,11 +323,22 @@  rte_jhash(const void *key, uint32_t length, uint32_t initval)
  *   Calculated hash value.
  */
 static inline uint32_t
+rte_jhash_32b(const uint32_t *k, uint32_t length, uint32_t initval)
+{
+	uint32_t initval2 = 0;
+
+	rte_jhash_32b_2hashes(k, length, &initval, &initval2);
+
+	return initval;
+}
+
+static inline uint32_t
 rte_jhash2(const uint32_t *k, uint32_t length, uint32_t initval)
 {
 	uint32_t initval2 = 0;
 
-	rte_jhash2_2hashes(k, length, &initval, &initval2);
+	RTE_LOG(WARNING, HASH, "rte_jhash2 is deprecated\n");
+	rte_jhash_32b_2hashes(k, length, &initval, &initval2);
 
 	return initval;
 }