aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv6/sit.c
diff options
context:
space:
mode:
authorEric Dumazet <eric.dumazet@gmail.com>2010-09-26 20:38:18 -0400
committerDavid S. Miller <davem@davemloft.net>2010-09-28 00:30:44 -0400
commit15fc1f7056ebdc57e23f99077fec89e63e6fa941 (patch)
treea2c08d2a77cec6255a5718ed296592b1fc0d33ed /net/ipv6/sit.c
parent3c97af99a5aa17feaebb4eb0f85f51ab6c055797 (diff)
sit: percpu stats accounting
Maintain per_cpu tx_bytes, tx_packets, rx_bytes, rx_packets. Other seldom used fields are kept in netdev->stats structure, possibly unsafe. This is a preliminary work to support lockless transmit path, and correct RX stats, that are already unsafe. Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv6/sit.c')
-rw-r--r--net/ipv6/sit.c82
1 files changed, 64 insertions, 18 deletions
diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
index 8a0399822230..011ecf55d34e 100644
--- a/net/ipv6/sit.c
+++ b/net/ipv6/sit.c
@@ -63,8 +63,9 @@
63#define HASH_SIZE 16 63#define HASH_SIZE 16
64#define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&0xF) 64#define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&0xF)
65 65
66static void ipip6_tunnel_init(struct net_device *dev); 66static int ipip6_tunnel_init(struct net_device *dev);
67static void ipip6_tunnel_setup(struct net_device *dev); 67static void ipip6_tunnel_setup(struct net_device *dev);
68static void ipip6_dev_free(struct net_device *dev);
68 69
69static int sit_net_id __read_mostly; 70static int sit_net_id __read_mostly;
70struct sit_net { 71struct sit_net {
@@ -84,6 +85,33 @@ struct sit_net {
84#define for_each_ip_tunnel_rcu(start) \ 85#define for_each_ip_tunnel_rcu(start) \
85 for (t = rcu_dereference(start); t; t = rcu_dereference(t->next)) 86 for (t = rcu_dereference(start); t; t = rcu_dereference(t->next))
86 87
88/* often modified stats are per cpu, other are shared (netdev->stats) */
89struct pcpu_tstats {
90 unsigned long rx_packets;
91 unsigned long rx_bytes;
92 unsigned long tx_packets;
93 unsigned long tx_bytes;
94};
95
96static struct net_device_stats *ipip6_get_stats(struct net_device *dev)
97{
98 struct pcpu_tstats sum = { 0 };
99 int i;
100
101 for_each_possible_cpu(i) {
102 const struct pcpu_tstats *tstats = per_cpu_ptr(dev->tstats, i);
103
104 sum.rx_packets += tstats->rx_packets;
105 sum.rx_bytes += tstats->rx_bytes;
106 sum.tx_packets += tstats->tx_packets;
107 sum.tx_bytes += tstats->tx_bytes;
108 }
109 dev->stats.rx_packets = sum.rx_packets;
110 dev->stats.rx_bytes = sum.rx_bytes;
111 dev->stats.tx_packets = sum.tx_packets;
112 dev->stats.tx_bytes = sum.tx_bytes;
113 return &dev->stats;
114}
87/* 115/*
88 * Must be invoked with rcu_read_lock 116 * Must be invoked with rcu_read_lock
89 */ 117 */
@@ -214,7 +242,7 @@ static struct ip_tunnel *ipip6_tunnel_locate(struct net *net,
214 if (parms->name[0]) 242 if (parms->name[0])
215 strlcpy(name, parms->name, IFNAMSIZ); 243 strlcpy(name, parms->name, IFNAMSIZ);
216 else 244 else
217 sprintf(name, "sit%%d"); 245 strcpy(name, "sit%d");
218 246
219 dev = alloc_netdev(sizeof(*t), name, ipip6_tunnel_setup); 247 dev = alloc_netdev(sizeof(*t), name, ipip6_tunnel_setup);
220 if (dev == NULL) 248 if (dev == NULL)
@@ -230,7 +258,8 @@ static struct ip_tunnel *ipip6_tunnel_locate(struct net *net,
230 nt = netdev_priv(dev); 258 nt = netdev_priv(dev);
231 259
232 nt->parms = *parms; 260 nt->parms = *parms;
233 ipip6_tunnel_init(dev); 261 if (ipip6_tunnel_init(dev) < 0)
262 goto failed_free;
234 ipip6_tunnel_clone_6rd(dev, sitn); 263 ipip6_tunnel_clone_6rd(dev, sitn);
235 264
236 if (parms->i_flags & SIT_ISATAP) 265 if (parms->i_flags & SIT_ISATAP)
@@ -245,7 +274,7 @@ static struct ip_tunnel *ipip6_tunnel_locate(struct net *net,
245 return nt; 274 return nt;
246 275
247failed_free: 276failed_free:
248 free_netdev(dev); 277 ipip6_dev_free(dev);
249failed: 278failed:
250 return NULL; 279 return NULL;
251} 280}
@@ -546,6 +575,8 @@ static int ipip6_rcv(struct sk_buff *skb)
546 tunnel = ipip6_tunnel_lookup(dev_net(skb->dev), skb->dev, 575 tunnel = ipip6_tunnel_lookup(dev_net(skb->dev), skb->dev,
547 iph->saddr, iph->daddr); 576 iph->saddr, iph->daddr);
548 if (tunnel != NULL) { 577 if (tunnel != NULL) {
578 struct pcpu_tstats *tstats;
579
549 secpath_reset(skb); 580 secpath_reset(skb);
550 skb->mac_header = skb->network_header; 581 skb->mac_header = skb->network_header;
551 skb_reset_network_header(skb); 582 skb_reset_network_header(skb);
@@ -561,7 +592,11 @@ static int ipip6_rcv(struct sk_buff *skb)
561 return 0; 592 return 0;
562 } 593 }
563 594
564 skb_tunnel_rx(skb, tunnel->dev); 595 tstats = this_cpu_ptr(tunnel->dev->tstats);
596 tstats->rx_packets++;
597 tstats->rx_bytes += skb->len;
598
599 __skb_tunnel_rx(skb, tunnel->dev);
565 600
566 ipip6_ecn_decapsulate(iph, skb); 601 ipip6_ecn_decapsulate(iph, skb);
567 602
@@ -626,14 +661,13 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
626 struct net_device *dev) 661 struct net_device *dev)
627{ 662{
628 struct ip_tunnel *tunnel = netdev_priv(dev); 663 struct ip_tunnel *tunnel = netdev_priv(dev);
629 struct net_device_stats *stats = &dev->stats; 664 struct pcpu_tstats *tstats;
630 struct netdev_queue *txq = netdev_get_tx_queue(dev, 0);
631 struct iphdr *tiph = &tunnel->parms.iph; 665 struct iphdr *tiph = &tunnel->parms.iph;
632 struct ipv6hdr *iph6 = ipv6_hdr(skb); 666 struct ipv6hdr *iph6 = ipv6_hdr(skb);
633 u8 tos = tunnel->parms.iph.tos; 667 u8 tos = tunnel->parms.iph.tos;
634 __be16 df = tiph->frag_off; 668 __be16 df = tiph->frag_off;
635 struct rtable *rt; /* Route to the other host */ 669 struct rtable *rt; /* Route to the other host */
636 struct net_device *tdev; /* Device to other host */ 670 struct net_device *tdev; /* Device to other host */
637 struct iphdr *iph; /* Our new IP header */ 671 struct iphdr *iph; /* Our new IP header */
638 unsigned int max_headroom; /* The extra header space needed */ 672 unsigned int max_headroom; /* The extra header space needed */
639 __be32 dst = tiph->daddr; 673 __be32 dst = tiph->daddr;
@@ -704,20 +738,20 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
704 .oif = tunnel->parms.link, 738 .oif = tunnel->parms.link,
705 .proto = IPPROTO_IPV6 }; 739 .proto = IPPROTO_IPV6 };
706 if (ip_route_output_key(dev_net(dev), &rt, &fl)) { 740 if (ip_route_output_key(dev_net(dev), &rt, &fl)) {
707 stats->tx_carrier_errors++; 741 dev->stats.tx_carrier_errors++;
708 goto tx_error_icmp; 742 goto tx_error_icmp;
709 } 743 }
710 } 744 }
711 if (rt->rt_type != RTN_UNICAST) { 745 if (rt->rt_type != RTN_UNICAST) {
712 ip_rt_put(rt); 746 ip_rt_put(rt);
713 stats->tx_carrier_errors++; 747 dev->stats.tx_carrier_errors++;
714 goto tx_error_icmp; 748 goto tx_error_icmp;
715 } 749 }
716 tdev = rt->dst.dev; 750 tdev = rt->dst.dev;
717 751
718 if (tdev == dev) { 752 if (tdev == dev) {
719 ip_rt_put(rt); 753 ip_rt_put(rt);
720 stats->collisions++; 754 dev->stats.collisions++;
721 goto tx_error; 755 goto tx_error;
722 } 756 }
723 757
@@ -725,7 +759,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
725 mtu = dst_mtu(&rt->dst) - sizeof(struct iphdr); 759 mtu = dst_mtu(&rt->dst) - sizeof(struct iphdr);
726 760
727 if (mtu < 68) { 761 if (mtu < 68) {
728 stats->collisions++; 762 dev->stats.collisions++;
729 ip_rt_put(rt); 763 ip_rt_put(rt);
730 goto tx_error; 764 goto tx_error;
731 } 765 }
@@ -764,7 +798,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
764 struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom); 798 struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom);
765 if (!new_skb) { 799 if (!new_skb) {
766 ip_rt_put(rt); 800 ip_rt_put(rt);
767 txq->tx_dropped++; 801 dev->stats.tx_dropped++;
768 dev_kfree_skb(skb); 802 dev_kfree_skb(skb);
769 return NETDEV_TX_OK; 803 return NETDEV_TX_OK;
770 } 804 }
@@ -800,14 +834,14 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
800 iph->ttl = iph6->hop_limit; 834 iph->ttl = iph6->hop_limit;
801 835
802 nf_reset(skb); 836 nf_reset(skb);
803 837 tstats = this_cpu_ptr(dev->tstats);
804 IPTUNNEL_XMIT(); 838 __IPTUNNEL_XMIT(tstats, &dev->stats);
805 return NETDEV_TX_OK; 839 return NETDEV_TX_OK;
806 840
807tx_error_icmp: 841tx_error_icmp:
808 dst_link_failure(skb); 842 dst_link_failure(skb);
809tx_error: 843tx_error:
810 stats->tx_errors++; 844 dev->stats.tx_errors++;
811 dev_kfree_skb(skb); 845 dev_kfree_skb(skb);
812 return NETDEV_TX_OK; 846 return NETDEV_TX_OK;
813} 847}
@@ -1084,12 +1118,19 @@ static const struct net_device_ops ipip6_netdev_ops = {
1084 .ndo_start_xmit = ipip6_tunnel_xmit, 1118 .ndo_start_xmit = ipip6_tunnel_xmit,
1085 .ndo_do_ioctl = ipip6_tunnel_ioctl, 1119 .ndo_do_ioctl = ipip6_tunnel_ioctl,
1086 .ndo_change_mtu = ipip6_tunnel_change_mtu, 1120 .ndo_change_mtu = ipip6_tunnel_change_mtu,
1121 .ndo_get_stats = ipip6_get_stats,
1087}; 1122};
1088 1123
1124static void ipip6_dev_free(struct net_device *dev)
1125{
1126 free_percpu(dev->tstats);
1127 free_netdev(dev);
1128}
1129
1089static void ipip6_tunnel_setup(struct net_device *dev) 1130static void ipip6_tunnel_setup(struct net_device *dev)
1090{ 1131{
1091 dev->netdev_ops = &ipip6_netdev_ops; 1132 dev->netdev_ops = &ipip6_netdev_ops;
1092 dev->destructor = free_netdev; 1133 dev->destructor = ipip6_dev_free;
1093 1134
1094 dev->type = ARPHRD_SIT; 1135 dev->type = ARPHRD_SIT;
1095 dev->hard_header_len = LL_MAX_HEADER + sizeof(struct iphdr); 1136 dev->hard_header_len = LL_MAX_HEADER + sizeof(struct iphdr);
@@ -1101,7 +1142,7 @@ static void ipip6_tunnel_setup(struct net_device *dev)
1101 dev->features |= NETIF_F_NETNS_LOCAL; 1142 dev->features |= NETIF_F_NETNS_LOCAL;
1102} 1143}
1103 1144
1104static void ipip6_tunnel_init(struct net_device *dev) 1145static int ipip6_tunnel_init(struct net_device *dev)
1105{ 1146{
1106 struct ip_tunnel *tunnel = netdev_priv(dev); 1147 struct ip_tunnel *tunnel = netdev_priv(dev);
1107 1148
@@ -1112,6 +1153,11 @@ static void ipip6_tunnel_init(struct net_device *dev)
1112 memcpy(dev->broadcast, &tunnel->parms.iph.daddr, 4); 1153 memcpy(dev->broadcast, &tunnel->parms.iph.daddr, 4);
1113 1154
1114 ipip6_tunnel_bind_dev(dev); 1155 ipip6_tunnel_bind_dev(dev);
1156 dev->tstats = alloc_percpu(struct pcpu_tstats);
1157 if (!dev->tstats)
1158 return -ENOMEM;
1159
1160 return 0;
1115} 1161}
1116 1162
1117static void __net_init ipip6_fb_tunnel_init(struct net_device *dev) 1163static void __net_init ipip6_fb_tunnel_init(struct net_device *dev)