diff mbox series

[RFC,iproute-next,5/5] rdma: Add PD resource tracking information

Message ID c3c9c2facd32c549e9f9742d7dbaafd9dd68c83f.1519071002.git.swise@opengridcomputing.com
State RFC, archived
Delegated to: David Ahern
Headers show
Series cm_id, cq, mr, and pd resource tracking | expand

Commit Message

Steve Wise Feb. 14, 2018, 9:07 p.m. UTC
Sample output:

# rdma resource show pd
link cxgb4_0/- local_dma_lkey 0x0 usecnt 4 flags 0x0 pid 30503 comm rping
link cxgb4_0/- local_dma_lkey 0x0 usecnt 0 flags 0x0 pid 30488 comm rping
link cxgb4_0/- local_dma_lkey 0x0 usecnt 5 flags 0x0 pid 30498 comm rping
link cxgb4_0/- local_dma_lkey 0x0 usecnt 0 flags 0x0 pid 30501 comm rping
link cxgb4_0/- local_dma_lkey 0x0 usecnt 0 flags 0x0 pid 0 comm [ib_srp]
link mlx4_0/- local_dma_lkey 0x0 usecnt 4 flags 0x0 pid 30494 comm rping
link mlx4_0/- local_dma_lkey 0x0 usecnt 0 flags 0x0 pid 30488 comm rping
link mlx4_0/- local_dma_lkey 0x0 usecnt 5 flags 0x0 pid 30489 comm rping
link mlx4_0/- local_dma_lkey 0x0 usecnt 0 flags 0x0 pid 30492 comm rping
link mlx4_0/- local_dma_lkey 0x8000 usecnt 0 flags 0x0 pid 0 comm [ib_srpt]
link mlx4_0/- local_dma_lkey 0x8000 usecnt 0 flags 0x0 pid 0 comm [ib_srp]
link mlx4_0/- local_dma_lkey 0x8000 usecnt 1 flags 0x0 pid 0 comm [ib_core]

Signed-off-by: Steve Wise <swise@opengridcomputing.com>
---
 rdma/res.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 96 insertions(+)

Comments

Leon Romanovsky Feb. 23, 2018, 2:22 p.m. UTC | #1
On Wed, Feb 14, 2018 at 01:07:01PM -0800, Steve Wise wrote:
> Sample output:
>
> # rdma resource show pd
> link cxgb4_0/- local_dma_lkey 0x0 usecnt 4 flags 0x0 pid 30503 comm rping

One more thing, flags need to be pre-parsed and accessible with "-d" command,
as we did with dev,link capabilities.

Thanks
Steve Wise Feb. 26, 2018, 3:09 p.m. UTC | #2
> 
> On Wed, Feb 14, 2018 at 01:07:01PM -0800, Steve Wise wrote:
> > Sample output:
> >
> > # rdma resource show pd
> > link cxgb4_0/- local_dma_lkey 0x0 usecnt 4 flags 0x0 pid 30503 comm
rping
> 
> One more thing, flags need to be pre-parsed and accessible with "-d"
> command,
> as we did with dev,link capabilities.

Will do.  

Thanks for reviewing this series!

Steve.
Steve Wise Feb. 27, 2018, 12:47 a.m. UTC | #3
> > On Wed, Feb 14, 2018 at 01:07:01PM -0800, Steve Wise wrote:
> > > Sample output:
> > >
> > > # rdma resource show pd
> > > link cxgb4_0/- local_dma_lkey 0x0 usecnt 4 flags 0x0 pid 30503 comm
> rping
> >
> > One more thing, flags need to be pre-parsed and accessible with "-d"
> > command,
> > as we did with dev,link capabilities.
> 
> Will do.
> 
> Thanks for reviewing this series!
> 

Turns out the only flags field was in the pd, and pd->flags only has one
flag, currently, indicating that the global_dma_rkey is in use.  Since the
kernel side only sends up the global_dma_rkey if that flag is set, I just
dropped the PD_FLAGS attribute in both patch series.  If pd flags grow, we
can add it, but I don't expect that.


Steve.
diff mbox series

Patch

