From: Jiri Pirko <jiri@resnulli.us>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, nogahf@mellanox.com, idosch@mellanox.com,
eladr@mellanox.com, yotamg@mellanox.com, ogerlitz@mellanox.com,
roopa@cumulusnetworks.com, nikolay@cumulusnetworks.com,
linville@tuxdriver.com, tgraf@suug.ch, gospo@cumulusnetworks.com,
sfeldma@gmail.com, sd@queasysnail.net, eranbe@mellanox.com,
ast@plumgrid.com, edumazet@google.com,
hannes@stressinduktion.org, f.fainelli@gmail.com
Subject: [patch net-next v4 3/4] net: core: add SW stats to if_stats_msg
Date: Thu, 16 Jun 2016 10:37:16 +0200 [thread overview]
Message-ID: <1466066237-7719-4-git-send-email-jiri@resnulli.us> (raw)
In-Reply-To: <1466066237-7719-1-git-send-email-jiri@resnulli.us>
From: Nogah Frankel <nogahf@mellanox.com>
If there is a dedicated ndo to return SW stats - use
it. Otherwise (indicates that there is no HW stats) use
the default stats ndo.
Return results under IFLA_STATS_LINK_SW_64.
Signed-off-by: Nogah Frankel <nogahf@mellanox.com>
Reviewed-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
---
include/uapi/linux/if_link.h | 1 +
net/core/rtnetlink.c | 41 +++++++++++++++++++++++++++++++++++------
2 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
index 98175e7..fcfb944 100644
--- a/include/uapi/linux/if_link.h
+++ b/include/uapi/linux/if_link.h
@@ -823,6 +823,7 @@ enum {
IFLA_STATS_UNSPEC, /* also used as 64bit pad attribute */
IFLA_STATS_LINK_64,
IFLA_STATS_LINK_XSTATS,
+ IFLA_STATS_LINK_SW_64,
__IFLA_STATS_MAX,
};
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 7958cde..d2acf9d 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -1068,6 +1068,11 @@ static int rtnl_phys_switch_id_fill(struct sk_buff *skb, struct net_device *dev)
return 0;
}
+static void copy_rtnl_link_stats64(void *v, const struct rtnl_link_stats64 *b)
+{
+ memcpy(v, b, sizeof(*b));
+}
+
static noinline_for_stack int rtnl_fill_stats(struct sk_buff *skb,
struct net_device *dev)
{
@@ -3490,10 +3495,13 @@ static int rtnl_fill_statsinfo(struct sk_buff *skb, struct net_device *dev,
unsigned int flags, unsigned int filter_mask,
int *idxattr, int *prividx)
{
+ struct rtnl_link_stats64 *stats64_sp = NULL;
+ struct rtnl_link_stats64 *sp;
struct if_stats_msg *ifsm;
struct nlmsghdr *nlh;
struct nlattr *attr;
int s_prividx = *prividx;
+ int err;
ASSERT_RTNL();
@@ -3506,24 +3514,20 @@ static int rtnl_fill_statsinfo(struct sk_buff *skb, struct net_device *dev,
ifsm->filter_mask = filter_mask;
if (stats_attr_valid(filter_mask, IFLA_STATS_LINK_64, *idxattr)) {
- struct rtnl_link_stats64 *sp;
-
attr = nla_reserve_64bit(skb, IFLA_STATS_LINK_64,
sizeof(struct rtnl_link_stats64),
IFLA_STATS_UNSPEC);
if (!attr)
goto nla_put_failure;
- sp = nla_data(attr);
- dev_get_stats(dev, sp);
+ stats64_sp = nla_data(attr);
+ dev_get_stats(dev, stats64_sp);
}
if (stats_attr_valid(filter_mask, IFLA_STATS_LINK_XSTATS, *idxattr)) {
const struct rtnl_link_ops *ops = dev->rtnl_link_ops;
if (ops && ops->fill_linkxstats) {
- int err;
-
*idxattr = IFLA_STATS_LINK_XSTATS;
attr = nla_nest_start(skb,
IFLA_STATS_LINK_XSTATS);
@@ -3538,6 +3542,28 @@ static int rtnl_fill_statsinfo(struct sk_buff *skb, struct net_device *dev,
}
}
+ if (stats_attr_valid(filter_mask, IFLA_STATS_LINK_SW_64, *idxattr)) {
+ attr = nla_reserve_64bit(skb, IFLA_STATS_LINK_SW_64,
+ sizeof(struct rtnl_link_stats64),
+ IFLA_STATS_UNSPEC);
+ if (!attr)
+ goto nla_put_failure;
+
+ sp = nla_data(attr);
+
+ if (dev_have_sw_stats(dev)) {
+ dev_get_sw_stats(dev, sp);
+ } else {
+ /* if SW stats are not available we return default
+ * stats. We query only if we don't already have them.
+ */
+ if (stats64_sp)
+ copy_rtnl_link_stats64(sp, stats64_sp);
+ else
+ dev_get_stats(dev, sp);
+ }
+ }
+
nlmsg_end(skb, nlh);
return 0;
@@ -3554,6 +3580,7 @@ nla_put_failure:
static const struct nla_policy ifla_stats_policy[IFLA_STATS_MAX + 1] = {
[IFLA_STATS_LINK_64] = { .len = sizeof(struct rtnl_link_stats64) },
+ [IFLA_STATS_LINK_SW_64] = { .len = sizeof(struct rtnl_link_stats64) },
};
static size_t if_nlmsg_stats_size(const struct net_device *dev,
@@ -3563,6 +3590,8 @@ static size_t if_nlmsg_stats_size(const struct net_device *dev,
if (stats_attr_valid(filter_mask, IFLA_STATS_LINK_64, 0))
size += nla_total_size_64bit(sizeof(struct rtnl_link_stats64));
+ if (stats_attr_valid(filter_mask, IFLA_STATS_LINK_SW_64, 0))
+ size += nla_total_size_64bit(sizeof(struct rtnl_link_stats64));
if (stats_attr_valid(filter_mask, IFLA_STATS_LINK_XSTATS, 0)) {
const struct rtnl_link_ops *ops = dev->rtnl_link_ops;
--
2.5.5
next prev parent reply other threads:[~2016-06-16 8:37 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-16 8:37 [patch net-next v4 0/4] return offloaded stats as default and expose original sw stats Jiri Pirko
2016-06-16 8:37 ` [patch net-next v4 1/4] netdevice: add SW statistics ndo Jiri Pirko
2016-06-16 8:37 ` [patch net-next v4 2/4] rtnetlink: add HW/SW stats distinction in rtnl_fill_stats Jiri Pirko
2016-06-16 8:37 ` Jiri Pirko [this message]
2016-06-17 0:20 ` [patch net-next v4 3/4] net: core: add SW stats to if_stats_msg David Miller
2016-06-17 7:32 ` Jiri Pirko
2016-06-16 8:37 ` [patch net-next v4 4/4] mlxsw: spectrum: Implement SW stats ndo and expose HW stats by default Jiri Pirko
2016-06-17 0:26 ` [patch net-next v4 0/4] return offloaded stats as default and expose original sw stats David Miller
2016-06-17 8:24 ` Jiri Pirko
2016-06-17 13:48 ` David Ahern
2016-06-17 14:05 ` Jiri Pirko
2016-06-17 14:54 ` Jamal Hadi Salim
2016-06-17 14:57 ` Jiri Pirko
2016-06-17 15:35 ` David Ahern
2016-06-17 15:42 ` Jiri Pirko
2016-06-17 17:12 ` Florian Fainelli
2016-06-18 8:00 ` Jiri Pirko
2016-06-18 13:58 ` Jamal Hadi Salim
2016-06-19 10:57 ` Jiri Pirko
2016-06-20 3:14 ` Roopa Prabhu
2016-06-20 12:28 ` Jamal Hadi Salim
2016-06-20 13:09 ` Jiri Pirko
2016-06-22 14:30 ` Roopa Prabhu
2016-06-20 3:06 ` Roopa Prabhu
2016-06-20 2:57 ` Roopa Prabhu
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=1466066237-7719-4-git-send-email-jiri@resnulli.us \
--to=jiri@resnulli.us \
--cc=ast@plumgrid.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=eladr@mellanox.com \
--cc=eranbe@mellanox.com \
--cc=f.fainelli@gmail.com \
--cc=gospo@cumulusnetworks.com \
--cc=hannes@stressinduktion.org \
--cc=idosch@mellanox.com \
--cc=linville@tuxdriver.com \
--cc=netdev@vger.kernel.org \
--cc=nikolay@cumulusnetworks.com \
--cc=nogahf@mellanox.com \
--cc=ogerlitz@mellanox.com \
--cc=roopa@cumulusnetworks.com \
--cc=sd@queasysnail.net \
--cc=sfeldma@gmail.com \
--cc=tgraf@suug.ch \
--cc=yotamg@mellanox.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).