[RFC 1/4] net/af_packet: remove volatile from statistics
Scott Mitchell
scott.k.mitch1 at gmail.com
Wed Jan 28 20:57:16 CET 2026
Can you clarify why removal of volatile is safe (visibility, ordering)
when the producer thread and consumer thread can be different?
On Wed, Jan 28, 2026 at 9:39 AM Stephen Hemminger
<stephen at networkplumber.org> wrote:
>
> Statistics are only updated from a single thread at a time and
> the compiler should not have to worry about optimizing them.
> The statistics returned are 64 bit so use uint64_t instead
> of arch specific unsigned long.
>
> Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
> ---
> drivers/net/af_packet/rte_eth_af_packet.c | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c
> index ef11b8fb6b..158393dd70 100644
> --- a/drivers/net/af_packet/rte_eth_af_packet.c
> +++ b/drivers/net/af_packet/rte_eth_af_packet.c
> @@ -57,10 +57,10 @@ struct __rte_cache_aligned pkt_rx_queue {
> uint8_t vlan_strip;
> uint8_t timestamp_offloading;
>
> - volatile unsigned long rx_pkts;
> - volatile unsigned long rx_bytes;
> - volatile unsigned long rx_nombuf;
> - volatile unsigned long rx_dropped_pkts;
> + uint64_t rx_pkts;
> + uint64_t rx_bytes;
> + uint64_t rx_nombuf;
> + uint64_t rx_dropped_pkts;
> };
>
> struct __rte_cache_aligned pkt_tx_queue {
> @@ -72,9 +72,9 @@ struct __rte_cache_aligned pkt_tx_queue {
> unsigned int framecount;
> unsigned int framenum;
>
> - volatile unsigned long tx_pkts;
> - volatile unsigned long err_pkts;
> - volatile unsigned long tx_bytes;
> + uint64_t tx_pkts;
> + uint64_t tx_bytes;
> + uint64_t err_pkts;
> };
>
> struct pmd_internals {
> --
> 2.51.0
>
More information about the dev
mailing list