]>
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; | |
b0a688a5 IK |
24 | print_color_string(PRINT_ANY, COLOR_NONE, "poll-ctx", "poll-ctx %s ", |
25 | poll_ctx_to_str(poll_ctx)); | |
fcdd2e0c LR |
26 | } |
27 | ||
8a56ef32 YF |
28 | static 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 | ||
83ea7228 | 42 | static int res_cq_line(struct rd *rd, const char *name, int idx, |
5a823593 | 43 | struct nlattr **nla_line) |
83ea7228 | 44 | { |
83ea7228 LR |
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; | |
83ea7228 LR |
52 | |
53 | if (!nla_line[RDMA_NLDEV_ATTR_RES_CQE] || | |
f9313484 | 54 | !nla_line[RDMA_NLDEV_ATTR_RES_USECNT]) |
83ea7228 | 55 | return MNL_CB_ERROR; |
83ea7228 LR |
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]); | |
78728b7e LR |
60 | if (rd_is_filtered_attr(rd, "users", users, |
61 | nla_line[RDMA_NLDEV_ATTR_RES_USECNT])) | |
83ea7228 LR |
62 | goto out; |
63 | ||
78728b7e | 64 | if (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]) |
83ea7228 LR |
65 | poll_ctx = |
66 | mnl_attr_get_u8(nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX]); | |
78728b7e LR |
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; | |
83ea7228 LR |
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 | ||
78728b7e LR |
77 | if (rd_is_filtered_attr(rd, "pid", pid, |
78 | nla_line[RDMA_NLDEV_ATTR_RES_PID])) | |
83ea7228 LR |
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]); | |
78728b7e LR |
83 | if (rd_is_filtered_attr(rd, "cqn", cqn, |
84 | nla_line[RDMA_NLDEV_ATTR_RES_CQN])) | |
83ea7228 | 85 | goto out; |
83ea7228 LR |
86 | if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN]) |
87 | ctxn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_CTXN]); | |
78728b7e LR |
88 | if (rd_is_filtered_attr(rd, "ctxn", ctxn, |
89 | nla_line[RDMA_NLDEV_ATTR_RES_CTXN])) | |
83ea7228 LR |
90 | goto out; |
91 | ||
92 | if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) | |
93 | /* discard const from mnl_attr_get_str */ | |
94 | comm = (char *)mnl_attr_get_str( | |
95 | nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]); | |
96 | ||
b0a688a5 | 97 | open_json_object(NULL); |
83ea7228 | 98 | print_dev(rd, idx, name); |
127ff956 LR |
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]); | |
8a56ef32 | 104 | print_cq_dim_setting(rd, nla_line[RDMA_NLDEV_ATTR_DEV_DIM]); |
127ff956 LR |
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]); | |
83ea7228 LR |
107 | print_comm(rd, comm, nla_line); |
108 | ||
83ea7228 LR |
109 | print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]); |
110 | newline(rd); | |
111 | ||
112 | out: if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) | |
113 | free(comm); | |
114 | return MNL_CB_OK; | |
115 | } | |
116 | ||
5a823593 LR |
117 | int 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 | ||
fcdd2e0c LR |
134 | int 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; | |
83ea7228 | 139 | int ret = MNL_CB_OK; |
fcdd2e0c LR |
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) { | |
5a823593 LR |
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); | |
83ea7228 LR |
160 | |
161 | if (ret != MNL_CB_OK) | |
162 | break; | |
fcdd2e0c | 163 | } |
83ea7228 | 164 | return ret; |
fcdd2e0c | 165 | } |