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(uint8_t poll_ctx, struct nlattr *attr)
21{
22 if (!attr)
23 return;
24 print_string(PRINT_ANY, "poll-ctx", "poll-ctx %s ", poll_ctx_to_str(poll_ctx));
25}
26
27static void print_cq_dim_setting(struct nlattr *attr)
28{
29 uint8_t dim_setting;
30
31 if (!attr)
32 return;
33
34 dim_setting = mnl_attr_get_u8(attr);
35 if (dim_setting > 1)
36 return;
37
38 print_on_off(PRINT_ANY, "adaptive-moderation", "adaptive-moderation %s ", dim_setting);
39}
40
41static int res_cq_line_raw(struct rd *rd, const char *name, int idx,
42 struct nlattr **nla_line)
43{
44 if (!nla_line[RDMA_NLDEV_ATTR_RES_RAW])
45 return MNL_CB_ERROR;
46
47 open_json_object(NULL);
48 print_dev(idx, name);
49 print_raw_data(rd, nla_line);
50 close_json_object();
51 newline();
52
53 return MNL_CB_OK;
54}
55
56static int res_cq_line(struct rd *rd, const char *name, int idx,
57 struct nlattr **nla_line)
58{
59 char *comm = NULL;
60 uint32_t pid = 0;
61 uint8_t poll_ctx = 0;
62 uint32_t ctxn = 0;
63 uint32_t cqn = 0;
64 uint64_t users;
65 uint32_t cqe;
66 SPRINT_BUF(b);
67
68 if (!nla_line[RDMA_NLDEV_ATTR_RES_CQE] ||
69 !nla_line[RDMA_NLDEV_ATTR_RES_USECNT])
70 return MNL_CB_ERROR;
71
72 cqe = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CQE]);
73
74 users = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_USECNT]);
75 if (rd_is_filtered_attr(rd, "users", users,
76 nla_line[RDMA_NLDEV_ATTR_RES_USECNT]))
77 goto out;
78
79 if (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX])
80 poll_ctx =
81 mnl_attr_get_u8(nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]);
82 if (rd_is_string_filtered_attr(rd, "poll-ctx",
83 poll_ctx_to_str(poll_ctx),
84 nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]))
85 goto out;
86
87 if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
88 pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]);
89 if (!get_task_name(pid, b, sizeof(b)))
90 comm = b;
91 } else if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) {
92
93 comm = (char *)mnl_attr_get_str(
94 nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
95 }
96
97 if (rd_is_filtered_attr(rd, "pid", pid,
98 nla_line[RDMA_NLDEV_ATTR_RES_PID]))
99 goto out;
100
101 if (nla_line[RDMA_NLDEV_ATTR_RES_CQN])
102 cqn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CQN]);
103 if (rd_is_filtered_attr(rd, "cqn", cqn,
104 nla_line[RDMA_NLDEV_ATTR_RES_CQN]))
105 goto out;
106 if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN])
107 ctxn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CTXN]);
108 if (rd_is_filtered_attr(rd, "ctxn", ctxn,
109 nla_line[RDMA_NLDEV_ATTR_RES_CTXN]))
110 goto out;
111
112 open_json_object(NULL);
113 print_dev(idx, name);
114 res_print_u32("cqn", cqn, nla_line[RDMA_NLDEV_ATTR_RES_CQN]);
115 res_print_u32("cqe", cqe, nla_line[RDMA_NLDEV_ATTR_RES_CQE]);
116 res_print_u64("users", users, nla_line[RDMA_NLDEV_ATTR_RES_USECNT]);
117 print_poll_ctx(poll_ctx, nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]);
118 print_cq_dim_setting(nla_line[RDMA_NLDEV_ATTR_DEV_DIM]);
119 res_print_u32("ctxn", ctxn, nla_line[RDMA_NLDEV_ATTR_RES_CTXN]);
120 res_print_u32("pid", pid, nla_line[RDMA_NLDEV_ATTR_RES_PID]);
121 print_comm(comm, nla_line);
122
123 print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]);
124 close_json_object();
125 newline();
126
127out:
128 return MNL_CB_OK;
129}
130
131int res_cq_idx_parse_cb(const struct nlmsghdr *nlh, void *data)
132{
133 struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
134 struct rd *rd = data;
135 const char *name;
136 uint32_t idx;
137
138 mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
139 if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME])
140 return MNL_CB_ERROR;
141
142 name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
143 idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
144
145 return (rd->show_raw) ? res_cq_line_raw(rd, name, idx, tb) :
146 res_cq_line(rd, name, idx, tb);
147}
148
149int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data)
150{
151 struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
152 struct nlattr *nla_table, *nla_entry;
153 struct rd *rd = data;
154 int ret = MNL_CB_OK;
155 const char *name;
156 uint32_t idx;
157
158 mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
159 if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] ||
160 !tb[RDMA_NLDEV_ATTR_RES_CQ])
161 return MNL_CB_ERROR;
162
163 name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
164 idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
165 nla_table = tb[RDMA_NLDEV_ATTR_RES_CQ];
166
167 mnl_attr_for_each_nested(nla_entry, nla_table) {
168 struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {};
169
170 ret = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line);
171 if (ret != MNL_CB_OK)
172 break;
173
174 ret = (rd->show_raw) ? res_cq_line_raw(rd, name, idx, nla_line) :
175 res_cq_line(rd, name, idx, nla_line);
176
177 if (ret != MNL_CB_OK)
178 break;
179 }
180 return ret;
181}
182