netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steve Wise <swise@opengridcomputing.com>
To: dsahern@gmail.com
Cc: leon@kernel.org, stephen@networkplumber.org,
	netdev@vger.kernel.org, linux-rdma@vger.kernel.org
Subject: [PATCH RFC iproute-next 5/5] rdma: Add PD resource tracking information
Date: Wed, 14 Feb 2018 13:07:01 -0800	[thread overview]
Message-ID: <c3c9c2facd32c549e9f9742d7dbaafd9dd68c83f.1519071002.git.swise@opengridcomputing.com> (raw)
In-Reply-To: <cover.1519071002.git.swise@opengridcomputing.com>

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(+)

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 }
 	};
 
-- 
1.8.3.1

  parent reply	other threads:[~2018-02-19 20:12 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-19 20:10 [PATCH RFC iproute-next 0/5] cm_id, cq, mr, and pd resource tracking Steve Wise
2018-02-14 21:05 ` [PATCH RFC iproute-next 1/5] rdma: update rdma_netlink.h Steve Wise
2018-02-14 21:07 ` [PATCH RFC iproute-next 3/5] rdma: Add CQ resource tracking information Steve Wise
2018-02-20 13:09   ` Leon Romanovsky
2018-02-26 15:06     ` Steve Wise
2018-02-14 21:07 ` [PATCH RFC iproute-next 4/5] rdma: Add MR " Steve Wise
2018-02-20 14:12   ` Leon Romanovsky
2018-02-26 15:08     ` Steve Wise
2018-02-14 21:07 ` Steve Wise [this message]
2018-02-23 14:22   ` [PATCH RFC iproute-next 5/5] rdma: Add PD " Leon Romanovsky
2018-02-26 15:09     ` Steve Wise
2018-02-27  0:47       ` Steve Wise
2018-02-14 21:07 ` [PATCH RFC iproute-next 2/5] rdma: Add CM_ID " Steve Wise
2018-02-20 12:57   ` Leon Romanovsky
2018-02-20 15:15     ` Parav Pandit
2018-02-26 15:05     ` Steve Wise

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=c3c9c2facd32c549e9f9742d7dbaafd9dd68c83f.1519071002.git.swise@opengridcomputing.com \
    --to=swise@opengridcomputing.com \
    --cc=dsahern@gmail.com \
    --cc=leon@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.org \
    /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).