net/af_packet: cache align Rx/Tx structs

Message ID 20240426073824.100386-1-mattias.ronnblom@ericsson.com (mailing list archive)
State Changes Requested
Delegated to: Ferruh Yigit
Headers
Series net/af_packet: cache align Rx/Tx structs |

Checks

Context Check Description
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-compile-amd64-testing fail Testing issues
ci/iol-abi-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-compile-arm64-testing success Testing PASS

Commit Message

Mattias Rönnblom April 26, 2024, 7:38 a.m. UTC
  Cache align Rx and Tx queue struct to avoid false sharing.

RX struct happens to be 64 bytes on x86_64 already, so cache alignment
has no effect there, but it does on 32-bit ISAs.

TX struct is 56 bytes on x86_64.

Both structs keep counters, and in the RX case they are updated even
for empty polls.

Fixes: 364e08f2bbc0 ("af_packet: add PMD for AF_PACKET-based virtual devices")
Cc: stable@dpdk.org

Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>
---
 drivers/net/af_packet/rte_eth_af_packet.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
  

Comments

Ferruh Yigit April 26, 2024, 8:27 a.m. UTC | #1
On 4/26/2024 8:38 AM, Mattias Rönnblom wrote:
> Cache align Rx and Tx queue struct to avoid false sharing.
> 
> RX struct happens to be 64 bytes on x86_64 already, so cache alignment
> has no effect there, but it does on 32-bit ISAs.
> 
> TX struct is 56 bytes on x86_64.
> 
> Both structs keep counters, and in the RX case they are updated even
> for empty polls.
> 
> Fixes: 364e08f2bbc0 ("af_packet: add PMD for AF_PACKET-based virtual devices")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>
> ---
>  drivers/net/af_packet/rte_eth_af_packet.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c
> index 397a32db58..28aeb7d08e 100644
> --- a/drivers/net/af_packet/rte_eth_af_packet.c
> +++ b/drivers/net/af_packet/rte_eth_af_packet.c
> @@ -6,6 +6,7 @@
>   * All rights reserved.
>   */
>  
> +#include <rte_common.h>
>  #include <rte_string_fns.h>
>  #include <rte_mbuf.h>
>  #include <ethdev_driver.h>
> @@ -53,7 +54,7 @@ struct pkt_rx_queue {
>  
>  	volatile unsigned long rx_pkts;
>  	volatile unsigned long rx_bytes;
> -};
> +} __rte_cache_aligned;
>  
>  struct pkt_tx_queue {
>  	int sockfd;
> @@ -67,7 +68,7 @@ struct pkt_tx_queue {
>  	volatile unsigned long tx_pkts;
>  	volatile unsigned long err_pkts;
>  	volatile unsigned long tx_bytes;
> -};
> +} __rte_cache_aligned;
>  
>  struct pmd_internals {
>  	unsigned nb_queues;

Hi Mattias,

I guess my comment missed, location of '__rte_cache_aligned' tag changed
for MSVC support, it should be like:
```
struct __rte_cache_aligned pkt_rx_queue {
...
};
```
  
Mattias Rönnblom April 26, 2024, 10:20 a.m. UTC | #2
On 2024-04-26 10:27, Ferruh Yigit wrote:
> On 4/26/2024 8:38 AM, Mattias Rönnblom wrote:
>> Cache align Rx and Tx queue struct to avoid false sharing.
>>
>> RX struct happens to be 64 bytes on x86_64 already, so cache alignment
>> has no effect there, but it does on 32-bit ISAs.
>>
>> TX struct is 56 bytes on x86_64.
>>
>> Both structs keep counters, and in the RX case they are updated even
>> for empty polls.
>>
>> Fixes: 364e08f2bbc0 ("af_packet: add PMD for AF_PACKET-based virtual devices")
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>
>> ---
>>   drivers/net/af_packet/rte_eth_af_packet.c | 5 +++--
>>   1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c
>> index 397a32db58..28aeb7d08e 100644
>> --- a/drivers/net/af_packet/rte_eth_af_packet.c
>> +++ b/drivers/net/af_packet/rte_eth_af_packet.c
>> @@ -6,6 +6,7 @@
>>    * All rights reserved.
>>    */
>>   
>> +#include <rte_common.h>
>>   #include <rte_string_fns.h>
>>   #include <rte_mbuf.h>
>>   #include <ethdev_driver.h>
>> @@ -53,7 +54,7 @@ struct pkt_rx_queue {
>>   
>>   	volatile unsigned long rx_pkts;
>>   	volatile unsigned long rx_bytes;
>> -};
>> +} __rte_cache_aligned;
>>   
>>   struct pkt_tx_queue {
>>   	int sockfd;
>> @@ -67,7 +68,7 @@ struct pkt_tx_queue {
>>   	volatile unsigned long tx_pkts;
>>   	volatile unsigned long err_pkts;
>>   	volatile unsigned long tx_bytes;
>> -};
>> +} __rte_cache_aligned;
>>   
>>   struct pmd_internals {
>>   	unsigned nb_queues;
> 
> Hi Mattias,
> 
> I guess my comment missed, location of '__rte_cache_aligned' tag changed
> for MSVC support, it should be like:
> ```
> struct __rte_cache_aligned pkt_rx_queue {
> ...
> };
> ```

Right. Sorry, forgot about that.

I've made a v3 (which is actually marked v3).
  

Patch

diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c
index 397a32db58..28aeb7d08e 100644
--- a/drivers/net/af_packet/rte_eth_af_packet.c
+++ b/drivers/net/af_packet/rte_eth_af_packet.c
@@ -6,6 +6,7 @@ 
  * All rights reserved.
  */
 
+#include <rte_common.h>
 #include <rte_string_fns.h>
 #include <rte_mbuf.h>
 #include <ethdev_driver.h>
@@ -53,7 +54,7 @@  struct pkt_rx_queue {
 
 	volatile unsigned long rx_pkts;
 	volatile unsigned long rx_bytes;
-};
+} __rte_cache_aligned;
 
 struct pkt_tx_queue {
 	int sockfd;
@@ -67,7 +68,7 @@  struct pkt_tx_queue {
 	volatile unsigned long tx_pkts;
 	volatile unsigned long err_pkts;
 	volatile unsigned long tx_bytes;
-};
+} __rte_cache_aligned;
 
 struct pmd_internals {
 	unsigned nb_queues;