Skip to content

Commit 8f84985

Browse files
Li RongQingdavem330
authored andcommitted
net: unify the pcpu_tstats and br_cpu_netstats as one
They are same, so unify them as one, pcpu_sw_netstats. Define pcpu_sw_netstat in netdevice.h, remove pcpu_tstats from if_tunnel and remove br_cpu_netstats from br_private.h Cc: Cong Wang <xiyou.wangcong@gmail.com> Cc: Stephen Hemminger <stephen@networkplumber.org> Signed-off-by: Li RongQing <roy.qing.li@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 653864d commit 8f84985

16 files changed

Lines changed: 60 additions & 66 deletions

File tree

‎drivers/net/vxlan.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ static void vxlan_rcv(struct vxlan_sock *vs,
10811081
struct iphdr *oip = NULL;
10821082
struct ipv6hdr *oip6 = NULL;
10831083
struct vxlan_dev *vxlan;
1084-
struct pcpu_tstats *stats;
1084+
struct pcpu_sw_netstats *stats;
10851085
union vxlan_addr saddr;
10861086
__u32 vni;
10871087
int err = 0;
@@ -1587,11 +1587,12 @@ EXPORT_SYMBOL_GPL(vxlan_xmit_skb);
15871587
static void vxlan_encap_bypass(struct sk_buff *skb, struct vxlan_dev *src_vxlan,
15881588
struct vxlan_dev *dst_vxlan)
15891589
{
1590-
struct pcpu_tstats *tx_stats = this_cpu_ptr(src_vxlan->dev->tstats);
1591-
struct pcpu_tstats *rx_stats = this_cpu_ptr(dst_vxlan->dev->tstats);
1590+
struct pcpu_sw_netstats *tx_stats, *rx_stats;
15921591
union vxlan_addr loopback;
15931592
union vxlan_addr *remote_ip = &dst_vxlan->default_dst.remote_ip;
15941593

1594+
tx_stats = this_cpu_ptr(src_vxlan->dev->tstats);
1595+
rx_stats = this_cpu_ptr(dst_vxlan->dev->tstats);
15951596
skb->pkt_type = PACKET_HOST;
15961597
skb->encapsulation = 0;
15971598
skb->dev = dst_vxlan->dev;
@@ -1897,12 +1898,12 @@ static int vxlan_init(struct net_device *dev)
18971898
struct vxlan_sock *vs;
18981899
int i;
18991900

1900-
dev->tstats = alloc_percpu(struct pcpu_tstats);
1901+
dev->tstats = alloc_percpu(struct pcpu_sw_netstats);
19011902
if (!dev->tstats)
19021903
return -ENOMEM;
19031904

19041905
for_each_possible_cpu(i) {
1905-
struct pcpu_tstats *vxlan_stats;
1906+
struct pcpu_sw_netstats *vxlan_stats;
19061907
vxlan_stats = per_cpu_ptr(dev->tstats, i);
19071908
u64_stats_init(&vxlan_stats->syncp);
19081909
}

‎include/linux/if_tunnel.h‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,4 @@
1313
#define for_each_ip_tunnel_rcu(pos, start) \
1414
for (pos = rcu_dereference(start); pos; pos = rcu_dereference(pos->next))
1515

16-
/* often modified stats are per cpu, other are shared (netdev->stats) */
17-
struct pcpu_tstats {
18-
u64 rx_packets;
19-
u64 rx_bytes;
20-
u64 tx_packets;
21-
u64 tx_bytes;
22-
struct u64_stats_sync syncp;
23-
};
24-
2516
#endif /* _IF_TUNNEL_H_ */

‎include/linux/netdevice.h‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ struct net_device {
14091409
union {
14101410
void *ml_priv;
14111411
struct pcpu_lstats __percpu *lstats; /* loopback stats */
1412-
struct pcpu_tstats __percpu *tstats; /* tunnel stats */
1412+
struct pcpu_sw_netstats __percpu *tstats;
14131413
struct pcpu_dstats __percpu *dstats; /* dummy stats */
14141414
struct pcpu_vstats __percpu *vstats; /* veth stats */
14151415
};
@@ -1685,6 +1685,15 @@ struct packet_offload {
16851685
struct list_head list;
16861686
};
16871687

1688+
/* often modified stats are per cpu, other are shared (netdev->stats) */
1689+
struct pcpu_sw_netstats {
1690+
u64 rx_packets;
1691+
u64 rx_bytes;
1692+
u64 tx_packets;
1693+
u64 tx_bytes;
1694+
struct u64_stats_sync syncp;
1695+
};
1696+
16881697
#include <linux/notifier.h>
16891698

16901699
/* netdevice notifier chain. Please remember to update the rtnetlink

‎include/net/ip6_tunnel.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static inline void ip6tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
7979
err = ip6_local_out(skb);
8080

8181
if (net_xmit_eval(err) == 0) {
82-
struct pcpu_tstats *tstats = this_cpu_ptr(dev->tstats);
82+
struct pcpu_sw_netstats *tstats = this_cpu_ptr(dev->tstats);
8383
u64_stats_update_begin(&tstats->syncp);
8484
tstats->tx_bytes += pkt_len;
8585
tstats->tx_packets++;

‎include/net/ip_tunnels.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@ struct sk_buff *iptunnel_handle_offloads(struct sk_buff *skb, bool gre_csum,
162162

163163
static inline void iptunnel_xmit_stats(int err,
164164
struct net_device_stats *err_stats,
165-
struct pcpu_tstats __percpu *stats)
165+
struct pcpu_sw_netstats __percpu *stats)
166166
{
167167
if (err > 0) {
168-
struct pcpu_tstats *tstats = this_cpu_ptr(stats);
168+
struct pcpu_sw_netstats *tstats = this_cpu_ptr(stats);
169169

170170
u64_stats_update_begin(&tstats->syncp);
171171
tstats->tx_bytes += err;

‎net/bridge/br_device.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev)
3232
const unsigned char *dest = skb->data;
3333
struct net_bridge_fdb_entry *dst;
3434
struct net_bridge_mdb_entry *mdst;
35-
struct br_cpu_netstats *brstats = this_cpu_ptr(br->stats);
35+
struct pcpu_sw_netstats *brstats = this_cpu_ptr(br->stats);
3636
u16 vid = 0;
3737

3838
rcu_read_lock();
@@ -90,12 +90,12 @@ static int br_dev_init(struct net_device *dev)
9090
struct net_bridge *br = netdev_priv(dev);
9191
int i;
9292

93-
br->stats = alloc_percpu(struct br_cpu_netstats);
93+
br->stats = alloc_percpu(struct pcpu_sw_netstats);
9494
if (!br->stats)
9595
return -ENOMEM;
9696

9797
for_each_possible_cpu(i) {
98-
struct br_cpu_netstats *br_dev_stats;
98+
struct pcpu_sw_netstats *br_dev_stats;
9999
br_dev_stats = per_cpu_ptr(br->stats, i);
100100
u64_stats_init(&br_dev_stats->syncp);
101101
}
@@ -135,12 +135,12 @@ static struct rtnl_link_stats64 *br_get_stats64(struct net_device *dev,
135135
struct rtnl_link_stats64 *stats)
136136
{
137137
struct net_bridge *br = netdev_priv(dev);
138-
struct br_cpu_netstats tmp, sum = { 0 };
138+
struct pcpu_sw_netstats tmp, sum = { 0 };
139139
unsigned int cpu;
140140

141141
for_each_possible_cpu(cpu) {
142142
unsigned int start;
143-
const struct br_cpu_netstats *bstats
143+
const struct pcpu_sw_netstats *bstats
144144
= per_cpu_ptr(br->stats, cpu);
145145
do {
146146
start = u64_stats_fetch_begin_bh(&bstats->syncp);

‎net/bridge/br_input.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static int br_pass_frame_up(struct sk_buff *skb)
2828
{
2929
struct net_device *indev, *brdev = BR_INPUT_SKB_CB(skb)->brdev;
3030
struct net_bridge *br = netdev_priv(brdev);
31-
struct br_cpu_netstats *brstats = this_cpu_ptr(br->stats);
31+
struct pcpu_sw_netstats *brstats = this_cpu_ptr(br->stats);
3232

3333
u64_stats_update_begin(&brstats->syncp);
3434
brstats->rx_packets++;

‎net/bridge/br_private.h‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -210,21 +210,13 @@ static inline struct net_bridge_port *br_port_get_rtnl(const struct net_device *
210210
rtnl_dereference(dev->rx_handler_data) : NULL;
211211
}
212212

213-
struct br_cpu_netstats {
214-
u64 rx_packets;
215-
u64 rx_bytes;
216-
u64 tx_packets;
217-
u64 tx_bytes;
218-
struct u64_stats_sync syncp;
219-
};
220-
221213
struct net_bridge
222214
{
223215
spinlock_t lock;
224216
struct list_head port_list;
225217
struct net_device *dev;
226218

227-
struct br_cpu_netstats __percpu *stats;
219+
struct pcpu_sw_netstats __percpu *stats;
228220
spinlock_t hash_lock;
229221
struct hlist_head hash[BR_HASH_SIZE];
230222
#ifdef CONFIG_BRIDGE_NETFILTER

‎net/ipv4/ip_tunnel.c‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ struct rtnl_link_stats64 *ip_tunnel_get_stats64(struct net_device *dev,
132132
int i;
133133

134134
for_each_possible_cpu(i) {
135-
const struct pcpu_tstats *tstats = per_cpu_ptr(dev->tstats, i);
135+
const struct pcpu_sw_netstats *tstats =
136+
per_cpu_ptr(dev->tstats, i);
136137
u64 rx_packets, rx_bytes, tx_packets, tx_bytes;
137138
unsigned int start;
138139

@@ -460,7 +461,7 @@ static struct ip_tunnel *ip_tunnel_create(struct net *net,
460461
int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb,
461462
const struct tnl_ptk_info *tpi, bool log_ecn_error)
462463
{
463-
struct pcpu_tstats *tstats;
464+
struct pcpu_sw_netstats *tstats;
464465
const struct iphdr *iph = ip_hdr(skb);
465466
int err;
466467

@@ -1049,12 +1050,12 @@ int ip_tunnel_init(struct net_device *dev)
10491050
int i, err;
10501051

10511052
dev->destructor = ip_tunnel_dev_free;
1052-
dev->tstats = alloc_percpu(struct pcpu_tstats);
1053+
dev->tstats = alloc_percpu(struct pcpu_sw_netstats);
10531054
if (!dev->tstats)
10541055
return -ENOMEM;
10551056

10561057
for_each_possible_cpu(i) {
1057-
struct pcpu_tstats *ipt_stats;
1058+
struct pcpu_sw_netstats *ipt_stats;
10581059
ipt_stats = per_cpu_ptr(dev->tstats, i);
10591060
u64_stats_init(&ipt_stats->syncp);
10601061
}

‎net/ipv4/ip_vti.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static int vti_rcv(struct sk_buff *skb)
6060
tunnel = ip_tunnel_lookup(itn, skb->dev->ifindex, TUNNEL_NO_KEY,
6161
iph->saddr, iph->daddr, 0);
6262
if (tunnel != NULL) {
63-
struct pcpu_tstats *tstats;
63+
struct pcpu_sw_netstats *tstats;
6464
u32 oldmark = skb->mark;
6565
int ret;
6666

0 commit comments

Comments
 (0)