patches for DPDK stable branches
 help / color / mirror / Atom feed
* [PATCH] net/af_packet: cache align Rx/Tx structs
       [not found] <20240423090813.94110-1-mattias.ronnblom@ericsson.com>
@ 2024-04-26  7:38 ` Mattias Rönnblom
  2024-04-26  8:27   ` Ferruh Yigit
  2024-04-26  9:05   ` [PATCH v3] " Mattias Rönnblom
  0 siblings, 2 replies; 8+ messages in thread
From: Mattias Rönnblom @ 2024-04-26  7:38 UTC (permalink / raw)
  To: dev
  Cc: hofors, Morten Brørup, Stephen Hemminger, Thomas Monjalon,
	John W . Linville, Ferruh Yigit, Mattias Rönnblom, stable

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;
-- 
2.34.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] net/af_packet: cache align Rx/Tx structs
  2024-04-26  7:38 ` [PATCH] net/af_packet: cache align Rx/Tx structs Mattias Rönnblom
@ 2024-04-26  8:27   ` Ferruh Yigit
  2024-04-26 10:20     ` Mattias Rönnblom
  2024-04-26  9:05   ` [PATCH v3] " Mattias Rönnblom
  1 sibling, 1 reply; 8+ messages in thread
From: Ferruh Yigit @ 2024-04-26  8:27 UTC (permalink / raw)
  To: Mattias Rönnblom, dev
  Cc: hofors, Morten Brørup, Stephen Hemminger, Thomas Monjalon,
	John W . Linville, stable

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 {
...
};
```

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v3] net/af_packet: cache align Rx/Tx structs
  2024-04-26  7:38 ` [PATCH] net/af_packet: cache align Rx/Tx structs Mattias Rönnblom
  2024-04-26  8:27   ` Ferruh Yigit
@ 2024-04-26  9:05   ` Mattias Rönnblom
  2024-04-26  9:22     ` Morten Brørup
                       ` (2 more replies)
  1 sibling, 3 replies; 8+ messages in thread
From: Mattias Rönnblom @ 2024-04-26  9:05 UTC (permalink / raw)
  To: dev
  Cc: hofors, Morten Brørup, Stephen Hemminger, Thomas Monjalon,
	John W . Linville, Ferruh Yigit, Mattias Rönnblom, stable

Cache align Rx and Tx queue struct to avoid false sharing.

The 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.

The TX struct is 56 bytes on x86_64.

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

v3: Move __rte_cache_aligned directive to a MSVC-compatible location.

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..6b7b16f348 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>
@@ -39,7 +40,7 @@
 #define DFLT_FRAME_SIZE		(1 << 11)
 #define DFLT_FRAME_COUNT	(1 << 9)
 
-struct pkt_rx_queue {
+struct __rte_cache_aligned pkt_rx_queue {
 	int sockfd;
 
 	struct iovec *rd;
@@ -55,7 +56,7 @@ struct pkt_rx_queue {
 	volatile unsigned long rx_bytes;
 };
 
-struct pkt_tx_queue {
+struct __rte_cache_aligned pkt_tx_queue {
 	int sockfd;
 	unsigned int frame_data_size;
 
-- 
2.34.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [PATCH v3] net/af_packet: cache align Rx/Tx structs
  2024-04-26  9:05   ` [PATCH v3] " Mattias Rönnblom
@ 2024-04-26  9:22     ` Morten Brørup
  2024-04-26 15:10     ` Stephen Hemminger
  2024-04-26 15:41     ` Tyler Retzlaff
  2 siblings, 0 replies; 8+ messages in thread
From: Morten Brørup @ 2024-04-26  9:22 UTC (permalink / raw)
  To: Mattias Rönnblom, dev
  Cc: hofors, Stephen Hemminger, Thomas Monjalon, John W . Linville,
	Ferruh Yigit, stable

> From: Mattias Rönnblom [mailto:mattias.ronnblom@ericsson.com]
> Sent: Friday, 26 April 2024 11.05
> 
> Cache align Rx and Tx queue struct to avoid false sharing.

Should an RTE_CACHE_GUARD be added at the end of these two structs?

If not,
Reviewed-by: Morten Brørup <mb@smartsharesystems.com>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] net/af_packet: cache align Rx/Tx structs
  2024-04-26  8:27   ` Ferruh Yigit
@ 2024-04-26 10:20     ` Mattias Rönnblom
  0 siblings, 0 replies; 8+ messages in thread
From: Mattias Rönnblom @ 2024-04-26 10:20 UTC (permalink / raw)
  To: Ferruh Yigit, Mattias Rönnblom, dev
  Cc: Morten Brørup, Stephen Hemminger, Thomas Monjalon,
	John W . Linville, stable

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).

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3] net/af_packet: cache align Rx/Tx structs
  2024-04-26  9:05   ` [PATCH v3] " Mattias Rönnblom
  2024-04-26  9:22     ` Morten Brørup
@ 2024-04-26 15:10     ` Stephen Hemminger
  2024-04-26 15:41     ` Tyler Retzlaff
  2 siblings, 0 replies; 8+ messages in thread
From: Stephen Hemminger @ 2024-04-26 15:10 UTC (permalink / raw)
  To: Mattias Rönnblom
  Cc: dev, hofors, Morten Brørup, Thomas Monjalon,
	John W . Linville, Ferruh Yigit, stable

On Fri, 26 Apr 2024 11:05:02 +0200
Mattias Rönnblom <mattias.ronnblom@ericsson.com> wrote:

> Cache align Rx and Tx queue struct to avoid false sharing.
> 
> The 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.
> 
> The TX struct is 56 bytes on x86_64.
> 
> Both structs keep counters, and in the RX case they are updated even
> for empty polls.
> 
> v3: Move __rte_cache_aligned directive to a MSVC-compatible location.
> 
> 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>

Looks good.

Acked-by: Stephen Hemminger <stephen@networkplumber.org>

If you want to go further with this:
   - could rx and tx rings be next to each other so that any of the lookahead
     in cpu helps, not hurts?
   - what about secondary process support
   - would sendmmsg() and recvmmsg() help for bursting.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3] net/af_packet: cache align Rx/Tx structs
  2024-04-26  9:05   ` [PATCH v3] " Mattias Rönnblom
  2024-04-26  9:22     ` Morten Brørup
  2024-04-26 15:10     ` Stephen Hemminger
@ 2024-04-26 15:41     ` Tyler Retzlaff
  2024-04-29  8:46       ` Ferruh Yigit
  2 siblings, 1 reply; 8+ messages in thread
From: Tyler Retzlaff @ 2024-04-26 15:41 UTC (permalink / raw)
  To: Mattias Rönnblom
  Cc: dev, hofors, Morten Brørup, Stephen Hemminger,
	Thomas Monjalon, John W . Linville, Ferruh Yigit, stable

On Fri, Apr 26, 2024 at 11:05:02AM +0200, Mattias Rönnblom wrote:
> Cache align Rx and Tx queue struct to avoid false sharing.
> 
> The 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.
> 
> The TX struct is 56 bytes on x86_64.
> 
> Both structs keep counters, and in the RX case they are updated even
> for empty polls.
> 
> v3: Move __rte_cache_aligned directive to a MSVC-compatible location.
> 
> 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>
> ---
Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3] net/af_packet: cache align Rx/Tx structs
  2024-04-26 15:41     ` Tyler Retzlaff
@ 2024-04-29  8:46       ` Ferruh Yigit
  0 siblings, 0 replies; 8+ messages in thread
From: Ferruh Yigit @ 2024-04-29  8:46 UTC (permalink / raw)
  To: Tyler Retzlaff, Mattias Rönnblom
  Cc: dev, hofors, Morten Brørup, Stephen Hemminger,
	Thomas Monjalon, John W . Linville, stable

On 4/26/2024 4:41 PM, Tyler Retzlaff wrote:
> On Fri, Apr 26, 2024 at 11:05:02AM +0200, Mattias Rönnblom wrote:
>> Cache align Rx and Tx queue struct to avoid false sharing.
>>
>> The 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.
>>
>> The TX struct is 56 bytes on x86_64.
>>
>> Both structs keep counters, and in the RX case they are updated even
>> for empty polls.
>>
>> v3: Move __rte_cache_aligned directive to a MSVC-compatible location.
>>
>> 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>
>> ---
>
> Reviewed-by: Morten Brørup <mb@smartsharesystems.com>
> Acked-by: Stephen Hemminger <stephen@networkplumber.org>
> Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> 

Applied to dpdk-next-net/main, thanks.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-04-29  8:46 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20240423090813.94110-1-mattias.ronnblom@ericsson.com>
2024-04-26  7:38 ` [PATCH] net/af_packet: cache align Rx/Tx structs Mattias Rönnblom
2024-04-26  8:27   ` Ferruh Yigit
2024-04-26 10:20     ` Mattias Rönnblom
2024-04-26  9:05   ` [PATCH v3] " Mattias Rönnblom
2024-04-26  9:22     ` Morten Brørup
2024-04-26 15:10     ` Stephen Hemminger
2024-04-26 15:41     ` Tyler Retzlaff
2024-04-29  8:46       ` Ferruh Yigit

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).