lib/table: fix cache alignment issue
PATCH 1/1 lib/table: fix cache alignment issue
When create softnic hash table with 16 keys, it failed on 32bit environment because of the structure rte_bucket_4_16 alignment issue. Add __rte_cache_aligned to ensure correct cache align.
--- lib/librte_table/rte_table_hash_key16.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_table/rte_table_hash_key16.c +1 -1
@@ -44,7 +44,7 @@ struct rte_bucket_4_16 {uint64_t key[4 ][2 ];/* Cache line 2 */ -uint8_t data[0 ]; + uint8_t data[0] __rte_cache_aligned; };struct rte_table_hash {
Signature · 1 line
2.17.1
PATCH v2 1/1 lib/table: fix cache alignment issue
When create softnic hash table with 16 keys, it failed on 32bit environment because of the structure rte_bucket_4_16 alignment issue. Add __rte_cache_aligned to ensure correct cache align.
---v1->v2: Correct patch time
--- lib/librte_table/rte_table_hash_key16.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_table/rte_table_hash_key16.c +1 -1
@@ -44,7 +44,7 @@ struct rte_bucket_4_16 {uint64_t key[4 ][2 ];/* Cache line 2 */ -uint8_t data[0 ]; + uint8_t data[0] __rte_cache_aligned; };struct rte_table_hash {
Signature · 1 line
2.17.1
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Ting Xu
Sent: Wednesday, June 17, 2020 1:44 PM
To: [email protected]
Cc: Dumitrescu, Cristian <[email protected]>; [email protected]
Subject: [dpdk-dev] [PATCH v2] lib/table: fix cache alignment issue
When create softnic hash table with 16 keys, it failed on 32bit environment because of the structure rte_bucket_4_16 alignment issue. Add __rte_cache_aligned to ensure correct cache align.
---v1->v2: Correct patch time
--- lib/librte_table/rte_table_hash_key16.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_table/rte_table_hash_key16.c +1 -1
@@ -44,7 +44,7 @@ struct rte_bucket_4_16 {uint64_t key[4 ][2 ];/* Cache line 2 */ -uint8_t data[0 ]; + uint8_t data[0] __rte_cache_aligned; };struct rte_table_hash {
--
2.17.1
PATCH v3 1/1 lib/table: fix cache alignment issue
In reply to Ting XuWhen create softnic hash table with 16 keys, it failed on 32bit environment because of the structure rte_bucket_4_16 alignment issue. Add __rte_cache_aligned to ensure correct cache align.
---v2->v3: Rebasev1->v2: Correct patch time
--- lib/librte_table/rte_table_hash_key16.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_table/rte_table_hash_key16.c +1 -1
@@ -44,7 +44,7 @@ struct rte_bucket_4_16 {uint64_t key[4 ][2 ];/* Cache line 2 */ -uint8_t data[0 ]; + uint8_t data[0] __rte_cache_aligned; };struct rte_table_hash {
Signature · 1 line
2.17.1
Quoted 41 lines
-----Original Message-----
From: Xu, Ting <[email protected]>
Sent: Thursday, July 9, 2020 2:48 AM
To: [email protected]
Cc: Dumitrescu, Cristian <[email protected]>; Xu, Ting <[email protected]>; [email protected]
Subject: [PATCH v3] lib/table: fix cache alignment issueWhen create softnic hash table with 16 keys, it failed on 32bit environment because of the structure
rte_bucket_4_16alignment issue. Add__rte_cache_alignedto ensure correct cache align.Fixes 8aa327214c ("table: hash")Signed-off-by Ting Xu <[email protected]>---
v2->v3: Rebasev1->v2: Correct patch time--- lib/librte_table/rte_table_hash_key16.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/librte_table/rte_table_hash_key16.c +1
-2@@ -44,7 +44,7 @@ struct rte_bucket_4_16 {uint64_t key[4 ][2 ];/* Cache line 2 */ -uint8_t data[0 ]; + uint8_t data[0] __rte_cache_aligned; };struct rte_table_hash { --
Quoted 1 line
2.17.1
Hi Ting,
This fix is breaking the execution for systems with cache line of 128 bytes, as typically (on 64-bit systems) this structure would be 64-byte in size and adding the __rte_cache_aligned would force doubling the size of this structure through padding enforced by the compiler.
Can you please confirm this is caused by check below failing in the table create function:
sizeof(struct rte_bucket_4_16) % 64) != 0
Since all the other fields in this data structure are explicitly declared as 64-bit fields, due to the alignment rules I was expecting the compiler to add a 32-bit padding field after the "next" field, which is a pointer that would only take 32 bits on 32-bit systems. I am not sure why this did not take place in your case, any thoughts?
Not sure why we would run Soft NIC on 32-bit systems, might be better to disable Soft NIC for 32-bit systems.
Thanks,
Cristian
Hi, Cristian
Quoted 52 lines
-----Original Message-----
From: Dumitrescu, Cristian <[email protected]>
Sent: Monday, July 20, 2020 10:38 PM
To: Xu, Ting <[email protected]>; [email protected]
Cc: [email protected]
Subject: RE: [PATCH v3] lib/table: fix cache alignment issueQuoted 39 lines
-----Original Message-----
From: Xu, Ting <[email protected]>
Sent: Thursday, July 9, 2020 2:48 AM
To: [email protected]
Cc: Dumitrescu, Cristian <[email protected]>; Xu, Ting <[email protected]>; [email protected]
Subject: [PATCH v3] lib/table: fix cache alignment issueWhen create softnic hash table with 16 keys, it failed on 32bit environment because of the structure
rte_bucket_4_16alignment issue. Add__rte_cache_alignedto ensure correct cache align.Fixes 8aa327214c ("table: hash")Signed-off-by Ting Xu <[email protected]>---
v2->v3: Rebasev1->v2: Correct patch time--- lib/librte_table/rte_table_hash_key16.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/librte_table/rte_table_hash_key16.c +1
-2@@ -44,7 +44,7 @@ struct rte_bucket_4_16 {uint64_t key[4 ][2 ];/* Cache line 2 */ -uint8_t data[0 ]; + uint8_t data[0] __rte_cache_aligned; };struct rte_table_hash { --Quoted 1 line
2.17.1
Hi Ting,
Quoted 9 lines
This fix is breaking the execution for systems with cache line of 128 bytes, as typically (on 64-bit systems) this structure would be 64-byte in size and adding the
__rte_cache_alignedwould force doubling the size of this structure through padding enforced by the compiler.Can you please confirm this is caused by check below failing in the table create function:
sizeof(struct rte_bucket_4_16) % 64) != 0
The result of sizeof(struct rte_bucket_4_16) is 124 byte in this case, and this is the direct reason causing this failure.
Quoted 6 lines
Since all the other fields in this data structure are explicitly declared as 64-bit fields, due to the alignment rules I was expecting the compiler to add a 32-bit padding field after the "next" field, which is a pointer that would only take 32 bits on 32-bit systems. I am not sure why this did not take place in your case, any thoughts?
It shows that the size of the field struct rte_bucket_4_16 *next in struct rte_bucket_4_16 is only 32 bits. And there is no padding added by the compiler in my and the reporter's case. I tried to add a 32 bits pad field after the field next manually, and the result is correct then.
Is it because in 32-bit system, the compiler will not extend the 32 bits pointer to 64 bits, since the 32 bits size has already matched the cache line?
Quoted 3 lines
Not sure why we would run Soft NIC on 32-bit systems, might be better to disable Soft NIC for 32-bit systems.
To be honest, I do not know why we should run softnic on 32-bit system, I was just assigned this specific bug. It seems there is a complete test case for validation team to test softnic in 32-bit system. I am not sure is it OK to tell the validation team that we should disable softnic in 32-bit system now. Or we should fix this issue this time and discuss about the problem later?
Thanks!
Quoted 2 lines
Thanks,
Cristian
Quoted 88 lines
-----Original Message-----
From: Xu, Ting <[email protected]>
Sent: Tuesday, July 21, 2020 6:16 AM
To: Dumitrescu, Cristian <[email protected]>; [email protected]
Cc: [email protected]
Subject: RE: [PATCH v3] lib/table: fix cache alignment issueHi, Cristian
Quoted 46 lines
-----Original Message-----
From: Dumitrescu, Cristian <[email protected]>
Sent: Monday, July 20, 2020 10:38 PM
To: Xu, Ting <[email protected]>; [email protected]
Cc: [email protected]
Subject: RE: [PATCH v3] lib/table: fix cache alignment issueQuoted 37 lines
-----Original Message-----
From: Xu, Ting <[email protected]>
Sent: Thursday, July 9, 2020 2:48 AM
To: [email protected]
Cc: Dumitrescu, Cristian <[email protected]>; Xu, Ting <[email protected]>; [email protected]
Subject: [PATCH v3] lib/table: fix cache alignment issueWhen create softnic hash table with 16 keys, it failed on 32bit environment because of the structure
rte_bucket_4_16alignment issue. Add__rte_cache_alignedto ensure correct cache align.Fixes 8aa327214c ("table: hash")Signed-off-by Ting Xu <[email protected]>---
v2->v3: Rebasev1->v2: Correct patch time--- lib/librte_table/rte_table_hash_key16.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/librte_table/rte_table_hash_key16.c +1
-1@@ -44,7 +44,7 @@ struct rte_bucket_4_16 {uint64_t key[4 ][2 ];/* Cache line 2 */ -uint8_t data[0 ]; + uint8_t data[0] __rte_cache_aligned; };Quoted 7 lines
Quoted 3 lines
lib/librte_table/rte_table_hash_key16.c +0
-1struct rte_table_hash { --2.17.1
Hi Ting,
This fix is breaking the execution for systems with cache line of 128 bytes,
as
Quoted 8 lines
typically (on 64-bit systems) this structure would be 64-byte in size and adding the
__rte_cache_alignedwould force doubling the size of this structure through padding enforced by the compiler.Can you please confirm this is caused by check below failing in the table create function:
sizeof(struct rte_bucket_4_16) % 64) != 0The result of
sizeof(struct rte_bucket_4_16)is 124 byte in this case, and this is the direct reason causing this failure.Quoted 1 line
Since all the other fields in this data structure are explicitly declared as 64-
bit
Quoted 1 line
fields, due to the alignment rules I was expecting the compiler to add a 32-
bit
Quoted 1 line
padding field after the "next" field, which is a pointer that would only take
32
Quoted 1 line
bits on 32-bit systems. I am not sure why this did not take place in your
case,
Quoted 2 lines
any thoughts?
Quoted 12 lines
It shows that the size of the field struct
rte_bucket_4_16*next in structrte_bucket_4_16is only 32 bits. And there is no padding added by the compiler in my and the reporter's case.
I tried to add a 32 bits pad field after the field next manually, and the result is correct then.
Is it because in 32-bit system, the compiler will not extend the 32 bits pointer to 64 bits, since the 32 bits size has already matched the cache line?Quoted 3 lines
Not sure why we would run Soft NIC on 32-bit systems, might be better to disable Soft NIC for 32-bit systems.
My proposed solution, which IMO provides the cleanest and most readable way to fix / maintain this code:
#ifdef RTE_ARCH_64
struct rte_bucket_4_16 {
//current definition of this struct
};#else
struct rte_bucket_4_16 {
//definition with padding fields for the 32-bit pointers to keep this struct to a multiple of 64 bytes
};#endif
We need to apply the same for 8-byte key and 32-byte key hash functions from the same folder.
What do you think, Ting?
Quoted 11 lines
To be honest, I do not know why we should run softnic on 32-bit system, I was just assigned this specific bug. It seems there is a complete test case for validation team to test softnic in 32-bit system.
I am not sure is it OK to tell the validation team that we should disable softnic in 32-bit system now. Or we should fix this issue this time and discuss about the problem later?Thanks!
Quoted 2 lines
Thanks,
Cristian
Hi, Cristian,
Quoted 128 lines
-----Original Message-----
From: Dumitrescu, Cristian <[email protected]>
Sent: Wednesday, July 22, 2020 5:17 AM
To: Xu, Ting <[email protected]>; [email protected]
Cc: [email protected]
Subject: RE: [PATCH v3] lib/table: fix cache alignment issueQuoted 91 lines
-----Original Message-----
From: Xu, Ting <[email protected]>
Sent: Tuesday, July 21, 2020 6:16 AM
To: Dumitrescu, Cristian <[email protected]>; [email protected]
Cc: [email protected]
Subject: RE: [PATCH v3] lib/table: fix cache alignment issueHi, Cristian
Quoted 46 lines
-----Original Message-----
From: Dumitrescu, Cristian <[email protected]>
Sent: Monday, July 20, 2020 10:38 PM
To: Xu, Ting <[email protected]>; [email protected]
Cc: [email protected]
Subject: RE: [PATCH v3] lib/table: fix cache alignment issueQuoted 37 lines
-----Original Message-----
From: Xu, Ting <[email protected]>
Sent: Thursday, July 9, 2020 2:48 AM
To: [email protected]
Cc: Dumitrescu, Cristian <[email protected]>; Xu, Ting <[email protected]>; [email protected]
Subject: [PATCH v3] lib/table: fix cache alignment issueWhen create softnic hash table with 16 keys, it failed on 32bit environment because of the structure
rte_bucket_4_16alignment issue. Add__rte_cache_alignedto ensure correct cache align.Fixes 8aa327214c ("table: hash")Signed-off-by Ting Xu <[email protected]>---
v2->v3: Rebasev1->v2: Correct patch time--- lib/librte_table/rte_table_hash_key16.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/librte_table/rte_table_hash_key16.c +1
-1@@ -44,7 +44,7 @@ struct rte_bucket_4_16 {uint64_t key[4 ][2 ];/* Cache line 2 */ -uint8_t data[0 ]; + uint8_t data[0] __rte_cache_aligned; };Quoted 8 lines
Quoted 3 lines
lib/librte_table/rte_table_hash_key16.c +0
-1struct rte_table_hash { --2.17.1
Hi Ting,
This fix is breaking the execution for systems with cache line of 128 bytes,
as
Quoted 8 lines
typically (on 64-bit systems) this structure would be 64-byte in size and adding the
__rte_cache_alignedwould force doubling the size of this structure through padding enforced by the compiler.Can you please confirm this is caused by check below failing in the table create function:
sizeof(struct rte_bucket_4_16) % 64) != 0The result of
sizeof(struct rte_bucket_4_16)is 124 byte in this case, and this is the direct reason causing this failure.Quoted 2 lines
Since all the other fields in this data structure are explicitly declared as 64-
bit
Quoted 2 lines
fields, due to the alignment rules I was expecting the compiler to add a 32-
bit
Quoted 2 lines
padding field after the "next" field, which is a pointer that would only take
32
Quoted 2 lines
bits on 32-bit systems. I am not sure why this did not take place in your
case,
Quoted 2 lines
any thoughts?
Quoted 8 lines
It shows that the size of the field struct
rte_bucket_4_16*next in structrte_bucket_4_16is only 32 bits. And there is no padding added by the compiler in my and the reporter's case.
I tried to add a 32 bits pad field after the field next manually, and the result is correct then.
Is it because in 32-bit system, the compiler will not extend the 32 bits pointer to 64 bits, since the 32 bits size has already matched the cacheline?
Quoted 5 lines
Quoted 4 lines
Not sure why we would run Soft NIC on 32-bit systems, might be better to disable Soft NIC for 32-bit systems.
My proposed solution, which IMO provides the cleanest and most readable way to fix / maintain this code:
#ifdef
RTE_ARCH_64struct rte_bucket_4_16 { //current definition of this struct };#else
struct rte_bucket_4_16 { //definition with padding fields for the 32-bit pointers to keep this
Quoted 9 lines
struct to a multiple of 64 bytes };
#endif
We need to apply the same for 8-byte key and 32-byte key hash functions from the same folder.
What do you think, Ting?
Thanks for your advice. I think it makes sense.
I have updated a new patch version based on this method, could you please help review?
Thanks!
Quoted 11 lines
Quoted 11 lines
To be honest, I do not know why we should run softnic on 32-bit system, I was just assigned this specific bug. It seems there is a complete test case for validation team to test softnic in 32-bit system. I am not sure is it OK to tell the validation team that we should disable softnic in 32-bit system now. Or we should fix this issue this time and discuss about the problem later?
Thanks!
Quoted 2 lines
Thanks,
Cristian
PATCH v4 1/1 lib/table: fix cache alignment issue
In reply to Ting XuWhen create softnic hash table with 16 keys, it failed on 32-bit environment, because the pointer field in structure rte_bucket_4_16 is only 32 bits. Add a padding field in 32-bit environment to keep the structure to a multiple of 64 bytes. Apply this to 8-byte and 32-byte key hash function as well.
---v3->v4: Change design based on commentv2->v3: Rebasev1->v2: Correct patch time
--- lib/librte_table/rte_table_hash_key16.c | 17 +++++++++++++++++ lib/librte_table/rte_table_hash_key32.c | 17 +++++++++++++++++ lib/librte_table/rte_table_hash_key8.c | 16 ++++++++++++++++ 3 files changed, 50 insertions(+)
lib/librte_table/rte_table_hash_key16.c +17 -0
@@ -33,6 +33,7 @@#endif +#ifdef RTE_ARCH_64 struct rte_bucket_4_16 { /* Cache line 0 */ uint64_t signature[4 + 1];
@@ -46,6 +47,22 @@ struct rte_bucket_4_16 {/* Cache line 2 */ uint8_t data[0 ]; }; +#else +struct rte_bucket_4_16 { +/* Cache line 0 */ +uint64_t signature[4 +1 ]; +uint64_t lru_list; +struct rte_bucket_4_16 *next; +uint32_t pad; +uint64_t next_valid; + +/* Cache line 1 */ +uint64_t key[4 ][2 ]; + +/* Cache line 2 */ +uint8_t data[0 ]; +}; +#endif struct rte_table_hash {struct rte_table_stats stats;
lib/librte_table/rte_table_hash_key32.c +17 -0
@@ -33,6 +33,7 @@#endif +#ifdef RTE_ARCH_64 struct rte_bucket_4_32 { /* Cache line 0 */ uint64_t signature[4 + 1];
@@ -46,6 +47,22 @@ struct rte_bucket_4_32 {/* Cache line 3 */ uint8_t data[0 ]; }; +#else +struct rte_bucket_4_32 { +/* Cache line 0 */ +uint64_t signature[4 +1 ]; +uint64_t lru_list; +struct rte_bucket_4_32 *next; +uint32_t pad; +uint64_t next_valid; + +/* Cache lines 1 and 2 */ +uint64_t key[4 ][4 ]; + +/* Cache line 3 */ +uint8_t data[0 ]; +}; +#endif struct rte_table_hash {struct rte_table_stats stats;
lib/librte_table/rte_table_hash_key8.c +16 -0
@@ -31,6 +31,7 @@#endif +#ifdef RTE_ARCH_64 struct rte_bucket_4_8 { /* Cache line 0 */ uint64_t signature;
@@ -43,6 +44,21 @@ struct rte_bucket_4_8 {/* Cache line 1 */ uint8_t data[0 ]; }; +#else +struct rte_bucket_4_8 { +/* Cache line 0 */ +uint64_t signature; +uint64_t lru_list; +struct rte_bucket_4_8 *next; +uint32_t pad; +uint64_t next_valid; + +uint64_t key[4 ]; + +/* Cache line 1 */ +uint8_t data[0 ]; +}; +#endif struct rte_table_hash {struct rte_table_stats stats;
Signature · 1 line
2.17.1
Quoted 17 lines
lib/librte_table/rte_table_hash_key32.c +8
-0+#ifdef RTE_ARCH_64 struct rte_bucket_4_32 { /* Cache line 0 */ uint64_t signature[4 + 1];@@ -46,6 +47,22 @@ struct rte_bucket_4_32 { /* Cache line 3 */ uint8_t data[0]; }; +#else +struct rte_bucket_4_32 { + /* Cache line 0 */ + uint64_t signature[4 + 1]; + uint64_t lru_list; + struct rte_bucket_4_32 *next; + uint32_t pad;
lib/librte_table/rte_table_hash_key32.c struct rte_bucket_4_32 { · line 66
Quoted 10 lines
lib/librte_table/rte_table_hash_key32.c +9
-0+uint64_t next_valid; + +/* Cache lines 1 and 2 */ +uint64_t key[4 ][4 ]; + +/* Cache line 3 */ + uint8_t data[0]; +}; +#endif
Hi Ting,
Yes, it looks good, but as mentioned previously please do the same on the other files in the same folder and add the changes to your patch, as we need to keep all these files in sync:
rte_table_hash_key8.c, struct rte_bucket_4_8rte_table_hash_key32.c, struct rte_bucket_4_32
Thanks,
Cristian
Hi, Cristian,
Quoted 37 lines
-----Original Message-----
From: Dumitrescu, Cristian <[email protected]>
Sent: Wednesday, July 22, 2020 4:27 PM
To: Xu, Ting <[email protected]>; [email protected]
Cc: [email protected]
Subject: RE: [PATCH v4] lib/table: fix cache alignment issueQuoted 15 lines
lib/librte_table/rte_table_hash_key32.c +8
-0+#ifdef RTE_ARCH_64 struct rte_bucket_4_32 { /* Cache line 0 */ uint64_t signature[4 + 1];@@ -46,6 +47,22 @@ struct rte_bucket_4_32 { /* Cache line 3 */ uint8_t data[0]; }; +#else +struct rte_bucket_4_32 { + /* Cache line 0 */ + uint64_t signature[4 + 1]; + uint64_t lru_list; + struct rte_bucket_4_32 *next; + uint32_t pad;lib/librte_table/rte_table_hash_key32.c struct rte_bucket_4_32 { · line 66
Quoted 10 lines
lib/librte_table/rte_table_hash_key32.c +9
-0+uint64_t next_valid; + +/* Cache lines 1 and 2 */ +uint64_t key[4 ][4 ]; + +/* Cache line 3 */ + uint8_t data[0]; +}; +#endif Hi Ting,
Quoted 7 lines
Yes, it looks good, but as mentioned previously please do the same on the other files in the same folder and add the changes to your patch, as we need to keep all these files in sync:
rte_table_hash_key8.c, structrte_bucket_4_8rte_table_hash_key32.c, structrte_bucket_4_32
I have did the changes to 8 and 32 bytes in this patch.
Quoted 2 lines
Thanks,
Cristian
Quoted 51 lines
-----Original Message-----
From: Xu, Ting <[email protected]>
Sent: Wednesday, July 22, 2020 9:31 AM
To: Dumitrescu, Cristian <[email protected]>; [email protected]
Cc: [email protected]
Subject: RE: [PATCH v4] lib/table: fix cache alignment issueHi, Cristian,
Quoted 37 lines
-----Original Message-----
From: Dumitrescu, Cristian <[email protected]>
Sent: Wednesday, July 22, 2020 4:27 PM
To: Xu, Ting <[email protected]>; [email protected]
Cc: [email protected]
Subject: RE: [PATCH v4] lib/table: fix cache alignment issueQuoted 15 lines
lib/librte_table/rte_table_hash_key32.c +8
-0+#ifdef RTE_ARCH_64 struct rte_bucket_4_32 { /* Cache line 0 */ uint64_t signature[4 + 1];@@ -46,6 +47,22 @@ struct rte_bucket_4_32 { /* Cache line 3 */ uint8_t data[0]; }; +#else +struct rte_bucket_4_32 { + /* Cache line 0 */ + uint64_t signature[4 + 1]; + uint64_t lru_list; + struct rte_bucket_4_32 *next; + uint32_t pad;lib/librte_table/rte_table_hash_key32.c struct rte_bucket_4_32 { · line 66
Quoted 10 lines
lib/librte_table/rte_table_hash_key32.c +9
-0+uint64_t next_valid; + +/* Cache lines 1 and 2 */ +uint64_t key[4 ][4 ]; + +/* Cache line 3 */ + uint8_t data[0]; +}; +#endif Hi Ting,
Quoted 2 lines
Yes, it looks good, but as mentioned previously please do the same on the other files in the same folder and add the changes to your patch, as we
need
Quoted 11 lines
Quoted 3 lines
to keep all these files in sync:
rte_table_hash_key8.c, structrte_bucket_4_8rte_table_hash_key32.c,struct
Quoted 2 lines
rte_bucket_4_32I have did the changes to 8 and 32 bytes in this patch.
Quoted 2 lines
Thanks,
Cristian
Upss, sorry, somehow I missed it. I just acked this patch. Thanks, Ting!
Regards,
Cristian
Quoted 19 lines
-----Original Message-----
From: Xu, Ting <[email protected]>
Sent: Wednesday, July 22, 2020 3:16 AM
To: [email protected]
Cc: Dumitrescu, Cristian <[email protected]>; Xu, Ting <[email protected]>; [email protected]
Subject: [PATCH v4] lib/table: fix cache alignment issueWhen create softnic hash table with 16 keys, it failed on 32-bit environment, because the pointer field in structure
rte_bucket_4_16is only 32 bits. Add a padding field in 32-bit environment to keep the structure to a multiple of 64 bytes. Apply this to 8-byte and 32-byte key hash function as well.Fixes 8aa327214c ("table: hash")
Quoted 7 lines
Signed-off-by Ting Xu <[email protected]>---
v3->v4: Change design based on commentv2->v3: Rebasev1->v2: Correct patch time
---
Quoted 6 lines · Ting Xu
When create softnic hash table with 16 keys, it failed on 32-bit environment, because the pointer field in structure
rte_bucket_4_16is only 32 bits. Add a padding field in 32-bit environment to keep the structure to a multiple of 64 bytes. Apply this to 8-byte and 32-byte key hash function as well.
Please correct me if I am wrong, but it simply means this part of the table library never worked for 32-bit.
It seems more adding 32-bit support rather than a fix and then I wonder if it has its place in rc3.
Now, looking at the details:
For 64-bit on my x86, we have:
struct rte_bucket_4_8 {
uint64_t signature; /* 0 8 */
uint64_t lru_list; /* 8 8 */
struct rte_bucket_4_8 * next; /* 16 8 */
uint64_t next_valid; /* 24 8 */
uint64_t key[4]; /* 32 32 */
/* --- cacheline 1 boundary (64 bytes) --- */
uint8_t data[]; /* 64 0 */
/* size: 64, cachelines: 1, members: 6 */
};For 32-bit, we have:
struct rte_bucket_4_8 {
uint64_t signature; /* 0 8 */
uint64_t lru_list; /* 8 8 */
struct rte_bucket_4_8 * next; /* 16 4 */
uint64_t next_valid; /* 20 8 */
uint64_t key[4]; /* 28 32 */
uint8_t data[]; /* 60 0 */ /* size: 60, cachelines: 1, members: 6 */
/* last cacheline: 60 bytes */
} __attribute__((__packed__));^^ it is interesting that a packed attribute ends up here. I saw no such attribute in the library code. Compiler black magic at work I guess...
Quoted 38 lines
Fixes 8aa327214c ("table: hash")Signed-off-by Ting Xu <[email protected]>---
v3->v4: Change design based on commentv2->v3: Rebasev1->v2: Correct patch time--- lib/librte_table/rte_table_hash_key16.c | 17 +++++++++++++++++ lib/librte_table/rte_table_hash_key32.c | 17 +++++++++++++++++ lib/librte_table/rte_table_hash_key8.c | 16 ++++++++++++++++ 3 files changed, 50 insertions(+)lib/librte_table/rte_table_hash_key16.c +7
-0@@ -33,6 +33,7 @@#endif +#ifdef RTE_ARCH_64 struct rte_bucket_4_16 { /* Cache line 0 */ uint64_t signature[4 + 1];@@ -46,6 +47,22 @@ struct rte_bucket_4_16 { /* Cache line 2 */ uint8_t data[0]; }; +#else +struct rte_bucket_4_16 { + /* Cache line 0 */ + uint64_t signature[4 + 1]; + uint64_t lru_list; + struct rte_bucket_4_16 *next;
lib/librte_table/rte_table_hash_key16.c struct rte_bucket_4_16 { · line 65
Quoted 10 lines
lib/librte_table/rte_table_hash_key16.c +10
-0+uint32_t pad; +uint64_t next_valid; + +/* Cache line 1 */ +uint64_t key[4 ][2 ]; + +/* Cache line 2 */ + uint8_t data[0]; +}; +#endif
The change could simply be:
@@ -38,6 +38,9 @@ struct rte_bucket_4_16 {
uint64_t signature[4 + 1];
uint64_t lru_list;
struct rte_bucket_4_16 *next;
+#ifndef RTE_ARCH_64
+ uint32_t pad;
+#endif
uint64_t next_valid;
/* Cache line 1 */It avoids duplicating the whole structure definition (we could miss updating one side of the #ifdef later).
Idem for the other "8" and "32" structures.
Signature · 1 line
David Marchand
Quoted 18 lines
-----Original Message-----
From: David Marchand <[email protected]>
Sent: Wednesday, July 29, 2020 1:01 PM
To: Xu, Ting <[email protected]>; Dumitrescu, Cristian <[email protected]>
Cc: dev <[email protected]>; dpdk stable <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v4] lib/table: fix cache alignment issueQuoted 6 lines · Ting Xu
When create softnic hash table with 16 keys, it failed on 32-bit environment, because the pointer field in structure
rte_bucket_4_16is only 32 bits. Add a padding field in 32-bit environment to keep the structure to a multiple of 64 bytes. Apply this to 8-byte and 32-byte key hash function as well.
Quoted 5 lines
Please correct me if I am wrong, but it simply means this part of the table library never worked for 32-bit.
It seems more adding 32-bit support rather than a fix and then I wonder if it has its place in rc3.
Functionally. the code works, but performance is affected.
The only thing that prevents the code from working is the check in the table create function that checks the size of the above structure is 64 bytes, which caught this issue.
Quoted 29 lines
Now, looking at the details:
For 64-bit on my x86, we have:
struct
rte_bucket_4_8{uint64_t signature; /* 0 8 */ uint64_t lru_list; /* 8 8 */ struct rte_bucket_4_8 * next; /* 16 8 */ uint64_t next_valid; /* 24 8 */ uint64_t key[4]; /* 32 32 */ /* --- cacheline 1 boundary (64 bytes) --- */ uint8_t data[]; /* 64 0 */ /* size: 64, cachelines: 1, members: 6 */ };For 32-bit, we have:
struct
rte_bucket_4_8{uint64_t signature; /* 0 8 */ uint64_t lru_list; /* 8 8 */ struct rte_bucket_4_8 * next; /* 16 4 */ uint64_t next_valid; /* 20 8 */ uint64_t key[4]; /* 28 32 */ uint8_t data[]; /* 60 0 */
Quoted 8 lines
/* size: 60, cachelines: 1, members: 6 */ /* last cacheline: 60 bytes */ } __attribute__((__packed__));^^ it is interesting that a packed attribute ends up here. I saw no such attribute in the library code. Compiler black magic at work I guess...
Where do you see the packet attribute? I don't see it in the code.
A packet attribute would explain this issue, i.e. why did the compiler decide not to insert an expected padfing of 4 bytes right after the "next" field, that would allow the field "next_valid" to be aligned to its natural boundary of 8 bytes.
Quoted 71 lines
Quoted 11 lines
Fixes 8aa327214c ("table: hash")Signed-off-by Ting Xu <[email protected]>---
v3->v4: Change design based on commentv2->v3: Rebasev1->v2: Correct patch timeReview
Quoted 7 lines
--- lib/librte_table/rte_table_hash_key16.c | 17 +++++++++++++++++ lib/librte_table/rte_table_hash_key32.c | 17 +++++++++++++++++ lib/librte_table/rte_table_hash_key8.c | 16 ++++++++++++++++ 3 files changed, 50 insertions(+)(quoted diff) +0
-0
b/lib/librte_table/rte_table_hash_key16.cQuoted 21 lines
index
2cca1c924..c4384b114100644lib/librte_table/rte_table_hash_key16.c +7
-0@@ -33,6 +33,7 @@#endif +#ifdef RTE_ARCH_64 struct rte_bucket_4_16 { /* Cache line 0 */ uint64_t signature[4 + 1];@@ -46,6 +47,22 @@ struct rte_bucket_4_16 { /* Cache line 2 */ uint8_t data[0]; }; +#else +struct rte_bucket_4_16 { + /* Cache line 0 */ + uint64_t signature[4 + 1]; + uint64_t lru_list; + struct rte_bucket_4_16 *next;lib/librte_table/rte_table_hash_key16.c struct rte_bucket_4_16 { · line 65
Quoted 10 lines
lib/librte_table/rte_table_hash_key16.c +10
-0+uint32_t pad; +uint64_t next_valid; + +/* Cache line 1 */ +uint64_t key[4 ][2 ]; + +/* Cache line 2 */ + uint8_t data[0]; +}; +#endif The change could simply be:
(quoted diff) +3
-0@@ -38,6 +38,9 @@ struct rte_bucket_4_16 { uint64_t signature[4 + 1]; uint64_t lru_list; struct rte_bucket_4_16 *next; +#ifndef RTE_ARCH_64 + uint32_t pad; +#endif uint64_t next_valid; /* Cache line 1 */It avoids duplicating the whole structure definition (we could miss updating one side of the #ifdef later).
Idem for the other "8" and "32" structures.--
David Marchand
Quoted 9 lines · Cristian
Quoted 5 lines
Please correct me if I am wrong, but it simply means this part of the table library never worked for 32-bit.
It seems more adding 32-bit support rather than a fix and then I wonder if it has its place in rc3.Functionally. the code works, but performance is affected.
The only thing that prevents the code from working is the check in the table create function that checks the size of the above structure is 64 bytes, which caught this issue.
Yes, and that's my point.
It was not working.
It was not tested.
This patch asks for backport in stable branches, I will let Kevin and Luca comment.
Quoted 34 lines
Quoted 34 lines
Now, looking at the details:
For 64-bit on my x86, we have:
struct
rte_bucket_4_8{uint64_t signature; /* 0 8 */ uint64_t lru_list; /* 8 8 */ struct rte_bucket_4_8 * next; /* 16 8 */ uint64_t next_valid; /* 24 8 */ uint64_t key[4]; /* 32 32 */ /* --- cacheline 1 boundary (64 bytes) --- */ uint8_t data[]; /* 64 0 */ /* size: 64, cachelines: 1, members: 6 */ };For 32-bit, we have:
struct
rte_bucket_4_8{uint64_t signature; /* 0 8 */ uint64_t lru_list; /* 8 8 */ struct rte_bucket_4_8 * next; /* 16 4 */ uint64_t next_valid; /* 20 8 */ uint64_t key[4]; /* 28 32 */ uint8_t data[]; /* 60 0 *//* size: 60, cachelines: 1, members: 6 */ /* last cacheline: 60 bytes */ } __attribute__((__packed__));
Quoted 6 lines
Quoted 4 lines
^^ it is interesting that a packed attribute ends up here. I saw no such attribute in the library code. Compiler black magic at work I guess...
Where do you see the packet attribute? I don't see it in the code.
That's pahole reporting this.
Maybe the tool extrapolates this attribute based on the next_valid field placement... I don't know.
Quoted 1 line
A packet attribute would explain this issue, i.e. why did the compiler decide not to insert an expected padfing of 4 bytes right after the "next" field, that would allow the field "
next_valid" to be aligned to its natural boundary of 8 bytes.
Or a 64-bit field on 32-bit has a special alignment that I am not aware of.
Quoted 63 lines
Quoted 63 lines
Quoted 12 lines
Fixes 8aa327214c ("table: hash")Signed-off-by Ting Xu <[email protected]>---
v3->v4: Change design based on commentv2->v3: Rebasev1->v2: Correct patch timeReview
Quoted 7 lines
--- lib/librte_table/rte_table_hash_key16.c | 17 +++++++++++++++++ lib/librte_table/rte_table_hash_key32.c | 17 +++++++++++++++++ lib/librte_table/rte_table_hash_key8.c | 16 ++++++++++++++++ 3 files changed, 50 insertions(+)(quoted diff) +0
-0
b/lib/librte_table/rte_table_hash_key16.cQuoted 21 lines
index
2cca1c924..c4384b114100644lib/librte_table/rte_table_hash_key16.c +7
-0@@ -33,6 +33,7 @@#endif +#ifdef RTE_ARCH_64 struct rte_bucket_4_16 { /* Cache line 0 */ uint64_t signature[4 + 1];@@ -46,6 +47,22 @@ struct rte_bucket_4_16 { /* Cache line 2 */ uint8_t data[0]; }; +#else +struct rte_bucket_4_16 { + /* Cache line 0 */ + uint64_t signature[4 + 1]; + uint64_t lru_list; + struct rte_bucket_4_16 *next;lib/librte_table/rte_table_hash_key16.c struct rte_bucket_4_16 { · line 65
Quoted 10 lines
lib/librte_table/rte_table_hash_key16.c +10
-0+uint32_t pad; +uint64_t next_valid; + +/* Cache line 1 */ +uint64_t key[4 ][2 ]; + +/* Cache line 2 */ + uint8_t data[0]; +}; +#endif The change could simply be:
(quoted diff) +3
-0@@ -38,6 +38,9 @@ struct rte_bucket_4_16 { uint64_t signature[4 + 1]; uint64_t lru_list; struct rte_bucket_4_16 *next; +#ifndef RTE_ARCH_64 + uint32_t pad; +#endif uint64_t next_valid;
Quoted 5 lines
Quoted 5 lines
lib/librte_table/rte_table_hash_key8.c +0
-0/* Cache line 1 */ It avoids duplicating the whole structure definition (we could miss updating one side of the #ifdef later).
Idem for the other "8" and "32" structures.
What about this comment?
Signature · 1 line
David Marchand
Quoted 22 lines
-----Original Message-----
From: David Marchand <[email protected]>
Sent: Wednesday, July 29, 2020 2:28 PM
To: Dumitrescu, Cristian <[email protected]>
Cc: Xu, Ting <[email protected]>; dev <[email protected]>; dpdk stable <[email protected]>; Kevin Traynor <[email protected]>; Luca Boccassi <[email protected]>
Subject: Re: [dpdk-stable] [dpdk-dev] [PATCH v4] lib/table: fix cache alignment issueQuoted 8 lines · Cristian
Quoted 5 lines
Please correct me if I am wrong, but it simply means this part of the table library never worked for 32-bit.
It seems more adding 32-bit support rather than a fix and then I wonder if it has its place in rc3.Functionally. the code works, but performance is affected.
Quoted 9 lines
Quoted 1 line
The only thing that prevents the code from working is the check in the
table create function that checks the size of the above structure is 64 bytes, which caught this issue.
Yes, and that's my point.
It was not working.
It was not tested.
Not sure when this code was last tested on 32-bit systems, I'll let the validation folks comment on this, but I cannot rule out a change in compiler behavior either.
This is a low complexity and low impact change, hence low risk IMO.
Quoted 132 lines
This patch asks for backport in stable branches, I will let Kevin and Luca comment.
Quoted 34 lines
Quoted 34 lines
Now, looking at the details:
For 64-bit on my x86, we have:
struct
rte_bucket_4_8{uint64_t signature; /* 0 8 */ uint64_t lru_list; /* 8 8 */ struct rte_bucket_4_8 * next; /* 16 8 */ uint64_t next_valid; /* 24 8 */ uint64_t key[4]; /* 32 32 */ /* --- cacheline 1 boundary (64 bytes) --- */ uint8_t data[]; /* 64 0 */ /* size: 64, cachelines: 1, members: 6 */ };For 32-bit, we have:
struct
rte_bucket_4_8{uint64_t signature; /* 0 8 */ uint64_t lru_list; /* 8 8 */ struct rte_bucket_4_8 * next; /* 16 4 */ uint64_t next_valid; /* 20 8 */ uint64_t key[4]; /* 28 32 */ uint8_t data[]; /* 60 0 *//* size: 60, cachelines: 1, members: 6 */ /* last cacheline: 60 bytes */ } __attribute__((__packed__));Quoted 6 lines
Quoted 4 lines
^^ it is interesting that a packed attribute ends up here. I saw no such attribute in the library code. Compiler black magic at work I guess...
Where do you see the packet attribute? I don't see it in the code.
That's pahole reporting this.
Maybe the tool extrapolates this attribute based on thenext_validfield placement... I don't know.Quoted 1 line
A packet attribute would explain this issue, i.e. why did the compiler decide
not to insert an expected padfing of 4 bytes right after the "next" field, that would allow the field "
next_valid" to be aligned to its natural boundary of 8 bytes.Or a 64-bit field on 32-bit has a special alignment that I am not aware of.
Quoted 63 lines
Quoted 63 lines
Quoted 12 lines
Fixes 8aa327214c ("table: hash")Signed-off-by Ting Xu <[email protected]>---
v3->v4: Change design based on commentv2->v3: Rebasev1->v2: Correct patch timeReview
Quoted 7 lines
--- lib/librte_table/rte_table_hash_key16.c | 17 +++++++++++++++++ lib/librte_table/rte_table_hash_key32.c | 17 +++++++++++++++++ lib/librte_table/rte_table_hash_key8.c | 16 ++++++++++++++++ 3 files changed, 50 insertions(+)(quoted diff) +0
-0
b/lib/librte_table/rte_table_hash_key16.cQuoted 21 lines
index
2cca1c924..c4384b114100644lib/librte_table/rte_table_hash_key16.c +7
-0@@ -33,6 +33,7 @@#endif +#ifdef RTE_ARCH_64 struct rte_bucket_4_16 { /* Cache line 0 */ uint64_t signature[4 + 1];@@ -46,6 +47,22 @@ struct rte_bucket_4_16 { /* Cache line 2 */ uint8_t data[0]; }; +#else +struct rte_bucket_4_16 { + /* Cache line 0 */ + uint64_t signature[4 + 1]; + uint64_t lru_list; + struct rte_bucket_4_16 *next;lib/librte_table/rte_table_hash_key16.c struct rte_bucket_4_16 { · line 65
Quoted 10 lines
lib/librte_table/rte_table_hash_key16.c +10
-0+uint32_t pad; +uint64_t next_valid; + +/* Cache line 1 */ +uint64_t key[4 ][2 ]; + +/* Cache line 2 */ + uint8_t data[0]; +}; +#endif The change could simply be:
(quoted diff) +3
-0@@ -38,6 +38,9 @@ struct rte_bucket_4_16 { uint64_t signature[4 + 1]; uint64_t lru_list; struct rte_bucket_4_16 *next; +#ifndef RTE_ARCH_64 + uint32_t pad; +#endif uint64_t next_valid;Quoted 5 lines
Quoted 5 lines
lib/librte_table/rte_table_hash_key8.c +0
-0/* Cache line 1 */ It avoids duplicating the whole structure definition (we could miss updating one side of the #ifdef later).
Idem for the other "8" and "32" structures.What about this comment?
--
David Marchand
Quoted 30 lines · Cristian
Quoted 20 lines
-----Original Message-----
From: David Marchand <[email protected]>
Sent: Wednesday, July 29, 2020 2:28 PM
To: Dumitrescu, Cristian <[email protected]>
Cc: Xu, Ting <[email protected]>; dev <[email protected]>; dpdk stable <[email protected]>; Kevin Traynor <[email protected]>; Luca Boccassi <[email protected]>
Subject: Re: [dpdk-stable] [dpdk-dev] [PATCH v4] lib/table: fix cache alignment issueQuoted 8 lines · Cristian
Quoted 5 lines
Please correct me if I am wrong, but it simply means this part of the table library never worked for 32-bit.
It seems more adding 32-bit support rather than a fix and then I wonder if it has its place in rc3.Functionally. the code works, but performance is affected.
Quoted 9 lines
Quoted 1 line
The only thing that prevents the code from working is the check in the
table create function that checks the size of the above structure is 64 bytes, which caught this issue.
Yes, and that's my point.
It was not working.
It was not tested.
Quoted 3 lines
Not sure when this code was last tested on 32-bit systems, I'll let the validation folks comment on this, but I cannot rule out a change in compiler behavior either.
This is a low complexity and low impact change, hence low risk IMO.
Risk is to be evaluated when there is a need. I got pinged on this, like it was the end of the times.
Then I find something that is not worth looking at, hence I am a bit irritated.
And please, for the 2nd time, can you look at my comment below?
Quoted 45 lines
Quoted 45 lines
Quoted 45 lines
Quoted 45 lines
Review
Quoted 1 line
(quoted diff) +0
-0
b/lib/librte_table/rte_table_hash_key16.cQuoted 21 lines
index
2cca1c924..c4384b114100644lib/librte_table/rte_table_hash_key16.c +7
-0@@ -33,6 +33,7 @@#endif +#ifdef RTE_ARCH_64 struct rte_bucket_4_16 { /* Cache line 0 */ uint64_t signature[4 + 1];@@ -46,6 +47,22 @@ struct rte_bucket_4_16 { /* Cache line 2 */ uint8_t data[0]; }; +#else +struct rte_bucket_4_16 { + /* Cache line 0 */ + uint64_t signature[4 + 1]; + uint64_t lru_list; + struct rte_bucket_4_16 *next;lib/librte_table/rte_table_hash_key16.c struct rte_bucket_4_16 { · line 65
Quoted 10 lines
lib/librte_table/rte_table_hash_key16.c +10
-0+uint32_t pad; +uint64_t next_valid; + +/* Cache line 1 */ +uint64_t key[4 ][2 ]; + +/* Cache line 2 */ + uint8_t data[0]; +}; +#endif The change could simply be:
(quoted diff) +3
-0@@ -38,6 +38,9 @@ struct rte_bucket_4_16 { uint64_t signature[4 + 1]; uint64_t lru_list; struct rte_bucket_4_16 *next; +#ifndef RTE_ARCH_64 + uint32_t pad; +#endif uint64_t next_valid;
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
lib/librte_table/rte_table_hash_key8.c +0
-0/* Cache line 1 */ It avoids duplicating the whole structure definition (we could miss updating one side of the #ifdef later).
Idem for the other "8" and "32" structures.What about this comment?
What about this comment?
Signature · 1 line
David Marchand
Quoted 50 lines
-----Original Message-----
From: David Marchand <[email protected]>
Sent: Wednesday, July 29, 2020 3:00 PM
To: Dumitrescu, Cristian <[email protected]>
Cc: Xu, Ting <[email protected]>; dev <[email protected]>; dpdk stable <[email protected]>; Kevin Traynor <[email protected]>; Luca Boccassi <[email protected]>
Subject: Re: [dpdk-stable] [dpdk-dev] [PATCH v4] lib/table: fix cache alignment issueQuoted 6 lines · Cristian
Quoted 6 lines
-----Original Message-----
From: David Marchand <[email protected]>
Sent: Wednesday, July 29, 2020 2:28 PM
To: Dumitrescu, Cristian <[email protected]>
Cc: Xu, Ting <[email protected]>; dev <[email protected]>; dpdk stable <[email protected]>; Kevin Traynor <[email protected]>; LucaBoccassi
Quoted 12 lines
Quoted 12 lines
<[email protected]>
Subject: Re: [dpdk-stable] [dpdk-dev] [PATCH v4] lib/table: fix cache alignment issueQuoted 6 lines · Cristian
Quoted 5 lines
Please correct me if I am wrong, but it simply means this part of the table library never worked for 32-bit.
It seems more adding 32-bit support rather than a fix and then I wonder if it has its place in rc3.Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Functionally. the code works, but performance is affected.
The only thing that prevents the code from working is the check in the
table create function that checks the size of the above structure is 64
bytes,
Quoted 9 lines
Quoted 7 lines
which caught this issue.
Yes, and that's my point.
It was not working.
It was not tested.Not sure when this code was last tested on 32-bit systems, I'll let the
validation folks comment on this, but I cannot rule out a change in compiler behavior either.
Quoted 1 line
Quoted 7 lines
Quoted 1 line
This is a low complexity and low impact change, hence low risk IMO.
Risk is to be evaluated when there is a need. I got pinged on this, like it was the end of the times.
Then I find something that is not worth looking at, hence I am a bit irritated.
I got pinged as well, and I also had to allocate time on this patch. It probably means it is important for somebody.
Quoted 2 lines
And please, for the 2nd time, can you look at my comment below?
Sorry, I missed it first.
Quoted 48 lines
Quoted 48 lines
Quoted 48 lines
Quoted 48 lines
Quoted 48 lines
Review
Quoted 2 lines
(quoted diff) +0
-0
b/lib/librte_table/rte_table_hash_key16.cQuoted 21 lines
index
2cca1c924..c4384b114100644lib/librte_table/rte_table_hash_key16.c +7
-0@@ -33,6 +33,7 @@#endif +#ifdef RTE_ARCH_64 struct rte_bucket_4_16 { /* Cache line 0 */ uint64_t signature[4 + 1];@@ -46,6 +47,22 @@ struct rte_bucket_4_16 { /* Cache line 2 */ uint8_t data[0]; }; +#else +struct rte_bucket_4_16 { + /* Cache line 0 */ + uint64_t signature[4 + 1]; + uint64_t lru_list; + struct rte_bucket_4_16 *next;lib/librte_table/rte_table_hash_key16.c struct rte_bucket_4_16 { · line 65
Quoted 10 lines
lib/librte_table/rte_table_hash_key16.c +10
-0+uint32_t pad; +uint64_t next_valid; + +/* Cache line 1 */ +uint64_t key[4 ][2 ]; + +/* Cache line 2 */ + uint8_t data[0]; +}; +#endif The change could simply be:
(quoted diff) +3
-0@@ -38,6 +38,9 @@ struct rte_bucket_4_16 { uint64_t signature[4 + 1]; uint64_t lru_list; struct rte_bucket_4_16 *next; +#ifndef RTE_ARCH_64 + uint32_t pad; +#endif uint64_t next_valid; /* Cache line 1 */
Quoted 9 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
It avoids duplicating the whole structure definition (we could miss updating one side of the #ifdef later).
Idem for the other "8" and "32" structures.What about this comment?
What about this comment?
You might suspect I also thought about this option. My preference is for the option in the patch for the reasons that IMO it is easier to read and understand the reason for the difference, even though the code is slightly larger. It also leaves the 64-bit code untouched, so it is easier to remove when we finally decide at some point to drop the 32-bit support.
But I can live with the option you describe as well. Thanks for the input.
For me, it would be great if somebody on this list could indicate why the 4-byte padding was not inserted by the compiler automatically, and hence the need for this fix.
Quoted 3 lines
--
David Marchand
Hi, all,
Quoted 142 lines
-----Original Message-----
From: Dumitrescu, Cristian <[email protected]>
Sent: Wednesday, July 29, 2020 10:53 PM
To: David Marchand <[email protected]>
Cc: Xu, Ting <[email protected]>; dev <[email protected]>; dpdk stable <[email protected]>; Kevin Traynor <[email protected]>; Luca Boccassi <[email protected]>
Subject: RE: [dpdk-stable] [dpdk-dev] [PATCH v4] lib/table: fix cache alignment issueQuoted 51 lines
-----Original Message-----
From: David Marchand <[email protected]>
Sent: Wednesday, July 29, 2020 3:00 PM
To: Dumitrescu, Cristian <[email protected]>
Cc: Xu, Ting <[email protected]>; dev <[email protected]>; dpdk stable <[email protected]>; Kevin Traynor <[email protected]>; Luca Boccassi <[email protected]>
Subject: Re: [dpdk-stable] [dpdk-dev] [PATCH v4] lib/table: fix cache alignment issueQuoted 6 lines · Cristian
Quoted 6 lines
-----Original Message-----
From: David Marchand <[email protected]>
Sent: Wednesday, July 29, 2020 2:28 PM
To: Dumitrescu, Cristian <[email protected]>
Cc: Xu, Ting <[email protected]>; dev <[email protected]>; dpdk stable <[email protected]>; Kevin Traynor <[email protected]>; LucaBoccassi
Quoted 12 lines
Quoted 12 lines
<[email protected]>
Subject: Re: [dpdk-stable] [dpdk-dev] [PATCH v4] lib/table: fix cache alignment issueQuoted 6 lines · Cristian
Quoted 5 lines
Please correct me if I am wrong, but it simply means this part of the table library never worked for 32-bit.
It seems more adding 32-bit support rather than a fix and then I wonder if it has its place in rc3.Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Functionally. the code works, but performance is affected.
The only thing that prevents the code from working is the check in the
table create function that checks the size of the above structure is 64
bytes,
Quoted 10 lines
Quoted 7 lines
which caught this issue.
Yes, and that's my point.
It was not working.
It was not tested.Not sure when this code was last tested on 32-bit systems, I'll let the
validation folks comment on this, but I cannot rule out a change in compiler behavior either.
Quoted 1 line
Quoted 7 lines
Quoted 1 line
This is a low complexity and low impact change, hence low risk IMO.
Risk is to be evaluated when there is a need. I got pinged on this, like it was the end of the times.
Then I find something that is not worth looking at, hence I am a bit irritated.
I got pinged as well, and I also had to allocate time on this patch. It probably means it is important for somebody.
Quoted 2 lines
And please, for the 2nd time, can you look at my comment below?
Sorry, I missed it first.
Quoted 48 lines
Quoted 48 lines
Quoted 48 lines
Quoted 48 lines
Quoted 48 lines
Review
Quoted 2 lines
(quoted diff) +0
-0
b/lib/librte_table/rte_table_hash_key16.cQuoted 21 lines
index
2cca1c924..c4384b114100644lib/librte_table/rte_table_hash_key16.c +1
-0@@ -33,6 +33,7 @@#endif +#ifdef RTE_ARCH_64 struct rte_bucket_4_16 { /* Cache line 0 */ uint64_t signature[4 + 1]; @@ -46,6 +47,22 @@ structrte_bucket_4_16 { /* Cache line 2 */ uint8_t data[0];};
lib/librte_table/rte_table_hash_key16.c +6
-0+#else +struct rte_bucket_4_16 { + /* Cache line 0 */ + uint64_t signature[4 + 1]; + uint64_t lru_list; + struct rte_bucket_4_16 *next;lib/librte_table/rte_table_hash_key16.c
Quoted 10 lines
lib/librte_table/rte_table_hash_key16.c +10
-0+uint32_t pad; +uint64_t next_valid; + +/* Cache line 1 */ +uint64_t key[4 ][2 ]; + +/* Cache line 2 */ + uint8_t data[0]; +}; +#endif The change could simply be:
(quoted diff) +3
-0@@ -38,6 +38,9 @@ struct rte_bucket_4_16 { uint64_t signature[4 + 1]; uint64_t lru_list; struct rte_bucket_4_16 *next; +#ifndef RTE_ARCH_64 + uint32_t pad; +#endif uint64_t next_valid; /* Cache line 1 */Quoted 9 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
It avoids duplicating the whole structure definition (we could miss updating one side of the #ifdef later).
Idem for the other "8" and "32" structures.What about this comment?
What about this comment?
You might suspect I also thought about this option. My preference is for the option in the patch for the reasons that IMO it is easier to read and understand the reason for the difference, even though the code is slightly larger. It also leaves the 64-bit code untouched, so it is easier to remove when we finally decide at some point to drop the 32-bit support.
Quoted 6 lines
But I can live with the option you describe as well. Thanks for the input.
For me, it would be great if somebody on this list could indicate why the 4- byte padding was not inserted by the compiler automatically, and hence the need for this fix.
Thanks for your help and additional works on this patch.
The validation team tested this case in a 32-bit environment, besides, there are a series of similar tests in 32-bit environment as well. There might be some practical needs for this. Therefore, before we decide to drop 32-bit support formally, I think such modification is OK, if we cannot fix the compiler issue directly.
Shall I update the patch as David suggested to make it simpler?
Quoted 3 lines
Quoted 3 lines
--
David Marchand
Quoted 12 lines · David Marchand
Quoted 9 lines · Cristian
Quoted 5 lines
Please correct me if I am wrong, but it simply means this part of the table library never worked for 32-bit.
It seems more adding 32-bit support rather than a fix and then I wonder if it has its place in rc3.Functionally. the code works, but performance is affected.
The only thing that prevents the code from working is the check in the table create function that checks the size of the above structure is 64 bytes, which caught this issue.
Quoted 8 lines
Yes, and that's my point.
It was not working.
It was not tested.This patch asks for backport in stable branches, I will let Kevin and Luca comment.
It should be in master first, but then it's a fix so I think it can go to stable if requested and supported by the table maintainer in the event of any (future) regressions.
Quoted 124 lines
Quoted 35 lines
Quoted 35 lines
Now, looking at the details:
For 64-bit on my x86, we have:
struct
rte_bucket_4_8{uint64_t signature; /* 0 8 */ uint64_t lru_list; /* 8 8 */ struct rte_bucket_4_8 * next; /* 16 8 */ uint64_t next_valid; /* 24 8 */ uint64_t key[4]; /* 32 32 */ /* --- cacheline 1 boundary (64 bytes) --- */ uint8_t data[]; /* 64 0 */ /* size: 64, cachelines: 1, members: 6 */ };For 32-bit, we have:
struct
rte_bucket_4_8{uint64_t signature; /* 0 8 */ uint64_t lru_list; /* 8 8 */ struct rte_bucket_4_8 * next; /* 16 4 */ uint64_t next_valid; /* 20 8 */ uint64_t key[4]; /* 28 32 */ uint8_t data[]; /* 60 0 *//* size: 60, cachelines: 1, members: 6 */ /* last cacheline: 60 bytes */ } __attribute__((__packed__));Quoted 6 lines
Quoted 4 lines
^^ it is interesting that a packed attribute ends up here. I saw no such attribute in the library code. Compiler black magic at work I guess...
Where do you see the packet attribute? I don't see it in the code.
That's pahole reporting this.
Maybe the tool extrapolates this attribute based on thenext_validfield placement... I don't know.Quoted 1 line
A packet attribute would explain this issue, i.e. why did the compiler decide not to insert an expected padfing of 4 bytes right after the "next" field, that would allow the field "
next_valid" to be aligned to its natural boundary of 8 bytes.Or a 64-bit field on 32-bit has a special alignment that I am not aware of.
Quoted 63 lines
Quoted 63 lines
Quoted 12 lines
Fixes 8aa327214c ("table: hash")Signed-off-by Ting Xu <[email protected]>---
v3->v4: Change design based on commentv2->v3: Rebasev1->v2: Correct patch timeReview
Quoted 7 lines
--- lib/librte_table/rte_table_hash_key16.c | 17 +++++++++++++++++ lib/librte_table/rte_table_hash_key32.c | 17 +++++++++++++++++ lib/librte_table/rte_table_hash_key8.c | 16 ++++++++++++++++ 3 files changed, 50 insertions(+)(quoted diff) +0
-0
b/lib/librte_table/rte_table_hash_key16.cQuoted 21 lines
index
2cca1c924..c4384b114100644lib/librte_table/rte_table_hash_key16.c +7
-0@@ -33,6 +33,7 @@#endif +#ifdef RTE_ARCH_64 struct rte_bucket_4_16 { /* Cache line 0 */ uint64_t signature[4 + 1];@@ -46,6 +47,22 @@ struct rte_bucket_4_16 { /* Cache line 2 */ uint8_t data[0]; }; +#else +struct rte_bucket_4_16 { + /* Cache line 0 */ + uint64_t signature[4 + 1]; + uint64_t lru_list; + struct rte_bucket_4_16 *next;lib/librte_table/rte_table_hash_key16.c struct rte_bucket_4_16 { · line 65
Quoted 10 lines
lib/librte_table/rte_table_hash_key16.c +10
-0+uint32_t pad; +uint64_t next_valid; + +/* Cache line 1 */ +uint64_t key[4 ][2 ]; + +/* Cache line 2 */ + uint8_t data[0]; +}; +#endif The change could simply be:
(quoted diff) +3
-0@@ -38,6 +38,9 @@ struct rte_bucket_4_16 { uint64_t signature[4 + 1]; uint64_t lru_list; struct rte_bucket_4_16 *next; +#ifndef RTE_ARCH_64 + uint32_t pad; +#endif uint64_t next_valid;Quoted 5 lines
Quoted 5 lines
lib/librte_table/rte_table_hash_key8.c +0
-0/* Cache line 1 */ It avoids duplicating the whole structure definition (we could miss updating one side of the #ifdef later).
Idem for the other "8" and "32" structures.What about this comment?
Hi, All
Sorry to bother you again. Since the next release is coming, and this patch is deferred for some time, I'd like to know that shall we continue to merge it?
What is the key issue that blocks us? Thanks!
Best Regards,
Xu Ting
Quoted 166 lines
-----Original Message-----
From: Kevin Traynor <[email protected]>
Sent: Thursday, July 30, 2020 6:35 PM
To: David Marchand <[email protected]>; Dumitrescu, Cristian <[email protected]>
Cc: Xu, Ting <[email protected]>; dev <[email protected]>; dpdk stable <[email protected]>; Luca Boccassi <[email protected]>
Subject: Re: [dpdk-stable] [dpdk-dev] [PATCH v4] lib/table: fix cache alignment issueQuoted 11 lines · David Marchand
Quoted 9 lines · Cristian
Quoted 5 lines
Please correct me if I am wrong, but it simply means this part of the table library never worked for 32-bit.
It seems more adding 32-bit support rather than a fix and then I wonder if it has its place in rc3.Functionally. the code works, but performance is affected.
The only thing that prevents the code from working is the check in the
table create function that checks the size of the above structure is 64 bytes, which caught this issue.
Quoted 9 lines
Yes, and that's my point.
It was not working.
It was not tested.This patch asks for backport in stable branches, I will let Kevin and Luca comment.
It should be in master first, but then it's a fix so I think it can go to stable if requested and supported by the table maintainer in the event of any (future) regressions.
Quoted 39 lines
Quoted 39 lines
Quoted 38 lines
Now, looking at the details:
For 64-bit on my x86, we have:
struct
rte_bucket_4_8{uint64_t signature; /* 0 8 */ uint64_t lru_list; /* 8 8 */ struct rte_bucket_4_8 * next; /* 16 8 */ uint64_t next_valid; /* 24 8 */ uint64_t key[4]; /* 32 32 */ /* --- cacheline 1 boundary (64 bytes) --- */ uint8_t data[]; /* 64 0 */ /* size: 64, cachelines: 1, members: 6 */ };For 32-bit, we have:
struct
rte_bucket_4_8{uint64_t signature; /* 0 8 */ uint64_t lru_list; /* 8 8 */ struct rte_bucket_4_8 * next; /* 16 4 */ uint64_t next_valid; /* 20 8 */ uint64_t key[4]; /* 28 32 */ uint8_t data[]; /* 60 0 *//* size: 60, cachelines: 1, members: 6 */ /* last cacheline: 60 bytes */ } __attribute__((__packed__));^^ it is interesting that a packed attribute ends up here. I saw no such attribute in the library code. Compiler black magic at work I guess...
Quoted 7 lines
Quoted 1 line
Where do you see the packet attribute? I don't see it in the code.
That's pahole reporting this.
Maybe the tool extrapolates this attribute based on thenext_validfield placement... I don't know.Quoted 1 line
A packet attribute would explain this issue, i.e. why did the compiler
decide not to insert an expected padfing of 4 bytes right after the "next" field, that would allow the field "
next_valid" to be aligned to its natural boundary of 8 bytes.Quoted 77 lines
Or a 64-bit field on 32-bit has a special alignment that I am not aware of.
Quoted 63 lines
Quoted 63 lines
Quoted 12 lines
Fixes 8aa327214c ("table: hash")Signed-off-by Ting Xu <[email protected]>---
v3->v4: Change design based on commentv2->v3: Rebasev1->v2: Correct patch timeReview
Quoted 7 lines
--- lib/librte_table/rte_table_hash_key16.c | 17 +++++++++++++++++ lib/librte_table/rte_table_hash_key32.c | 17 +++++++++++++++++ lib/librte_table/rte_table_hash_key8.c | 16 ++++++++++++++++ 3 files changed, 50 insertions(+)(quoted diff) +0
-0
b/lib/librte_table/rte_table_hash_key16.cQuoted 21 lines
index
2cca1c924..c4384b114100644lib/librte_table/rte_table_hash_key16.c +7
-0@@ -33,6 +33,7 @@#endif +#ifdef RTE_ARCH_64 struct rte_bucket_4_16 { /* Cache line 0 */ uint64_t signature[4 + 1];@@ -46,6 +47,22 @@ struct rte_bucket_4_16 { /* Cache line 2 */ uint8_t data[0]; }; +#else +struct rte_bucket_4_16 { + /* Cache line 0 */ + uint64_t signature[4 + 1]; + uint64_t lru_list; + struct rte_bucket_4_16 *next;lib/librte_table/rte_table_hash_key16.c struct rte_bucket_4_16 { · line 65
Quoted 10 lines
lib/librte_table/rte_table_hash_key16.c +10
-0+uint32_t pad; +uint64_t next_valid; + +/* Cache line 1 */ +uint64_t key[4 ][2 ]; + +/* Cache line 2 */ + uint8_t data[0]; +}; +#endif The change could simply be:
(quoted diff) +3
-0@@ -38,6 +38,9 @@ struct rte_bucket_4_16 { uint64_t signature[4 + 1]; uint64_t lru_list; struct rte_bucket_4_16 *next; +#ifndef RTE_ARCH_64 + uint32_t pad; +#endif uint64_t next_valid;Quoted 5 lines
Quoted 5 lines
lib/librte_table/rte_table_hash_key8.c +0
-0/* Cache line 1 */ It avoids duplicating the whole structure definition (we could miss updating one side of the #ifdef later).
Idem for the other "8" and "32" structures.What about this comment?
Quoted 3 lines · Ting
Sorry to bother you again. Since the next release is coming, and this patch is deferred for some time, I'd like to know that shall we continue to merge it?
What is the key issue that blocks us? Thanks!
Afaics, Kevin email did not get a reply, so I understand this as an implicit ack from the table maintainers.
I will take this patch as is (i.e. with the request for backport) in rc1.
Signature · 1 line
David Marchand
Quoted 11 lines
-----Original Message-----
From: David Marchand <[email protected]>
Sent: Tuesday, September 15, 2020 4:03 PM
To: Xu, Ting <[email protected]>
Cc: Kevin Traynor <[email protected]>; Dumitrescu, Cristian <[email protected]>; dev <[email protected]>; dpdk stable <[email protected]>; Luca Boccassi <[email protected]>
Subject: Re: [dpdk-stable] [dpdk-dev] [PATCH v4] lib/table: fix cache alignment issueOn Wed, Sep 9, 2020 at 8:19 AM Xu, Ting <[email protected]> wrote:
Quoted 9 lines
Quoted 1 line
Sorry to bother you again. Since the next release is coming, and this patch is
deferred for some time, I'd like to know that shall we continue to merge it?
Quoted 2 lines
What is the key issue that blocks us? Thanks!
Afaics, Kevin email did not get a reply, so I understand this as an implicit ack from the table maintainers.
I will take this patch as is (i.e. with the request for backport) in rc1.
Kindly remind RC1 is coming soon. If there is no additional comments, could this be merged?
Quoted 3 lines
--
David Marchand
Quoted 11 lines · Ting Xu
When create softnic hash table with 16 keys, it failed on 32-bit environment, because the pointer field in structure
rte_bucket_4_16is only 32 bits. Add a padding field in 32-bit environment to keep the structure to a multiple of 64 bytes. Apply this to 8-byte and 32-byte key hash function as well.Fixes 8aa327214c ("table: hash")Signed-off-by Ting Xu <[email protected]>
Applied, thanks.
Signature · 1 line
David Marchand