net/netstatistics: add tx/rx bytes statistics for dev

We can see them in ifconfig:

ap> ifconfig
wlan0   Link encap:Ethernet HWaddr 42:64:7f:b3:12:03 at UP mtu 1500
        inet addr:10.0.1.2 DRaddr:10.0.1.1 Mask:255.255.255.0
        inet6 DRaddr: ::

        RX: Received Fragment Errors   Bytes
            00000b9b 00000000 00000000 21daf5
            IPv4     IPv6     ARP      Dropped
            00000a33 00000137 00000031 00000000
        TX: Queued   Sent     Errors   Timeouts Bytes
            00000ac4 00000ac4 00000000 00000000 1a2103
        Total Errors: 00000000

Signed-off-by: meijian <meijian@xiaomi.com>
This commit is contained in:
meijian 2024-09-02 15:51:53 +08:00 • committed by Xiang Xiao
parent 0fbfcf4caf
commit a7224cf35a
13 changed files with 65 additions and 45 deletions

View file

@ -120,6 +120,11 @@
} \
while (0)
#define _NETDEV_BYTES(dev,name) \
do { \
(dev)->d_statistics.name += (dev)->d_len; \
} while (0)
# if CONFIG_NETDEV_STATISTICS_LOG_PERIOD > 0
# define NETDEV_STATISTICS_WORK LPWORK
# define _NETDEV_STATISTIC_LOG(dev,name) \
@ -139,7 +144,12 @@
# define _NETDEV_STATISTIC_LOG(dev,name) _NETDEV_STATISTIC(dev,name)
# endif
# define NETDEV_RXPACKETS(dev) _NETDEV_STATISTIC_LOG(dev,rx_packets)
# define NETDEV_RXPACKETS(dev) \
do { \
_NETDEV_STATISTIC_LOG(dev,rx_packets); \
_NETDEV_BYTES(dev,rx_bytes); \
} while (0)
# define NETDEV_RXFRAGMENTS(dev) _NETDEV_STATISTIC(dev,rx_fragments)
# define NETDEV_RXERRORS(dev) _NETDEV_ERROR(dev,rx_errors)
# ifdef CONFIG_NET_IPv4
@ -159,11 +169,15 @@
# endif
# define NETDEV_RXDROPPED(dev) _NETDEV_STATISTIC(dev,rx_dropped)
# define NETDEV_TXPACKETS(dev) _NETDEV_STATISTIC_LOG(dev,tx_packets)
# define NETDEV_TXPACKETS(dev) \
do { \
_NETDEV_STATISTIC_LOG(dev,tx_packets); \
_NETDEV_BYTES(dev,tx_bytes); \
} while (0)
# define NETDEV_TXDONE(dev) _NETDEV_STATISTIC(dev,tx_done)
# define NETDEV_TXERRORS(dev) _NETDEV_ERROR(dev,tx_errors)
# define NETDEV_TXTIMEOUTS(dev) _NETDEV_ERROR(dev,tx_timeouts)
# define NETDEV_ERRORS(dev) _NETDEV_STATISTIC(dev,errors)
#else
@ -235,6 +249,7 @@ struct netdev_statistics_s
uint32_t rx_arp; /* Number of Rx ARP packets received */
#endif
uint32_t rx_dropped; /* Unsupported Rx packets received */
uint64_t rx_bytes; /* Number of bytes received */
/* Tx Status */
@ -242,6 +257,7 @@ struct netdev_statistics_s
uint32_t tx_done; /* Number of packets completed */
uint32_t tx_errors; /* Number of receive errors (incl timeouts) */
uint32_t tx_timeouts; /* Number of Tx timeout errors */
uint64_t tx_bytes; /* Number of bytes send */
/* Other status */