[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220407084050.184989-3-michaelgur@nvidia.com>
Date: Thu, 7 Apr 2022 11:40:50 +0300
From: Michael Guralnik <michaelgur@...dia.com>
To: <netdev@...r.kernel.org>
CC: <jiri@...dia.com>, <ariela@...dia.com>, <maorg@...dia.com>,
<saeedm@...dia.com>, <kuba@...nel.org>, <moshe@...dia.com>,
Michael Guralnik <michaelgur@...dia.com>
Subject: [RFC PATCH net-next 2/2] devlink: Add statistics to port get
Add a list of all registered stats and their value to the port get
command.
Signed-off-by: Michael Guralnik <michaelgur@...dia.com>
---
include/uapi/linux/devlink.h | 4 ++++
net/core/devlink.c | 39 ++++++++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+)
diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index b897b80770f6..8da01e551695 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -553,6 +553,10 @@ enum devlink_attr {
DEVLINK_ATTR_REGION_MAX_SNAPSHOTS, /* u32 */
+ DEVLINK_ATTR_STATS_ENTRY, /* nested */
+ DEVLINK_ATTR_STATS_NAME, /* string */
+ DEVLINK_ATTR_STATS_VALUE, /* u64 */
+
/* add new attributes above here, update the policy in devlink.c */
__DEVLINK_ATTR_MAX,
diff --git a/net/core/devlink.c b/net/core/devlink.c
index 9636d7998630..b735cca727a7 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -1080,6 +1080,41 @@ devlink_nl_port_function_attrs_put(struct sk_buff *msg, struct devlink_port *por
return err;
}
+static int devlink_port_stats_get(struct devlink_port *port)
+{
+ if (!port->stats.get)
+ return -EOPNOTSUPP;
+ return port->stats.get(port);
+}
+
+static int devlink_nl_port_stats_put(struct sk_buff *msg, struct devlink_port *port)
+{
+ struct nlattr *stats_attr, *stats_entry_attr;
+ struct devlink_port_stat_item *stats_item;
+ int err;
+
+ stats_attr = nla_nest_start(msg, DEVLINK_ATTR_STATS);
+ if (!stats_attr)
+ return -EMSGSIZE;
+
+ err = devlink_port_stats_get(port);
+ if (err)
+ return err;
+
+ list_for_each_entry(stats_item, &port->stats.stats_list, list) {
+ stats_entry_attr = nla_nest_start(msg, DEVLINK_ATTR_STATS_ENTRY);
+ if (!stats_entry_attr)
+ return -EMSGSIZE;
+
+ nla_put_string(msg, DEVLINK_ATTR_STATS_NAME, stats_item->stat->name);
+ nla_put_u32(msg, DEVLINK_ATTR_STATS_VALUE, stats_item->stat->val);
+
+ nla_nest_end(msg, stats_entry_attr);
+ }
+ nla_nest_end(msg, stats_attr);
+ return 0;
+}
+
static int devlink_nl_port_fill(struct sk_buff *msg,
struct devlink_port *devlink_port,
enum devlink_command cmd, u32 portid, u32 seq,
@@ -1132,6 +1167,8 @@ static int devlink_nl_port_fill(struct sk_buff *msg,
if (devlink_nl_port_function_attrs_put(msg, devlink_port, extack))
goto nla_put_failure;
+ if (devlink_nl_port_stats_put(msg, devlink_port))
+ goto nla_put_failure;
genlmsg_end(msg, hdr);
return 0;
@@ -8670,6 +8707,8 @@ static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX + 1] = {
[DEVLINK_ATTR_RATE_TX_MAX] = { .type = NLA_U64 },
[DEVLINK_ATTR_RATE_NODE_NAME] = { .type = NLA_NUL_STRING },
[DEVLINK_ATTR_RATE_PARENT_NODE_NAME] = { .type = NLA_NUL_STRING },
+ [DEVLINK_ATTR_STATS_NAME] = {.type = NLA_NUL_STRING },
+ [DEVLINK_ATTR_STATS_VALUE] = {.type = NLA_U64 },
};
static const struct genl_small_ops devlink_nl_ops[] = {
--
2.17.2
Powered by blists - more mailing lists