netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Oleksij Rempel <o.rempel@pengutronix.de>
To: Vladimir Oltean <olteanv@gmail.com>
Cc: Woojung Huh <woojung.huh@microchip.com>,
	Andrew Lunn <andrew@lunn.ch>,
	Arun.Ramadoss@microchip.com,
	Florian Fainelli <f.fainelli@gmail.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Vivien Didelot <vivien.didelot@gmail.com>,
	Eric Dumazet <edumazet@google.com>,
	Paolo Abeni <pabeni@redhat.com>,
	kernel@pengutronix.de, Jakub Kicinski <kuba@kernel.org>,
	UNGLinuxDriver@microchip.com,
	"David S. Miller" <davem@davemloft.net>
Subject: Re: [PATCH net-next v1 1/1] net: dsa: microchip: add stats64 support for ksz8 series of switches
Date: Wed, 7 Dec 2022 07:14:09 +0100	[thread overview]
Message-ID: <20221207061409.GB19179@pengutronix.de> (raw)
In-Reply-To: <20221206170801.othuifyrm3qrz7ub@skbuf>

On Tue, Dec 06, 2022 at 07:08:01PM +0200, Vladimir Oltean wrote:
> On Mon, Dec 05, 2022 at 06:29:04AM +0100, Oleksij Rempel wrote:
> > +void ksz88xx_r_mib_stats64(struct ksz_device *dev, int port)
> > +{
> > +	struct ethtool_pause_stats *pstats;
> > +	struct rtnl_link_stats64 *stats;
> > +	struct ksz88xx_stats_raw *raw;
> > +	struct ksz_port_mib *mib;
> > +
> > +	mib = &dev->ports[port].mib;
> > +	stats = &mib->stats64;
> > +	pstats = &mib->pause_stats;
> > +	raw = (struct ksz88xx_stats_raw *)mib->counters;
> > +
> > +	spin_lock(&mib->stats64_lock);
> > +
> > +	stats->rx_packets = raw->rx_bcast + raw->rx_mcast + raw->rx_ucast +
> > +		raw->rx_pause;
> > +	stats->tx_packets = raw->tx_bcast + raw->tx_mcast + raw->tx_ucast +
> > +		raw->tx_pause;
> > +
> > +	/* HW counters are counting bytes + FCS which is not acceptable
> > +	 * for rtnl_link_stats64 interface
> > +	 */
> > +	stats->rx_bytes = raw->rx + raw->rx_hi - stats->rx_packets * ETH_FCS_LEN;
> > +	stats->tx_bytes = raw->tx + raw->tx_hi - stats->tx_packets * ETH_FCS_LEN;
> 
> What are rx_hi, tx_hi compared to rx, tx?

rx, tx are packets with normal priority and rx_hi, tx_hi are packets
with high prio.

> > +
> > +	stats->rx_length_errors = raw->rx_undersize + raw->rx_fragments +
> > +		raw->rx_oversize;
> > +
> > +	stats->rx_crc_errors = raw->rx_crc_err;
> > +	stats->rx_frame_errors = raw->rx_align_err;
> > +	stats->rx_dropped = raw->rx_discards;
> > +	stats->rx_errors = stats->rx_length_errors + stats->rx_crc_errors +
> > +		stats->rx_frame_errors  + stats->rx_dropped;
> > +
> > +	stats->tx_window_errors = raw->tx_late_col;
> > +	stats->tx_fifo_errors = raw->tx_discards;
> > +	stats->tx_aborted_errors = raw->tx_exc_col;
> > +	stats->tx_errors = stats->tx_window_errors + stats->tx_fifo_errors +
> > +		stats->tx_aborted_errors;
> > +
> > +	stats->multicast = raw->rx_mcast;
> > +	stats->collisions = raw->tx_total_col;
> > +
> > +	pstats->tx_pause_frames = raw->tx_pause;
> > +	pstats->rx_pause_frames = raw->rx_pause;
> 
> FWIW, ksz_get_pause_stats() can sleep, just ksz_get_stats64() can't. So
> the pause stats don't need to be periodically read (unless you want to
> do that to prevent 32-bit overflows).

KSZ driver is using worker to read stats periodically. Since all needed
locks are already taken, I copy pause stats as well.

Otherwise it will need some different locking, which will make things
look different but do not reduce CPU load. 

Regards,
Oleksij
-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

  reply	other threads:[~2022-12-07  6:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-05  5:29 [PATCH net-next v1 1/1] net: dsa: microchip: add stats64 support for ksz8 series of switches Oleksij Rempel
2022-12-06 17:08 ` Vladimir Oltean
2022-12-07  6:14   ` Oleksij Rempel [this message]
2022-12-06 19:41 ` Jakub Kicinski
2022-12-07  6:16   ` Oleksij Rempel
2022-12-07 23:48     ` Jakub Kicinski
2022-12-08  5:55       ` Oleksij Rempel
2022-12-08 16:27         ` Jakub Kicinski
2022-12-08 16:30 ` patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221207061409.GB19179@pengutronix.de \
    --to=o.rempel@pengutronix.de \
    --cc=Arun.Ramadoss@microchip.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=f.fainelli@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=vivien.didelot@gmail.com \
    --cc=woojung.huh@microchip.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).