]>
Commit | Line | Data |
---|---|---|
fcdd2e0c LR |
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 | ||
fcdd2e0c LR |
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 | ||
127ff956 | 20 | static void print_poll_ctx(struct rd *rd, uint8_t poll_ctx, struct nlattr *attr) |
fcdd2e0c | 21 | { |
127ff956 LR |
22 | if (!attr) |
23 | return; | |
24 | ||
fcdd2e0c LR |
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 | ||
8a56ef32 YF |
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 | ||
83ea7228 | 47 | static int res_cq_line(struct rd *rd, const char *name, int idx, |
5a823593 | 48 | struct nlattr **nla_line) |
83ea7228 | 49 | { |
83ea7228 LR |
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; | |
83ea7228 LR |
57 | |
58 | if (!nla_line[RDMA_NLDEV_ATTR_RES_CQE] || | |
f9313484 | 59 | !nla_line[RDMA_NLDEV_ATTR_RES_USECNT]) |
83ea7228 | 60 | return MNL_CB_ERROR; |
83ea7228 LR |
61 | |
62 | cqe = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CQE]); | |
63 | ||
64 | users = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_USECNT]); | |
78728b7e LR |
65 | if (rd_is_filtered_attr(rd, "users", users, |
66 | nla_line[RDMA_NLDEV_ATTR_RES_USECNT])) | |
83ea7228 LR |
67 | goto out; |
68 | ||
78728b7e | 69 | if (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]) |
83ea7228 LR |
70 | poll_ctx = |
71 | mnl_attr_get_u8(nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]); | |
78728b7e LR |
72 | if (rd_is_string_filtered_attr(rd, "poll-ctx", |
73 | poll_ctx_to_str(poll_ctx), | |
74 | nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX])) | |
75 | goto out; | |
83ea7228 LR |
76 | |
77 | if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) { | |
78 | pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]); | |
79 | comm = get_task_name(pid); | |
80 | } | |
81 | ||
78728b7e LR |
82 | if (rd_is_filtered_attr(rd, "pid", pid, |
83 | nla_line[RDMA_NLDEV_ATTR_RES_PID])) | |
83ea7228 LR |
84 | goto out; |
85 | ||
86 | if (nla_line[RDMA_NLDEV_ATTR_RES_CQN]) | |
87 | cqn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CQN]); | |
78728b7e LR |
88 | if (rd_is_filtered_attr(rd, "cqn", cqn, |
89 | nla_line[RDMA_NLDEV_ATTR_RES_CQN])) | |
83ea7228 | 90 | goto out; |
83ea7228 LR |
91 | if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN]) |
92 | ctxn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CTXN]); | |
78728b7e LR |
93 | if (rd_is_filtered_attr(rd, "ctxn", ctxn, |
94 | nla_line[RDMA_NLDEV_ATTR_RES_CTXN])) | |
83ea7228 LR |
95 | goto out; |
96 | ||
97 | if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) | |
98 | /* discard const from mnl_attr_get_str */ | |
99 | comm = (char *)mnl_attr_get_str( | |
100 | nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]); | |
101 | ||
102 | if (rd->json_output) | |
103 | jsonw_start_array(rd->jw); | |
104 | ||
105 | print_dev(rd, idx, name); | |
127ff956 LR |
106 | res_print_uint(rd, "cqn", cqn, nla_line[RDMA_NLDEV_ATTR_RES_CQN]); |
107 | res_print_uint(rd, "cqe", cqe, nla_line[RDMA_NLDEV_ATTR_RES_CQE]); | |
108 | res_print_uint(rd, "users", users, | |
109 | nla_line[RDMA_NLDEV_ATTR_RES_USECNT]); | |
110 | print_poll_ctx(rd, poll_ctx, nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]); | |
8a56ef32 | 111 | print_cq_dim_setting(rd, nla_line[RDMA_NLDEV_ATTR_DEV_DIM]); |
127ff956 LR |
112 | res_print_uint(rd, "ctxn", ctxn, nla_line[RDMA_NLDEV_ATTR_RES_CTXN]); |
113 | res_print_uint(rd, "pid", pid, nla_line[RDMA_NLDEV_ATTR_RES_PID]); | |
83ea7228 LR |
114 | print_comm(rd, comm, nla_line); |
115 | ||
83ea7228 LR |
116 | print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]); |
117 | newline(rd); | |
118 | ||
119 | out: if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) | |
120 | free(comm); | |
121 | return MNL_CB_OK; | |
122 | } | |
123 | ||
5a823593 LR |
124 | int res_cq_idx_parse_cb(const struct nlmsghdr *nlh, void *data) |
125 | { | |
126 | struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {}; | |
127 | struct rd *rd = data; | |
128 | const char *name; | |
129 | uint32_t idx; | |
130 | ||
131 | mnl_attr_parse(nlh, 0, rd_attr_cb, tb); | |
132 | if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME]) | |
133 | return MNL_CB_ERROR; | |
134 | ||
135 | name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]); | |
136 | idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]); | |
137 | ||
138 | return res_cq_line(rd, name, idx, tb); | |
139 | } | |
140 | ||
fcdd2e0c LR |
141 | int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data) |
142 | { | |
143 | struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {}; | |
144 | struct nlattr *nla_table, *nla_entry; | |
145 | struct rd *rd = data; | |
83ea7228 | 146 | int ret = MNL_CB_OK; |
fcdd2e0c LR |
147 | const char *name; |
148 | uint32_t idx; | |
149 | ||
150 | mnl_attr_parse(nlh, 0, rd_attr_cb, tb); | |
151 | if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] || | |
152 | !tb[RDMA_NLDEV_ATTR_RES_CQ]) | |
153 | return MNL_CB_ERROR; | |
154 | ||
155 | name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]); | |
156 | idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]); | |
157 | nla_table = tb[RDMA_NLDEV_ATTR_RES_CQ]; | |
158 | ||
159 | mnl_attr_for_each_nested(nla_entry, nla_table) { | |
5a823593 LR |
160 | struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {}; |
161 | ||
162 | ret = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line); | |
163 | if (ret != MNL_CB_OK) | |
164 | break; | |
165 | ||
166 | ret = res_cq_line(rd, name, idx, nla_line); | |
83ea7228 LR |
167 | |
168 | if (ret != MNL_CB_OK) | |
169 | break; | |
fcdd2e0c | 170 | } |
83ea7228 | 171 | return ret; |
fcdd2e0c | 172 | } |