All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@nvidia.com>
To: Mark Zhang <markzhang@nvidia.com>
Cc: Leon Romanovsky <leon@kernel.org>,
	Doug Ledford <dledford@redhat.com>,
	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>,
	Mike Marciniszyn <mike.marciniszyn@cornelisnetworks.com>,
	Mustafa Ismail <mustafa.ismail@intel.com>,
	Naresh Kumar PBS <nareshkumar.pbs@broadcom.com>,
	Neta Ostrovsky <netao@nvidia.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 v1 05/11] RDMA/counter: Add optional counter support
Date: Tue, 28 Sep 2021 08:51:35 -0300	[thread overview]
Message-ID: <20210928115135.GG964074@nvidia.com> (raw)
In-Reply-To: <d9cd401a-b5fe-65ea-21c4-6d4c037fd641@nvidia.com>

On Tue, Sep 28, 2021 at 05:03:24PM +0800, Mark Zhang wrote:
> On 9/28/2021 1:03 AM, Jason Gunthorpe wrote:
> > On Wed, Sep 15, 2021 at 02:07:24AM +0300, Leon Romanovsky wrote:
> > > +int rdma_counter_modify(struct ib_device *dev, u32 port, int index, bool enable)
> > > +{
> > > +	struct rdma_hw_stats *stats;
> > > +	int ret;
> > > +
> > > +	if (!dev->ops.modify_hw_stat)
> > > +		return -EOPNOTSUPP;
> > > +
> > > +	stats = ib_get_hw_stats_port(dev, port);
> > > +	if (!stats)
> > > +		return -EINVAL;
> > > +
> > > +	mutex_lock(&stats->lock);
> > > +	ret = dev->ops.modify_hw_stat(dev, port, index, enable);
> > > +	if (!ret)
> > > +		enable ? clear_bit(index, stats->is_disabled) :
> > > +			set_bit(index, stats->is_disabled);
> > 
> > This is not a kernel coding style write out the if, use success
> > oriented flow
> > 
> > Also, shouldn't this logic protect the driver from being called on
> > non-optional counters?
> 
> We leave it to driver, driver would return failure if modify is not
> supported. Is it good?

I think the core code should do it

> > >   	for (i = 0; i < data->stats->num_counters; i++) {
> > > -		attr = &data->attrs[i];
> > > +		if (data->stats->descs[i].flags & IB_STAT_FLAG_OPTIONAL)
> > > +			continue;
> > > +		attr = &data->attrs[pos];
> > >   		sysfs_attr_init(&attr->attr.attr);
> > >   		attr->attr.attr.name = data->stats->descs[i].name;
> > >   		attr->attr.attr.mode = 0444;
> > >   		attr->attr.show = hw_stat_device_show;
> > >   		attr->show = show_hw_stats;
> > > -		data->group.attrs[i] = &attr->attr.attr;
> > > +		data->group.attrs[pos] = &attr->attr.attr;
> > > +		pos++;
> > >   	}
> > 
> > This isn't OK, the hw_stat_device_show() computes the stat index like
> > this:
> > 
> > 	return stat_attr->show(ibdev, ibdev->hw_stats_data->stats,
> > 			       stat_attr - ibdev->hw_stats_data->attrs, 0, buf);
> > 
> > Which assumes the stats are packed contiguously. This only works
> > because mlx5 is always putting the optional stats at the end.
> 
> Yes you are right, thanks. Maybe we can add an "index" field in struct
> hw_stats_device/port_attribute, then set it in setup and use it in show.

You could just add a WARN_ON check that optional stats are at the end
I suppose

Jason

  reply	other threads:[~2021-09-28 11:51 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 ` [PATCH rdma-next v1 04/11] RDMA/counter: Add an is_disabled field " Leon Romanovsky
2021-09-27 16:53   ` 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 [this message]
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=20210928115135.GG964074@nvidia.com \
    --to=jgg@nvidia.com \
    --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=kuba@kernel.org \
    --cc=leon@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=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.