From: Heiner Kallweit <hkallweit1@gmail.com>
To: David Miller <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Realtek linux nic maintainers <nic_swsd@realtek.com>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: [PATCH net-next 2/4] net: core: add devm_netdev_alloc_pcpu_stats
Date: Thu, 29 Oct 2020 18:31:21 +0100 [thread overview]
Message-ID: <78eb7e22-902c-0227-3bbf-d324eb232ade@gmail.com> (raw)
In-Reply-To: <1fdb8ecd-be0a-755d-1d92-c62ed8399e77@gmail.com>
We have netdev_alloc_pcpu_stats(), and we have devm_alloc_percpu().
Add a managed version of netdev_alloc_pcpu_stats, e.g. for allocating
the per-cpu stats in the probe() callback of a driver. It needs to be
a macro for dealing properly with the type argument.
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
include/linux/netdevice.h | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 568fab708..6e06fef32 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -2596,6 +2596,20 @@ static inline void dev_lstats_add(struct net_device *dev, unsigned int len)
#define netdev_alloc_pcpu_stats(type) \
__netdev_alloc_pcpu_stats(type, GFP_KERNEL)
+#define devm_netdev_alloc_pcpu_stats(dev, type) \
+({ \
+ typeof(type) __percpu *pcpu_stats = devm_alloc_percpu(dev, type);\
+ if (pcpu_stats) { \
+ int __cpu; \
+ for_each_possible_cpu(__cpu) { \
+ typeof(type) *stat; \
+ stat = per_cpu_ptr(pcpu_stats, __cpu); \
+ u64_stats_init(&stat->syncp); \
+ } \
+ } \
+ pcpu_stats; \
+})
+
enum netdev_lag_tx_type {
NETDEV_LAG_TX_TYPE_UNKNOWN,
NETDEV_LAG_TX_TYPE_RANDOM,
--
2.29.1
next prev parent reply other threads:[~2020-10-29 17:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-29 17:28 [PATCH net-next 0/4] net: add functionality to net core byte/packet counters and use it in r8169 Heiner Kallweit
2020-10-29 17:29 ` [PATCH net-next 1/4] net: core: add dev_sw_netstats_tx_add Heiner Kallweit
2020-10-29 17:31 ` Heiner Kallweit [this message]
2020-10-29 17:33 ` [PATCH net-next 3/4] r8169: use struct pcpu_sw_netstats for rx/tx packet/byte counters Heiner Kallweit
2020-10-29 17:34 ` [PATCH net-next 4/4] r8169: remove no longer needed private " Heiner Kallweit
2020-10-31 18:35 ` [PATCH net-next 0/4] net: add functionality to net core byte/packet counters and use it in r8169 Jakub Kicinski
-- strict thread matches above, loose matches on Subject: below --
2020-10-15 15:47 Heiner Kallweit
2020-10-15 15:49 ` [PATCH net-next 2/4] net: core: add devm_netdev_alloc_pcpu_stats Heiner Kallweit
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=78eb7e22-902c-0227-3bbf-d324eb232ade@gmail.com \
--to=hkallweit1@gmail.com \
--cc=davem@davemloft.net \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=nic_swsd@realtek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).