public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
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>,
	<dennis.dalessandro@cornelisnetworks.com>, <galpress@amazon.com>,
	<kuba@kernel.org>, <maorg@nvidia.com>,
	<mike.marciniszyn@cornelisnetworks.com>,
	<mustafa.ismail@intel.com>, <bharat@chelsio.com>,
	<selvin.xavier@broadcom.com>, <shiraz.saleem@intel.com>,
	<yishaih@nvidia.com>, <zyjzyj2000@gmail.com>,
	Mark Zhang <markzhang@nvidia.com>
Subject: [PATCH rdma-next v4 09/13] RDMA/nldev: Allow optional-counter status configuration through RDMA netlink
Date: Fri, 8 Oct 2021 15:24:35 +0300	[thread overview]
Message-ID: <20211008122439.166063-10-markzhang@nvidia.com> (raw)
In-Reply-To: <20211008122439.166063-1-markzhang@nvidia.com>

From: Aharon Landau <aharonl@nvidia.com>

Provide an option to allow users to enable/disable optional counters
through RDMA netlink. Limiting it to users with ADMIN capability only.

Examples:
1. Enable optional counters cc_rx_ce_pkts and cc_rx_cnp_pkts (and
   disable all others):
$ sudo rdma statistic set link rocep8s0f0/1 optional-counters \
    cc_rx_ce_pkts,cc_rx_cnp_pkts

2. Remove all optional counters:
$ sudo rdma statistic unset link rocep8s0f0/1 optional-counters

Signed-off-by: Aharon Landau <aharonl@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Mark Zhang <markzhang@nvidia.com>
---
 drivers/infiniband/core/nldev.c | 61 ++++++++++++++++++++++++++++++---
 1 file changed, 57 insertions(+), 4 deletions(-)

diff --git a/drivers/infiniband/core/nldev.c b/drivers/infiniband/core/nldev.c
index 8361eb08e13b..fedc0fa6ebf9 100644
--- a/drivers/infiniband/core/nldev.c
+++ b/drivers/infiniband/core/nldev.c
@@ -1945,6 +1945,50 @@ static int nldev_stat_set_mode_doit(struct sk_buff *msg,
 	return ret;
 }
 
+static int nldev_stat_set_counter_dynamic_doit(struct nlattr *tb[],
+					       struct ib_device *device,
+					       u32 port)
+{
+	struct rdma_hw_stats *stats;
+	int rem, i, index, ret = 0;
+	struct nlattr *entry_attr;
+	unsigned long *target;
+
+	stats = ib_get_hw_stats_port(device, port);
+	if (!stats)
+		return -EINVAL;
+
+	target = kcalloc(BITS_TO_LONGS(stats->num_counters),
+			 sizeof(*stats->is_disabled), GFP_KERNEL);
+	if (!target)
+		return -ENOMEM;
+
+	nla_for_each_nested(entry_attr, tb[RDMA_NLDEV_ATTR_STAT_HWCOUNTERS],
+			    rem) {
+		index = nla_get_u32(entry_attr);
+		if ((index >= stats->num_counters) ||
+		    !(stats->descs[index].flags & IB_STAT_FLAG_OPTIONAL)) {
+			ret = -EINVAL;
+			goto out;
+		}
+
+		set_bit(index, target);
+	}
+
+	for (i = 0; i < stats->num_counters; i++) {
+		if (!(stats->descs[i].flags & IB_STAT_FLAG_OPTIONAL))
+			continue;
+
+		ret = rdma_counter_modify(device, port, i, test_bit(i, target));
+		if (ret)
+			goto out;
+	}
+
+out:
+	kfree(target);
+	return ret;
+}
+
 static int nldev_stat_set_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
 			       struct netlink_ext_ack *extack)
 {
@@ -1971,7 +2015,8 @@ static int nldev_stat_set_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
 		goto err_put_device;
 	}
 
