LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
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>,
	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: Re: [PATCH rdma-next v3 05/13] RDMA/counter: Add an is_disabled field in struct rdma_hw_stats
Date: Wed, 6 Oct 2021 14:49:07 +0300	[thread overview]
Message-ID: <YV2NMzu0izn2vWrJ@unreal> (raw)
In-Reply-To: <09596ef74f4c213cb236e057e20e98264b67f16e.1633513239.git.leonro@nvidia.com>

On Wed, Oct 06, 2021 at 12:52:08PM +0300, Leon Romanovsky wrote:
> 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/nldev.c | 11 ++++++++++-
>  drivers/infiniband/core/verbs.c | 10 ++++++++++
>  include/rdma/ib_verbs.h         |  3 +++
>  3 files changed, 23 insertions(+), 1 deletion(-)
> 
> 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/verbs.c b/drivers/infiniband/core/verbs.c
> index c3319a7584a2..d957b23a0e23 100644
> --- a/drivers/infiniband/core/verbs.c
> +++ b/drivers/infiniband/core/verbs.c
> @@ -2994,11 +2994,20 @@ struct rdma_hw_stats *rdma_alloc_hw_stats_struct(
>  	if (!stats)
>  		return NULL;
>  
> +	stats->is_disabled = kcalloc(BITS_TO_LONGS(num_counters),
> +				     sizeof(*stats->is_disabled), 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;
>  }
>  EXPORT_SYMBOL(rdma_alloc_hw_stats_struct);
>  
> @@ -3008,6 +3017,7 @@ EXPORT_SYMBOL(rdma_alloc_hw_stats_struct);
>   */
>  void rdma_free_hw_stats_struct(struct rdma_hw_stats *stats)
>  {
> +	kfree(stats->is_disabled);
>  	kfree(stats);

Jason,

This hunk needs to be the following for the representors case. Can you
please fix it locally?

diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c
index d957b23a0e23..e9e042b31386 100644
--- a/drivers/infiniband/core/verbs.c
+++ b/drivers/infiniband/core/verbs.c
@@ -3017,6 +3017,9 @@ EXPORT_SYMBOL(rdma_alloc_hw_stats_struct);
  */
 void rdma_free_hw_stats_struct(struct rdma_hw_stats *stats)
 {
+       if (!stats)
+               return;
+
        kfree(stats->is_disabled);
        kfree(stats);
 }

Thanks

>  }
>  EXPORT_SYMBOL(rdma_free_hw_stats_struct);
> diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h
> index 938c0c0a1c19..ae467365706b 100644
> --- a/include/rdma/ib_verbs.h
> +++ b/include/rdma/ib_verbs.h
> @@ -565,6 +565,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)
> @@ -577,6 +579,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[];
>  };
> -- 
> 2.31.1
> 

  reply	other threads:[~2021-10-06 11:49 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1633513239.git.leonro@nvidia.com>
2021-10-06  9:52 ` [PATCH mlx5-next v3 01/13] net/mlx5: Add ifc bits to support optional counters Leon Romanovsky
2021-10-06  9:52 ` [PATCH mlx5-next v3 02/13] net/mlx5: Add priorities for counters in RDMA namespaces Leon Romanovsky
2021-10-06  9:52 ` [PATCH rdma-next v3 03/13] RDMA/counter: Add a descriptor in struct rdma_hw_stats Leon Romanovsky
2021-10-06  9:52 ` [PATCH rdma-next v3 04/13] RDMA/core: Add a helper API rdma_free_hw_stats_struct Leon Romanovsky
2021-10-06  9:52 ` [PATCH rdma-next v3 05/13] RDMA/counter: Add an is_disabled field in struct rdma_hw_stats Leon Romanovsky
2021-10-06 11:49   ` Leon Romanovsky [this message]
2021-10-06  9:52 ` [PATCH rdma-next v3 06/13] RDMA/counter: Add optional counter support Leon Romanovsky
2021-10-06  9:52 ` [PATCH rdma-next v3 07/13] RDMA/nldev: Add support to get status of all counters Leon Romanovsky
2021-10-06  9:52 ` [PATCH rdma-next v3 08/13] RDMA/nldev: Split nldev_stat_set_mode_doit out of nldev_stat_set_doit Leon Romanovsky
2021-10-06  9:52 ` [PATCH rdma-next v3 09/13] RDMA/nldev: Allow optional-counter status configuration through RDMA netlink Leon Romanovsky
2021-10-07 13:07   ` Jason Gunthorpe
2021-10-06  9:52 ` [PATCH rdma-next v3 10/13] RDMA/mlx5: Support optional counters in hw_stats initialization Leon Romanovsky
2021-10-06  9:52 ` [PATCH rdma-next v3 11/13] RDMA/mlx5: Add steering support in optional flow counters Leon Romanovsky
2021-10-06  9:52 ` [PATCH rdma-next v3 12/13] RDMA/mlx5: Add modify_op_stat() support Leon Romanovsky
2021-10-06  9:52 ` [PATCH rdma-next v3 13/13] 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=YV2NMzu0izn2vWrJ@unreal \
    --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=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 \
    --subject='Re: [PATCH rdma-next v3 05/13] RDMA/counter: Add an is_disabled field in struct rdma_hw_stats' \
    /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

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).