From: Patrisious Haddad <phaddad@nvidia.com>
To: <leon@kernel.org>, <dsahern@gmail.com>, <stephen@networkplumber.org>
Cc: Patrisious Haddad <phaddad@nvidia.com>, <netdev@vger.kernel.org>,
<jgg@nvidia.com>, <linux-rdma@vger.kernel.org>,
Mark Bloch <mbloch@nvidia.com>
Subject: [PATCH iproute2-next 2/2] rdma: Add optional-counter option to rdma stat bind commands
Date: Wed, 19 Mar 2025 10:25:26 +0200 [thread overview]
Message-ID: <20250319082529.287168-3-phaddad@nvidia.com> (raw)
In-Reply-To: <20250319082529.287168-1-phaddad@nvidia.com>
Add a new optional filter named optional-counter to commands:
rdma stat qp set link [link_name] auto
The new filter value can be either on or off and it must be the last
provided filter in the command, not providing it would be the same as off.
It indicates that when binding counters to a QP we also want the
currently enabled optional-counters on the link to be bound as well.
In addition Adjust rdma statistic man page to reflect the new
optional-counter changes.
Signed-off-by: Patrisious Haddad <phaddad@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
---
man/man8/rdma-statistic.8 | 6 +++++
rdma/stat.c | 50 +++++++++++++++++++++++++++++++++++++--
rdma/utils.c | 1 +
3 files changed, 55 insertions(+), 2 deletions(-)
diff --git a/man/man8/rdma-statistic.8 b/man/man8/rdma-statistic.8
index 7dd2b02c..337e31ef 100644
--- a/man/man8/rdma-statistic.8
+++ b/man/man8/rdma-statistic.8
@@ -39,6 +39,7 @@ rdma-statistic \- RDMA statistic counter configuration
.B auto
.RI "{ " CRITERIA " | "
.BR off " }"
+.B [ optional-counters | on/off ]
.ti -8
.B rdma statistic
@@ -180,6 +181,11 @@ rdma statistic qp set link mlx5_2/1 auto type on
On device mlx5_2 port 1, for each new user QP bind it with a counter automatically. Per counter for QPs with same qp type.
.RE
.PP
+rdma statistic qp set link mlx5_2/1 auto type on optional-counters on
+.RS 4
+On device mlx5_2 port 1, for each new user QP bind it with a counter automatically. Per counter for QPs with same qp type. Whilst also binding the currently enabled optional-counters.
+.RE
+.PP
rdma statistic qp set link mlx5_2/1 auto pid on
.RS 4
On device mlx5_2 port 1, for each new user QP bind it with a counter automatically. Per counter for QPs with same pid.
diff --git a/rdma/stat.c b/rdma/stat.c
index bf78f7cc..2c1bf68e 100644
--- a/rdma/stat.c
+++ b/rdma/stat.c
@@ -7,6 +7,7 @@
#include "rdma.h"
#include "res.h"
#include "stat.h"
+#include "utils.h"
#include <inttypes.h>
static int stat_help(struct rd *rd)
@@ -62,7 +63,8 @@ static struct counter_param auto_params[] = {
{ NULL },
};
-static int prepare_auto_mode_str(uint32_t mask, char *output, int len)
+static int prepare_auto_mode_str(uint32_t mask, bool opcnt, char *output,
+ int len)
{
char s[] = "qp auto";
int i, outlen = strlen(s);
@@ -90,6 +92,10 @@ static int prepare_auto_mode_str(uint32_t mask, char *output, int len)
if (outlen + strlen(" on") >= len)
return -EINVAL;
strcat(output, " on");
+
+ strcat(output, " optional-counters ");
+ strcat(output, (opcnt) ? "on" : "off");
+
} else {
if (outlen + strlen(" off") >= len)
return -EINVAL;
@@ -104,6 +110,7 @@ static int qp_link_get_mode_parse_cb(const struct nlmsghdr *nlh, void *data)
struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
uint32_t mode = 0, mask = 0;
char output[128] = {};
+ bool opcnt = false;
uint32_t idx, port;
const char *name;
@@ -126,7 +133,10 @@ static int qp_link_get_mode_parse_cb(const struct nlmsghdr *nlh, void *data)
if (!tb[RDMA_NLDEV_ATTR_STAT_AUTO_MODE_MASK])
return MNL_CB_ERROR;
mask = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_STAT_AUTO_MODE_MASK]);
- prepare_auto_mode_str(mask, output, sizeof(output));
+ if (tb[RDMA_NLDEV_ATTR_STAT_OPCOUNTER_ENABLED])
+ opcnt = mnl_attr_get_u8(
+ tb[RDMA_NLDEV_ATTR_STAT_OPCOUNTER_ENABLED]);
+ prepare_auto_mode_str(mask, opcnt, output, sizeof(output));
} else {
snprintf(output, sizeof(output), "qp auto off");
}
@@ -351,6 +361,7 @@ static const struct filters stat_valid_filters[MAX_NUMBER_OF_FILTERS] = {
{ .name = "lqpn", .is_number = true },
{ .name = "pid", .is_number = true },
{ .name = "qp-type", .is_number = false },
+ { .name = "optional-counters", .is_number = false },
};
static int stat_qp_show_one_link(struct rd *rd)
@@ -395,9 +406,37 @@ static int stat_qp_show(struct rd *rd)
return rd_exec_cmd(rd, cmds, "parameter");
}
+static bool stat_get_on_off(struct rd *rd, const char *arg, int *ret)
+{
+ bool value = false;
+
+ if (strcmpx(rd_argv(rd), arg) != 0) {
+ *ret = -EINVAL;
+ return false;
+ }
+
+ rd_arg_inc(rd);
+
+ if (rd_is_multiarg(rd)) {
+ pr_err("The parameter %s shouldn't include range\n", arg);
+ *ret = EINVAL;
+ return false;
+ }
+
+ value = parse_on_off(arg, rd_argv(rd), ret);
+ if (*ret)
+ return false;
+
+ rd_arg_inc(rd);
+
+ return value;
+}
+
static int stat_qp_set_link_auto_sendmsg(struct rd *rd, uint32_t mask)
{
uint32_t seq;
+ bool opcnt;
+ int ret;
rd_prepare_msg(rd, RDMA_NLDEV_CMD_STAT_SET,
&seq, (NLM_F_REQUEST | NLM_F_ACK));
@@ -408,6 +447,13 @@ static int stat_qp_set_link_auto_sendmsg(struct rd *rd, uint32_t mask)
mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_STAT_MODE,
RDMA_COUNTER_MODE_AUTO);
mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_STAT_AUTO_MODE_MASK, mask);
+ if (rd_argc(rd)) {
+ opcnt = stat_get_on_off(rd, "optional-counters", &ret);
+ if (ret)
+ return ret;
+ mnl_attr_put_u8(rd->nlh, RDMA_NLDEV_ATTR_STAT_OPCOUNTER_ENABLED,
+ opcnt);
+ }
return rd_sendrecv_msg(rd, seq);
}
diff --git a/rdma/utils.c b/rdma/utils.c
index 07cb0224..87003b2c 100644
--- a/rdma/utils.c
+++ b/rdma/utils.c
@@ -479,6 +479,7 @@ static const enum mnl_attr_data_type nldev_policy[RDMA_NLDEV_ATTR_MAX] = {
[RDMA_NLDEV_ATTR_PARENT_NAME] = MNL_TYPE_STRING,
[RDMA_NLDEV_ATTR_EVENT_TYPE] = MNL_TYPE_U8,
[RDMA_NLDEV_SYS_ATTR_MONITOR_MODE] = MNL_TYPE_U8,
+ [RDMA_NLDEV_ATTR_STAT_OPCOUNTER_ENABLED] = MNL_TYPE_U8,
};
static int rd_attr_check(const struct nlattr *attr, int *typep)
--
2.47.0
next prev parent reply other threads:[~2025-03-19 8:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-19 8:25 [PATCH iproute2-next 0/2] Add optional-counters binding support Patrisious Haddad
2025-03-19 8:25 ` [PATCH iproute2-next 1/2] rdma: update uapi headers Patrisious Haddad
2025-03-19 8:25 ` Patrisious Haddad [this message]
2025-03-24 2:50 ` [PATCH iproute2-next 0/2] Add optional-counters binding support patchwork-bot+netdevbpf
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=20250319082529.287168-3-phaddad@nvidia.com \
--to=phaddad@nvidia.com \
--cc=dsahern@gmail.com \
--cc=jgg@nvidia.com \
--cc=leon@kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=mbloch@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
/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