Commit 625788b5 authored by Eric Dumazet's avatar Eric Dumazet Committed by Jakub Kicinski
Browse files

net: add per-cpu storage and net->core_stats



Before adding yet another possibly contended atomic_long_t,
it is time to add per-cpu storage for existing ones:
 dev->tx_dropped, dev->rx_dropped, and dev->rx_nohandler

Because many devices do not have to increment such counters,
allocate the per-cpu storage on demand, so that dev_get_stats()
does not have to spend considerable time folding zero counters.

Note that some drivers have abused these counters which
were supposed to be only used by core networking stack.

v4: should use per_cpu_ptr() in dev_get_stats() (Jakub)
v3: added a READ_ONCE() in netdev_core_stats_alloc() (Paolo)
v2: add a missing include (reported by kernel test robot <lkp@intel.com>)
    Change in netdev_core_stats_alloc() (Jakub)

Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Cc: jeffreyji <jeffreyji@google.com>
Reviewed-by: default avatarBrian Vazquez <brianvv@google.com>
Reviewed-by: default avatarJakub Kicinski <kuba@kernel.org>
Acked-by: default avatarPaolo Abeni <pabeni@redhat.com>
Link: https://lore.kernel.org/r/20220311051420.2608812-1-eric.dumazet@gmail.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent a8c06337
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -5120,7 +5120,7 @@ static netdev_tx_t bond_xmit_broadcast(struct sk_buff *skb,
	if (xmit_suc)
		return NETDEV_TX_OK;

	atomic_long_inc(&bond_dev->tx_dropped);
	dev_core_stats_tx_dropped_inc(bond_dev);
	return NET_XMIT_DROP;
}

+2 −2
Original line number Diff line number Diff line
@@ -370,7 +370,7 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
	i = skb_get_queue_mapping(skb);
	if (unlikely(i >= bp->tx_nr_rings)) {
		dev_kfree_skb_any(skb);
		atomic_long_inc(&dev->tx_dropped);
		dev_core_stats_tx_dropped_inc(dev);
		return NETDEV_TX_OK;
	}

@@ -646,7 +646,7 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
	if (txr->kick_pending)
		bnxt_txr_db_kick(bp, txr, txr->tx_prod);
	txr->tx_buf_ring[txr->tx_prod].skb = NULL;
	atomic_long_inc(&dev->tx_dropped);
	dev_core_stats_tx_dropped_inc(dev);
	return NETDEV_TX_OK;
}

+2 −2
Original line number Diff line number Diff line
@@ -887,8 +887,8 @@ static void hns_get_ethtool_stats(struct net_device *netdev,
	p[21] = net_stats->rx_compressed;
	p[22] = net_stats->tx_compressed;

	p[23] = netdev->rx_dropped.counter;
	p[24] = netdev->tx_dropped.counter;
	p[23] = 0; /* was netdev->rx_dropped.counter */
	p[24] = 0; /* was netdev->tx_dropped.counter */

	p[25] = priv->tx_timeout_count;

+1 −1
Original line number Diff line number Diff line
@@ -207,7 +207,7 @@ rx_handler_result_t rmnet_rx_handler(struct sk_buff **pskb)
	dev = skb->dev;
	port = rmnet_get_port_rcu(dev);
	if (unlikely(!port)) {
		atomic_long_inc(&skb->dev->rx_nohandler);
		dev_core_stats_rx_nohandler_inc(skb->dev);
		kfree_skb(skb);
		goto done;
	}
+1 −1
Original line number Diff line number Diff line
@@ -555,7 +555,7 @@ static void ipvlan_multicast_enqueue(struct ipvl_port *port,
		schedule_work(&port->wq);
	} else {
		spin_unlock(&port->backlog.lock);
		atomic_long_inc(&skb->dev->rx_dropped);
		dev_core_stats_rx_dropped_inc(skb->dev);
		kfree_skb(skb);
	}
}
Loading