-	if (!tb[RDMA_NLDEV_ATTR_STAT_MODE]) {
+	if (!tb[RDMA_NLDEV_ATTR_STAT_MODE] &&
+	    !tb[RDMA_NLDEV_ATTR_STAT_HWCOUNTERS]) {
 		ret = -EINVAL;
 		goto err_put_device;
 	}
@@ -1991,9 +2036,17 @@ static int nldev_stat_set_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
 		goto err_free_msg;
 	}
 
-	ret = nldev_stat_set_mode_doit(msg, extack, tb, device, port);
-	if (ret)
-		goto err_free_msg;
+	if (tb[RDMA_NLDEV_ATTR_STAT_MODE]) {
+		ret = nldev_stat_set_mode_doit(msg, extack, tb, device, port);
+		if (ret)
+			goto err_free_msg;
+	}
+
+	if (tb[RDMA_NLDEV_ATTR_STAT_HWCOUNTERS]) {
+		ret = nldev_stat_set_counter_dynamic_doit(tb, device, port);
+		if (ret)
+			goto err_free_msg;
+	}
 
 	nlmsg_end(msg, nlh);
 	ib_device_put(device);
-- 
2.26.2


  parent reply	other threads:[~2021-10-08 12:26 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-08 12:24 [PATCH rdma-next v4 00/13] Optional counter statistics support Mark Zhang
2021-10-08 12:24 ` [PATCH rdma-next v4 01/13] net/mlx5: Add ifc bits to support optional counters Mark Zhang
2021-10-08 12:24 ` [PATCH rdma-next v4 02/13] net/mlx5: Add priorities for counters in RDMA namespaces Mark Zhang
2021-10-08 12:24 ` [PATCH rdma-next v4 03/13] RDMA/counter: Add a descriptor in struct rdma_hw_stats Mark Zhang
2021-10-08 12:24 ` [PATCH rdma-next v4 04/13] RDMA/core: Add a helper API rdma_free_hw_stats_struct Mark Zhang
2021-10-08 12:24 ` [PATCH rdma-next v4 05/13] RDMA/counter: Add an is_disabled field in struct rdma_hw_stats Mark Zhang
2021-10-08 12:24 ` [PATCH rdma-next v4 06/13] RDMA/counter: Add optional counter support Mark Zhang
2021-10-08 12:24 ` [PATCH rdma-next v4 07/13] RDMA/nldev: Add support to get status of all counters Mark Zhang
2021-10-08 12:24 ` [PATCH rdma-next v4 08/13] RDMA/nldev: Split nldev_stat_set_mode_doit out of nldev_stat_set_doit Mark Zhang
2021-10-08 12:24 ` Mark Zhang [this message]
2021-10-08 12:24 ` [PATCH rdma-next v4 10/13] RDMA/mlx5: Support optional counters in hw_stats initialization Mark Zhang
2021-10-08 12:24 ` [PATCH rdma-next v4 11/13] RDMA/mlx5: Add steering support in optional flow counters Mark Zhang
2021-10-08 12:24 ` [PATCH rdma-next v4 12/13] RDMA/mlx5: Add modify_op_stat() support Mark Zhang
2021-10-08 12:24 ` [PATCH rdma-next v4 13/13] RDMA/mlx5: Add optional counter support in get_hw_stats callback Mark Zhang
2021-10-08 18:57 ` [PATCH rdma-next v4 00/13] Optional counter statistics support Jason Gunthorpe
2021-10-09  9:04   ` Leon Romanovsky
2021-10-12 15:53     ` 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=20211008122439.166063-10-markzhang@nvidia.com \
    --to=markzhang@nvidia.com \
    --cc=aharonl@nvidia.com \
    --cc=bharat@chelsio.com \
    --cc=dennis.dalessandro@cornelisnetworks.com \
    --cc=dledford@redhat.com \
    --cc=galpress@amazon.com \
    --cc=jgg@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=leonro@nvidia.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=maorg@nvidia.com \
    --cc=mike.marciniszyn@cornelisnetworks.com \
    --cc=mustafa.ismail@intel.com \
    --cc=netao@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=saeedm@nvidia.com \
    --cc=selvin.xavier@broadcom.com \
    --cc=shiraz.saleem@intel.com \
    --cc=yishaih@nvidia.com \
    --cc=zyjzyj2000@gmail.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