All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] backports: handle netdev->tstats
@ 2015-05-05 13:22 Johannes Berg
  2015-05-11 21:57 ` Hauke Mehrtens
  0 siblings, 1 reply; 2+ messages in thread
From: Johannes Berg @ 2015-05-05 13:22 UTC (permalink / raw)
  To: backports; +Cc: arend, Johannes Berg

From: Johannes Berg <johannes.berg@intel.com>

This adds the necessary backporting to handle netdev->tstats which
was introduced in 3.14 (and some helper macros in 3.15).

For some reason my spatch isn't reliably patching the occurrence
in net/mac80211/tx.c, so for now I'm including a manual patch.

Change-Id: Ib22e307a9bd31f6c31372ef8cc2828ca6e14fce4
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
 backport/backport-include/linux/netdevice.h        | 30 ++++++++++++++++++++++
 .../network/0055-netdev-tstats-assign.cocci        | 10 ++++++++
 .../network/0055-netdev-tstats-tx.patch            | 11 ++++++++
 .../network/0056-netdev-tstats.cocci               |  9 +++++++
 4 files changed, 60 insertions(+)
 create mode 100644 patches/collateral-evolutions/network/0055-netdev-tstats-assign.cocci
 create mode 100644 patches/collateral-evolutions/network/0055-netdev-tstats-tx.patch
 create mode 100644 patches/collateral-evolutions/network/0056-netdev-tstats.cocci

diff --git a/backport/backport-include/linux/netdevice.h b/backport/backport-include/linux/netdevice.h
index abbfe1d43b7e..b99816a44dd3 100644
--- a/backport/backport-include/linux/netdevice.h
+++ b/backport/backport-include/linux/netdevice.h
@@ -80,6 +80,20 @@ static inline void dev_consume_skb_any(struct sk_buff *skb)
 {
 	dev_kfree_skb_any(skb);
 }
+
+struct pcpu_sw_netstats {
+	u64     rx_packets;
+	u64     rx_bytes;
+	u64     tx_packets;
+	u64     tx_bytes;
+	struct u64_stats_sync   syncp;
+};
+
+#define netdev_tstats(dev)	((struct pcpu_sw_netstats *)dev->ml_priv)
+#define netdev_assign_tstats(dev, e)	dev->ml_priv = (e);
+#else
+#define netdev_tstats(dev)	dev->tstats
+#define netdev_assign_tstats(dev, e)	dev->tstats = (e);
 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,14,0) */
 
 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,7,8)
@@ -254,4 +268,20 @@ static inline struct sk_buff *napi_alloc_skb(struct napi_struct *napi,
 #define IFF_TX_SKB_SHARING 0
 #endif
 
+#ifndef netdev_alloc_pcpu_stats
+#define netdev_alloc_pcpu_stats(type)				\
+({								\
+	typeof(type) __percpu *pcpu_stats = alloc_percpu(type); \
+	if (pcpu_stats)	{					\
+		int i;						\
+		for_each_possible_cpu(i) {			\
+			typeof(type) *stat;			\
+			stat = per_cpu_ptr(pcpu_stats, i);	\
+			u64_stats_init(&stat->syncp);		\
+		}						\
+	}							\
+	pcpu_stats;						\
+})
+#endif /* netdev_alloc_pcpu_stats */
+
 #endif /* __BACKPORT_NETDEVICE_H */
diff --git a/patches/collateral-evolutions/network/0055-netdev-tstats-assign.cocci b/patches/collateral-evolutions/network/0055-netdev-tstats-assign.cocci
new file mode 100644
index 000000000000..b41b4f17e654
--- /dev/null
+++ b/patches/collateral-evolutions/network/0055-netdev-tstats-assign.cocci
@@ -0,0 +1,10 @@
+@nd@
+identifier dev;
+@@
+struct net_device *dev;
+@@
+identifier nd.dev;
+expression E;
+@@
+-dev->tstats = E;
++netdev_assign_tstats(dev, E);
diff --git a/patches/collateral-evolutions/network/0055-netdev-tstats-tx.patch b/patches/collateral-evolutions/network/0055-netdev-tstats-tx.patch
new file mode 100644
index 000000000000..aa79e0298cb1
--- /dev/null
+++ b/patches/collateral-evolutions/network/0055-netdev-tstats-tx.patch
@@ -0,0 +1,11 @@
+--- a/net/mac80211/tx.c
++++ b/net/mac80211/tx.c
+@@ -39,7 +39,7 @@
+ 
+ static inline void ieee80211_tx_stats(struct net_device *dev, u32 len)
+ {
+-	struct pcpu_sw_netstats *tstats = this_cpu_ptr(dev->tstats);
++	struct pcpu_sw_netstats *tstats = this_cpu_ptr(netdev_tstats(dev));
+ 
+ 	u64_stats_update_begin(&tstats->syncp);
+ 	tstats->tx_packets++;
diff --git a/patches/collateral-evolutions/network/0056-netdev-tstats.cocci b/patches/collateral-evolutions/network/0056-netdev-tstats.cocci
new file mode 100644
index 000000000000..99d71c05713e
--- /dev/null
+++ b/patches/collateral-evolutions/network/0056-netdev-tstats.cocci
@@ -0,0 +1,9 @@
+@nd@
+identifier dev;
+@@
+struct net_device *dev;
+@@
+identifier nd.dev;
+@@
+-dev->tstats
++netdev_tstats(dev)
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] backports: handle netdev->tstats
  2015-05-05 13:22 [PATCH] backports: handle netdev->tstats Johannes Berg
@ 2015-05-11 21:57 ` Hauke Mehrtens
  0 siblings, 0 replies; 2+ messages in thread
From: Hauke Mehrtens @ 2015-05-11 21:57 UTC (permalink / raw)
  To: Johannes Berg, backports; +Cc: arend, Johannes Berg

On 05/05/2015 03:22 PM, Johannes Berg wrote:
> From: Johannes Berg <johannes.berg@intel.com>
> 
> This adds the necessary backporting to handle netdev->tstats which
> was introduced in 3.14 (and some helper macros in 3.15).
> 
> For some reason my spatch isn't reliably patching the occurrence
> in net/mac80211/tx.c, so for now I'm including a manual patch.
> 
> Change-Id: Ib22e307a9bd31f6c31372ef8cc2828ca6e14fce4
> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
> ---
>  backport/backport-include/linux/netdevice.h        | 30 ++++++++++++++++++++++
>  .../network/0055-netdev-tstats-assign.cocci        | 10 ++++++++
>  .../network/0055-netdev-tstats-tx.patch            | 11 ++++++++
>  .../network/0056-netdev-tstats.cocci               |  9 +++++++
>  4 files changed, 60 insertions(+)
>  create mode 100644 patches/collateral-evolutions/network/0055-netdev-tstats-assign.cocci
>  create mode 100644 patches/collateral-evolutions/network/0055-netdev-tstats-tx.patch
>  create mode 100644 patches/collateral-evolutions/network/0056-netdev-tstats.cocci
> 
Thank you for the patch, it was applied and pushed out.

Hauke

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-05-11 21:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-05 13:22 [PATCH] backports: handle netdev->tstats Johannes Berg
2015-05-11 21:57 ` Hauke Mehrtens

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.