Commit a003ec1f authored by Jakub Kicinski's avatar Jakub Kicinski
Browse files

Merge branch 'net-add-and-use-function-dev_fetch_sw_netstats-for-fetching-pcpu_sw_netstats'



Heiner Kallweit says:

====================
net: add and use function dev_fetch_sw_netstats for fetching pcpu_sw_netstats

In several places the same code is used to populate rtnl_link_stats64
fields with data from pcpu_sw_netstats. Therefore factor out this code
to a new function dev_fetch_sw_netstats().
====================

Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents 3618ad2a 5fc3594d
Loading
Loading
Loading
Loading
+1 −33
Original line number Diff line number Diff line
@@ -97,41 +97,9 @@ static void hfi1_ipoib_dev_get_stats64(struct net_device *dev,
				       struct rtnl_link_stats64 *storage)
{
	struct hfi1_ipoib_dev_priv *priv = hfi1_ipoib_priv(dev);
	u64 rx_packets = 0ull;
	u64 rx_bytes = 0ull;
	u64 tx_packets = 0ull;
	u64 tx_bytes = 0ull;
	int i;

	netdev_stats_to_stats64(storage, &dev->stats);

	for_each_possible_cpu(i) {
		const struct pcpu_sw_netstats *stats;
		unsigned int start;
		u64 trx_packets;
		u64 trx_bytes;
		u64 ttx_packets;
		u64 ttx_bytes;

		stats = per_cpu_ptr(priv->netstats, i);
		do {
			start = u64_stats_fetch_begin_irq(&stats->syncp);
			trx_packets = stats->rx_packets;
			trx_bytes = stats->rx_bytes;
			ttx_packets = stats->tx_packets;
			ttx_bytes = stats->tx_bytes;
		} while (u64_stats_fetch_retry_irq(&stats->syncp, start));

		rx_packets += trx_packets;
		rx_bytes += trx_bytes;
		tx_packets += ttx_packets;
		tx_bytes += ttx_bytes;
	}

	storage->rx_packets += rx_packets;
	storage->rx_bytes += rx_bytes;
	storage->tx_packets += tx_packets;
	storage->tx_bytes += tx_bytes;
	dev_fetch_sw_netstats(storage, priv->netstats);
}

static const struct net_device_ops hfi1_ipoib_netdev_ops = {
+1 −21
Original line number Diff line number Diff line
@@ -3647,30 +3647,10 @@ static int macsec_change_mtu(struct net_device *dev, int new_mtu)
static void macsec_get_stats64(struct net_device *dev,
			       struct rtnl_link_stats64 *s)
{
	int cpu;

	if (!dev->tstats)
		return;

	for_each_possible_cpu(cpu) {
		struct pcpu_sw_netstats *stats;
		struct pcpu_sw_netstats tmp;
		int start;

		stats = per_cpu_ptr(dev->tstats, cpu);
		do {
			start = u64_stats_fetch_begin_irq(&stats->syncp);
			tmp.rx_packets = stats->rx_packets;
			tmp.rx_bytes   = stats->rx_bytes;
			tmp.tx_packets = stats->tx_packets;
			tmp.tx_bytes   = stats->tx_bytes;
		} while (u64_stats_fetch_retry_irq(&stats->syncp, start));

		s->rx_packets += tmp.rx_packets;
		s->rx_bytes   += tmp.rx_bytes;
		s->tx_packets += tmp.tx_packets;
		s->tx_bytes   += tmp.tx_bytes;
	}
	dev_fetch_sw_netstats(s, dev->tstats);

	s->rx_dropped = dev->stats.rx_dropped;
	s->tx_dropped = dev->stats.tx_dropped;
+1 −23
Original line number Diff line number Diff line
@@ -126,31 +126,9 @@ static void qmimux_get_stats64(struct net_device *net,
			       struct rtnl_link_stats64 *stats)
{
	struct qmimux_priv *priv = netdev_priv(net);
	unsigned int start;
	int cpu;

	netdev_stats_to_stats64(stats, &net->stats);

	for_each_possible_cpu(cpu) {
		struct pcpu_sw_netstats *stats64;
		u64 rx_packets, rx_bytes;
		u64 tx_packets, tx_bytes;

		stats64 = per_cpu_ptr(priv->stats64, cpu);

		do {
			start = u64_stats_fetch_begin_irq(&stats64->syncp);
			rx_packets = stats64->rx_packets;
			rx_bytes = stats64->rx_bytes;
			tx_packets = stats64->tx_packets;
			tx_bytes = stats64->tx_bytes;
		} while (u64_stats_fetch_retry_irq(&stats64->syncp, start));

		stats->rx_packets += rx_packets;
		stats->rx_bytes += rx_bytes;
		stats->tx_packets += tx_packets;
		stats->tx_bytes += tx_bytes;
	}
	dev_fetch_sw_netstats(stats, priv->stats64);
}

static const struct net_device_ops qmimux_netdev_ops = {
+1 −23
Original line number Diff line number Diff line
@@ -983,31 +983,9 @@ EXPORT_SYMBOL_GPL(usbnet_set_link_ksettings);
void usbnet_get_stats64(struct net_device *net, struct rtnl_link_stats64 *stats)
{
	struct usbnet *dev = netdev_priv(net);
	unsigned int start;
	int cpu;

	netdev_stats_to_stats64(stats, &net->stats);

	for_each_possible_cpu(cpu) {
		struct pcpu_sw_netstats *stats64;
		u64 rx_packets, rx_bytes;
		u64 tx_packets, tx_bytes;

		stats64 = per_cpu_ptr(dev->stats64, cpu);

		do {
			start = u64_stats_fetch_begin_irq(&stats64->syncp);
			rx_packets = stats64->rx_packets;
			rx_bytes = stats64->rx_bytes;
			tx_packets = stats64->tx_packets;
			tx_bytes = stats64->tx_bytes;
		} while (u64_stats_fetch_retry_irq(&stats64->syncp, start));

		stats->rx_packets += rx_packets;
		stats->rx_bytes += rx_bytes;
		stats->tx_packets += tx_packets;
		stats->tx_bytes += tx_bytes;
	}
	dev_fetch_sw_netstats(stats, dev->stats64);
}
EXPORT_SYMBOL_GPL(usbnet_get_stats64);

+1 −22
Original line number Diff line number Diff line
@@ -139,34 +139,13 @@ static void qtnf_netdev_get_stats64(struct net_device *ndev,
				    struct rtnl_link_stats64 *stats)
{
	struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
	unsigned int start;
	int cpu;

	netdev_stats_to_stats64(stats, &ndev->stats);

	if (!vif->stats64)
		return;

	for_each_possible_cpu(cpu) {
		struct pcpu_sw_netstats *stats64;
		u64 rx_packets, rx_bytes;
		u64 tx_packets, tx_bytes;

		stats64 = per_cpu_ptr(vif->stats64, cpu);

		do {
			start = u64_stats_fetch_begin_irq(&stats64->syncp);
			rx_packets = stats64->rx_packets;
			rx_bytes = stats64->rx_bytes;
			tx_packets = stats64->tx_packets;
			tx_bytes = stats64->tx_bytes;
		} while (u64_stats_fetch_retry_irq(&stats64->syncp, start));

		stats->rx_packets += rx_packets;
		stats->rx_bytes += rx_bytes;
		stats->tx_packets += tx_packets;
		stats->tx_bytes += tx_bytes;
	}
	dev_fetch_sw_netstats(stats, vif->stats64);
}

/* Netdev handler for transmission timeout.
Loading