1
2
3
4
5
6
7#include "res.h"
8#include <inttypes.h>
9
10static const char *poll_ctx_to_str(uint8_t idx)
11{
12 static const char * const cm_id_states_str[] = {
13 "DIRECT", "SOFTIRQ", "WORKQUEUE", "UNBOUND_WORKQUEUE"};
14
15 if (idx < ARRAY_SIZE(cm_id_states_str))
16 return cm_id_states_str[idx];
17 return "UNKNOWN";
18}
19
20static void print_poll_ctx(struct rd *rd, uint8_t poll_ctx, struct nlattr *attr)
21{
22 if (!attr)
23 return;
24 print_color_string(PRINT_ANY, COLOR_NONE, "poll-ctx", "poll-ctx %s ",
25 poll_ctx_to_str(poll_ctx));
26}
27
28static void print_cq_dim_setting(struct rd *rd, struct nlattr *attr)
29{
30 uint8_t dim_setting;
31
32 if (!attr)
33 return;
34
35 dim_setting = mnl_attr_get_u8(attr);
36 if (dim_setting > 1)
37 return;
38
39 print_on_off(rd, "adaptive-moderation", dim_setting);
40}
41
42static int res_cq_line(struct rd *rd, const char *name, int idx,
43 struct nlattr **nla_line)
44{
45 char *comm = NULL;
46 uint32_t pid = 0;
47 uint8_t poll_ctx = 0;
48 uint32_t ctxn = 0;
49 uint32_t cqn = 0;
50 uint64_t users;
51 uint32_t cqe;
52
53 if (!nla_line[RDMA_NLDEV_ATTR_RES_CQE] ||
54 !nla_line[RDMA_NLDEV_ATTR_RES_USECNT])
55 return MNL_CB_ERROR;
56
57 cqe = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CQE]);
58
59 users = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_USECNT]);
60 if (rd_is_filtered_attr(rd, "users", users,
61 nla_line[RDMA_NLDEV_ATTR_RES_USECNT]))
62 goto out;
63
64 if (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX])
65 poll_ctx =
66 mnl_attr_get_u8(nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]);
67 if (rd_is_string_filtered_attr(rd, "poll-ctx",
68 poll_ctx_to_str(poll_ctx),
69 nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]))
70 goto out;
71
72 if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
73 pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]);
74 comm = get_task_name(pid);
75 }
76
77 if (rd_is_filtered_attr(rd, "pid", pid,
78 nla_line[RDMA_NLDEV_ATTR_RES_PID]))
79 goto out;
80
81 if (nla_line[RDMA_NLDEV_ATTR_RES_CQN])
82 cqn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CQN]);
83 if (rd_is_filtered_attr(rd, "cqn", cqn,
84 nla_line[RDMA_NLDEV_ATTR_RES_CQN]))
85 goto out;
86 if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN])
87 ctxn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CTXN]);
88 if (rd_is_filtered_attr(rd, "ctxn", ctxn,
89 nla_line[RDMA_NLDEV_ATTR_RES_CTXN]))
90 goto out;
91
92 if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
93
94 comm = (char *)mnl_attr_get_str(
95 nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
96
97 open_json_object(NULL);
98 print_dev(rd, idx, name);
99 res_print_uint(rd, "cqn", cqn, nla_line[RDMA_NLDEV_ATTR_RES_CQN]);
100 res_print_uint(rd, "cqe", cqe, nla_line[RDMA_NLDEV_ATTR_RES_CQE]);
101 res_print_uint(rd, "users", users,
102 nla_line[RDMA_NLDEV_ATTR_RES_USECNT]);
103 print_poll_ctx(rd, poll_ctx, nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]);
104 print_cq_dim_setting(rd, nla_line[RDMA_NLDEV_ATTR_DEV_DIM]);
105 res_print_uint(rd, "ctxn", ctxn, nla_line[RDMA_NLDEV_ATTR_RES_CTXN]);
106 res_print_uint(rd, "pid", pid, nla_line[RDMA_NLDEV_ATTR_RES_PID]);
107 print_comm(rd, comm, nla_line);
108
109 print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]);
110 newline(rd);
111
112out: if (nla_line[RDMA_NLDEV_ATTR_RES_PID])
113 free(comm);
114 return MNL_CB_OK;
115}
116
117int res_cq_idx_parse_cb(const struct nlmsghdr *nlh, void *data)
118{
119 struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
120 struct rd *rd = data;
121 const char *name;
122 uint32_t idx;
123
124 mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
125 if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME])
126 return MNL_CB_ERROR;
127
128 name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
129 idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
130
131 return res_cq_line(rd, name, idx, tb);
132}
133
134int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data)
135{
136 struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
137 struct nlattr *nla_table, *nla_entry;
138 struct rd *rd = data;
139 int ret = MNL_CB_OK;
140 const char *name;
141 uint32_t idx;
142
143 mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
144 if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] ||
145 !tb[RDMA_NLDEV_ATTR_RES_CQ])
146 return MNL_CB_ERROR;
147
148 name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
149 idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
150 nla_table = tb[RDMA_NLDEV_ATTR_RES_CQ];
151
152 mnl_attr_for_each_nested(nla_entry, nla_table) {
153 struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {};
154
155 ret = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line);
156 if (ret != MNL_CB_OK)
157 break;
158
159 ret = res_cq_line(rd, name, idx, nla_line);
160
161 if (ret != MNL_CB_OK)
162 break;
163 }
164 return ret;
165}
166