[PATCH net-next 1/3] net: enetc: change the statistics of ring to unsigned long type

Wei Fang posted 3 patches 3 months, 2 weeks ago
There is a newer version of this series
[PATCH net-next 1/3] net: enetc: change the statistics of ring to unsigned long type
Posted by Wei Fang 3 months, 2 weeks ago
The statistics of the ring are all unsigned int type, so the statistics
will overflow quickly under heavy traffic. In addition, the statistics
of struct net_device_stats are obtained from struct enetc_ring_stats,
but the statistics of net_device_stats are all unsigned long type.
Considering these two factors, the statistics of enetc_ring_stats are
all changed to unsigned long type.

Signed-off-by: Wei Fang <wei.fang@nxp.com>
---
 drivers/net/ethernet/freescale/enetc/enetc.h | 22 ++++++++++----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/freescale/enetc/enetc.h b/drivers/net/ethernet/freescale/enetc/enetc.h
index 872d2cbd088b..62e8ee4d2f04 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc.h
+++ b/drivers/net/ethernet/freescale/enetc/enetc.h
@@ -96,17 +96,17 @@ struct enetc_rx_swbd {
 #define ENETC_TXBDS_MAX_NEEDED(x)	ENETC_TXBDS_NEEDED((x) + 1)
 
 struct enetc_ring_stats {
-	unsigned int packets;
-	unsigned int bytes;
-	unsigned int rx_alloc_errs;
-	unsigned int xdp_drops;
-	unsigned int xdp_tx;
-	unsigned int xdp_tx_drops;
-	unsigned int xdp_redirect;
-	unsigned int xdp_redirect_failures;
-	unsigned int recycles;
-	unsigned int recycle_failures;
-	unsigned int win_drop;
+	unsigned long packets;
+	unsigned long bytes;
+	unsigned long rx_alloc_errs;
+	unsigned long xdp_drops;
+	unsigned long xdp_tx;
+	unsigned long xdp_tx_drops;
+	unsigned long xdp_redirect;
+	unsigned long xdp_redirect_failures;
+	unsigned long recycles;
+	unsigned long recycle_failures;
+	unsigned long win_drop;
 };
 
 struct enetc_xdp_data {
-- 
2.34.1
Re: [PATCH net-next 1/3] net: enetc: change the statistics of ring to unsigned long type
Posted by Simon Horman 3 months, 2 weeks ago
On Fri, Jun 20, 2025 at 06:21:38PM +0800, Wei Fang wrote:
> The statistics of the ring are all unsigned int type, so the statistics
> will overflow quickly under heavy traffic. In addition, the statistics
> of struct net_device_stats are obtained from struct enetc_ring_stats,
> but the statistics of net_device_stats are all unsigned long type.
> Considering these two factors, the statistics of enetc_ring_stats are
> all changed to unsigned long type.
> 
> Signed-off-by: Wei Fang <wei.fang@nxp.com>
> ---
>  drivers/net/ethernet/freescale/enetc/enetc.h | 22 ++++++++++----------
>  1 file changed, 11 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/net/ethernet/freescale/enetc/enetc.h b/drivers/net/ethernet/freescale/enetc/enetc.h
> index 872d2cbd088b..62e8ee4d2f04 100644
> --- a/drivers/net/ethernet/freescale/enetc/enetc.h
> +++ b/drivers/net/ethernet/freescale/enetc/enetc.h
> @@ -96,17 +96,17 @@ struct enetc_rx_swbd {
>  #define ENETC_TXBDS_MAX_NEEDED(x)	ENETC_TXBDS_NEEDED((x) + 1)
>  
>  struct enetc_ring_stats {
> -	unsigned int packets;
> -	unsigned int bytes;
> -	unsigned int rx_alloc_errs;
> -	unsigned int xdp_drops;
> -	unsigned int xdp_tx;
> -	unsigned int xdp_tx_drops;
> -	unsigned int xdp_redirect;
> -	unsigned int xdp_redirect_failures;
> -	unsigned int recycles;
> -	unsigned int recycle_failures;
> -	unsigned int win_drop;
> +	unsigned long packets;
> +	unsigned long bytes;
> +	unsigned long rx_alloc_errs;
> +	unsigned long xdp_drops;
> +	unsigned long xdp_tx;
> +	unsigned long xdp_tx_drops;
> +	unsigned long xdp_redirect;
> +	unsigned long xdp_redirect_failures;
> +	unsigned long recycles;
> +	unsigned long recycle_failures;
> +	unsigned long win_drop;
>  };

Hi Wei fang,

If the desire is for an unsigned 64 bit integer, then
I think either u64 or unsigned long long would be good choices.

unsigned long may be 64bit or 32bit depending on the platform.