Skip to contentSkip to conversation

table: fix build error with gcc 8

PATCH In review Jasvinder Singh 8 participants 16 messages Apr 9, 2018 – Apr 10, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 table: fix build error with gcc 8

Fix build error with gcc 8.0 due to cast between function types.

Fixes 5a80bf0ae613 ("table: add cuckoo hash")
---
 lib/librte_table/rte_table_hash_cuckoo.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/librte_table/rte_table_hash_cuckoo.c +3 -1
index dcb4fe9..f7eae27 100644
@@ -103,11 +103,13 @@ rte_table_hash_cuckoo_create(void *params,
 		return NULL;
 	}
 
+	void *hash_func = p->f_hash;
+
 	/* Create cuckoo hash table */
 	struct rte_hash_parameters hash_cuckoo_params = {
 		.entries = p->n_keys,
 		.key_len = p->key_size,
-		.hash_func = (rte_hash_function)(p->f_hash),
+		.hash_func = (rte_hash_function) hash_func,
 		.hash_func_init_val = p->seed,
 		.socket_id = socket_id,
 		.name = p->name
Signature · 1 line
2.9.3
Acked-by on v1 1/1
#1 lore raw
Quoted 38 lines

-----Original Message-----
From: Singh, Jasvinder
Sent: Monday, April 9, 2018 1:50 PM
To: [email protected]
Cc: Dumitrescu, Cristian <[email protected]>
Subject: [PATCH] table: fix build error with gcc 8

Fix build error with gcc 8.0 due to cast between function types.

Fixes 5a80bf0ae613 ("table: add cuckoo hash")
---
 lib/librte_table/rte_table_hash_cuckoo.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/librte_table/rte_table_hash_cuckoo.c +3 -2
index dcb4fe9..f7eae27 100644
@@ -103,11 +103,13 @@ rte_table_hash_cuckoo_create(void *params,
 		return NULL;
 	}
 
+	void *hash_func = p->f_hash;
+
 	/* Create cuckoo hash table */
 	struct rte_hash_parameters hash_cuckoo_params = {
 		.entries = p->n_keys,
 		.key_len = p->key_size,
-		.hash_func = (rte_hash_function)(p->f_hash),
+		.hash_func = (rte_hash_function) hash_func,
 		.hash_func_init_val = p->seed,
 		.socket_id = socket_id,
 		.name = p->name
--
Quoted 1 line

2.9.3

#3 lore raw
Quoted 9 lines

-----Original Message-----
From: Richardson, Bruce
Sent: Monday, April 9, 2018 2:09 PM
To: Singh, Jasvinder <[email protected]>
Cc: [email protected]; Dumitrescu, Cristian <[email protected]>
Subject: Re: [dpdk-dev] [PATCH] table: fix build error with gcc 8

On Mon, Apr 09, 2018 at 01:49:48PM +0100, Jasvinder Singh wrote:

Quoted 8 lines
Quoted 4 lines

Fix build error with gcc 8.0 due to cast between function types.

Fixes 5a80bf0ae613 ("table: add cuckoo hash")

What's the actual error message? Why do the types not match?

/Bruce

Error log is captured below;

CC rte_table_hash_cuckoo.o
/librte_table/rte_table_hash_cuckoo.c: In function 'rte_table_hash_cuckoo_create':
/librte_table/rte_table_hash_cuckoo.c:110:16: error: cast between incompatible
function types from 'rte_table_hash_op_hash' {aka 'long unsigned int (*)(void *, void *, unsigned int, long unsigned int)'} to 'uint32_t (*)(const void *, uint32_t, uint32_t)' {aka 'unsigned int (*)(const void *, unsigned int, unsigned int)'} [-Werror=cast-function-type]
.hash_func = (rte_hash_function) p->f_hash,

                ^

cc1: all warnings being treated as errors

#6 lore raw
In reply to Jasvinder Singh
Quoted 17 lines · On Mon, 9 Apr 2018 13:49:48 +0100 Jasvinder Singh <[email protected]>…

Fix build error with gcc 8.0 due to cast between function types.

Fixes 5a80bf0ae613 ("table: add cuckoo hash")
---
 lib/librte_table/rte_table_hash_cuckoo.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/librte_table/rte_table_hash_cuckoo.c +1 -0
index dcb4fe9..f7eae27 100644
@@ -103,11 +103,13 @@ rte_table_hash_cuckoo_create(void *params,
 		return NULL;
 	}
 
+	void *hash_func = p->f_hash;

lib/librte_table/rte_table_hash_cuckoo.c rte_table_hash_cuckoo_create(void *params, · line 115

Quoted 10 lines
lib/librte_table/rte_table_hash_cuckoo.c +2 -1
+
 	/* Create cuckoo hash table */
 	struct rte_hash_parameters hash_cuckoo_params = {
 		.entries = p->n_keys,
 		.key_len = p->key_size,
-		.hash_func = (rte_hash_function)(p->f_hash),
+		.hash_func = (rte_hash_function) hash_func,
 		.hash_func_init_val = p->seed,
 		.socket_id = socket_id,
 		.name = p->name

This is just tricking the compiler into not complaining. I would really rather see the two hash functions made the same.

#4 lore raw
In reply to Singh, Jasvinder
Quoted 20 lines · Jasvinder
Quoted 9 lines

-----Original Message-----
From: Richardson, Bruce
Sent: Monday, April 9, 2018 2:09 PM
To: Singh, Jasvinder <[email protected]>
Cc: [email protected]; Dumitrescu, Cristian <[email protected]>
Subject: Re: [dpdk-dev] [PATCH] table: fix build error with gcc 8

On Mon, Apr 09, 2018 at 01:49:48PM +0100, Jasvinder Singh wrote:

Quoted 8 lines
Quoted 4 lines

Fix build error with gcc 8.0 due to cast between function types.

Fixes 5a80bf0ae613 ("table: add cuckoo hash")

What's the actual error message? Why do the types not match?

/Bruce

Error log is captured below;

Quoted 9 lines

CC rte_table_hash_cuckoo.o
/librte_table/rte_table_hash_cuckoo.c: In function 'rte_table_hash_cuckoo_create':
/librte_table/rte_table_hash_cuckoo.c:110:16: error: cast between incompatible
function types from 'rte_table_hash_op_hash' {aka 'long unsigned int (*)(void *, void *, unsigned int, long unsigned int)'} to 'uint32_t (*)(const void *, uint32_t, uint32_t)' {aka 'unsigned int (*)(const void *, unsigned int, unsigned int)'} [-Werror=cast-function-type]
.hash_func = (rte_hash_function) p->f_hash,

                ^

cc1: all warnings being treated as errors

Even if the compiler isn't complaining now, how can that cast work? Looking at the error message given, it appears there are two big issues:

1. The expected function call takes 3 parameters:

	(const void *, uint32_t,  uint32_t),

but you are giving it a function that takes 4 parameters:
(void *, void *, unsigned int, long unsigned int)
2. The return type expected is "unsigned int", but you are giving a function returning "long unsigned int". On 32-bit systems, these are going to be the same size, but on 64-bit, they will be different. Similarly for the last function argument.

Is the error message correct?

/Bruce

#7 lore raw
In reply to Stephen Hemminger
Quoted 29 lines

-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Monday, April 9, 2018 4:10 PM
To: Singh, Jasvinder <[email protected]>
Cc: [email protected]; Dumitrescu, Cristian <[email protected]>
Subject: Re: [dpdk-dev] [PATCH] table: fix build error with gcc 8

Review

Quoted 9 lines · On Mon, 9 Apr 2018 13:49:48 +0100 Jasvinder Singh <[email protected]>…

Fix build error with gcc 8.0 due to cast between function types.

Fixes 5a80bf0ae613 ("table: add cuckoo hash")
---
 lib/librte_table/rte_table_hash_cuckoo.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/lib/librte_table/rte_table_hash_cuckoo.c

Quoted 7 lines

index dcb4fe9..f7eae27 100644

lib/librte_table/rte_table_hash_cuckoo.c +0 -0
@@ -103,11 +103,13 @@ rte_table_hash_cuckoo_create(void *params,
 		return NULL;
 	}
 
Quoted 14 lines

lib/librte_table/rte_table_hash_cuckoo.c rte_table_hash_cuckoo_create(void *params, · line 115

Quoted 11 lines
lib/librte_table/rte_table_hash_cuckoo.c +3 -1
+	void *hash_func = p->f_hash;
+
 	/* Create cuckoo hash table */
 	struct rte_hash_parameters hash_cuckoo_params = {
 		.entries = p->n_keys,
 		.key_len = p->key_size,
-		.hash_func = (rte_hash_function)(p->f_hash),
+		.hash_func = (rte_hash_function) hash_func,
 		.hash_func_init_val = p->seed,
 		.socket_id = socket_id,
 		.name = p->name

This is just tricking the compiler into not complaining. I would really rather see the two hash functions made the same.

(Adding Bruce as well to consolidate all conversations in a single thread.)

What we want to do here is be able to use the librte_hash under the same API as the several hash table flavors implemented in librte_table.

Both of these libraries allow configuring the hash function per each hash table instance. Problem is: hash function in librte_hash has only 3 parameters (no key mask), while hash function in librte_table has 4 parameters (includes key mask). The key mask helps a lot for practical protocol implementations by avoiding key copy & pre-process on lookup.

So then: how to plug in librte_hash under the same API as the suite of hash tables in librte_table? We don't want to re-implement cuckoo hash from librte_hash, we simply want to invoke it as a low-level primitive, similarly to how the LPM and ACL tables are plugged into librte_table.

Solution is: as an exception, pass a 3-parameter hash function to cuckoo hash flavor under the librte_table. Maybe this should be documented better. This currently triggers a build warning with gcc 8, which is easy to fix, hence this trivial patch.

Ideally, for every 3-parameter hash function, I would like to generate the corresponding 4-parameter hash function on-the-fly, but unfortunately this is not what C language can do.

Of course, IMO the best solution is to add key mask support to librte_hash.

Regards,
Cristian

#8 lore raw
Quoted 72 lines

From: dev [mailto:[email protected]] On Behalf Of Dumitrescu, Cristian
Sent: Monday, April 9, 2018 4:59 PM
To: Stephen Hemminger <[email protected]>; Singh, Jasvinder <[email protected]>; Richardson, Bruce <[email protected]>
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH] table: fix build error with gcc 8

Quoted 27 lines

-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Monday, April 9, 2018 4:10 PM
To: Singh, Jasvinder <[email protected]>
Cc: [email protected]; Dumitrescu, Cristian <[email protected]>
Subject: Re: [dpdk-dev] [PATCH] table: fix build error with gcc 8

Review

Quoted 9 lines · On Mon, 9 Apr 2018 13:49:48 +0100 Jasvinder Singh <[email protected]>…

Fix build error with gcc 8.0 due to cast between function types.

Fixes 5a80bf0ae613 ("table: add cuckoo hash")
---
 lib/librte_table/rte_table_hash_cuckoo.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/lib/librte_table/rte_table_hash_cuckoo.c

Quoted 7 lines

index dcb4fe9..f7eae27 100644

lib/librte_table/rte_table_hash_cuckoo.c +0 -0
@@ -103,11 +103,13 @@ rte_table_hash_cuckoo_create(void *params,
 		return NULL;
 	}
 
Quoted 14 lines

lib/librte_table/rte_table_hash_cuckoo.c rte_table_hash_cuckoo_create(void *params, · line 115

Quoted 11 lines
lib/librte_table/rte_table_hash_cuckoo.c +3 -1
+	void *hash_func = p->f_hash;
+
 	/* Create cuckoo hash table */
 	struct rte_hash_parameters hash_cuckoo_params = {
 		.entries = p->n_keys,
 		.key_len = p->key_size,
-		.hash_func = (rte_hash_function)(p->f_hash),
+		.hash_func = (rte_hash_function) hash_func,
 		.hash_func_init_val = p->seed,
 		.socket_id = socket_id,
 		.name = p->name

This is just tricking the compiler into not complaining. I would really rather see the two hash functions made the same.

(Adding Bruce as well to consolidate all conversations in a single thread.)

What we want to do here is be able to use the librte_hash under the same API as the several hash table flavors implemented in librte_table.

Both of these libraries allow configuring the hash function per each hash table instance. Problem is: hash function in librte_hash has only 3 parameters (no key mask), while hash function in librte_table has 4 parameters (includes key mask). The key mask helps a lot for practical protocol implementations by avoiding key copy & pre-process on lookup.

So then: how to plug in librte_hash under the same API as the suite of hash tables in librte_table? We don't want to re-implement cuckoo hash from librte_hash, we simply want to invoke it as a low-level primitive, similarly to how the LPM and ACL tables are plugged into librte_table.

Solution is: as an exception, pass a 3-parameter hash function to cuckoo hash flavor under the librte_table. Maybe this should be documented better. This currently triggers a build warning with gcc 8, which is easy to fix, hence this trivial patch.

Quoted 5 lines

Ideally, for every 3-parameter hash function, I would like to generate the corresponding 4-parameter hash function on-the-fly, but unfortunately this is not what C language can do.

Of course, IMO the best solution is to add key mask support to librte_hash.

Looking at the previous discussion I see the following as a possible solution;

Given the current code looks broken it should be fixed in this release.
Given the actual code fix is an API / ABI break (depending on solution) it cannot be merged official in this release. We have a NEXT_ABI macro - it allows us to break API/ABI conditionally at compile time.

With the above 3 points, I think the best solution is to correctly fix the problem that GCC 8 is identifying, and putting that new API inside the NEXT_ macros.

In this case, we can preserve backwards (buggy) behavior if required, and provide correct (but API/ABI breaking) code as well. This is a tough decision - particularly for distros - what do they package?

Given the current code, I don't see a better solution - but I hope I'm wrong :)

#5 lore raw
In reply to Bruce Richardson
Quoted 35 lines · On Mon, 9 Apr 2018 16:28:12 +0100 Bruce Richardson…
Quoted 20 lines · Jasvinder
Quoted 9 lines

-----Original Message-----
From: Richardson, Bruce
Sent: Monday, April 9, 2018 2:09 PM
To: Singh, Jasvinder <[email protected]>
Cc: [email protected]; Dumitrescu, Cristian <[email protected]>
Subject: Re: [dpdk-dev] [PATCH] table: fix build error with gcc 8

On Mon, Apr 09, 2018 at 01:49:48PM +0100, Jasvinder Singh wrote:

Quoted 8 lines
Quoted 4 lines

Fix build error with gcc 8.0 due to cast between function types.

Fixes 5a80bf0ae613 ("table: add cuckoo hash")

What's the actual error message? Why do the types not match?

/Bruce

Error log is captured below;

Quoted 9 lines

CC rte_table_hash_cuckoo.o
/librte_table/rte_table_hash_cuckoo.c: In function 'rte_table_hash_cuckoo_create':
/librte_table/rte_table_hash_cuckoo.c:110:16: error: cast between incompatible
function types from 'rte_table_hash_op_hash' {aka 'long unsigned int (*)(void *, void *, unsigned int, long unsigned int)'} to 'uint32_t (*)(const void *, uint32_t, uint32_t)' {aka 'unsigned int (*)(const void *, unsigned int, unsigned int)'} [-Werror=cast-function-type]
.hash_func = (rte_hash_function) p->f_hash,

                ^

cc1: all warnings being treated as errors

Even if the compiler isn't complaining now, how can that cast work? Looking at the error message given, it appears there are two big issues:

1. The expected function call takes 3 parameters:

	(const void *, uint32_t,  uint32_t),
Quoted 8 lines

but you are giving it a function that takes 4 parameters:
(void *, void *, unsigned int, long unsigned int)
2. The return type expected is "unsigned int", but you are giving a function returning "long unsigned int". On 32-bit systems, these are going to be the same size, but on 64-bit, they will be different. Similarly for the last function argument.

Is the error message correct?

Yes. the current code is working only by luck

#9 lore raw
In reply to Van Haaren, Harry
Quoted 81 lines · Harry
Quoted 72 lines

From: dev [mailto:[email protected]] On Behalf Of Dumitrescu, Cristian
Sent: Monday, April 9, 2018 4:59 PM
To: Stephen Hemminger <[email protected]>; Singh, Jasvinder <[email protected]>; Richardson, Bruce <[email protected]>
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH] table: fix build error with gcc 8

Quoted 27 lines

-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Monday, April 9, 2018 4:10 PM
To: Singh, Jasvinder <[email protected]>
Cc: [email protected]; Dumitrescu, Cristian <[email protected]>
Subject: Re: [dpdk-dev] [PATCH] table: fix build error with gcc 8

Review

Quoted 9 lines · On Mon, 9 Apr 2018 13:49:48 +0100 Jasvinder Singh <[email protected]>…

Fix build error with gcc 8.0 due to cast between function types.

Fixes 5a80bf0ae613 ("table: add cuckoo hash")
---
 lib/librte_table/rte_table_hash_cuckoo.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/lib/librte_table/rte_table_hash_cuckoo.c

Quoted 7 lines

index dcb4fe9..f7eae27 100644

lib/librte_table/rte_table_hash_cuckoo.c +0 -0
@@ -103,11 +103,13 @@ rte_table_hash_cuckoo_create(void *params,
 		return NULL;
 	}
 
Quoted 14 lines

lib/librte_table/rte_table_hash_cuckoo.c rte_table_hash_cuckoo_create(void *params, · line 115

Quoted 11 lines
lib/librte_table/rte_table_hash_cuckoo.c +3 -1
+	void *hash_func = p->f_hash;
+
 	/* Create cuckoo hash table */
 	struct rte_hash_parameters hash_cuckoo_params = {
 		.entries = p->n_keys,
 		.key_len = p->key_size,
-		.hash_func = (rte_hash_function)(p->f_hash),
+		.hash_func = (rte_hash_function) hash_func,
 		.hash_func_init_val = p->seed,
 		.socket_id = socket_id,
 		.name = p->name

This is just tricking the compiler into not complaining. I would really rather see the two hash functions made the same.

(Adding Bruce as well to consolidate all conversations in a single thread.)

What we want to do here is be able to use the librte_hash under the same API as the several hash table flavors implemented in librte_table.

Both of these libraries allow configuring the hash function per each hash table instance. Problem is: hash function in librte_hash has only 3 parameters (no key mask), while hash function in librte_table has 4 parameters (includes key mask). The key mask helps a lot for practical protocol implementations by avoiding key copy & pre-process on lookup.

So then: how to plug in librte_hash under the same API as the suite of hash tables in librte_table? We don't want to re-implement cuckoo hash from librte_hash, we simply want to invoke it as a low-level primitive, similarly to how the LPM and ACL tables are plugged into librte_table.

Solution is: as an exception, pass a 3-parameter hash function to cuckoo hash flavor under the librte_table. Maybe this should be documented better. This currently triggers a build warning with gcc 8, which is easy to fix, hence this trivial patch.

Quoted 5 lines

Ideally, for every 3-parameter hash function, I would like to generate the corresponding 4-parameter hash function on-the-fly, but unfortunately this is not what C language can do.

Of course, IMO the best solution is to add key mask support to librte_hash.

Looking at the previous discussion I see the following as a possible solution;

Quoted 7 lines

Given the current code looks broken it should be fixed in this release.
Given the actual code fix is an API / ABI break (depending on solution) it cannot be merged official in this release. We have a NEXT_ABI macro - it allows us to break API/ABI conditionally at compile time.

With the above 3 points, I think the best solution is to correctly fix the problem that GCC 8 is identifying, and putting that new API inside the NEXT_ macros.

In this case, we can preserve backwards (buggy) behavior if required, and provide correct (but API/ABI breaking) code as well. This is a tough decision - particularly for distros - what do they package?

+1 to use RTE_NEXT_ABI and deliver fixed code, and agree this is kind of pushing decision to distros.

Quoted 3 lines

Given the current code, I don't see a better solution - but I hope I'm wrong :)

#11 lore raw
In reply to Van Haaren, Harry
Quoted 98 lines

-----Original Message-----
From: Van Haaren, Harry
Sent: Monday, April 9, 2018 5:38 PM
To: Dumitrescu, Cristian <[email protected]>; Stephen Hemminger <[email protected]>; Singh, Jasvinder <[email protected]>; Richardson, Bruce <[email protected]>
Cc: [email protected]
Subject: RE: [dpdk-dev] [PATCH] table: fix build error with gcc 8

Quoted 1 line

From: dev [mailto:[email protected]] On Behalf Of Dumitrescu,

Cristian

Quoted 2 lines

Sent: Monday, April 9, 2018 4:59 PM
To: Stephen Hemminger <[email protected]>; Singh,

Jasvinder

Quoted 1 line

<[email protected]>; Richardson, Bruce

<[email protected]>

Quoted 23 lines

Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH] table: fix build error with gcc 8

Quoted 18 lines

-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Monday, April 9, 2018 4:10 PM
To: Singh, Jasvinder <[email protected]>
Cc: [email protected]; Dumitrescu, Cristian <[email protected]>
Subject: Re: [dpdk-dev] [PATCH] table: fix build error with gcc 8

Quoted 8 lines · On Mon, 9 Apr 2018 13:49:48 +0100 Jasvinder Singh <[email protected]>…

Fix build error with gcc 8.0 due to cast between function types.

Fixes 5a80bf0ae613 ("table: add cuckoo hash")
---
 lib/librte_table/rte_table_hash_cuckoo.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 6 lines
Quoted 6 lines

Review

Quoted 1 line
(quoted diff) +0 -0

b/lib/librte_table/rte_table_hash_cuckoo.c

lib/librte_table/rte_table_hash_cuckoo.c rte_table_hash_cuckoo_create(void

Quoted 4 lines

index dcb4fe9..f7eae27 100644

lib/librte_table/rte_table_hash_cuckoo.c +0 -0
@@ -103,11 +103,13 @@ rte_table_hash_cuckoo_create(void

*params,

Quoted 18 lines
Quoted 17 lines
Quoted 4 lines
lib/librte_table/rte_table_hash_cuckoo.c +1 -0
 		return NULL;
 	}
 
+	void *hash_func = p->f_hash;

lib/librte_table/rte_table_hash_cuckoo.c rte_table_hash_cuckoo_create(void *params, · line 115

Quoted 10 lines
lib/librte_table/rte_table_hash_cuckoo.c +2 -1
+
 	/* Create cuckoo hash table */
 	struct rte_hash_parameters hash_cuckoo_params = {
 		.entries = p->n_keys,
 		.key_len = p->key_size,
-		.hash_func = (rte_hash_function)(p->f_hash),
+		.hash_func = (rte_hash_function) hash_func,
 		.hash_func_init_val = p->seed,
 		.socket_id = socket_id,
 		.name = p->name

This is just tricking the compiler into not complaining. I would really rather see the two hash functions made the same.

Quoted 3 lines

(Adding Bruce as well to consolidate all conversations in a single thread.)

What we want to do here is be able to use the librte_hash under the same

API

Quoted 4 lines

as the several hash table flavors implemented in librte_table.

Both of these libraries allow configuring the hash function per each hash table instance. Problem is: hash function in librte_hash has only 3

parameters

Quoted 1 line

(no key mask), while hash function in librte_table has 4 parameters

(includes

Quoted 1 line

key mask). The key mask helps a lot for practical protocol implementations

by

Quoted 3 lines

avoiding key copy & pre-process on lookup.

So then: how to plug in librte_hash under the same API as the suite of

hash

Quoted 5 lines

tables in librte_table? We don't want to re-implement cuckoo hash from librte_hash, we simply want to invoke it as a low-level primitive, similarly to how the LPM and ACL tables are plugged into librte_table.

Solution is: as an exception, pass a 3-parameter hash function to cuckoo

hash

Quoted 1 line

flavor under the librte_table. Maybe this should be documented better.

This

Quoted 5 lines

currently triggers a build warning with gcc 8, which is easy to fix, hence this trivial patch.

Ideally, for every 3-parameter hash function, I would like to generate the corresponding 4-parameter hash function on-the-fly, but unfortunately this

is

Quoted 8 lines
Quoted 3 lines

not what C language can do.

Of course, IMO the best solution is to add key mask support to librte_hash.

Looking at the previous discussion I see the following as a possible solution;

Given the current code looks broken it should be fixed in this release.

The code is not broken. This is not a bug, it is a limitation for that particular table type. The only gap that I see is adding a Doxygen comment in the API header file.

User explicitly picks the hash table type it wants; when using this particular hash table type, that pointer needs to point to a 3-parameter function instead of 4. Given the limitation is clearly documented in Doxygen (current gap that we can quickly address), I don't see any problem.

If people think that this function conversion is not nice, it can be reworked in multiple ways at the expense of API (but not ABI) change:
1. Define the hash function field in the table parameter structure as opaque void * rather than 4-parameter version.
2. Create a separate parameter structure just for this hash table type.

Quoted 4 lines

Given the actual code fix is an API / ABI break (depending on solution) it cannot be merged official in this release.
We have a NEXT_ABI macro - it allows us to break API/ABI conditionally at compile time.

This is not new code introduced in this release cycle, this is just fixing the compiler warning, I fail to see how your ABI breakage mention is applicable.

Maybe we should talk more specifics over the code, where exactly in the code would you like to place your NEXT_ABI macro?

Quoted 10 lines

With the above 3 points, I think the best solution is to correctly fix the problem that GCC 8 is identifying, and putting that new API inside the NEXT_ macros.

In this case, we can preserve backwards (buggy) behavior if required, and provide correct (but API/ABI breaking) code as well. This is a tough decision - particularly for distros - what do they package?

Given the current code, I don't see a better solution - but I hope I'm wrong :)

#10 lore raw
In reply to Ferruh Yigit
Quoted 120 lines

-----Original Message-----
From: Yigit, Ferruh
Sent: Monday, April 9, 2018 5:43 PM
To: Van Haaren, Harry <[email protected]>; Dumitrescu, Cristian <[email protected]>; Stephen Hemminger <[email protected]>; Singh, Jasvinder <[email protected]>; Richardson, Bruce <[email protected]>
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH] table: fix build error with gcc 8

Quoted 1 line · Harry
Quoted 1 line

From: dev [mailto:[email protected]] On Behalf Of Dumitrescu,

Cristian

Quoted 2 lines
Quoted 2 lines

Sent: Monday, April 9, 2018 4:59 PM
To: Stephen Hemminger <[email protected]>; Singh,

Jasvinder

Quoted 1 line
Quoted 1 line

<[email protected]>; Richardson, Bruce

<[email protected]>

Quoted 10 lines
Quoted 10 lines

Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH] table: fix build error with gcc 8

Quoted 5 lines

-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Monday, April 9, 2018 4:10 PM
To: Singh, Jasvinder <[email protected]>
Cc: [email protected]; Dumitrescu, Cristian

<[email protected]>

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

Subject: Re: [dpdk-dev] [PATCH] table: fix build error with gcc 8

Quoted 8 lines · On Mon, 9 Apr 2018 13:49:48 +0100 Jasvinder Singh <[email protected]>…

Fix build error with gcc 8.0 due to cast between function types.

Fixes 5a80bf0ae613 ("table: add cuckoo hash")
---
 lib/librte_table/rte_table_hash_cuckoo.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Review

Quoted 1 line
(quoted diff) +0 -0

b/lib/librte_table/rte_table_hash_cuckoo.c

lib/librte_table/rte_table_hash_cuckoo.c rte_table_hash_cuckoo_create(void

Quoted 4 lines

index dcb4fe9..f7eae27 100644

lib/librte_table/rte_table_hash_cuckoo.c +0 -0
@@ -103,11 +103,13 @@ rte_table_hash_cuckoo_create(void

*params,

Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
Quoted 4 lines
lib/librte_table/rte_table_hash_cuckoo.c +1 -0
 		return NULL;
 	}
 
+	void *hash_func = p->f_hash;

lib/librte_table/rte_table_hash_cuckoo.c rte_table_hash_cuckoo_create(void *params, · line 115

Quoted 10 lines
lib/librte_table/rte_table_hash_cuckoo.c +2 -1
+
 	/* Create cuckoo hash table */
 	struct rte_hash_parameters hash_cuckoo_params = {
 		.entries = p->n_keys,
 		.key_len = p->key_size,
-		.hash_func = (rte_hash_function)(p->f_hash),
+		.hash_func = (rte_hash_function) hash_func,
 		.hash_func_init_val = p->seed,
 		.socket_id = socket_id,
 		.name = p->name

This is just tricking the compiler into not complaining. I would really rather see the two hash functions made the same.

Quoted 3 lines
Quoted 3 lines

(Adding Bruce as well to consolidate all conversations in a single thread.)

What we want to do here is be able to use the librte_hash under the

same API

Quoted 4 lines
Quoted 4 lines

as the several hash table flavors implemented in librte_table.

Both of these libraries allow configuring the hash function per each hash table instance. Problem is: hash function in librte_hash has only 3

parameters

Quoted 1 line
Quoted 1 line

(no key mask), while hash function in librte_table has 4 parameters

(includes

Quoted 1 line
Quoted 1 line

key mask). The key mask helps a lot for practical protocol

implementations by

Quoted 3 lines
Quoted 3 lines

avoiding key copy & pre-process on lookup.

So then: how to plug in librte_hash under the same API as the suite of

hash

Quoted 5 lines
Quoted 5 lines

tables in librte_table? We don't want to re-implement cuckoo hash from librte_hash, we simply want to invoke it as a low-level primitive, similarly to how the LPM and ACL tables are plugged into librte_table.

Solution is: as an exception, pass a 3-parameter hash function to cuckoo

hash

Quoted 1 line
Quoted 1 line

flavor under the librte_table. Maybe this should be documented better.

This

Quoted 5 lines
Quoted 5 lines

currently triggers a build warning with gcc 8, which is easy to fix, hence this trivial patch.

Ideally, for every 3-parameter hash function, I would like to generate the corresponding 4-parameter hash function on-the-fly, but unfortunately

this is

Quoted 3 lines
Quoted 3 lines

not what C language can do.

Of course, IMO the best solution is to add key mask support to

librte_hash.

Quoted 3 lines

Looking at the previous discussion I see the following as a possible

solution;

Quoted 3 lines

Given the current code looks broken it should be fixed in this release. Given the actual code fix is an API / ABI break (depending on solution) it

cannot be merged official in this release.

Quoted 1 line

We have a NEXT_ABI macro - it allows us to break API/ABI conditionally at

compile time.

Quoted 2 lines

With the above 3 points, I think the best solution is to correctly fix the

problem that GCC 8 is identifying, and putting that new API inside the NEXT_ macros.

Quoted 1 line
Quoted 8 lines
Quoted 1 line

In this case, we can preserve backwards (buggy) behavior if required, and

provide correct (but API/ABI breaking) code as well. This is a tough decision - particularly for distros - what do they package?

+1 to use RTE_NEXT_ABI and deliver fixed code, and agree this is kind of pushing
decision to distros.

Again, where is the bug, and where exactly in the code you want to put RTE_NEXT_ABI macro, and what is the problem fixed by using this macro?

As stated in the reply to Harry, this could be reworked in multiple ways if people think the function pointer conversion is misleading to the user.

Quoted 4 lines
Quoted 2 lines

Given the current code, I don't see a better solution - but I hope I'm wrong

:)

Quoted 1 line
#12 lore raw
In reply to Dumitrescu, Cristian
Quoted 120 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Dumitrescu, Cristian
Sent: Monday, April 9, 2018 6:02 PM
To: Van Haaren, Harry <[email protected]>; Stephen Hemminger <[email protected]>; Singh, Jasvinder <[email protected]>; Richardson, Bruce <[email protected]>
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH] table: fix build error with gcc 8

Quoted 96 lines

-----Original Message-----
From: Van Haaren, Harry
Sent: Monday, April 9, 2018 5:38 PM
To: Dumitrescu, Cristian <[email protected]>; Stephen Hemminger <[email protected]>; Singh, Jasvinder <[email protected]>; Richardson, Bruce <[email protected]>
Cc: [email protected]
Subject: RE: [dpdk-dev] [PATCH] table: fix build error with gcc 8

Quoted 1 line

From: dev [mailto:[email protected]] On Behalf Of Dumitrescu,

Cristian

Quoted 2 lines

Sent: Monday, April 9, 2018 4:59 PM
To: Stephen Hemminger <[email protected]>; Singh,

Jasvinder

Quoted 1 line

<[email protected]>; Richardson, Bruce

<[email protected]>

Quoted 23 lines

Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH] table: fix build error with gcc 8

Quoted 18 lines

-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Monday, April 9, 2018 4:10 PM
To: Singh, Jasvinder <[email protected]>
Cc: [email protected]; Dumitrescu, Cristian <[email protected]>
Subject: Re: [dpdk-dev] [PATCH] table: fix build error with gcc 8

Quoted 8 lines · On Mon, 9 Apr 2018 13:49:48 +0100 Jasvinder Singh <[email protected]>…

Fix build error with gcc 8.0 due to cast between function types.

Fixes 5a80bf0ae613 ("table: add cuckoo hash")
---
 lib/librte_table/rte_table_hash_cuckoo.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 6 lines
Quoted 6 lines

Review

Quoted 1 line
(quoted diff) +0 -0

b/lib/librte_table/rte_table_hash_cuckoo.c

lib/librte_table/rte_table_hash_cuckoo.c rte_table_hash_cuckoo_create(void

Quoted 4 lines

index dcb4fe9..f7eae27 100644

lib/librte_table/rte_table_hash_cuckoo.c +0 -0
@@ -103,11 +103,13 @@ rte_table_hash_cuckoo_create(void

*params,

Quoted 18 lines
Quoted 17 lines
Quoted 4 lines
lib/librte_table/rte_table_hash_cuckoo.c +1 -0
 		return NULL;
 	}
 
+	void *hash_func = p->f_hash;

lib/librte_table/rte_table_hash_cuckoo.c rte_table_hash_cuckoo_create(void *params, · line 115

Quoted 10 lines
lib/librte_table/rte_table_hash_cuckoo.c +2 -1
+
 	/* Create cuckoo hash table */
 	struct rte_hash_parameters hash_cuckoo_params = {
 		.entries = p->n_keys,
 		.key_len = p->key_size,
-		.hash_func = (rte_hash_function)(p->f_hash),
+		.hash_func = (rte_hash_function) hash_func,
 		.hash_func_init_val = p->seed,
 		.socket_id = socket_id,
 		.name = p->name

This is just tricking the compiler into not complaining. I would really rather see the two hash functions made the same.

Quoted 3 lines

(Adding Bruce as well to consolidate all conversations in a single thread.)

What we want to do here is be able to use the librte_hash under the same

API

Quoted 4 lines

as the several hash table flavors implemented in librte_table.

Both of these libraries allow configuring the hash function per each hash table instance. Problem is: hash function in librte_hash has only 3

parameters

Quoted 1 line

(no key mask), while hash function in librte_table has 4 parameters

(includes

Quoted 1 line

key mask). The key mask helps a lot for practical protocol implementations

by

Quoted 3 lines

avoiding key copy & pre-process on lookup.

So then: how to plug in librte_hash under the same API as the suite of

hash

Quoted 5 lines

tables in librte_table? We don't want to re-implement cuckoo hash from librte_hash, we simply want to invoke it as a low-level primitive, similarly to how the LPM and ACL tables are plugged into librte_table.

Solution is: as an exception, pass a 3-parameter hash function to cuckoo

hash

Quoted 1 line

flavor under the librte_table. Maybe this should be documented better.

This

Quoted 5 lines

currently triggers a build warning with gcc 8, which is easy to fix, hence this trivial patch.

Ideally, for every 3-parameter hash function, I would like to generate the corresponding 4-parameter hash function on-the-fly, but unfortunately this

is

Quoted 8 lines
Quoted 3 lines

not what C language can do.

Of course, IMO the best solution is to add key mask support to librte_hash.

Looking at the previous discussion I see the following as a possible solution;

Given the current code looks broken it should be fixed in this release.

The code is not broken. This is not a bug, it is a limitation for that particular table type. The only gap that I see is adding a Doxygen comment in the API header file.

Quoted 7 lines

User explicitly picks the hash table type it wants; when using this particular hash table type, that pointer needs to point to a 3-parameter function instead of 4. Given the limitation is clearly documented in Doxygen (current gap that we can quickly address), I don't see any problem.

If people think that this function conversion is not nice, it can be reworked in multiple ways at the expense of API (but not ABI) change:
1. Define the hash function field in the table parameter structure as opaque void * rather than 4-parameter version.
2. Create a separate parameter structure just for this hash table type.

Why just not define your f_hash member as a union:

struct rte_table_hash_params {
...

union {
    rte_table_hash_op_hash  f_hash_4params;
    rte_hash_function f_hash_3_params;
}; 

?

Quoted 21 lines
Quoted 5 lines

Given the actual code fix is an API / ABI break (depending on solution) it cannot be merged official in this release.
We have a NEXT_ABI macro - it allows us to break API/ABI conditionally at compile time.

This is not new code introduced in this release cycle, this is just fixing the compiler warning, I fail to see how your ABI breakage mention is applicable.

Maybe we should talk more specifics over the code, where exactly in the code would you like to place your NEXT_ABI macro?

Quoted 10 lines

With the above 3 points, I think the best solution is to correctly fix the problem that GCC 8 is identifying, and putting that new API inside the NEXT_ macros.

In this case, we can preserve backwards (buggy) behavior if required, and provide correct (but API/ABI breaking) code as well. This is a tough decision - particularly for distros - what do they package?

Given the current code, I don't see a better solution - but I hope I'm wrong :)

#13 lore raw
Quoted 9 lines
Quoted 2 lines

If people think that this function conversion is not nice, it can be reworked

in multiple ways at the expense of API (but not ABI) change:

Quoted 1 line

1. Define the hash function field in the table parameter structure as

opaque void * rather than 4-parameter version.

Quoted 1 line

2. Create a separate parameter structure just for this hash table type.

Why just not define your f_hash member as a union:

Quoted 9 lines

struct rte_table_hash_params {
...

union {
    rte_table_hash_op_hash  f_hash_4params;
    rte_hash_function f_hash_3_params;
};

?

Yes, agreed, this is yet another way to handle this, thanks Konstantin.

#15 lore raw
In reply to Van Haaren, Harry
Quoted 85 lines · Harry
Quoted 72 lines

From: dev [mailto:[email protected]] On Behalf Of Dumitrescu, Cristian
Sent: Monday, April 9, 2018 4:59 PM
To: Stephen Hemminger <[email protected]>; Singh, Jasvinder <[email protected]>; Richardson, Bruce <[email protected]>
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH] table: fix build error with gcc 8

Quoted 27 lines

-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Monday, April 9, 2018 4:10 PM
To: Singh, Jasvinder <[email protected]>
Cc: [email protected]; Dumitrescu, Cristian <[email protected]>
Subject: Re: [dpdk-dev] [PATCH] table: fix build error with gcc 8

Review

Quoted 9 lines · On Mon, 9 Apr 2018 13:49:48 +0100 Jasvinder Singh <[email protected]>…

Fix build error with gcc 8.0 due to cast between function types.

Fixes 5a80bf0ae613 ("table: add cuckoo hash")
---
 lib/librte_table/rte_table_hash_cuckoo.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/lib/librte_table/rte_table_hash_cuckoo.c

Quoted 7 lines

index dcb4fe9..f7eae27 100644

lib/librte_table/rte_table_hash_cuckoo.c +0 -0
@@ -103,11 +103,13 @@ rte_table_hash_cuckoo_create(void *params,
 		return NULL;
 	}
 
Quoted 14 lines

lib/librte_table/rte_table_hash_cuckoo.c rte_table_hash_cuckoo_create(void *params, · line 115

Quoted 11 lines
lib/librte_table/rte_table_hash_cuckoo.c +3 -1
+	void *hash_func = p->f_hash;
+
 	/* Create cuckoo hash table */
 	struct rte_hash_parameters hash_cuckoo_params = {
 		.entries = p->n_keys,
 		.key_len = p->key_size,
-		.hash_func = (rte_hash_function)(p->f_hash),
+		.hash_func = (rte_hash_function) hash_func,
 		.hash_func_init_val = p->seed,
 		.socket_id = socket_id,
 		.name = p->name

This is just tricking the compiler into not complaining. I would really rather see the two hash functions made the same.

(Adding Bruce as well to consolidate all conversations in a single thread.)

What we want to do here is be able to use the librte_hash under the same API as the several hash table flavors implemented in librte_table.

Both of these libraries allow configuring the hash function per each hash table instance. Problem is: hash function in librte_hash has only 3 parameters (no key mask), while hash function in librte_table has 4 parameters (includes key mask). The key mask helps a lot for practical protocol implementations by avoiding key copy & pre-process on lookup.

So then: how to plug in librte_hash under the same API as the suite of hash tables in librte_table? We don't want to re-implement cuckoo hash from librte_hash, we simply want to invoke it as a low-level primitive, similarly to how the LPM and ACL tables are plugged into librte_table.

Solution is: as an exception, pass a 3-parameter hash function to cuckoo hash flavor under the librte_table. Maybe this should be documented better. This currently triggers a build warning with gcc 8, which is easy to fix, hence this trivial patch.

Quoted 5 lines

Ideally, for every 3-parameter hash function, I would like to generate the corresponding 4-parameter hash function on-the-fly, but unfortunately this is not what C language can do.

Of course, IMO the best solution is to add key mask support to librte_hash.

Looking at the previous discussion I see the following as a possible solution;

Given the current code looks broken it should be fixed in this release.
Given the actual code fix is an API / ABI break (depending on solution) it cannot be merged official in this release. We have a NEXT_ABI macro - it allows us to break API/ABI conditionally at compile time.

Quoted 6 lines

With the above 3 points, I think the best solution is to correctly fix the problem that GCC 8 is identifying, and putting that new API inside the NEXT_ macros.

In this case, we can preserve backwards (buggy) behavior if required, and provide correct (but API/ABI breaking) code as well. This is a tough decision - particularly for distros - what do they package?

Given the current code, I don't see a better solution - but I hope I'm wrong :)

Why not make the hash_func pointer in the rte_hash_parameters structure an anonymous union, and reserve a bit in the extra_flag field to denote if the function pointer has 3 arguments or 4? Then rte_hash_hash can use the appropriate calling convention on hash_func.

Neil

#14 lore raw
In reply to Dumitrescu, Cristian

+CC Neil from other reply

Quoted 26 lines

From: Dumitrescu, Cristian
Sent: Monday, April 9, 2018 6:27 PM
To: Ananyev, Konstantin <[email protected]>; Van Haaren, Harry <[email protected]>; Stephen Hemminger <[email protected]>; Singh, Jasvinder <[email protected]>; Richardson, Bruce <[email protected]>
Cc: [email protected]
Subject: RE: [dpdk-dev] [PATCH] table: fix build error with gcc 8

Quoted 2 lines
Quoted 2 lines

If people think that this function conversion is not nice, it can be

reworked

Quoted 14 lines

in multiple ways at the expense of API (but not ABI) change:

Quoted 1 line

1. Define the hash function field in the table parameter structure as

opaque void * rather than 4-parameter version.

Quoted 1 line

2. Create a separate parameter structure just for this hash table type.

Why just not define your f_hash member as a union:

struct rte_table_hash_params {
...

union {
    rte_table_hash_op_hash  f_hash_4params;
    rte_hash_function f_hash_3_params;
};
Quoted 4 lines
Quoted 2 lines

?

Yes, agreed, this is yet another way to handle this, thanks Konstantin.

Agree that this solution is a lot better than raw casting.

The issue I have with casting is that it doesn't explicitly show that the signature is different, and that the code must be aware of that fact. With a union, at least the code explicitly states that there is a difference in signature, and that this is being handled by the code, so this looks a better solution.

Neil proposed an alternative solution using a bit to indicate calling params in a separate reply - another possibility.