diff --git a/rdma/res.c b/rdma/res.c
index 2b67d25..5e6bc42 100644
--- a/rdma/res.c
+++ b/rdma/res.c
@@ -932,6 +932,93 @@  static int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data)
 	return MNL_CB_OK;
 }
 
+static void print_flags(struct rd *rd, uint32_t val)
+{
+	if (rd->json_output)
+		jsonw_xint_field(rd->jw, "flags", val);
+	else
+		pr_out("flags 0x%x ", val);
+}
+
+static int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data)
+{
+	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
+	struct nlattr *nla_table, *nla_entry;
+	struct rd *rd = data;
+	const char *name;
+	uint32_t idx;
+
+	mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
+	if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] ||
+	    !tb[RDMA_NLDEV_ATTR_DEV_NAME] ||
+	    !tb[RDMA_NLDEV_ATTR_RES_PD])
+		return MNL_CB_ERROR;
+
+	name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
+	idx =  mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
+	nla_table = tb[RDMA_NLDEV_ATTR_RES_PD];
+
+	mnl_attr_for_each_nested(nla_entry, nla_table) {
+		struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {};
+		uint32_t local_dma_lkey, unsafe_global_rkey = 0;
+		uint32_t flags, pid = 0;
+		char *comm = NULL;
+		uint64_t usecnt;
+		int err;
+
+		err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line);
+		if (err != MNL_CB_OK)
+			return MNL_CB_ERROR;
+
+		if (!nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY] ||
+		    !nla_line[RDMA_NLDEV_ATTR_RES_USECNT] ||
+		    !nla_line[RDMA_NLDEV_ATTR_RES_PD_FLAGS] ||
+		    (!nla_line[RDMA_NLDEV_ATTR_RES_PID] &&
+		     !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])) {
+			return MNL_CB_ERROR;
+		}
+
+		local_dma_lkey = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY]);
+		usecnt = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_USECNT]);
+		flags = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PD_FLAGS]);
+		if (nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY])
+			unsafe_global_rkey = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY]);
+
+		if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
+			pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]);
+			comm = get_task_name(pid);
+		}
+
+		if (rd_check_is_filtered(rd, "pid", pid))
+			continue;
+
+		if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
+			/* discard const from mnl_attr_get_str */
+			comm = (char *)mnl_attr_get_str(nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
+
+		if (rd->json_output)
+			jsonw_start_array(rd->jw);
+
+		print_link(rd, idx, name, 0, nla_line);
+		print_key(rd, "local_dma_lkey", local_dma_lkey);
+		print_usecnt(rd, usecnt);
+		print_flags(rd, flags);
+		if (nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY])
+			print_key(rd, "unsafe_global_rkey", unsafe_global_rkey);
+		print_pid(rd, pid);
+		print_comm(rd, comm, nla_line);
+
+		if (nla_line[RDMA_NLDEV_ATTR_RES_PID])
+			free(comm);
+
+		if (rd->json_output)
+			jsonw_end_array(rd->jw);
+		else
+			pr_out("\n");
+	}
+	return MNL_CB_OK;
+}
+
 RES_FUNC(res_no_args,	RDMA_NLDEV_CMD_RES_GET,	NULL, true);
 
 static const struct
@@ -1005,6 +1092,14 @@  filters mr_valid_filters[MAX_NUMBER_OF_FILTERS] = {{ .name = "link",
 
 RES_FUNC(res_mr,	RDMA_NLDEV_CMD_RES_MR_GET, mr_valid_filters, true);
 
+static const struct
+filters pd_valid_filters[MAX_NUMBER_OF_FILTERS] = {{ .name = "link",
+						   .is_number = false },
+						   { .name = "pid",
+						   .is_number = true }};
+
+RES_FUNC(res_pd,	RDMA_NLDEV_CMD_RES_PD_GET, pd_valid_filters, true);
+
 static int res_show(struct rd *rd)
 {
 	const struct rd_cmd cmds[] = {
@@ -1013,6 +1108,7 @@  static int res_show(struct rd *rd)
 		{ "cm_id",	res_cm_id	},
 		{ "cq",		res_cq		},
 		{ "mr",		res_mr		},
+		{ "pd",		res_pd		},
 		{ 0 }
 	};