]> git.proxmox.com Git - mirror_iproute2.git/blob - rdma/res-cq.c
rdma: Control CQ adaptive moderation (DIM)
[mirror_iproute2.git] / rdma / res-cq.c
1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2 /*
3 * res-cq.c RDMA tool
4 * Authors: Leon Romanovsky <leonro@mellanox.com>
5 */
6
7 #include "res.h"
8 #include <inttypes.h>
9
10 static 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
20 static void print_poll_ctx(struct rd *rd, uint8_t poll_ctx, struct nlattr *attr)
21 {
22 if (!attr)
23 return;
24
25 if (rd->json_output) {
26 jsonw_string_field(rd->jw, "poll-ctx",
27 poll_ctx_to_str(poll_ctx));
28 return;
29 }
30 pr_out("poll-ctx %s ", poll_ctx_to_str(poll_ctx));
31 }
32
33 static void print_cq_dim_setting(struct rd *rd, struct nlattr *attr)
34 {
35 uint8_t dim_setting;
36
37 if (!attr)
38 return;
39
40 dim_setting = mnl_attr_get_u8(attr);
41 if (dim_setting > 1)
42 return;
43
44 print_on_off(rd, "adaptive-moderation", dim_setting);
45 }
46
47 static int res_cq_line(struct rd *rd, const char *name, int idx,
48 struct nlattr **nla_line)
49 {
50 char *comm = NULL;
51 uint32_t pid = 0;
52 uint8_t poll_ctx = 0;
53 uint32_t ctxn = 0;
54 uint32_t cqn = 0;
55 uint64_t users;
56 uint32_t cqe;
57
58 if (!nla_line[RDMA_NLDEV_ATTR_RES_CQE] ||
59 !nla_line[RDMA_NLDEV_ATTR_RES_USECNT] ||
60 (!nla_line[RDMA_NLDEV_ATTR_RES_PID] &&
61 !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])) {
62 return MNL_CB_ERROR;
63 }
64
65 cqe = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CQE]);
66
67 users = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_USECNT]);
68 if (rd_is_filtered_attr(rd, "users", users,
69 nla_line[RDMA_NLDEV_ATTR_RES_USECNT]))
70 goto out;
71
72 if (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX])
73 poll_ctx =
74 mnl_attr_get_u8(nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]);
75 if (rd_is_string_filtered_attr(rd, "poll-ctx",
76 poll_ctx_to_str(poll_ctx),
77 nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]))
78 goto out;
79
80 if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) {
81 pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]);
82 comm = get_task_name(pid);
83 }
84
85 if (rd_is_filtered_attr(rd, "pid", pid,
86 nla_line[RDMA_NLDEV_ATTR_RES_PID]))
87 goto out;
88
89 if (nla_line[RDMA_NLDEV_ATTR_RES_CQN])
90 cqn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CQN]);
91 if (rd_is_filtered_attr(rd, "cqn", cqn,
92 nla_line[RDMA_NLDEV_ATTR_RES_CQN]))
93 goto out;
94 if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN])
95 ctxn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CTXN]);
96 if (rd_is_filtered_attr(rd, "ctxn", ctxn,
97 nla_line[RDMA_NLDEV_ATTR_RES_CTXN]))
98 goto out;
99
100 if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])
101 /* discard const from mnl_attr_get_str */
102 comm = (char *)mnl_attr_get_str(
103 nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]);
104
105 if (rd->json_output)
106 jsonw_start_array(rd->jw);
107
108 print_dev(rd, idx, name);
109 res_print_uint(rd, "cqn", cqn, nla_line[RDMA_NLDEV_ATTR_RES_CQN]);
110 res_print_uint(rd, "cqe", cqe, nla_line[RDMA_NLDEV_ATTR_RES_CQE]);
111 res_print_uint(rd, "users", users,
112 nla_line[RDMA_NLDEV_ATTR_RES_USECNT]);
113 print_poll_ctx(rd, poll_ctx, nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]);
114 print_cq_dim_setting(rd, nla_line[RDMA_NLDEV_ATTR_DEV_DIM]);
115 res_print_uint(rd, "ctxn", ctxn, nla_line[RDMA_NLDEV_ATTR_RES_CTXN]);
116 res_print_uint(rd, "pid", pid, nla_line[RDMA_NLDEV_ATTR_RES_PID]);
117 print_comm(rd, comm, nla_line);
118
119 print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]);
120 newline(rd);
121
122 out: if (nla_line[RDMA_NLDEV_ATTR_RES_PID])
123 free(comm);
124 return MNL_CB_OK;
125 }
126
127 int res_cq_idx_parse_cb(const struct nlmsghdr *nlh, void *data)
128 {
129 struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
130 struct rd *rd = data;
131 const char *name;
132 uint32_t idx;
133
134 mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
135 if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME])
136 return MNL_CB_ERROR;
137
138 name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
139 idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
140
141 return res_cq_line(rd, name, idx, tb);
142 }
143
144 int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data)
145 {
146 struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
147 struct nlattr *nla_table, *nla_entry;
148 struct rd *rd = data;
149 int ret = MNL_CB_OK;
150 const char *name;
151 uint32_t idx;
152
153 mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
154 if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] ||
155 !tb[RDMA_NLDEV_ATTR_RES_CQ])
156 return MNL_CB_ERROR;
157
158 name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
159 idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
160 nla_table = tb[RDMA_NLDEV_ATTR_RES_CQ];
161
162 mnl_attr_for_each_nested(nla_entry, nla_table) {
163 struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {};
164
165 ret = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line);
166 if (ret != MNL_CB_OK)
167 break;
168
169 ret = res_cq_line(rd, name, idx, nla_line);
170
171 if (ret != MNL_CB_OK)
172 break;
173 }
174 return ret;
175 }