From: Michael Margolin <mrgolin@amazon.com>
To: <jgg@nvidia.com>, <leon@kernel.org>, <linux-rdma@vger.kernel.org>
Cc: <sleybo@amazon.com>, <matua@amazon.com>, <gal.pressman@linux.dev>,
"Yonatan Nachum" <ynachum@amazon.com>
Subject: [PATCH for-next 2/4] RDMA/core: Add Completion Counters to resource tracking
Date: Tue, 7 Apr 2026 11:54:22 +0000 [thread overview]
Message-ID: <20260407115424.13359-3-mrgolin@amazon.com> (raw)
In-Reply-To: <20260407115424.13359-1-mrgolin@amazon.com>
Track completion counter objects in the resource tracking database so
they are visible through the rdma netlink interface. The rdma tool
displays the comp_cntr count in the resource summary.
Add RDMA_RESTRACK_COMP_CNTR type, embed rdma_restrack_entry in
ib_comp_cntr, and add the res_to_dev mapping. Register the resource
on create and remove it on destroy.
Reviewed-by: Yonatan Nachum <ynachum@amazon.com>
Signed-off-by: Michael Margolin <mrgolin@amazon.com>
---
drivers/infiniband/core/nldev.c | 1 +
drivers/infiniband/core/restrack.c | 2 ++
drivers/infiniband/core/uverbs_std_types_comp_cntr.c | 6 ++++++
include/rdma/ib_verbs.h | 1 +
include/rdma/restrack.h | 4 ++++
5 files changed, 14 insertions(+)
diff --git a/drivers/infiniband/core/nldev.c b/drivers/infiniband/core/nldev.c
index 96c745d5bac4..155954fef3e2 100644
--- a/drivers/infiniband/core/nldev.c
+++ b/drivers/infiniband/core/nldev.c
@@ -446,6 +446,7 @@ static int fill_res_info(struct sk_buff *msg, struct ib_device *device,
[RDMA_RESTRACK_MR] = "mr",
[RDMA_RESTRACK_CTX] = "ctx",
[RDMA_RESTRACK_SRQ] = "srq",
+ [RDMA_RESTRACK_COMP_CNTR] = "comp_cntr",
};
struct nlattr *table_attr;
diff --git a/drivers/infiniband/core/restrack.c b/drivers/infiniband/core/restrack.c
index ac3688952cab..d152cc5f042b 100644
--- a/drivers/infiniband/core/restrack.c
+++ b/drivers/infiniband/core/restrack.c
@@ -102,6 +102,8 @@ static struct ib_device *res_to_dev(struct rdma_restrack_entry *res)
return container_of(res, struct ib_srq, res)->device;
case RDMA_RESTRACK_DMAH:
return container_of(res, struct ib_dmah, res)->device;
+ case RDMA_RESTRACK_COMP_CNTR:
+ return container_of(res, struct ib_comp_cntr, res)->device;
default:
WARN_ONCE(true, "Wrong resource tracking type %u\n", res->type);
return NULL;
diff --git a/drivers/infiniband/core/uverbs_std_types_comp_cntr.c b/drivers/infiniband/core/uverbs_std_types_comp_cntr.c
index a62c20d4e5a4..708cac838d43 100644
--- a/drivers/infiniband/core/uverbs_std_types_comp_cntr.c
+++ b/drivers/infiniband/core/uverbs_std_types_comp_cntr.c
@@ -8,6 +8,7 @@
#include <rdma/ib_umem_dmabuf.h>
#include "rdma_core.h"
#include "uverbs.h"
+#include "restrack.h"
static int uverbs_free_comp_cntr(struct ib_uobject *uobject,
enum rdma_remove_reason why,
@@ -20,6 +21,7 @@ static int uverbs_free_comp_cntr(struct ib_uobject *uobject,
if (ret)
return ret;
+ rdma_restrack_del(&cc->res);
ib_umem_release(cc->comp_umem);
ib_umem_release(cc->err_umem);
kfree(cc);
@@ -120,7 +122,11 @@ static int UVERBS_HANDLER(UVERBS_METHOD_COMP_CNTR_CREATE)(
if (ret)
goto err_err_umem;
+ rdma_restrack_new(&cc->res, RDMA_RESTRACK_COMP_CNTR);
+ rdma_restrack_set_name(&cc->res, NULL);
+
uobj->object = cc;
+ rdma_restrack_add(&cc->res);
uverbs_finalize_uobj_create(attrs, UVERBS_ATTR_CREATE_COMP_CNTR_HANDLE);
ret = uverbs_copy_to(attrs,
diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h
index 76fa705389a4..2193e9d678cb 100644
--- a/include/rdma/ib_verbs.h
+++ b/include/rdma/ib_verbs.h
@@ -1754,6 +1754,7 @@ struct ib_comp_cntr {
struct ib_umem *err_umem;
u64 comp_count_max_value;
u64 err_count_max_value;
+ struct rdma_restrack_entry res;
};
struct ib_comp_cntr_attach_attr {
diff --git a/include/rdma/restrack.h b/include/rdma/restrack.h
index 451f99e3717d..4ab72bc6d8c7 100644
--- a/include/rdma/restrack.h
+++ b/include/rdma/restrack.h
@@ -60,6 +60,10 @@ enum rdma_restrack_type {
* @RDMA_RESTRACK_DMAH: DMA handle
*/
RDMA_RESTRACK_DMAH,
+ /**
+ * @RDMA_RESTRACK_COMP_CNTR: Completion Counter
+ */
+ RDMA_RESTRACK_COMP_CNTR,
/**
* @RDMA_RESTRACK_MAX: Last entry, used for array dclarations
*/
--
2.47.3
next prev parent reply other threads:[~2026-04-07 11:54 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-07 11:54 [PATCH for-next 0/4] Introduce Completion Counters Michael Margolin
2026-04-07 11:54 ` [PATCH for-next 1/4] RDMA/core: Add Completion Counters support Michael Margolin
2026-04-07 14:17 ` Jason Gunthorpe
2026-04-09 16:00 ` Michael Margolin
2026-04-09 16:13 ` Jason Gunthorpe
2026-04-09 17:29 ` Sean Hefty
2026-04-09 18:55 ` Jason Gunthorpe
2026-04-09 19:15 ` Sean Hefty
2026-04-09 19:44 ` Jason Gunthorpe
2026-04-09 22:23 ` Sean Hefty
2026-04-09 18:36 ` Michael Margolin
2026-04-07 11:54 ` Michael Margolin [this message]
2026-04-07 11:54 ` [PATCH for-next 3/4] RDMA/efa: Update device interface Michael Margolin
2026-04-07 11:54 ` [PATCH for-next 4/4] RDMA/efa: Add Completion Counters support Michael Margolin
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=20260407115424.13359-3-mrgolin@amazon.com \
--to=mrgolin@amazon.com \
--cc=gal.pressman@linux.dev \
--cc=jgg@nvidia.com \
--cc=leon@kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=matua@amazon.com \
--cc=sleybo@amazon.com \
--cc=ynachum@amazon.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