From: Leon Romanovsky <leon@kernel.org>
To: Doug Ledford <dledford@redhat.com>, Jason Gunthorpe <jgg@nvidia.com>
Cc: Aharon Landau <aharonl@nvidia.com>,
"David S. Miller" <davem@davemloft.net>,
Dennis Dalessandro <dennis.dalessandro@cornelisnetworks.com>,
Gal Pressman <galpress@amazon.com>,
Jakub Kicinski <kuba@kernel.org>,
linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org,
Maor Gottlieb <maorg@nvidia.com>,
Mark Zhang <markzhang@nvidia.com>,
Mike Marciniszyn <mike.marciniszyn@cornelisnetworks.com>,
Mustafa Ismail <mustafa.ismail@intel.com>,
Naresh Kumar PBS <nareshkumar.pbs@broadcom.com>,
netdev@vger.kernel.org, Potnuri Bharat Teja <bharat@chelsio.com>,
Saeed Mahameed <saeedm@nvidia.com>,
Selvin Xavier <selvin.xavier@broadcom.com>,
Shiraz Saleem <shiraz.saleem@intel.com>,
Yishai Hadas <yishaih@nvidia.com>,
Zhu Yanjun <zyjzyj2000@gmail.com>
Subject: [PATCH rdma-next v1 04/11] RDMA/counter: Add an is_disabled field in struct rdma_hw_stats
Date: Wed, 15 Sep 2021 02:07:23 +0300 [thread overview]
Message-ID: <97ef07eab2b56b39f3c93e12364237d5aec2acb6.1631660727.git.leonro@nvidia.com> (raw)
In-Reply-To: <cover.1631660727.git.leonro@nvidia.com>
From: Aharon Landau <aharonl@nvidia.com>
Add a bitmap in rdma_hw_stat structure, with each bit indicates whether
the corresponding counter is currently disabled or not. By default
hwcounters are enabled.
Signed-off-by: Aharon Landau <aharonl@nvidia.com>
Reviewed-by: Mark Zhang <markzhang@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
drivers/infiniband/core/counters.c | 8 +++++++-
drivers/infiniband/core/nldev.c | 11 ++++++++++-
drivers/infiniband/core/sysfs.c | 7 ++++++-
include/rdma/ib_verbs.h | 12 ++++++++++++
4 files changed, 35 insertions(+), 3 deletions(-)
diff --git a/drivers/infiniband/core/counters.c b/drivers/infiniband/core/counters.c
index df9e6c5e4ddf..a9559e33a113 100644
--- a/drivers/infiniband/core/counters.c
+++ b/drivers/infiniband/core/counters.c
@@ -165,6 +165,7 @@ static struct rdma_counter *alloc_and_bind(struct ib_device *dev, u32 port,
return counter;
err_mode:
+ kfree(counter->stats->is_disabled);
kfree(counter->stats);
err_stats:
rdma_restrack_put(&counter->res);
@@ -186,6 +187,7 @@ static void rdma_counter_free(struct rdma_counter *counter)
mutex_unlock(&port_counter->lock);
rdma_restrack_del(&counter->res);
+ kfree(counter->stats->is_disabled);
kfree(counter->stats);
kfree(counter);
}
@@ -618,6 +620,7 @@ void rdma_counter_init(struct ib_device *dev)
fail:
for (i = port; i >= rdma_start_port(dev); i--) {
port_counter = &dev->port_data[port].port_counter;
+ kfree(port_counter->hstats->is_disabled);
kfree(port_counter->hstats);
port_counter->hstats = NULL;
mutex_destroy(&port_counter->lock);
@@ -631,7 +634,10 @@ void rdma_counter_release(struct ib_device *dev)
rdma_for_each_port(dev, port) {
port_counter = &dev->port_data[port].port_counter;
- kfree(port_counter->hstats);
+ if (port_counter->hstats) {
+ kfree(port_counter->hstats->is_disabled);
+ kfree(port_counter->hstats);
+ }
mutex_destroy(&port_counter->lock);
}
}
diff --git a/drivers/infiniband/core/nldev.c b/drivers/infiniband/core/nldev.c
index 3f6b98a87566..67519730b1ac 100644
--- a/drivers/infiniband/core/nldev.c
+++ b/drivers/infiniband/core/nldev.c
@@ -968,15 +968,21 @@ static int fill_stat_counter_hwcounters(struct sk_buff *msg,
if (!table_attr)
return -EMSGSIZE;
- for (i = 0; i < st->num_counters; i++)
+ mutex_lock(&st->lock);
+ for (i = 0; i < st->num_counters; i++) {
+ if (test_bit(i, st->is_disabled))
+ continue;
if (rdma_nl_stat_hwcounter_entry(msg, st->descs[i].name,
st->value[i]))
goto err;
+ }
+ mutex_unlock(&st->lock);
nla_nest_end(msg, table_attr);
return 0;
err:
+ mutex_unlock(&st->lock);
nla_nest_cancel(msg, table_attr);
return -EMSGSIZE;
}
@@ -2104,6 +2110,9 @@ static int stat_get_doit_default_counter(struct sk_buff *skb,
goto err_stats;
}
for (i = 0; i < num_cnts; i++) {
+ if (test_bit(i, stats->is_disabled))
+ continue;
+
v = stats->value[i] +
rdma_counter_get_hwstat_value(device, port, i);
if (rdma_nl_stat_hwcounter_entry(msg,
diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
index c3663cfdcd52..a26bf960f7ef 100644
--- a/drivers/infiniband/core/sysfs.c
+++ b/drivers/infiniband/core/sysfs.c
@@ -754,8 +754,10 @@ static void ib_port_release(struct kobject *kobj)
for (i = 0; i != ARRAY_SIZE(port->groups); i++)
kfree(port->groups[i].attrs);
- if (port->hw_stats_data)
+ if (port->hw_stats_data) {
+ kfree(port->hw_stats_data->stats->is_disabled);
kfree(port->hw_stats_data->stats);
+ }
kfree(port->hw_stats_data);
kfree(port);
}
@@ -919,6 +921,7 @@ alloc_hw_stats_device(struct ib_device *ibdev)
err_free_data:
kfree(data);
err_free_stats:
+ kfree(stats->is_disabled);
kfree(stats);
return ERR_PTR(-ENOMEM);
}
@@ -926,6 +929,7 @@ alloc_hw_stats_device(struct ib_device *ibdev)
void ib_device_release_hw_stats(struct hw_stats_device_data *data)
{
kfree(data->group.attrs);
+ kfree(data->stats->is_disabled);
kfree(data->stats);
kfree(data);
}
@@ -1018,6 +1022,7 @@ alloc_hw_stats_port(struct ib_port *port, struct attribute_group *group)
err_free_data:
kfree(data);
err_free_stats:
+ kfree(stats->is_disabled);
kfree(stats);
return ERR_PTR(-ENOMEM);
}
diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h
index 6e484678b1fd..f016bc0cd9de 100644
--- a/include/rdma/ib_verbs.h
+++ b/include/rdma/ib_verbs.h
@@ -566,6 +566,8 @@ struct rdma_stat_desc {
* their own value during their allocation routine.
* @descs - Array of pointers to static descriptors used for the counters
* in directory.
+ * @is_disabled - A bitmap to indicate each counter is currently disabled
+ * or not.
* @num_counters - How many hardware counters there are. If name is
* shorter than this number, a kernel oops will result. Driver authors
* are encouraged to leave BUILD_BUG_ON(ARRAY_SIZE(@name) < num_counters)
@@ -578,6 +580,7 @@ struct rdma_hw_stats {
unsigned long timestamp;
unsigned long lifespan;
const struct rdma_stat_desc *descs;
+ unsigned long *is_disabled;
int num_counters;
u64 value[];
};
@@ -601,11 +604,20 @@ static inline struct rdma_hw_stats *rdma_alloc_hw_stats_struct(
if (!stats)
return NULL;
+ stats->is_disabled = kcalloc(BITS_TO_LONGS(num_counters),
+ sizeof(long), GFP_KERNEL);
+ if (!stats->is_disabled)
+ goto err;
+
stats->descs = descs;
stats->num_counters = num_counters;
stats->lifespan = msecs_to_jiffies(lifespan);
return stats;
+
+err:
+ kfree(stats);
+ return NULL;
}
--
2.31.1
next prev parent reply other threads:[~2021-09-14 23:07 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-14 23:07 [PATCH rdma-next v1 00/11] Optional counter statistics support Leon Romanovsky
2021-09-14 23:07 ` [PATCH mlx5-next v1 01/11] net/mlx5: Add ifc bits to support optional counters Leon Romanovsky
2021-09-14 23:07 ` [PATCH mlx5-next v1 02/11] net/mlx5: Add priorities for counters in RDMA namespaces Leon Romanovsky
2021-09-14 23:07 ` [PATCH rdma-next v1 03/11] RDMA/counter: Add a descriptor in struct rdma_hw_stats Leon Romanovsky
2021-09-14 23:07 ` Leon Romanovsky [this message]
2021-09-27 16:53 ` [PATCH rdma-next v1 04/11] RDMA/counter: Add an is_disabled field " Jason Gunthorpe
2021-09-28 3:28 ` Mark Zhang
2021-09-28 11:51 ` Jason Gunthorpe
2021-09-14 23:07 ` [PATCH rdma-next v1 05/11] RDMA/counter: Add optional counter support Leon Romanovsky
2021-09-27 17:03 ` Jason Gunthorpe
2021-09-28 9:03 ` Mark Zhang
2021-09-28 11:51 ` Jason Gunthorpe
2021-09-29 12:14 ` Leon Romanovsky
2021-09-14 23:07 ` [PATCH rdma-next v1 06/11] RDMA/nldev: Add support to get status of all counters Leon Romanovsky
2021-09-27 17:30 ` Jason Gunthorpe
2021-09-28 9:12 ` Mark Zhang
2021-09-28 11:52 ` Jason Gunthorpe
2021-09-28 12:51 ` Mark Zhang
2021-09-29 12:26 ` Leon Romanovsky
2021-09-29 23:56 ` Jason Gunthorpe
2021-09-14 23:07 ` [PATCH rdma-next v1 07/11] RDMA/nldev: Allow optional-counter status configuration through RDMA netlink Leon Romanovsky
2021-09-27 17:20 ` Jason Gunthorpe
2021-09-29 12:27 ` Leon Romanovsky
2021-09-14 23:07 ` [PATCH rdma-next v1 08/11] RDMA/mlx5: Support optional counters in hw_stats initialization Leon Romanovsky
2021-09-14 23:07 ` [PATCH rdma-next v1 09/11] RDMA/mlx5: Add steering support in optional flow counters Leon Romanovsky
2021-09-14 23:07 ` [PATCH rdma-next v1 10/11] RDMA/mlx5: Add modify_op_stat() support Leon Romanovsky
2021-09-14 23:07 ` [PATCH rdma-next v1 11/11] RDMA/mlx5: Add optional counter support in get_hw_stats callback Leon Romanovsky
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=97ef07eab2b56b39f3c93e12364237d5aec2acb6.1631660727.git.leonro@nvidia.com \
--to=leon@kernel.org \
--cc=aharonl@nvidia.com \
--cc=bharat@chelsio.com \
--cc=davem@davemloft.net \
--cc=dennis.dalessandro@cornelisnetworks.com \
--cc=dledford@redhat.com \
--cc=galpress@amazon.com \
--cc=jgg@nvidia.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=maorg@nvidia.com \
--cc=markzhang@nvidia.com \
--cc=mike.marciniszyn@cornelisnetworks.com \
--cc=mustafa.ismail@intel.com \
--cc=nareshkumar.pbs@broadcom.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;
as well as URLs for NNTP newsgroup(s).