Stir up struct net_device_stats usage and whereabouts.
Subsystems (4)
cover Stir up struct net_device_stats usage and whereabouts.
There is a on-device statistics already, so those drivers, that needs some statistics, may use this one. This set relaxes bridge, tunnels and mr devices thus, making them occupy less memory.
Besides, the get_stats pointer and the pointer it returns are no longer NULL, while there are still some places, that check for this.
PATCH 1/10 : The dev->get_stats pointer is not NULL nowadays.
And so does the pointer is returns, but sysfs and netlinks still check for both cases.
--- net/core/net-sysfs.c | 9 ++++----- net/core/rtnetlink.c | 20 ++++++++------------ 2 files changed, 12 insertions(+), 17 deletions(-)
net/core/net-sysfs.c +4 -5
@@ -242,11 +242,11 @@ static ssize_t netstat_show(const struct device *d, offset % sizeof(unsigned long) != 0);read_lock (&dev_base_lock); -if (dev_isalive (dev) && dev->get_stats && - (stats = (*dev->get_stats)(dev))) +if (dev_isalive (dev)) { + stats = dev->get_stats (dev); ret =sprintf (buf, fmt_ulong, *(unsigned long *)(((u8 *) stats) + offset)); - + }read_unlock (&dev_base_lock);return ret; }
@@ -457,8 +457,7 @@ int netdev_register_kobject(struct net_device *net)strlcpy (dev->bus_id, net->name,BUS_ID_SIZE );#ifdef CONFIG_SYSFS -if (net->get_stats) - *groups++ = &netstat_group; + *groups++ = &netstat_group;#ifdef CONFIG_WIRELESS_EXT if (net->wireless_handlers && net->wireless_handlers->get_wireless_stats)
net/core/rtnetlink.c +8 -12
@@ -606,6 +606,8 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev, {struct ifinfomsg *ifm;struct nlmsghdr *nlh; +struct net_device_stats *stats; +struct nlattr *attr; nlh =nlmsg_put (skb, pid, seq, type,sizeof (*ifm), flags);if (nlh ==NULL )
@@ -652,19 +654,13 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,NLA_PUT (skb,IFLA_BROADCAST , dev->addr_len, dev->broadcast); } -if (dev->get_stats) { -struct net_device_stats *stats = dev->get_stats (dev); -if (stats) { -struct nlattr *attr; + attr =nla_reserve (skb,IFLA_STATS , +sizeof (struct rtnl_link_stats )); +if (attr ==NULL ) + goto nla_put_failure; - attr =nla_reserve (skb,IFLA_STATS , -sizeof (struct rtnl_link_stats )); -if (attr ==NULL ) - goto nla_put_failure; - -copy_rtnl_link_stats (nla_data (attr), stats); - } - } + stats = dev->get_stats (dev); +copy_rtnl_link_stats (nla_data (attr), stats);if (dev->rtnl_link_ops) {if (rtnl_link_fill (skb, dev) <0 )
Signature · 1 line
1.5.3.4
PATCH 2/10 : Use on-device stats instead of private ones.
In reply to Pavel EmelyanovEven though bridges require 6 fields from struct net_device_stats, the on-device stats are always there, so we may just use them.
The br_dev_get_stats is no longer required after this.
--- net/bridge/br_device.c | 11 ++--------- net/bridge/br_forward.c | 2 +- net/bridge/br_input.c | 10 +++++----- net/bridge/br_private.h | 1 - 4 files changed, 8 insertions(+), 16 deletions(-)
net/bridge/br_device.c +2 -9
@@ -21,12 +21,6 @@#include <asm/uaccess.h> #include "br_private.h" -static struct net_device_stats *br_dev_get_stats (struct net_device *dev) -{ -struct net_bridge *br =netdev_priv (dev); -return &br->statistics; -} -/* net device transmit always called with no BH (preempt_disabled) */ int br_dev_xmit (struct sk_buff *skb,struct net_device *dev) {
@@ -34,8 +28,8 @@ int br_dev_xmit(struct sk_buff *skb, struct net_device *dev)const unsigned char *dest = skb->data;struct net_bridge_fdb_entry *dst; - br->statistics.tx_packets++; - br->statistics.tx_bytes += skb->len; + dev->stats.tx_packets++; + dev->stats.tx_bytes += skb->len;skb_reset_mac_header (skb);skb_pull (skb,ETH_HLEN );
@@ -161,7 +155,6 @@ void br_dev_setup(struct net_device *dev)ether_setup (dev); dev->do_ioctl = br_dev_ioctl; - dev->get_stats = br_dev_get_stats; dev->hard_start_xmit = br_dev_xmit; dev->open = br_dev_open; dev->set_multicast_list = br_dev_set_multicast_list;
net/bridge/br_forward.c +1 -1
@@ -115,7 +115,7 @@ static void br_flood(struct net_bridge *br, struct sk_buff *skb,struct sk_buff *skb2;if ((skb2 =skb_clone (skb,GFP_ATOMIC )) ==NULL ) { - br->statistics.tx_dropped++; + br->dev->stats.tx_dropped++;kfree_skb (skb);return ; }
net/bridge/br_input.c +5 -5
@@ -24,13 +24,13 @@ const u8 br_group_address[ETH_ALEN] = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x00 };static void br_pass_frame_up (struct net_bridge *br,struct sk_buff *skb) { -struct net_device *indev; +struct net_device *indev, *brdev = br->dev; - br->statistics.rx_packets++; - br->statistics.rx_bytes += skb->len; + brdev->stats.rx_packets++; + brdev->stats.rx_bytes += skb->len; indev = skb->dev; - skb->dev = br->dev; + skb->dev = brdev;NF_HOOK (PF_BRIDGE ,NF_BR_LOCAL_IN , skb, indev,NULL , netif_receive_skb);
@@ -64,7 +64,7 @@ int br_handle_frame_finish(struct sk_buff *skb) dst =NULL ;if (is_multicast_ether_addr (dest)) { - br->statistics.multicast++; + br->dev->stats.multicast++; skb2 = skb; }else if ((dst =__br_fdb_get (br, dest)) && dst->is_local) { skb2 = skb;
net/bridge/br_private.h +0 -1
@@ -90,7 +90,6 @@ struct net_bridgespinlock_t lock;struct list_head port_list;struct net_device *dev; -struct net_device_stats statistics;spinlock_t hash_lock;struct hlist_head hash[BR_HASH_SIZE ];struct list_head age_list;
Signature · 1 line
1.5.3.4
PATCH 3/10 : Use on-device stats instead of private ones.
In reply to Pavel EmelyanovJust switch from tunnel->stat to tunnel->dev->stats. The ip_tunnel->stat member intself will be removed after I fix its other users (very soon).
--- net/ipv4/ip_gre.c | 32 ++++++++++++++------------------ 1 files changed, 14 insertions(+), 18 deletions(-)
net/ipv4/ip_gre.c +14 -18
@@ -617,6 +617,8 @@ static int ipgre_rcv(struct sk_buff *skb)read_lock (&ipgre_lock);if ((tunnel =ipgre_tunnel_lookup (dev_net (skb->dev), iph->saddr, iph->daddr, key)) !=NULL ) { +struct net_device_stats *stats = &tunnel->dev->stats; +secpath_reset (skb); skb->protocol = *(__be16 *)(h +2 );
@@ -641,28 +643,28 @@ static int ipgre_rcv(struct sk_buff *skb)/* Looped back packet, drop it! */ if (skb->rtable->fl.iif ==0 ) goto drop; - tunnel->stat.multicast++; + stats->multicast++; skb->pkt_type =PACKET_BROADCAST ; }#endif if (((flags&GRE_CSUM ) && csum) || (!(flags&GRE_CSUM ) && tunnel->parms.i_flags&GRE_CSUM )) { - tunnel->stat.rx_crc_errors++; - tunnel->stat.rx_errors++; + stats->rx_crc_errors++; + stats->rx_errors++; goto drop; }if (tunnel->parms.i_flags&GRE_SEQ ) {if (!(flags&GRE_SEQ ) || (tunnel->i_seqno && (s32)(seqno - tunnel->i_seqno) <0 )) { - tunnel->stat.rx_fifo_errors++; - tunnel->stat.rx_errors++; + stats->rx_fifo_errors++; + stats->rx_errors++; goto drop; } tunnel->i_seqno = seqno +1 ; } - tunnel->stat.rx_packets++; - tunnel->stat.rx_bytes += skb->len; + stats->rx_packets++; + stats->rx_bytes += skb->len; skb->dev = tunnel->dev;dst_release (skb->dst); skb->dst =NULL ;
@@ -684,7 +686,7 @@ drop_nolock:static int ipgre_tunnel_xmit (struct sk_buff *skb,struct net_device *dev) {struct ip_tunnel *tunnel =netdev_priv (dev); -struct net_device_stats *stats = &tunnel->stat; +struct net_device_stats *stats = &tunnel->dev->stats;struct iphdr *old_iph =ip_hdr (skb);struct iphdr *tiph;u8 tos;
@@ -698,7 +700,7 @@ static int ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)int mtu;if (tunnel->recursion++) { - tunnel->stat.collisions++; + stats->collisions++; goto tx_error; }
@@ -714,7 +716,7 @@ static int ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)/* NBMA tunnel */ if (skb->dst ==NULL ) { - tunnel->stat.tx_fifo_errors++; + stats->tx_fifo_errors++; goto tx_error; }
@@ -765,7 +767,7 @@ static int ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev) .tos = RT_TOS(tos) } }, .proto = IPPROTO_GRE };if (ip_route_output_key (dev_net (dev), &rt, &fl)) { - tunnel->stat.tx_carrier_errors++; + stats->tx_carrier_errors++; goto tx_error; } }
@@ -773,7 +775,7 @@ static int ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)if (tdev == dev) {ip_rt_put (rt); - tunnel->stat.collisions++; + stats->collisions++; goto tx_error; }
@@ -1098,11 +1100,6 @@ done:return err; } -static struct net_device_stats *ipgre_tunnel_get_stats (struct net_device *dev) -{ -return &(((struct ip_tunnel *)netdev_priv (dev))->stat); -} -static int ipgre_tunnel_change_mtu (struct net_device *dev,int new_mtu) {struct ip_tunnel *tunnel =netdev_priv (dev);
@@ -1228,7 +1225,6 @@ static void ipgre_tunnel_setup(struct net_device *dev) dev->uninit = ipgre_tunnel_uninit; dev->destructor = free_netdev; dev->hard_start_xmit = ipgre_tunnel_xmit; - dev->get_stats = ipgre_tunnel_get_stats; dev->do_ioctl = ipgre_tunnel_ioctl; dev->change_mtu = ipgre_tunnel_change_mtu;
Signature · 1 line
1.5.3.4
PATCH 4/10 : Use on-device stats instead of private ones.
In reply to Pavel Emelyanov--- net/ipv4/ipip.c | 22 ++++++++-------------- 1 files changed, 8 insertions(+), 14 deletions(-)
net/ipv4/ipip.c +8 -14
@@ -496,8 +496,8 @@ static int ipip_rcv(struct sk_buff *skb) skb->protocol =htons (ETH_P_IP ); skb->pkt_type =PACKET_HOST ; - tunnel->stat.rx_packets++; - tunnel->stat.rx_bytes += skb->len; + tunnel->dev->stats.rx_packets++; + tunnel->dev->stats.rx_bytes += skb->len; skb->dev = tunnel->dev;dst_release (skb->dst); skb->dst =NULL ;
@@ -520,7 +520,7 @@ static int ipip_rcv(struct sk_buff *skb)static int ipip_tunnel_xmit (struct sk_buff *skb,struct net_device *dev) {struct ip_tunnel *tunnel =netdev_priv (dev); -struct net_device_stats *stats = &tunnel->stat; +struct net_device_stats *stats = &tunnel->dev->stats;struct iphdr *tiph = &tunnel->parms.iph;u8 tos = tunnel->parms.iph.tos;__be16 df = tiph->frag_off;
@@ -533,7 +533,7 @@ static int ipip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)int mtu;if (tunnel->recursion++) { - tunnel->stat.collisions++; + stats->collisions++; goto tx_error; }
@@ -546,7 +546,7 @@ static int ipip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)if (!dst) {/* NBMA tunnel */ if ((rt = skb->rtable) ==NULL ) { - tunnel->stat.tx_fifo_errors++; + stats->tx_fifo_errors++; goto tx_error; }if ((dst = rt->rt_gateway) ==0 )
@@ -561,7 +561,7 @@ static int ipip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev) .tos = RT_TOS(tos) } }, .proto = IPPROTO_IPIP };if (ip_route_output_key (dev_net (dev), &rt, &fl)) { - tunnel->stat.tx_carrier_errors++; + stats->tx_carrier_errors++; goto tx_error_icmp; } }
@@ -569,7 +569,7 @@ static int ipip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)if (tdev == dev) {ip_rt_put (rt); - tunnel->stat.collisions++; + stats->collisions++; goto tx_error; }
@@ -579,7 +579,7 @@ static int ipip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev) mtu = skb->dst ?dst_mtu (skb->dst) : dev->mtu;if (mtu <68 ) { - tunnel->stat.collisions++; + stats->collisions++;ip_rt_put (rt); goto tx_error; }
@@ -813,11 +813,6 @@ done:return err; } -static struct net_device_stats *ipip_tunnel_get_stats (struct net_device *dev) -{ -return &(((struct ip_tunnel *)netdev_priv (dev))->stat); -} -static int ipip_tunnel_change_mtu (struct net_device *dev,int new_mtu) {if (new_mtu <68 || new_mtu >0xFFF8 -sizeof (struct iphdr ))
@@ -830,7 +825,6 @@ static void ipip_tunnel_setup(struct net_device *dev) { dev->uninit = ipip_tunnel_uninit; dev->hard_start_xmit = ipip_tunnel_xmit; - dev->get_stats = ipip_tunnel_get_stats; dev->do_ioctl = ipip_tunnel_ioctl; dev->change_mtu = ipip_tunnel_change_mtu; dev->destructor = free_netdev;
Signature · 1 line
1.5.3.4
PATCH 5/10 : Use on-device stats instead of private ones.
In reply to Pavel Emelyanov--- net/ipv6/sit.c | 24 +++++++++--------------- 1 files changed, 9 insertions(+), 15 deletions(-)
net/ipv6/sit.c +9 -15
@@ -578,13 +578,13 @@ static int ipip6_rcv(struct sk_buff *skb)if ((tunnel->dev->priv_flags &IFF_ISATAP ) && !isatap_chksrc (skb, iph, tunnel)) { - tunnel->stat.rx_errors++; + tunnel->dev->stats.rx_errors++;read_unlock (&ipip6_lock);kfree_skb (skb);return 0 ; } - tunnel->stat.rx_packets++; - tunnel->stat.rx_bytes += skb->len; + tunnel->dev->stats.rx_packets++; + tunnel->dev->stats.rx_bytes += skb->len; skb->dev = tunnel->dev;dst_release (skb->dst); skb->dst =NULL ;
@@ -624,7 +624,7 @@ static inline __be32 try_6to4(struct in6_addr *v6dst)static int ipip6_tunnel_xmit (struct sk_buff *skb,struct net_device *dev) {struct ip_tunnel *tunnel =netdev_priv (dev); -struct net_device_stats *stats = &tunnel->stat; +struct net_device_stats *stats = &tunnel->dev->stats;struct iphdr *tiph = &tunnel->parms.iph;struct ipv6hdr *iph6 =ipv6_hdr (skb);u8 tos = tunnel->parms.iph.tos;
@@ -638,7 +638,7 @@ static int ipip6_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)int addr_type;if (tunnel->recursion++) { - tunnel->stat.collisions++; + stats->collisions++; goto tx_error; }
@@ -705,20 +705,20 @@ static int ipip6_tunnel_xmit(struct sk_buff *skb, struct net_device *dev) .oif = tunnel->parms.link, .proto = IPPROTO_IPV6 };if (ip_route_output_key (dev_net (dev), &rt, &fl)) { - tunnel->stat.tx_carrier_errors++; + stats->tx_carrier_errors++; goto tx_error_icmp; } }if (rt->rt_type !=RTN_UNICAST ) {ip_rt_put (rt); - tunnel->stat.tx_carrier_errors++; + stats->tx_carrier_errors++; goto tx_error_icmp; } tdev = rt->u.dst.dev;if (tdev == dev) {ip_rt_put (rt); - tunnel->stat.collisions++; + stats->collisions++; goto tx_error; }
@@ -728,7 +728,7 @@ static int ipip6_tunnel_xmit(struct sk_buff *skb, struct net_device *dev) mtu = skb->dst ?dst_mtu (skb->dst) : dev->mtu;if (mtu <68 ) { - tunnel->stat.collisions++; + stats->collisions++;ip_rt_put (rt); goto tx_error; }
@@ -1003,11 +1003,6 @@ done:return err; } -static struct net_device_stats *ipip6_tunnel_get_stats (struct net_device *dev) -{ -return &(((struct ip_tunnel *)netdev_priv (dev))->stat); -} -static int ipip6_tunnel_change_mtu (struct net_device *dev,int new_mtu) {if (new_mtu <IPV6_MIN_MTU || new_mtu >0xFFF8 -sizeof (struct iphdr ))
@@ -1021,7 +1016,6 @@ static void ipip6_tunnel_setup(struct net_device *dev) dev->uninit = ipip6_tunnel_uninit; dev->destructor = free_netdev; dev->hard_start_xmit = ipip6_tunnel_xmit; - dev->get_stats = ipip6_tunnel_get_stats; dev->do_ioctl = ipip6_tunnel_ioctl; dev->change_mtu = ipip6_tunnel_change_mtu;
Signature · 1 line
1.5.3.4
PATCH 6/10 : Ipip tunnel uses on-device stats.
In reply to Pavel EmelyanovThe ipmr uses ipip tunnels for its purposes and updates the tunnels' stats, but the ipip driver is already switched to use on-device ones.
Actually, this is a part of the patch #4 from this set.
--- net/ipv4/ipmr.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
net/ipv4/ipmr.c +2 -2
@@ -1230,8 +1230,8 @@ static void ipmr_queue_xmit(struct sk_buff *skb, struct mfc_cache *c, int vifi)if (vif->flags &VIFF_TUNNEL ) {ip_encap (skb, vif->local, vif->remote);/* FIXME: extra output firewall step used to be here. --RR */ - ((struct ip_tunnel *)netdev_priv (vif->dev))->stat.tx_packets++; - ((struct ip_tunnel *)netdev_priv (vif->dev))->stat.tx_bytes+=skb->len; + vif->dev->stats.tx_packets++; + vif->dev->stats.tx_bytes += skb->len; }IPCB (skb)->flags |=IPSKB_FORWARDED ;
Signature · 1 line
1.5.3.4
PATCH 7/10 : Remove stat member from ip_tunnel struct.
In reply to Pavel EmelyanovAll users already use on-device statistics, so this field can be safely removed.
--- include/net/ipip.h | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
include/net/ipip.h +0 -1
@@ -11,7 +11,6 @@ struct ip_tunnel {struct ip_tunnel *next;struct net_device *dev; -struct net_device_stats stat;int recursion;/* Depth of hard_start_xmit recursion */ int err_count;/* Number of arrived ICMP errors */
Signature · 1 line
1.5.3.4
PATCH 8/10 : Use on-device stats instead of private ones.
In reply to Pavel EmelyanovThis tunnel uses its own private structure and requires separate patch to switch from private stats to on-device ones.
--- include/net/ip6_tunnel.h | 1 - net/ipv6/ip6_tunnel.c | 26 ++++++-------------------- 2 files changed, 6 insertions(+), 21 deletions(-)
include/net/ip6_tunnel.h +0 -1
@@ -19,7 +19,6 @@struct ip6_tnl {struct ip6_tnl *next;/* next tunnel in list */ struct net_device *dev;/* virtual device associated with tunnel */ -struct net_device_stats stat;/* statistics for tunnel device */ int recursion;/* depth of hard_start_xmit recursion */ struct ip6_tnl_parm parms;/* tunnel configuration parameters */ struct flowi fl;/* flowi template for xmit */
net/ipv6/ip6_tunnel.c +6 -20
@@ -711,7 +711,7 @@ static int ip6_tnl_rcv(struct sk_buff *skb, __u16 protocol, }if (!ip6_tnl_rcv_ctl (t)) { - t->stat.rx_dropped++; + t->dev->stats.rx_dropped++;read_unlock (&ip6_tnl_lock); goto discard; }
@@ -728,8 +728,8 @@ static int ip6_tnl_rcv(struct sk_buff *skb, __u16 protocol,dscp_ecn_decapsulate (t, ipv6h, skb); - t->stat.rx_packets++; - t->stat.rx_bytes += skb->len; + t->dev->stats.rx_packets++; + t->dev->stats.rx_bytes += skb->len;netif_rx (skb);read_unlock (&ip6_tnl_lock);return 0 ;
@@ -849,7 +849,7 @@ static int ip6_tnl_xmit2(struct sk_buff *skb, __u32 *pmtu) {struct ip6_tnl *t =netdev_priv (dev); -struct net_device_stats *stats = &t->stat; +struct net_device_stats *stats = &t->dev->stats;struct ipv6hdr *ipv6h =ipv6_hdr (skb);struct ipv6_tel_txoption opt;struct dst_entry *dst;
@@ -1043,11 +1043,11 @@ static int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev) { struct ip6_tnl *t = netdev_priv(dev); -struct net_device_stats *stats = &t->stat; +struct net_device_stats *stats = &t->dev->stats;int ret;if (t->recursion++) { - t->stat.collisions++; + stats->collisions++; goto tx_err; }
@@ -1289,19 +1289,6 @@ ip6_tnl_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) }/** -* ip6_tnl_get_stats - return the stats for tunnel device -* @dev: virtual device associated with tunnel -* -* Return: stats for device -**/ - -static struct net_device_stats * -ip6_tnl_get_stats (struct net_device *dev) -{ -return &(((struct ip6_tnl *)netdev_priv (dev))->stat); -} - -/** * ip6_tnl_change_mtu - change mtu manually for tunnel device * @dev: virtual device associated with tunnel * @new_mtu: the new mtu
@@ -1334,7 +1321,6 @@ static void ip6_tnl_dev_setup(struct net_device *dev) dev->uninit = ip6_tnl_dev_uninit; dev->destructor = free_netdev; dev->hard_start_xmit = ip6_tnl_xmit; - dev->get_stats = ip6_tnl_get_stats; dev->do_ioctl = ip6_tnl_ioctl; dev->change_mtu = ip6_tnl_change_mtu;
Signature · 1 line
1.5.3.4
PATCH 9/10 : Use on-device stats instead of private ones.
In reply to Pavel EmelyanovThese devices use the private area of appropriate size for statistics. Turning them to use on-device ones make them "privless" and thus - really small wrt kmalloc cache, they are allocated from.
Besides, code looks nicer, because of absence of multi-braced type casts and dereferences.
--- net/ipv4/ipmr.c | 25 +++++++++---------------- 1 files changed, 9 insertions(+), 16 deletions(-)
net/ipv4/ipmr.c +9 -16
@@ -181,26 +181,20 @@ static int reg_vif_num = -1;static int reg_vif_xmit (struct sk_buff *skb,struct net_device *dev) {read_lock (&mrt_lock); - ((struct net_device_stats *)netdev_priv (dev))->tx_bytes += skb->len; - ((struct net_device_stats *)netdev_priv (dev))->tx_packets++; + dev->stats->tx_bytes += skb->len; + dev->stats->tx_packets++;ipmr_cache_report (skb, reg_vif_num,IGMPMSG_WHOLEPKT );read_unlock (&mrt_lock);kfree_skb (skb);return 0 ; } -static struct net_device_stats *reg_vif_get_stats (struct net_device *dev) -{ -return (struct net_device_stats *)netdev_priv (dev); -} -static void reg_vif_setup (struct net_device *dev) { dev->type =ARPHRD_PIMREG ; dev->mtu =ETH_DATA_LEN -sizeof (struct iphdr ) -8 ; dev->flags =IFF_NOARP ; dev->hard_start_xmit = reg_vif_xmit; - dev->get_stats = reg_vif_get_stats; dev->destructor = free_netdev; }
@@ -209,8 +203,7 @@ static struct net_device *ipmr_reg_vif(void)struct net_device *dev;struct in_device *in_dev; - dev =alloc_netdev (sizeof (struct net_device_stats ),"pimreg" , - reg_vif_setup); + dev =alloc_netdev (0 ,"pimreg" , reg_vif_setup);if (dev ==NULL )return NULL ;
@@ -1170,8 +1163,8 @@ static void ipmr_queue_xmit(struct sk_buff *skb, struct mfc_cache *c, int vifi)if (vif->flags &VIFF_REGISTER ) { vif->pkt_out++; vif->bytes_out+=skb->len; - ((struct net_device_stats *)netdev_priv (vif->dev))->tx_bytes += skb->len; - ((struct net_device_stats *)netdev_priv (vif->dev))->tx_packets++; + vif->dev->stats->tx_bytes += skb->len; + vif->dev->stats->tx_packets++;ipmr_cache_report (skb, vifi,IGMPMSG_WHOLEPKT );kfree_skb (skb);return ;
@@ -1487,8 +1480,8 @@ int pim_rcv_v1(struct sk_buff * skb) skb->pkt_type =PACKET_HOST ;dst_release (skb->dst); skb->dst =NULL ; - ((struct net_device_stats *)netdev_priv (reg_dev))->rx_bytes += skb->len; - ((struct net_device_stats *)netdev_priv (reg_dev))->rx_packets++; + reg_dev->stats->rx_bytes += skb->len; + reg_dev->stats->rx_packets++;nf_reset (skb);netif_rx (skb);dev_put (reg_dev);
@@ -1542,8 +1535,8 @@ static int pim_rcv(struct sk_buff * skb) skb->ip_summed =0 ; skb->pkt_type =PACKET_HOST ;dst_release (skb->dst); - ((struct net_device_stats *)netdev_priv (reg_dev))->rx_bytes += skb->len; - ((struct net_device_stats *)netdev_priv (reg_dev))->rx_packets++; + reg_dev->stats->rx_bytes += skb->len; + reg_dev->stats->rx_packets++; skb->dst =NULL ;nf_reset (skb);netif_rx (skb);
Signature · 1 line
1.5.3.4
PATCH 10/10 : Use on-device stats instead of private ones.
In reply to Pavel EmelyanovSimilar to ipmr.
--- net/ipv6/ip6mr.c | 22 +++++++--------------- 1 files changed, 7 insertions(+), 15 deletions(-)
net/ipv6/ip6mr.c +7 -15
@@ -388,8 +388,8 @@ static int pim6_rcv(struct sk_buff *skb) skb->ip_summed =0 ; skb->pkt_type =PACKET_HOST ;dst_release (skb->dst); - ((struct net_device_stats *)netdev_priv (reg_dev))->rx_bytes += skb->len; - ((struct net_device_stats *)netdev_priv (reg_dev))->rx_packets++; + reg_dev->stats->rx_bytes += skb->len; + reg_dev->stats->rx_packets++; skb->dst =NULL ;nf_reset (skb);netif_rx (skb);
@@ -409,26 +409,20 @@ static struct inet6_protocol pim6_protocol = {static int reg_vif_xmit (struct sk_buff *skb,struct net_device *dev) {read_lock (&mrt_lock); - ((struct net_device_stats *)netdev_priv (dev))->tx_bytes += skb->len; - ((struct net_device_stats *)netdev_priv (dev))->tx_packets++; + dev->stats->tx_bytes += skb->len; + dev->stats->tx_packets++;ip6mr_cache_report (skb, reg_vif_num,MRT6MSG_WHOLEPKT );read_unlock (&mrt_lock);kfree_skb (skb);return 0 ; } -static struct net_device_stats *reg_vif_get_stats (struct net_device *dev) -{ -return (struct net_device_stats *)netdev_priv (dev); -} -static void reg_vif_setup (struct net_device *dev) { dev->type =ARPHRD_PIMREG ; dev->mtu =1500 -sizeof (struct ipv6hdr ) -8 ; dev->flags =IFF_NOARP ; dev->hard_start_xmit = reg_vif_xmit; - dev->get_stats = reg_vif_get_stats; dev->destructor = free_netdev; }
@@ -436,9 +430,7 @@ static struct net_device *ip6mr_reg_vif(void) {struct net_device *dev; - dev =alloc_netdev (sizeof (struct net_device_stats ),"pim6reg" , - reg_vif_setup); - + dev =alloc_netdev (0 ,"pim6reg" , reg_vif_setup);if (dev ==NULL )return NULL ;
@@ -1377,8 +1369,8 @@ static int ip6mr_forward2(struct sk_buff *skb, struct mfc6_cache *c, int vifi)if (vif->flags &MIFF_REGISTER ) { vif->pkt_out++; vif->bytes_out += skb->len; - ((struct net_device_stats *)netdev_priv (vif->dev))->tx_bytes += skb->len; - ((struct net_device_stats *)netdev_priv (vif->dev))->tx_packets++; + vif->dev->stats->tx_bytes += skb->len; + vif->dev->stats->tx_packets++;ip6mr_cache_report (skb, vifi,MRT6MSG_WHOLEPKT );kfree_skb (skb);return 0 ;
Signature · 1 line
1.5.3.4
David Miller
maintainerFrom: Pavel Emelyanov <[email protected]>
Date: Tue, 20 May 2008 20:27:03 +0400
Quoted 8 lines
There is a on-device statistics already, so those drivers, that needs some statistics, may use this one. This set relaxes bridge, tunnels and mr devices thus, making them occupy less memory.
Besides, the
get_statspointer and the pointer it returns are no longer NULL, while there are still some places, that check for this.Signed-off-by Pavel Emelyanov <[email protected]>
All applied, thanks Pavel.
I'll push these out to net-next-2.6 after some build tests.