RDMA/core: Add Completion Counters to resource tracking

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>
Link: https://patch.msgid.link/20260722083603.30334-5-mrgolin@amazon.com
Signed-off-by: Leon Romanovsky <leon@kernel.org>
This commit is contained in:
Michael Margolin
2026-07-22 05:45:47 -04:00
committed by Leon Romanovsky
parent c1c13e596f
commit 0774c6dd20
5 changed files with 26 additions and 1 deletions
+8
View File
@@ -451,8 +451,10 @@ 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 ib_comp_cntr_caps comp_cntr_caps = {};
struct nlattr *table_attr;
u64 curr, max;
int ret, i;
@@ -464,6 +466,9 @@ static int fill_res_info(struct sk_buff *msg, struct ib_device *device,
if (!table_attr)
return -EMSGSIZE;
if (device->ops.query_comp_cntr_caps)
device->ops.query_comp_cntr_caps(device, &comp_cntr_caps, NULL);
for (i = 0; i < RDMA_RESTRACK_MAX; i++) {
if (!names[i])
continue;
@@ -484,6 +489,9 @@ static int fill_res_info(struct sk_buff *msg, struct ib_device *device,
case RDMA_RESTRACK_SRQ:
max = device->attrs.max_srq;
break;
case RDMA_RESTRACK_COMP_CNTR:
max = comp_cntr_caps.max_counters;
break;
default:
max = 0;
}
+2
View File
@@ -104,6 +104,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;
@@ -6,6 +6,7 @@
#include <rdma/uverbs_std_types.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,
struct uverbs_attr_bundle *attrs)
@@ -16,10 +17,14 @@ static int uverbs_free_comp_cntr(struct ib_uobject *uobject, enum rdma_remove_re
if (atomic_read(&cc->usecnt))
return -EBUSY;
rdma_restrack_begin_del(&cc->res);
ret = cc->device->ops.destroy_comp_cntr(cc);
if (ret)
if (ret) {
rdma_restrack_abort_del(&cc->res);
return ret;
}
rdma_restrack_commit_del(&cc->res);
kfree(cc);
return 0;
}
@@ -44,15 +49,20 @@ static int UVERBS_HANDLER(UVERBS_METHOD_COMP_CNTR_CREATE)(struct uverbs_attr_bun
cc->device = ib_dev;
cc->uobject = uobj;
rdma_restrack_new(&cc->res, RDMA_RESTRACK_COMP_CNTR);
rdma_restrack_set_name(&cc->res, NULL);
ret = ib_dev->ops.create_comp_cntr(cc, attrs);
if (ret)
goto err_free;
uobj->object = cc;
rdma_restrack_add(&cc->res);
uverbs_finalize_uobj_create(attrs, UVERBS_ATTR_CREATE_COMP_CNTR_HANDLE);
return 0;
err_free:
rdma_restrack_put(&cc->res);
kfree(cc);
return ret;
}
+1
View File
@@ -1765,6 +1765,7 @@ struct ib_comp_cntr {
struct ib_device *device;
struct ib_uobject *uobject;
atomic_t usecnt;
struct rdma_restrack_entry res;
};
enum ib_comp_cntr_entry {
+4
View File
@@ -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
*/