From: Mark Zhang <markzhang@nvidia.com>
To: <jgg@nvidia.com>, <dledford@redhat.com>, <saeedm@nvidia.com>
Cc: <linux-rdma@vger.kernel.org>, <netdev@vger.kernel.org>,
<aharonl@nvidia.com>, <netao@nvidia.com>, <leonro@nvidia.com>,
Mark Zhang <markzhang@nvidia.com>
Subject: [PATCH rdma-next 10/10] RDMA/nldev: Add support to get current enabled optional counters
Date: Wed, 18 Aug 2021 14:24:28 +0300 [thread overview]
Message-ID: <20210818112428.209111-11-markzhang@nvidia.com> (raw)
In-Reply-To: <20210818112428.209111-1-markzhang@nvidia.com>
From: Aharon Landau <aharonl@nvidia.com>
This patch adds the ability to show the added and supported optional
counters for each link through RDMA netlink.
Examples:
$ rdma statistic mode
link rocep8s0f0/1
Optional-set: cc_rx_ce_pkts
$ rdma statistic mode supported
link rocep8s0f0/1
Optional-set: cc_rx_ce_pkts cc_rx_cnp_pkts cc_tx_cnp_pkts
link rocep8s0f1/1
Optional-set: cc_rx_ce_pkts cc_rx_cnp_pkts cc_tx_cnp_pkts
Signed-off-by: Aharon Landau <aharonl@nvidia.com>
Signed-off-by: Neta Ostrovsky <netao@nvidia.com>
Signed-off-by: Mark Zhang <markzhang@nvidia.com>
---
drivers/infiniband/core/nldev.c | 91 +++++++++++++++++++++++++++++++-
include/uapi/rdma/rdma_netlink.h | 2 +
2 files changed, 91 insertions(+), 2 deletions(-)
diff --git a/drivers/infiniband/core/nldev.c b/drivers/infiniband/core/nldev.c
index b665651dfb1d..611e4fe6a244 100644
--- a/drivers/infiniband/core/nldev.c
+++ b/drivers/infiniband/core/nldev.c
@@ -159,6 +159,8 @@ static const struct nla_policy nldev_policy[RDMA_NLDEV_ATTR_MAX] = {
[RDMA_NLDEV_ATTR_STAT_OPCOUNTER_ENTRY_NAME] = { .type = NLA_NUL_STRING,
.len = RDMA_NLDEV_ATTR_OPCOUNTER_NAME_SIZE },
[RDMA_NLDEV_ATTR_STAT_OPCOUNTER_ENTRY_VALUE] = { .type = NLA_U64 },
+ [RDMA_NLDEV_ATTR_STAT_OP_MODE_LIST] = { .type = NLA_U8 },
+ [RDMA_NLDEV_ATTR_STAT_OP_MODE_LIST_SUPPORTED] = { .type = NLA_U8 },
};
static int put_driver_name_print_type(struct sk_buff *msg, const char *name,
@@ -946,7 +948,7 @@ int rdma_nl_stat_hwcounter_entry(struct sk_buff *msg, const char *name,
EXPORT_SYMBOL(rdma_nl_stat_hwcounter_entry);
static int rdma_nl_stat_opcounter_entry(struct sk_buff *msg, const char *name,
- u64 value)
+ u64 value, bool send_value)
{
struct nlattr *entry_attr;
@@ -960,6 +962,12 @@ static int rdma_nl_stat_opcounter_entry(struct sk_buff *msg, const char *name,
if (nla_put_u64_64bit(msg, RDMA_NLDEV_ATTR_STAT_OPCOUNTER_ENTRY_VALUE,
value, RDMA_NLDEV_ATTR_PAD))
goto err;
+ if (send_value) {
+ if (nla_put_u64_64bit(msg,
+ RDMA_NLDEV_ATTR_STAT_OPCOUNTER_ENTRY_VALUE,
+ value, RDMA_NLDEV_ATTR_PAD))
+ goto err;
+ }
nla_nest_end(msg, entry_attr);
return 0;
@@ -2148,6 +2156,79 @@ static int nldev_stat_del_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
return ret;
}
+static int stat_get_doit_list_opstats(struct sk_buff *skb,
+ struct nlmsghdr *nlh,
+ struct netlink_ext_ack *extack,
+ struct nlattr *tb[], u32 index,
+ struct ib_device *device, u32 port)
+{
+ struct rdma_op_stats *opstats;
+ struct nlattr *opstats_list;
+ bool list_supported = false;
+ struct sk_buff *msg;
+ int i, ret;
+
+ if (tb[RDMA_NLDEV_ATTR_STAT_OP_MODE_LIST_SUPPORTED])
+ list_supported = true;
+
+ opstats = device->port_data[port].port_counter.opstats;
+ if (!opstats)
+ return -EOPNOTSUPP;
+
+ msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
+ if (!msg) {
+ ret = -ENOMEM;
+ goto err;
+ }
+
+ nlh = nlmsg_put(msg, NETLINK_CB(skb).portid, nlh->nlmsg_seq,
+ RDMA_NL_GET_TYPE(RDMA_NL_NLDEV,
+ RDMA_NLDEV_CMD_STAT_GET),
+ 0, 0);
+
+ if (fill_nldev_handle(msg, device) ||
+ nla_put_u32(msg, RDMA_NLDEV_ATTR_PORT_INDEX, port)) {
+ ret = -EMSGSIZE;
+ goto err_msg;
+ }
+
+ opstats_list =
+ nla_nest_start(msg, RDMA_NLDEV_ATTR_STAT_OPCOUNTERS);
+
+ if (!opstats_list) {
+ ret = -EMSGSIZE;
+ goto err_msg;
+ }
+
+ mutex_lock(&opstats->lock);
+
+ for (i = 0; i < opstats->num_opcounters; i++) {
+ if (!opstats->opcounters[i].enabled && !list_supported)
+ continue;
+ ret = rdma_nl_stat_opcounter_entry(msg,
+ opstats->opcounters[i].name,
+ 0, false);
+ if (ret)
+ goto err_opstats_msg;
+ }
+ nla_nest_end(msg, opstats_list);
+
+ mutex_unlock(&opstats->lock);
+
+ nlmsg_end(msg, nlh);
+ ib_device_put(device);
+ return rdma_nl_unicast(sock_net(skb->sk), msg, NETLINK_CB(skb).portid);
+
+err_opstats_msg:
+ nla_nest_cancel(msg, opstats_list);
+ mutex_unlock(&opstats->lock);
+err_msg:
+ nlmsg_free(msg);
+err:
+ ib_device_put(device);
+ return ret;
+}
+
static int stat_get_optional_counter(struct sk_buff *msg,
struct ib_device *device, u32 port)
{
@@ -2172,7 +2253,8 @@ static int stat_get_optional_counter(struct sk_buff *msg,
continue;
ret = rdma_nl_stat_opcounter_entry(msg,
opstats->opcounters[i].name,
- opstats->opcounters[i].value);
+ opstats->opcounters[i].value,
+ true);
if (ret)
goto err;
}
@@ -2212,6 +2294,11 @@ static int stat_get_doit_default_counter(struct sk_buff *skb,
goto err;
}
+ if (tb[RDMA_NLDEV_ATTR_STAT_OP_MODE_LIST] ||
+ tb[RDMA_NLDEV_ATTR_STAT_OP_MODE_LIST_SUPPORTED])
+ return stat_get_doit_list_opstats(skb, nlh, extack, tb,
+ index, device, port);
+
if (!device->ops.alloc_hw_port_stats || !device->ops.get_hw_stats) {
ret = -EINVAL;
goto err;
diff --git a/include/uapi/rdma/rdma_netlink.h b/include/uapi/rdma/rdma_netlink.h
index 79e6ca87d2e0..57f39d8fe434 100644
--- a/include/uapi/rdma/rdma_netlink.h
+++ b/include/uapi/rdma/rdma_netlink.h
@@ -557,6 +557,8 @@ enum rdma_nldev_attr {
RDMA_NLDEV_ATTR_STAT_OPCOUNTER_ENTRY, /* nested table */
RDMA_NLDEV_ATTR_STAT_OPCOUNTER_ENTRY_NAME, /* string */
RDMA_NLDEV_ATTR_STAT_OPCOUNTER_ENTRY_VALUE, /* u64 */
+ RDMA_NLDEV_ATTR_STAT_OP_MODE_LIST, /* u8 */
+ RDMA_NLDEV_ATTR_STAT_OP_MODE_LIST_SUPPORTED, /* u8 */
/*
* Always the end
--
2.26.2
next prev parent reply other threads:[~2021-08-18 11:25 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-18 11:24 [PATCH rdma-next 00/10] Optional counter statistics support Mark Zhang
2021-08-18 11:24 ` [PATCH rdma-next 01/10] net/mlx5: Add support in bth_opcode as a match criteria Mark Zhang
2021-08-18 11:24 ` [PATCH rdma-next 02/10] net/mlx5: Add priorities for counters in RDMA namespaces Mark Zhang
2021-08-18 11:24 ` [PATCH rdma-next 03/10] RDMA/counters: Support to allocate per-port optional counter statistics Mark Zhang
2021-08-23 19:30 ` Jason Gunthorpe
2021-08-24 6:22 ` Mark Zhang
2021-08-24 13:14 ` Jason Gunthorpe
2021-08-18 11:24 ` [PATCH rdma-next 04/10] RDMA/mlx5: Add alloc_op_port_stats() support Mark Zhang
2021-08-23 19:19 ` Jason Gunthorpe
2021-08-18 11:24 ` [PATCH rdma-next 05/10] RDMA/mlx5: Add steering support in optional flow counters Mark Zhang
2021-08-18 11:24 ` [PATCH rdma-next 06/10] RDMA/nldev: Add support to add and remove optional counters Mark Zhang
2021-08-23 19:42 ` Jason Gunthorpe
2021-08-24 2:09 ` Mark Zhang
2021-08-18 11:24 ` [PATCH rdma-next 07/10] RDMA/mlx5: Add add_op_stat() and remove_op_stat() support Mark Zhang
2021-08-18 11:24 ` [PATCH rdma-next 08/10] RDMA/nldev: Add support to get optional counters statistics Mark Zhang
2021-08-18 11:24 ` [PATCH rdma-next 09/10] RDMA/mlx5: Add get_op_stats() support Mark Zhang
2021-08-18 11:24 ` Mark Zhang [this message]
2021-08-23 19:44 ` [PATCH rdma-next 10/10] RDMA/nldev: Add support to get current enabled optional counters Jason Gunthorpe
2021-08-24 2:13 ` Mark Zhang
2021-08-24 13:13 ` Jason Gunthorpe
2021-08-23 19:33 ` [PATCH rdma-next 00/10] Optional counter statistics support Jason Gunthorpe
2021-08-24 1:44 ` Mark Zhang
2021-08-24 13:11 ` Jason Gunthorpe
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=20210818112428.209111-11-markzhang@nvidia.com \
--to=markzhang@nvidia.com \
--cc=aharonl@nvidia.com \
--cc=dledford@redhat.com \
--cc=jgg@nvidia.com \
--cc=leonro@nvidia.com \
--cc=linux-rdma@vger.kernel.org \
--cc=netao@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=saeedm@nvidia.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).