Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: openvswitch: use core API to update/provide stats

Commit d3fd65484c781 ("net: core: add dev_sw_netstats_tx_add") has added
function "dev_sw_netstats_tx_add()" to update net device per-cpu TX
stats.

Use this function instead of own code.

While on it, remove internal_get_stats() and replace it
with dev_get_tstats64().

Signed-off-by: Lev Stipakov <lev@openvpn.net>
Reviewed-by: Heiner Kallweit <hkallweit1@gmail.com>
Link: https://lore.kernel.org/r/20201113215336.145998-1-lev@openvpn.net
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Lev Stipakov and committed by
Jakub Kicinski
865e6ae0 cf70b5cf

+7 -22
+7 -22
net/openvswitch/vport-internal_dev.c
··· 35 35 { 36 36 int len, err; 37 37 38 + /* store len value because skb can be freed inside ovs_vport_receive() */ 38 39 len = skb->len; 40 + 39 41 rcu_read_lock(); 40 42 err = ovs_vport_receive(internal_dev_priv(netdev)->vport, skb, NULL); 41 43 rcu_read_unlock(); 42 44 43 - if (likely(!err)) { 44 - struct pcpu_sw_netstats *tstats = this_cpu_ptr(netdev->tstats); 45 - 46 - u64_stats_update_begin(&tstats->syncp); 47 - tstats->tx_bytes += len; 48 - tstats->tx_packets++; 49 - u64_stats_update_end(&tstats->syncp); 50 - } else { 45 + if (likely(!err)) 46 + dev_sw_netstats_tx_add(netdev, 1, len); 47 + else 51 48 netdev->stats.tx_errors++; 52 - } 49 + 53 50 return NETDEV_TX_OK; 54 51 } 55 52 ··· 80 83 ovs_vport_free(vport); 81 84 } 82 85 83 - static void 84 - internal_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats) 85 - { 86 - memset(stats, 0, sizeof(*stats)); 87 - stats->rx_errors = dev->stats.rx_errors; 88 - stats->tx_errors = dev->stats.tx_errors; 89 - stats->tx_dropped = dev->stats.tx_dropped; 90 - stats->rx_dropped = dev->stats.rx_dropped; 91 - 92 - dev_fetch_sw_netstats(stats, dev->tstats); 93 - } 94 - 95 86 static const struct net_device_ops internal_dev_netdev_ops = { 96 87 .ndo_open = internal_dev_open, 97 88 .ndo_stop = internal_dev_stop, 98 89 .ndo_start_xmit = internal_dev_xmit, 99 90 .ndo_set_mac_address = eth_mac_addr, 100 - .ndo_get_stats64 = internal_get_stats, 91 + .ndo_get_stats64 = dev_get_tstats64, 101 92 }; 102 93 103 94 static struct rtnl_link_ops internal_dev_link_ops __read_mostly = {