Skip to content

Commit 865e6ae

Browse files
lstipakovkuba-moo
authored andcommitted
net: openvswitch: use core API to update/provide stats
Commit d3fd654 ("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>
1 parent cf70b5c commit 865e6ae

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

net/openvswitch/vport-internal_dev.c

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,18 @@ internal_dev_xmit(struct sk_buff *skb, struct net_device *netdev)
3535
{
3636
int len, err;
3737

38+
/* store len value because skb can be freed inside ovs_vport_receive() */
3839
len = skb->len;
40+
3941
rcu_read_lock();
4042
err = ovs_vport_receive(internal_dev_priv(netdev)->vport, skb, NULL);
4143
rcu_read_unlock();
4244

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
5148
netdev->stats.tx_errors++;
52-
}
49+
5350
return NETDEV_TX_OK;
5451
}
5552

@@ -83,24 +80,12 @@ static void internal_dev_destructor(struct net_device *dev)
8380
ovs_vport_free(vport);
8481
}
8582

86-
static void
87-
internal_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats)
88-
{
89-
memset(stats, 0, sizeof(*stats));
90-
stats->rx_errors = dev->stats.rx_errors;
91-
stats->tx_errors = dev->stats.tx_errors;
92-
stats->tx_dropped = dev->stats.tx_dropped;
93-
stats->rx_dropped = dev->stats.rx_dropped;
94-
95-
dev_fetch_sw_netstats(stats, dev->tstats);
96-
}
97-
9883
static const struct net_device_ops internal_dev_netdev_ops = {
9984
.ndo_open = internal_dev_open,
10085
.ndo_stop = internal_dev_stop,
10186
.ndo_start_xmit = internal_dev_xmit,
10287
.ndo_set_mac_address = eth_mac_addr,
103-
.ndo_get_stats64 = internal_get_stats,
88+
.ndo_get_stats64 = dev_get_tstats64,
10489
};
10590

10691
static struct rtnl_link_ops internal_dev_link_ops __read_mostly = {

0 commit comments

Comments
 (0)