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, 15 Oct 2020 17:49:20 +0200 [thread overview]
Message-ID: <1c618e2d-049c-7dfa-0f82-5f32fa4e9322@gmail.com> (raw)
In-Reply-To: <e25761cc-60c2-92fe-f7df-b8c55cf12ec7@gmail.com>
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 | 15 +++++++++++++++
net/devres.c | 6 ++++++
2 files changed, 21 insertions(+)
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 568fab708..f5f41c160 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -2596,6 +2596,21 @@ 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)
+void devm_free_pcpu_stats(void *data);
+
+#define devm_netdev_alloc_pcpu_stats(dev, type) \
+({ \
+ typeof(type) __percpu *pcpu_stats = netdev_alloc_pcpu_stats(type); \
+ if (pcpu_stats) { \
+ int rc = devm_add_action_or_reset(dev, \
+ devm_free_pcpu_stats, \
+ (__force void *)pcpu_stats); \
+ if (rc) \
+ pcpu_stats = NULL; \
+ } \
+ pcpu_stats; \
+})
+
enum netdev_lag_tx_type {
NETDEV_LAG_TX_TYPE_UNKNOWN,
NETDEV_LAG_TX_TYPE_RANDOM,
diff --git a/net/devres.c b/net/devres.c
index 1f9be2133..0d6545946 100644
--- a/net/devres.c
+++ b/net/devres.c
@@ -93,3 +93,9 @@ int devm_register_netdev(struct device *dev, struct net_device *ndev)
return 0;
}
EXPORT_SYMBOL(devm_register_netdev);
+
+void devm_free_pcpu_stats(void *data)
+{
+ free_percpu((__force void __percpu *)data);
+}
+EXPORT_SYMBOL_GPL(devm_free_pcpu_stats);
--
2.28.0
next prev parent reply other threads:[~2020-10-15 15:51 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-15 15:47 [PATCH net-next 0/4] net: add functionality to net core byte/packet counters and use it in r8169 Heiner Kallweit
2020-10-15 15:48 ` [PATCH net-next 1/4] net: core: add dev_sw_netstats_tx_add Heiner Kallweit
2020-10-15 15:49 ` Heiner Kallweit [this message]
2020-10-15 15:50 ` [PATCH net-next 3/4] r8169: use struct pcpu_sw_netstats for rx/tx packet/byte counters Heiner Kallweit
2020-10-15 15:51 ` [PATCH net-next 4/4] r8169: remove no longer needed private " Heiner Kallweit
2020-10-15 19:56 ` [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-29 17:28 Heiner Kallweit
2020-10-29 17:31 ` [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=1c618e2d-049c-7dfa-0f82-5f32fa4e9322@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).