Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Wei Wang <weiwan@google.com>
To: "David S . Miller" <davem@davemloft.net>, netdev@vger.kernel.org
Cc: Jakub Kicinski <kuba@kernel.org>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>,
Hannes Frederic Sowa <hannes@stressinduktion.org>,
Felix Fietkau <nbd@nbd.name>, Wei Wang <weiwan@google.com>
Subject: [RFC PATCH net-next 2/6] net: add sysfs attribute to control napi threaded mode
Date: Mon, 14 Sep 2020 10:24:49 -0700 [thread overview]
Message-ID: <20200914172453.1833883-3-weiwan@google.com> (raw)
In-Reply-To: <20200914172453.1833883-1-weiwan@google.com>
From: Paolo Abeni <pabeni@redhat.com>
this patch adds a new sysfs attribute to the network
device class. Said attribute is a bitmask that allows controlling
the threaded mode for all the napi instances of the given
network device.
The threaded mode can be switched only if related network device
is down.
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: Wei Wang <weiwan@google.com>
---
include/linux/netdevice.h | 1 +
net/core/net-sysfs.c | 102 ++++++++++++++++++++++++++++++++++++++
2 files changed, 103 insertions(+)
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 6797eb356e2e..37941d6a911d 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -1965,6 +1965,7 @@ struct net_device {
spinlock_t addr_list_lock;
unsigned char name_assign_type;
bool uc_promisc;
+ bool napi_threaded;
struct netdev_hw_addr_list uc;
struct netdev_hw_addr_list mc;
struct netdev_hw_addr_list dev_addrs;
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index efec66fa78b7..0172457a1bfe 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -538,6 +538,107 @@ static ssize_t phys_switch_id_show(struct device *dev,
}
static DEVICE_ATTR_RO(phys_switch_id);
+unsigned long *__alloc_thread_bitmap(struct net_device *netdev, int *bits)
+{
+ struct napi_struct *n;
+
+ *bits = 0;
+ list_for_each_entry(n, &netdev->napi_list, dev_list)
+ (*bits)++;
+
+ return kmalloc_array(BITS_TO_LONGS(*bits), sizeof(unsigned long),
+ GFP_ATOMIC | __GFP_ZERO);
+}
+
+static ssize_t threaded_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct net_device *netdev = to_net_dev(dev);
+ struct napi_struct *n;
+ unsigned long *bmap;
+ size_t count = 0;
+ int i, bits;
+
+ if (!rtnl_trylock())
+ return restart_syscall();
+
+ if (!dev_isalive(netdev))
+ goto unlock;
+
+ bmap = __alloc_thread_bitmap(netdev, &bits);
+ if (!bmap) {
+ count = -ENOMEM;
+ goto unlock;
+ }
+
+ i = 0;
+ list_for_each_entry(n, &netdev->napi_list, dev_list) {
+ if (test_bit(NAPI_STATE_THREADED, &n->state))
+ set_bit(i, bmap);
+ i++;
+ }
+
+ count = bitmap_print_to_pagebuf(true, buf, bmap, bits);
+ kfree(bmap);
+
+unlock:
+ rtnl_unlock();
+
+ return count;
+}
+
+static ssize_t threaded_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t len)
+{
+ struct net_device *netdev = to_net_dev(dev);
+ struct napi_struct *n;
+ unsigned long *bmap;
+ int i, bits;
+ size_t ret;
+
+ if (!capable(CAP_NET_ADMIN))
+ return -EPERM;
+
+ if (!rtnl_trylock())
+ return restart_syscall();
+
+ if (!dev_isalive(netdev)) {
+ ret = len;
+ goto unlock;
+ }
+
+ if (netdev->flags & IFF_UP) {
+ ret = -EBUSY;
+ goto unlock;
+ }
+
+ bmap = __alloc_thread_bitmap(netdev, &bits);
+ if (!bmap) {
+ ret = -ENOMEM;
+ goto unlock;
+ }
+
+ ret = bitmap_parselist(buf, bmap, bits);
+ if (ret)
+ goto free_unlock;
+
+ i = 0;
+ list_for_each_entry(n, &netdev->napi_list, dev_list) {
+ napi_set_threaded(n, test_bit(i, bmap));
+ i++;
+ }
+ ret = len;
+
+free_unlock:
+ kfree(bmap);
+
+unlock:
+ rtnl_unlock();
+ return ret;
+}
+static DEVICE_ATTR_RW(threaded);
+
static struct attribute *net_class_attrs[] __ro_after_init = {
&dev_attr_netdev_group.attr,
&dev_attr_type.attr,
@@ -570,6 +671,7 @@ static struct attribute *net_class_attrs[] __ro_after_init = {
&dev_attr_proto_down.attr,
&dev_attr_carrier_up_count.attr,
&dev_attr_carrier_down_count.attr,
+ &dev_attr_threaded.attr,
NULL,
};
ATTRIBUTE_GROUPS(net_class);
--
2.28.0.618.gf4bc123cb7-goog
next prev parent reply other threads:[~2020-09-14 17:27 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-14 17:24 [RFC PATCH net-next 0/6] implement kthread based napi poll Wei Wang
2020-09-14 17:24 ` [RFC PATCH net-next 1/6] net: implement threaded-able napi poll loop support Wei Wang
2020-09-25 19:45 ` Hannes Frederic Sowa
2020-09-25 23:50 ` Wei Wang
2020-09-26 14:22 ` Hannes Frederic Sowa
2020-09-28 8:45 ` Paolo Abeni
2020-09-28 18:13 ` Wei Wang
2020-09-14 17:24 ` Wei Wang [this message]
2020-09-14 17:24 ` [RFC PATCH net-next 3/6] net: extract napi poll functionality to __napi_poll() Wei Wang
2020-09-14 17:24 ` [RFC PATCH net-next 4/6] net: modify kthread handler to use __napi_poll() Wei Wang
2020-09-14 17:24 ` [RFC PATCH net-next 5/6] net: process RPS/RFS work in kthread context Wei Wang
2020-09-18 22:44 ` Wei Wang
2020-09-21 8:11 ` Eric Dumazet
2020-09-14 17:24 ` [RFC PATCH net-next 6/6] net: improve napi threaded config Wei Wang
2020-09-25 13:48 ` [RFC PATCH net-next 0/6] implement kthread based napi poll Magnus Karlsson
2020-09-25 17:15 ` Wei Wang
2020-09-25 17:30 ` Eric Dumazet
2020-09-25 18:16 ` Stephen Hemminger
2020-09-25 18:23 ` Eric Dumazet
2020-09-25 19:00 ` Stephen Hemminger
2020-09-25 19:06 ` Jakub Kicinski
2020-09-28 14:07 ` Magnus Karlsson
2020-09-28 17:43 ` Eric Dumazet
2020-09-28 18:15 ` Wei Wang
2020-09-29 19:19 ` Jakub Kicinski
2020-09-29 20:16 ` Wei Wang
2020-09-29 21:48 ` Jakub Kicinski
2020-09-30 8:23 ` David Laight
2020-09-30 8:58 ` Paolo Abeni
2020-09-30 15:58 ` Jakub Kicinski
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=20200914172453.1833883-3-weiwan@google.com \
--to=weiwan@google.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hannes@stressinduktion.org \
--cc=kuba@kernel.org \
--cc=nbd@nbd.name \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--subject='Re: [RFC PATCH net-next 2/6] net: add sysfs attribute to control napi threaded mode' \
/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
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).