[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20180410170812.18905-2-saeedm@mellanox.com>
Date: Tue, 10 Apr 2018 10:08:12 -0700
From: Saeed Mahameed <saeedm@...lanox.com>
To: netdev@...r.kernel.org
Cc: Saeed Mahameed <saeedm@...lanox.com>
Subject: [RFC net-next 2/2] net: net-sysfs: Reduce netstat_show read_lock critical section
Instead of holding the device chain read_lock also while calling
dev_get_stats just hold it only to check dev_isalive, if the dev is alive,
hold that dev via dev_hold then release the read_lock.
When done handling the device, dev_put it.
Signed-off-by: Saeed Mahameed <saeedm@...lanox.com>
---
net/core/net-sysfs.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index c476f0794132..ee6f9fed43df 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -563,13 +563,20 @@ static ssize_t netstat_show(const struct device *d,
offset % sizeof(u64) != 0);
read_lock(&dev_base_lock);
- if (dev_isalive(dev)) {
+ if (dev_isalive(dev))
+ dev_hold(dev);
+ else
+ dev = NULL;
+ read_unlock(&dev_base_lock);
+
+ if (dev) {
struct rtnl_link_stats64 temp;
const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
+ dev_put(dev);
ret = sprintf(buf, fmt_u64, *(u64 *)(((u8 *)stats) + offset));
}
- read_unlock(&dev_base_lock);
+
return ret;
}
--
2.14.3
Powered by blists - more mailing lists