net: add per-cpu storage and net->core_stats
Subsystems (10)
PATCH 1/1 net: add per-cpu storage and net->core_stats
From: Eric Dumazet <[email protected]>
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.
--- drivers/net/bonding/bond_main.c | 2 +- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 4 +- .../net/ethernet/hisilicon/hns/hns_ethtool.c | 4 +- .../ethernet/qualcomm/rmnet/rmnet_handlers.c | 2 +- drivers/net/ipvlan/ipvlan_core.c | 2 +- drivers/net/macvlan.c | 2 +- drivers/net/net_failover.c | 2 +- drivers/net/tun.c | 16 +++--- drivers/net/vxlan/vxlan_core.c | 2 +- include/linux/netdevice.h | 45 +++++++++++++---- include/net/bonding.h | 2 +- net/core/dev.c | 49 +++++++++++++++---- net/core/gro_cells.c | 2 +- net/hsr/hsr_device.c | 2 +- net/xfrm/xfrm_device.c | 2 +- 15 files changed, 98 insertions(+), 40 deletions(-)
drivers/net/bonding/bond_main.c +1 -1
@@ -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 ; }
drivers/net/ethernet/broadcom/bnxt/bnxt.c +2 -2
@@ -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 ; }
drivers/net/ethernet/hisilicon/hns/hns_ethtool.c +2 -2
@@ -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;
drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c +1 -1
@@ -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; }
drivers/net/ipvlan/ipvlan_core.c +1 -1
@@ -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); } }
drivers/net/macvlan.c +1 -1
@@ -371,7 +371,7 @@ static void macvlan_broadcast_enqueue(struct macvlan_port *port, free_nskb:kfree_skb (nskb); err: -atomic_long_inc (&skb->dev->rx_dropped); +dev_core_stats_rx_dropped_inc (skb->dev); } static void macvlan_flush_sources(struct macvlan_port *port,
drivers/net/net_failover.c +1 -1
@@ -89,7 +89,7 @@ static int net_failover_close(struct net_device *dev)static netdev_tx_t net_failover_drop_xmit (struct sk_buff *skb,struct net_device *dev) { -atomic_long_inc (&dev->tx_dropped); +dev_core_stats_tx_dropped_inc (dev);dev_kfree_skb_any (skb);return NETDEV_TX_OK ; }
drivers/net/tun.c +8 -8
@@ -1135,7 +1135,7 @@ static netdev_tx_t tun_net_xmit(struct sk_buff *skb, struct net_device *dev)return NETDEV_TX_OK ; drop: -atomic_long_inc (&dev->tx_dropped); +dev_core_stats_tx_dropped_inc (dev);skb_tx_error (skb);kfree_skb_reason (skb, drop_reason);rcu_read_unlock ();
@@ -1291,7 +1291,7 @@ static int tun_xdp_xmit(struct net_device *dev, int n,void *frame =tun_xdp_to_ptr (xdp);if (__ptr_ring_produce (&tfile->tx_ring, frame)) { -atomic_long_inc (&dev->tx_dropped); +dev_core_stats_tx_dropped_inc (dev);break ; } nxmit++;
@@ -1626,7 +1626,7 @@ static int tun_xdp_act(struct tun_struct *tun, struct bpf_prog *xdp_prog,trace_xdp_exception (tun->dev, xdp_prog, act); fallthrough;case XDP_DROP : -atomic_long_inc (&tun->dev->rx_dropped); +dev_core_stats_rx_dropped_inc (tun->dev);break ; }
@@ -1797,7 +1797,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,*/ skb =tun_build_skb (tun, tfile, from, &gso, len, &skb_xdp);if (IS_ERR (skb)) { -atomic_long_inc (&tun->dev->rx_dropped); +dev_core_stats_rx_dropped_inc (tun->dev);return PTR_ERR (skb); }if (!skb)
@@ -1826,7 +1826,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,if (IS_ERR (skb)) {if (PTR_ERR (skb) != -EAGAIN ) -atomic_long_inc (&tun->dev->rx_dropped); +dev_core_stats_rx_dropped_inc (tun->dev);if (frags)mutex_unlock (&tfile->napi_mutex);return PTR_ERR (skb);
@@ -1841,7 +1841,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, err = -EFAULT ; drop_reason =SKB_DROP_REASON_SKB_UCOPY_FAULT ; drop: -atomic_long_inc (&tun->dev->rx_dropped); +dev_core_stats_rx_dropped_inc (tun->dev);kfree_skb_reason (skb, drop_reason);if (frags) { tfile->napi.skb =NULL ;
@@ -1876,7 +1876,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, pi.proto =htons (ETH_P_IPV6 );break ;default : -atomic_long_inc (&tun->dev->rx_dropped); +dev_core_stats_rx_dropped_inc (tun->dev);kfree_skb (skb);return -EINVAL ; }
@@ -1956,7 +1956,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, skb_headlen(skb));if (unlikely (headlen >skb_headlen (skb))) { -atomic_long_inc (&tun->dev->rx_dropped); +dev_core_stats_rx_dropped_inc (tun->dev);napi_free_frags (&tfile->napi);rcu_read_unlock ();mutex_unlock (&tfile->napi_mutex);
drivers/net/vxlan/vxlan_core.c +1 -1
@@ -1760,7 +1760,7 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb)if (unlikely (!(vxlan->dev->flags &IFF_UP ))) {rcu_read_unlock (); -atomic_long_inc (&vxlan->dev->rx_dropped); +dev_core_stats_rx_dropped_inc (vxlan->dev);vxlan_vnifilter_count (vxlan, vni, vninode,VXLAN_VNI_STATS_RX_DROPS ,0 ); goto drop;
include/linux/netdevice.h +36 -9
76 lines not on this page · raw message
include/net/bonding.h +1 -1
@@ -770,7 +770,7 @@ extern const struct sysfs_ops slave_sysfs_ops;static inline netdev_tx_t bond_tx_drop (struct net_device *dev,struct sk_buff *skb) { -atomic_long_inc (&dev->tx_dropped); +dev_core_stats_tx_dropped_inc (dev);dev_kfree_skb_any (skb);return NET_XMIT_DROP ; }
net/core/dev.c +40 -9
105 lines not on this page · raw message
net/core/gro_cells.c +1 -1
@@ -28,7 +28,7 @@ int gro_cells_receive(struct gro_cells *gcells, struct sk_buff *skb)if (skb_queue_len (&cell->napi_skbs) > netdev_max_backlog) { drop: -atomic_long_inc (&dev->rx_dropped); +dev_core_stats_rx_dropped_inc (dev);kfree_skb (skb); res =NET_RX_DROP ; goto unlock;
net/hsr/hsr_device.c +1 -1
@@ -221,7 +221,7 @@ static netdev_tx_t hsr_dev_xmit(struct sk_buff *skb, struct net_device *dev)skb_reset_mac_len (skb);hsr_forward_skb (skb, master); }else { -atomic_long_inc (&dev->tx_dropped); +dev_core_stats_tx_dropped_inc (dev);dev_kfree_skb_any (skb); }return NETDEV_TX_OK ;
net/xfrm/xfrm_device.c +1 -1
@@ -143,7 +143,7 @@ struct sk_buff *validate_xmit_xfrm(struct sk_buff *skb, netdev_features_t featur segs =skb_gso_segment (skb, esp_features);if (IS_ERR (segs)) {kfree_skb (skb); -atomic_long_inc (&dev->tx_dropped); +dev_core_stats_tx_dropped_inc (dev);return NULL ; }else {consume_skb (skb);
Signature · 1 line
2.35.1.616.g0bdcbb4464-goog
Quoted 10 lines · On Wed, 9 Mar 2022 13:18:08 -0800 Eric Dumazet wrote:
From: Eric Dumazet <[email protected]>
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, anddev->rx_nohandlerBecause 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.
Quoted 6 lines
Note that some drivers have abused these counters which were supposed to be only used by core networking stack.
Signed-off-by Eric Dumazet <[email protected]>Cc jeffreyji <[email protected]>Cc Brian Vazquez <[email protected]>
Things to mention in passing, in case there is a v2:
- we could use a different header for this, netdevice.h is a monster
- netdev_core_stats_alloc() could have the last if inverted to keep success path unindented
Brian Vazquez
Reviewed-byThanks for the patch Eric!
Quoted 25 lines · Jakub Kicinski
Quoted 10 lines · On Wed, 9 Mar 2022 13:18:08 -0800 Eric Dumazet wrote:
From: Eric Dumazet <[email protected]>
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, anddev->rx_nohandlerBecause 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.Quoted 6 lines
Note that some drivers have abused these counters which were supposed to be only used by core networking stack.
Signed-off-by Eric Dumazet <[email protected]>Cc jeffreyji <[email protected]>Cc Brian Vazquez <[email protected]>Reviewed-by Jakub Kicinski <[email protected]>Things to mention in passing, in case there is a v2:
- we could use a different header for this,netdevice.his a monster
-netdev_core_stats_alloc()could have the last if inverted to keep success path unindented
kernel test robot
build botI love your patch! Yet something to improve:
Hi Eric,
I love your patch! Yet something to improve:
[auto build test ERROR on net-next/master]
url: https://github.com/0day-ci/linux/commits/Eric-Dumazet/net-add-per-cpu-storage-and-net-core_stats/20220310-051831 base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 7f415828f987fca9651694c7589560e55ffdf9a6 config: m68k-randconfig-r015-20220309 (https://download.01.org/0day-ci/archive/20220310/[email protected]/config) compiler: m68k-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/9e6510e2ec32ebae0469ff500b2ba5bb2eb7a761
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Eric-Dumazet/net-add-per-cpu-storage-and-net-core_stats/20220310-051831 git checkout 9e6510e2ec32ebae0469ff500b2ba5bb2eb7a761
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=m68k SHELL=/bin/bash drivers/media/dvb-frontends/
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
In file included from include/media/dvb_net.h:22,
from drivers/media/usb/dvb-usb-v2/dvb_usb.h:19,
from drivers/media/dvb-frontends/rtl2832_sdr.c:12:
>> include/linux/netdevice.h:201:9: error: unknown type name 'local_t'
201 | local_t rx_dropped;
| ^~~~~~~
include/linux/netdevice.h:202:9: error: unknown type name 'local_t'
202 | local_t tx_dropped;
| ^~~~~~~
include/linux/netdevice.h:203:9: error: unknown type name 'local_t'
203 | local_t rx_nohandler;
| ^~~~~~~
In file included from include/linux/compiler_types.h:68,
from <command-line>:
>> include/linux/netdevice.h:204:24: error: 'local_t' undeclared here (not in a function)
204 | } __aligned(4 * sizeof(local_t));
| ^~~~~~~
include/linux/compiler_attributes.h:33:68: note: in definition of macro '__aligned'
33 | #define __aligned(x) __attribute__((__aligned__(x)))
| ^
In file included from include/media/dvb_net.h:22,
from drivers/media/usb/dvb-usb-v2/dvb_usb.h:19,
from drivers/media/dvb-frontends/rtl2832_sdr.c:12:
include/linux/netdevice.h: In function 'dev_core_stats_rx_dropped_inc':
>> include/linux/netdevice.h:3863:17: error: implicit declaration of function 'local_inc'; did you mean 'local_lock'? [-Werror=implicit-function-declaration]
3863 | local_inc(&p->FIELD); \
| ^~~~~~~~~
include/linux/netdevice.h:3865:1: note: in expansion of macro 'DEV_CORE_STATS_INC'
3865 | DEV_CORE_STATS_INC(rx_dropped)
| ^~~~~~~~~~~~~~~~~~cc1: some warnings being treated as errors
vim +/local_t +201 include/linux/netdevice.h
196
197 /* per-cpu stats, allocated on demand.
198 * Try to fit them in a single cache line, for dev_get_stats() sake.
199 */
200 struct net_device_core_stats {
> 201 local_t rx_dropped; > 202 local_t tx_dropped; 203 local_t rx_nohandler; > 204 } __aligned(4 * sizeof(local_t));
205
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]