Commit 02da0b61 authored by David S. Miller's avatar David S. Miller

Merge branch 'drivers-net-add-sw_netstats_rx_add-helper'

Fabian Frederick says:

====================
drivers/net: add sw_netstats_rx_add helper

This small patchset creates netstats addition dev_sw_netstats_rx_add()
based on dev_lstats_add() and replaces some open coding
in both drivers/net and net branches.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 9b9dda5d 560b50cf
...@@ -54,7 +54,6 @@ struct bareudp_dev { ...@@ -54,7 +54,6 @@ struct bareudp_dev {
static int bareudp_udp_encap_recv(struct sock *sk, struct sk_buff *skb) static int bareudp_udp_encap_recv(struct sock *sk, struct sk_buff *skb)
{ {
struct metadata_dst *tun_dst = NULL; struct metadata_dst *tun_dst = NULL;
struct pcpu_sw_netstats *stats;
struct bareudp_dev *bareudp; struct bareudp_dev *bareudp;
unsigned short family; unsigned short family;
unsigned int len; unsigned int len;
...@@ -160,13 +159,9 @@ static int bareudp_udp_encap_recv(struct sock *sk, struct sk_buff *skb) ...@@ -160,13 +159,9 @@ static int bareudp_udp_encap_recv(struct sock *sk, struct sk_buff *skb)
len = skb->len; len = skb->len;
err = gro_cells_receive(&bareudp->gro_cells, skb); err = gro_cells_receive(&bareudp->gro_cells, skb);
if (likely(err == NET_RX_SUCCESS)) { if (likely(err == NET_RX_SUCCESS))
stats = this_cpu_ptr(bareudp->dev->tstats); dev_sw_netstats_rx_add(bareudp->dev, len);
u64_stats_update_begin(&stats->syncp);
stats->rx_packets++;
stats->rx_bytes += len;
u64_stats_update_end(&stats->syncp);
}
return 0; return 0;
drop: drop:
/* Consume bad packet */ /* Consume bad packet */
......
...@@ -217,7 +217,6 @@ static void geneve_rx(struct geneve_dev *geneve, struct geneve_sock *gs, ...@@ -217,7 +217,6 @@ static void geneve_rx(struct geneve_dev *geneve, struct geneve_sock *gs,
{ {
struct genevehdr *gnvh = geneve_hdr(skb); struct genevehdr *gnvh = geneve_hdr(skb);
struct metadata_dst *tun_dst = NULL; struct metadata_dst *tun_dst = NULL;
struct pcpu_sw_netstats *stats;
unsigned int len; unsigned int len;
int err = 0; int err = 0;
void *oiph; void *oiph;
...@@ -296,13 +295,9 @@ static void geneve_rx(struct geneve_dev *geneve, struct geneve_sock *gs, ...@@ -296,13 +295,9 @@ static void geneve_rx(struct geneve_dev *geneve, struct geneve_sock *gs,
len = skb->len; len = skb->len;
err = gro_cells_receive(&geneve->gro_cells, skb); err = gro_cells_receive(&geneve->gro_cells, skb);
if (likely(err == NET_RX_SUCCESS)) { if (likely(err == NET_RX_SUCCESS))
stats = this_cpu_ptr(geneve->dev->tstats); dev_sw_netstats_rx_add(geneve->dev, len);
u64_stats_update_begin(&stats->syncp);
stats->rx_packets++;
stats->rx_bytes += len;
u64_stats_update_end(&stats->syncp);
}
return; return;
drop: drop:
/* Consume bad packet */ /* Consume bad packet */
......
...@@ -182,8 +182,6 @@ static bool gtp_check_ms(struct sk_buff *skb, struct pdp_ctx *pctx, ...@@ -182,8 +182,6 @@ static bool gtp_check_ms(struct sk_buff *skb, struct pdp_ctx *pctx,
static int gtp_rx(struct pdp_ctx *pctx, struct sk_buff *skb, static int gtp_rx(struct pdp_ctx *pctx, struct sk_buff *skb,
unsigned int hdrlen, unsigned int role) unsigned int hdrlen, unsigned int role)
{ {
struct pcpu_sw_netstats *stats;
if (!gtp_check_ms(skb, pctx, hdrlen, role)) { if (!gtp_check_ms(skb, pctx, hdrlen, role)) {
netdev_dbg(pctx->dev, "No PDP ctx for this MS\n"); netdev_dbg(pctx->dev, "No PDP ctx for this MS\n");
return 1; return 1;
...@@ -204,11 +202,7 @@ static int gtp_rx(struct pdp_ctx *pctx, struct sk_buff *skb, ...@@ -204,11 +202,7 @@ static int gtp_rx(struct pdp_ctx *pctx, struct sk_buff *skb,
skb->dev = pctx->dev; skb->dev = pctx->dev;
stats = this_cpu_ptr(pctx->dev->tstats); dev_sw_netstats_rx_add(pctx->dev, skb->len);
u64_stats_update_begin(&stats->syncp);
stats->rx_packets++;
stats->rx_bytes += skb->len;
u64_stats_update_end(&stats->syncp);
netif_rx(skb); netif_rx(skb);
return 0; return 0;
......
...@@ -1826,7 +1826,6 @@ static bool vxlan_ecn_decapsulate(struct vxlan_sock *vs, void *oiph, ...@@ -1826,7 +1826,6 @@ static bool vxlan_ecn_decapsulate(struct vxlan_sock *vs, void *oiph,
/* Callback from net/ipv4/udp.c to receive packets */ /* Callback from net/ipv4/udp.c to receive packets */
static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) static int vxlan_rcv(struct sock *sk, struct sk_buff *skb)
{ {
struct pcpu_sw_netstats *stats;
struct vxlan_dev *vxlan; struct vxlan_dev *vxlan;
struct vxlan_sock *vs; struct vxlan_sock *vs;
struct vxlanhdr unparsed; struct vxlanhdr unparsed;
...@@ -1940,12 +1939,7 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) ...@@ -1940,12 +1939,7 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb)
goto drop; goto drop;
} }
stats = this_cpu_ptr(vxlan->dev->tstats); dev_sw_netstats_rx_add(vxlan->dev, skb->len);
u64_stats_update_begin(&stats->syncp);
stats->rx_packets++;
stats->rx_bytes += skb->len;
u64_stats_update_end(&stats->syncp);
gro_cells_receive(&vxlan->gro_cells, skb); gro_cells_receive(&vxlan->gro_cells, skb);
rcu_read_unlock(); rcu_read_unlock();
......
...@@ -2543,6 +2543,16 @@ struct pcpu_lstats { ...@@ -2543,6 +2543,16 @@ struct pcpu_lstats {
void dev_lstats_read(struct net_device *dev, u64 *packets, u64 *bytes); void dev_lstats_read(struct net_device *dev, u64 *packets, u64 *bytes);
static inline void dev_sw_netstats_rx_add(struct net_device *dev, unsigned int len)
{
struct pcpu_sw_netstats *tstats = this_cpu_ptr(dev->tstats);
u64_stats_update_begin(&tstats->syncp);
tstats->rx_bytes += len;
tstats->rx_packets++;
u64_stats_update_end(&tstats->syncp);
}
static inline void dev_lstats_add(struct net_device *dev, unsigned int len) static inline void dev_lstats_add(struct net_device *dev, unsigned int len)
{ {
struct pcpu_lstats *lstats = this_cpu_ptr(dev->lstats); struct pcpu_lstats *lstats = this_cpu_ptr(dev->lstats);
......
...@@ -360,7 +360,6 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb, ...@@ -360,7 +360,6 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb,
const struct tnl_ptk_info *tpi, struct metadata_dst *tun_dst, const struct tnl_ptk_info *tpi, struct metadata_dst *tun_dst,
bool log_ecn_error) bool log_ecn_error)
{ {
struct pcpu_sw_netstats *tstats;
const struct iphdr *iph = ip_hdr(skb); const struct iphdr *iph = ip_hdr(skb);
int err; int err;
...@@ -402,12 +401,7 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb, ...@@ -402,12 +401,7 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb,
} }
} }
tstats = this_cpu_ptr(tunnel->dev->tstats); dev_sw_netstats_rx_add(tunnel->dev, skb->len);
u64_stats_update_begin(&tstats->syncp);
tstats->rx_packets++;
tstats->rx_bytes += skb->len;
u64_stats_update_end(&tstats->syncp);
skb_scrub_packet(skb, !net_eq(tunnel->net, dev_net(tunnel->dev))); skb_scrub_packet(skb, !net_eq(tunnel->net, dev_net(tunnel->dev)));
if (tunnel->dev->type == ARPHRD_ETHER) { if (tunnel->dev->type == ARPHRD_ETHER) {
......
...@@ -95,7 +95,6 @@ static int vti_rcv_cb(struct sk_buff *skb, int err) ...@@ -95,7 +95,6 @@ static int vti_rcv_cb(struct sk_buff *skb, int err)
{ {
unsigned short family; unsigned short family;
struct net_device *dev; struct net_device *dev;
struct pcpu_sw_netstats *tstats;
struct xfrm_state *x; struct xfrm_state *x;
const struct xfrm_mode *inner_mode; const struct xfrm_mode *inner_mode;
struct ip_tunnel *tunnel = XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip4; struct ip_tunnel *tunnel = XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip4;
...@@ -138,13 +137,7 @@ static int vti_rcv_cb(struct sk_buff *skb, int err) ...@@ -138,13 +137,7 @@ static int vti_rcv_cb(struct sk_buff *skb, int err)
skb_scrub_packet(skb, !net_eq(tunnel->net, dev_net(skb->dev))); skb_scrub_packet(skb, !net_eq(tunnel->net, dev_net(skb->dev)));
skb->dev = dev; skb->dev = dev;
dev_sw_netstats_rx_add(dev, skb->len);
tstats = this_cpu_ptr(dev->tstats);
u64_stats_update_begin(&tstats->syncp);
tstats->rx_packets++;
tstats->rx_bytes += skb->len;
u64_stats_update_end(&tstats->syncp);
return 0; return 0;
} }
......
...@@ -347,7 +347,6 @@ static int vti6_rcv_cb(struct sk_buff *skb, int err) ...@@ -347,7 +347,6 @@ static int vti6_rcv_cb(struct sk_buff *skb, int err)
{ {
unsigned short family; unsigned short family;
struct net_device *dev; struct net_device *dev;
struct pcpu_sw_netstats *tstats;
struct xfrm_state *x; struct xfrm_state *x;
const struct xfrm_mode *inner_mode; const struct xfrm_mode *inner_mode;
struct ip6_tnl *t = XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip6; struct ip6_tnl *t = XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip6;
...@@ -390,12 +389,7 @@ static int vti6_rcv_cb(struct sk_buff *skb, int err) ...@@ -390,12 +389,7 @@ static int vti6_rcv_cb(struct sk_buff *skb, int err)
skb_scrub_packet(skb, !net_eq(t->net, dev_net(skb->dev))); skb_scrub_packet(skb, !net_eq(t->net, dev_net(skb->dev)));
skb->dev = dev; skb->dev = dev;
dev_sw_netstats_rx_add(dev, skb->len);
tstats = this_cpu_ptr(dev->tstats);
u64_stats_update_begin(&tstats->syncp);
tstats->rx_packets++;
tstats->rx_bytes += skb->len;
u64_stats_update_end(&tstats->syncp);
return 0; return 0;
} }
......
...@@ -225,7 +225,6 @@ static void internal_dev_destroy(struct vport *vport) ...@@ -225,7 +225,6 @@ static void internal_dev_destroy(struct vport *vport)
static netdev_tx_t internal_dev_recv(struct sk_buff *skb) static netdev_tx_t internal_dev_recv(struct sk_buff *skb)
{ {
struct net_device *netdev = skb->dev; struct net_device *netdev = skb->dev;
struct pcpu_sw_netstats *stats;
if (unlikely(!(netdev->flags & IFF_UP))) { if (unlikely(!(netdev->flags & IFF_UP))) {
kfree_skb(skb); kfree_skb(skb);
...@@ -240,12 +239,7 @@ static netdev_tx_t internal_dev_recv(struct sk_buff *skb) ...@@ -240,12 +239,7 @@ static netdev_tx_t internal_dev_recv(struct sk_buff *skb)
skb->pkt_type = PACKET_HOST; skb->pkt_type = PACKET_HOST;
skb->protocol = eth_type_trans(skb, netdev); skb->protocol = eth_type_trans(skb, netdev);
skb_postpull_rcsum(skb, eth_hdr(skb), ETH_HLEN); skb_postpull_rcsum(skb, eth_hdr(skb), ETH_HLEN);
dev_sw_netstats_rx_add(netdev, skb->len);
stats = this_cpu_ptr(netdev->tstats);
u64_stats_update_begin(&stats->syncp);
stats->rx_packets++;
stats->rx_bytes += skb->len;
u64_stats_update_end(&stats->syncp);
netif_rx(skb); netif_rx(skb);
return NETDEV_TX_OK; return NETDEV_TX_OK;
......
...@@ -210,7 +210,6 @@ static void xfrmi_scrub_packet(struct sk_buff *skb, bool xnet) ...@@ -210,7 +210,6 @@ static void xfrmi_scrub_packet(struct sk_buff *skb, bool xnet)
static int xfrmi_rcv_cb(struct sk_buff *skb, int err) static int xfrmi_rcv_cb(struct sk_buff *skb, int err)
{ {
const struct xfrm_mode *inner_mode; const struct xfrm_mode *inner_mode;
struct pcpu_sw_netstats *tstats;
struct net_device *dev; struct net_device *dev;
struct xfrm_state *x; struct xfrm_state *x;
struct xfrm_if *xi; struct xfrm_if *xi;
...@@ -255,13 +254,7 @@ static int xfrmi_rcv_cb(struct sk_buff *skb, int err) ...@@ -255,13 +254,7 @@ static int xfrmi_rcv_cb(struct sk_buff *skb, int err)
} }
xfrmi_scrub_packet(skb, xnet); xfrmi_scrub_packet(skb, xnet);
dev_sw_netstats_rx_add(dev, skb->len);
tstats = this_cpu_ptr(dev->tstats);
u64_stats_update_begin(&tstats->syncp);
tstats->rx_packets++;
tstats->rx_bytes += skb->len;
u64_stats_update_end(&tstats->syncp);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment