From: Jason Gunthorpe <jgg@ziepe.ca>
To: Leon Romanovsky <leon@kernel.org>
Cc: Doug Ledford <dledford@redhat.com>,
Leon Romanovsky <leonro@mellanox.com>,
RDMA mailing list <linux-rdma@vger.kernel.org>,
Majd Dibbiny <majd@mellanox.com>, Mark Zhang <markz@mellanox.com>,
Saeed Mahameed <saeedm@mellanox.com>,
linux-netdev <netdev@vger.kernel.org>
Subject: Re: [PATCH rdma-next v5 06/17] RDMA/counter: Add "auto" configuration mode support
Date: Thu, 4 Jul 2019 15:09:23 -0300 [thread overview]
Message-ID: <20190704180923.GA2700@ziepe.ca> (raw)
In-Reply-To: <20190702100246.17382-7-leon@kernel.org>
On Tue, Jul 02, 2019 at 01:02:35PM +0300, Leon Romanovsky wrote:
> From: Mark Zhang <markz@mellanox.com>
>
> In auto mode all QPs belong to one category are bind automatically to
> a single counter set. Currently only "qp type" is supported.
>
> In this mode the qp counter is set in RST2INIT modification, and when
> a qp is destroyed the counter is unbound.
>
> Signed-off-by: Mark Zhang <markz@mellanox.com>
> Reviewed-by: Majd Dibbiny <majd@mellanox.com>
> Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
> drivers/infiniband/core/counters.c | 221 +++++++++++++++++++++++++++++
> drivers/infiniband/core/device.c | 3 +
> drivers/infiniband/core/verbs.c | 9 ++
> include/rdma/ib_verbs.h | 18 +++
> include/rdma/rdma_counter.h | 8 ++
> 5 files changed, 259 insertions(+)
>
> diff --git a/drivers/infiniband/core/counters.c b/drivers/infiniband/core/counters.c
> index 6167914fba06..60639452669c 100644
> +++ b/drivers/infiniband/core/counters.c
> @@ -54,6 +54,227 @@ int rdma_counter_set_auto_mode(struct ib_device *dev, u8 port,
> return ret;
> }
>
> +static struct rdma_counter *rdma_counter_alloc(struct ib_device *dev, u8 port,
> + enum rdma_nl_counter_mode mode)
> +{
> + struct rdma_counter *counter;
> +
> + if (!dev->ops.counter_dealloc)
> + return NULL;
> +
> + counter = kzalloc(sizeof(*counter), GFP_KERNEL);
> + if (!counter)
> + return NULL;
> +
> + counter->device = dev;
> + counter->port = port;
> + counter->res.type = RDMA_RESTRACK_COUNTER;
> + counter->mode.mode = mode;
> + kref_init(&counter->kref);
> + mutex_init(&counter->lock);
> +
> + return counter;
> +}
> +
> +static void rdma_counter_free(struct rdma_counter *counter)
> +{
> + rdma_restrack_del(&counter->res);
> + kfree(counter);
> +}
> +
> +static void auto_mode_init_counter(struct rdma_counter *counter,
> + const struct ib_qp *qp,
> + enum rdma_nl_counter_mask new_mask)
> +{
> + struct auto_mode_param *param = &counter->mode.param;
> +
> + counter->mode.mode = RDMA_COUNTER_MODE_AUTO;
> + counter->mode.mask = new_mask;
> +
> + if (new_mask & RDMA_COUNTER_MASK_QP_TYPE)
> + param->qp_type = qp->qp_type;
> +}
> +
> +static bool auto_mode_match(struct ib_qp *qp, struct rdma_counter *counter,
> + enum rdma_nl_counter_mask auto_mask)
> +{
> + struct auto_mode_param *param = &counter->mode.param;
> + bool match = true;
> +
> + if (rdma_is_kernel_res(&counter->res) != rdma_is_kernel_res(&qp->res))
> + return false;
> +
> + /* Ensure that counter belong to right PID */
> + if (!rdma_is_kernel_res(&counter->res) &&
> + !rdma_is_kernel_res(&qp->res) &&
> + (task_pid_vnr(counter->res.task) != current->pid))
> + return false;
> +
> + if (auto_mask & RDMA_COUNTER_MASK_QP_TYPE)
> + match &= (param->qp_type == qp->qp_type);
> +
> + return match;
> +}
> +
> +static int __rdma_counter_bind_qp(struct rdma_counter *counter,
> + struct ib_qp *qp)
> +{
> + int ret;
> +
> + if (qp->counter)
> + return -EINVAL;
> +
> + if (!qp->device->ops.counter_bind_qp)
> + return -EOPNOTSUPP;
> +
> + mutex_lock(&counter->lock);
> + ret = qp->device->ops.counter_bind_qp(counter, qp);
> + mutex_unlock(&counter->lock);
> +
> + return ret;
> +}
> +
> +static int __rdma_counter_unbind_qp(struct ib_qp *qp)
> +{
> + struct rdma_counter *counter = qp->counter;
> + int ret;
> +
> + if (!qp->device->ops.counter_unbind_qp)
> + return -EOPNOTSUPP;
> +
> + mutex_lock(&counter->lock);
> + ret = qp->device->ops.counter_unbind_qp(qp);
> + mutex_unlock(&counter->lock);
> +
> + return ret;
> +}
> +
> +/**
> + * rdma_get_counter_auto_mode - Find the counter that @qp should be bound
> + * with in auto mode
> + *
> + * Return: The counter (with ref-count increased) if found
> + */
> +static struct rdma_counter *rdma_get_counter_auto_mode(struct ib_qp *qp,
> + u8 port)
> +{
> + struct rdma_port_counter *port_counter;
> + struct rdma_counter *counter = NULL;
> + struct ib_device *dev = qp->device;
> + struct rdma_restrack_entry *res;
> + struct rdma_restrack_root *rt;
> + unsigned long id = 0;
> +
> + port_counter = &dev->port_data[port].port_counter;
> + rt = &dev->res[RDMA_RESTRACK_COUNTER];
> + xa_lock(&rt->xa);
> + xa_for_each(&rt->xa, id, res) {
> + if (!rdma_is_visible_in_pid_ns(res))
> + continue;
> +
> + counter = container_of(res, struct rdma_counter, res);
> + if ((counter->device != qp->device) || (counter->port != port))
> + goto next;
> +
> + if (auto_mode_match(qp, counter, port_counter->mode.mask))
> + break;
> +next:
> + counter = NULL;
> + }
> +
> + if (counter)
> + kref_get(&counter->kref);
This still needs to be kref_get_unless_zero:
if (counter && !kref_get_unless_zero(&counter->kref))
counter = NULL;
Jason
next prev parent reply other threads:[~2019-07-04 18:09 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-02 10:02 [PATCH rdma-next v5 00/17] Statistics counter support Leon Romanovsky
2019-07-02 10:02 ` [PATCH mlx5-next v5 01/17] net/mlx5: Add rts2rts_qp_counters_set_id field in hca cap Leon Romanovsky
2019-07-02 10:02 ` [PATCH rdma-next v5 02/17] RDMA/restrack: Introduce statistic counter Leon Romanovsky
2019-07-02 10:02 ` [PATCH rdma-next v5 03/17] RDMA/restrack: Add an API to attach a task to a resource Leon Romanovsky
2019-07-02 10:02 ` [PATCH rdma-next v5 04/17] RDMA/restrack: Make is_visible_in_pid_ns() as an API Leon Romanovsky
2019-07-02 10:02 ` [PATCH rdma-next v5 05/17] RDMA/counter: Add set/clear per-port auto mode support Leon Romanovsky
2019-07-02 10:02 ` [PATCH rdma-next v5 06/17] RDMA/counter: Add "auto" configuration " Leon Romanovsky
2019-07-04 18:09 ` Jason Gunthorpe [this message]
2019-07-02 10:02 ` [PATCH mlx5-next v5 07/17] IB/mlx5: Support set qp counter Leon Romanovsky
2019-07-02 10:02 ` [PATCH rdma-next v5 08/17] IB/mlx5: Add counter set id as a parameter for mlx5_ib_query_q_counters() Leon Romanovsky
2019-07-02 10:02 ` [PATCH rdma-next v5 09/17] IB/mlx5: Support statistic q counter configuration Leon Romanovsky
2019-07-02 10:02 ` [PATCH rdma-next v5 10/17] RDMA/nldev: Allow counter auto mode configration through RDMA netlink Leon Romanovsky
2019-07-02 10:02 ` [PATCH rdma-next v5 11/17] RDMA/netlink: Implement counter dumpit calback Leon Romanovsky
2019-07-04 18:07 ` Jason Gunthorpe
2019-07-04 18:22 ` Leon Romanovsky
2019-07-02 10:02 ` [PATCH rdma-next v5 12/17] IB/mlx5: Add counter_alloc_stats() and counter_update_stats() support Leon Romanovsky
2019-07-02 10:02 ` [PATCH rdma-next v5 13/17] RDMA/core: Get sum value of all counters when perform a sysfs stat read Leon Romanovsky
2019-07-02 10:02 ` [PATCH rdma-next v5 14/17] RDMA/counter: Allow manual mode configuration support Leon Romanovsky
2019-07-02 10:02 ` [PATCH rdma-next v5 15/17] RDMA/nldev: Allow counter manual mode configration through RDMA netlink Leon Romanovsky
2019-07-02 10:02 ` [PATCH rdma-next v5 16/17] RDMA/nldev: Allow get counter mode " Leon Romanovsky
2019-07-02 10:02 ` [PATCH rdma-next v5 17/17] RDMA/nldev: Allow get default counter statistics " Leon Romanovsky
2019-07-04 18:25 ` [PATCH rdma-next v5 00/17] Statistics counter support Jason Gunthorpe
2019-07-04 18:39 ` Leon Romanovsky
2019-07-05 15:50 ` 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=20190704180923.GA2700@ziepe.ca \
--to=jgg@ziepe.ca \
--cc=dledford@redhat.com \
--cc=leon@kernel.org \
--cc=leonro@mellanox.com \
--cc=linux-rdma@vger.kernel.org \
--cc=majd@mellanox.com \
--cc=markz@mellanox.com \
--cc=netdev@vger.kernel.org \
--cc=saeedm@mellanox.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).