Commit | Line | Data |
---|---|---|
e0e4b8fa GG |
1 | /* SPDX-License-Identifier: GPL-2.0 */ |
2 | /* | |
3 | * Shared Memory Communications over RDMA (SMC-R) and RoCE | |
4 | * | |
5 | * Macros for SMC statistics | |
6 | * | |
7 | * Copyright IBM Corp. 2021 | |
8 | * | |
9 | * Author(s): Guvenc Gulce | |
10 | */ | |
11 | ||
12 | #ifndef NET_SMC_SMC_STATS_H_ | |
13 | #define NET_SMC_SMC_STATS_H_ | |
14 | #include <linux/init.h> | |
15 | #include <linux/mutex.h> | |
16 | #include <linux/percpu.h> | |
17 | #include <linux/ctype.h> | |
18 | #include <linux/smc.h> | |
19 | ||
20 | #include "smc_clc.h" | |
21 | ||
22 | #define SMC_MAX_FBACK_RSN_CNT 30 | |
23 | ||
e0e4b8fa GG |
24 | enum { |
25 | SMC_BUF_8K, | |
26 | SMC_BUF_16K, | |
27 | SMC_BUF_32K, | |
28 | SMC_BUF_64K, | |
29 | SMC_BUF_128K, | |
30 | SMC_BUF_256K, | |
31 | SMC_BUF_512K, | |
32 | SMC_BUF_1024K, | |
33 | SMC_BUF_G_1024K, | |
34 | SMC_BUF_MAX, | |
35 | }; | |
36 | ||
37 | struct smc_stats_fback { | |
38 | int fback_code; | |
39 | u16 count; | |
40 | }; | |
41 | ||
194730a9 | 42 | struct smc_stats_rsn { |
e0e4b8fa GG |
43 | struct smc_stats_fback srv[SMC_MAX_FBACK_RSN_CNT]; |
44 | struct smc_stats_fback clnt[SMC_MAX_FBACK_RSN_CNT]; | |
45 | u64 srv_fback_cnt; | |
46 | u64 clnt_fback_cnt; | |
47 | }; | |
48 | ||
49 | struct smc_stats_rmbcnt { | |
50 | u64 buf_size_small_peer_cnt; | |
51 | u64 buf_size_small_cnt; | |
52 | u64 buf_full_peer_cnt; | |
53 | u64 buf_full_cnt; | |
54 | u64 reuse_cnt; | |
55 | u64 alloc_cnt; | |
56 | u64 dgrade_cnt; | |
57 | }; | |
58 | ||
59 | struct smc_stats_memsize { | |
60 | u64 buf[SMC_BUF_MAX]; | |
61 | }; | |
62 | ||
63 | struct smc_stats_tech { | |
64 | struct smc_stats_memsize tx_rmbsize; | |
65 | struct smc_stats_memsize rx_rmbsize; | |
66 | struct smc_stats_memsize tx_pd; | |
67 | struct smc_stats_memsize rx_pd; | |
68 | struct smc_stats_rmbcnt rmb_tx; | |
69 | struct smc_stats_rmbcnt rmb_rx; | |
70 | u64 clnt_v1_succ_cnt; | |
71 | u64 clnt_v2_succ_cnt; | |
72 | u64 srv_v1_succ_cnt; | |
73 | u64 srv_v2_succ_cnt; | |
e0e4b8fa GG |
74 | u64 urg_data_cnt; |
75 | u64 splice_cnt; | |
76 | u64 cork_cnt; | |
77 | u64 ndly_cnt; | |
78 | u64 rx_bytes; | |
79 | u64 tx_bytes; | |
80 | u64 rx_cnt; | |
81 | u64 tx_cnt; | |
82 | }; | |
83 | ||
84 | struct smc_stats { | |
85 | struct smc_stats_tech smc[2]; | |
86 | u64 clnt_hshake_err_cnt; | |
87 | u64 srv_hshake_err_cnt; | |
88 | }; | |
89 | ||
194730a9 | 90 | #define SMC_STAT_PAYLOAD_SUB(_smc_stats, _tech, key, _len, _rc) \ |
e0e4b8fa | 91 | do { \ |
194730a9 | 92 | typeof(_smc_stats) stats = (_smc_stats); \ |
e0e4b8fa GG |
93 | typeof(_tech) t = (_tech); \ |
94 | typeof(_len) l = (_len); \ | |
95 | int _pos = fls64((l) >> 13); \ | |
96 | typeof(_rc) r = (_rc); \ | |
97 | int m = SMC_BUF_MAX - 1; \ | |
194730a9 | 98 | this_cpu_inc((*stats).smc[t].key ## _cnt); \ |
e0e4b8fa GG |
99 | if (r <= 0) \ |
100 | break; \ | |
101 | _pos = (_pos < m) ? ((l == 1 << (_pos + 12)) ? _pos - 1 : _pos) : m; \ | |
194730a9 GG |
102 | this_cpu_inc((*stats).smc[t].key ## _pd.buf[_pos]); \ |
103 | this_cpu_add((*stats).smc[t].key ## _bytes, r); \ | |
e0e4b8fa GG |
104 | } \ |
105 | while (0) | |
106 | ||
107 | #define SMC_STAT_TX_PAYLOAD(_smc, length, rcode) \ | |
108 | do { \ | |
109 | typeof(_smc) __smc = _smc; \ | |
194730a9 GG |
110 | struct net *_net = sock_net(&__smc->sk); \ |
111 | struct smc_stats __percpu *_smc_stats = _net->smc.smc_stats; \ | |
e0e4b8fa GG |
112 | typeof(length) _len = (length); \ |
113 | typeof(rcode) _rc = (rcode); \ | |
114 | bool is_smcd = !__smc->conn.lnk; \ | |
115 | if (is_smcd) \ | |
194730a9 | 116 | SMC_STAT_PAYLOAD_SUB(_smc_stats, SMC_TYPE_D, tx, _len, _rc); \ |
e0e4b8fa | 117 | else \ |
194730a9 | 118 | SMC_STAT_PAYLOAD_SUB(_smc_stats, SMC_TYPE_R, tx, _len, _rc); \ |
e0e4b8fa GG |
119 | } \ |
120 | while (0) | |
121 | ||
122 | #define SMC_STAT_RX_PAYLOAD(_smc, length, rcode) \ | |
123 | do { \ | |
124 | typeof(_smc) __smc = _smc; \ | |
194730a9 GG |
125 | struct net *_net = sock_net(&__smc->sk); \ |
126 | struct smc_stats __percpu *_smc_stats = _net->smc.smc_stats; \ | |
e0e4b8fa GG |
127 | typeof(length) _len = (length); \ |
128 | typeof(rcode) _rc = (rcode); \ | |
129 | bool is_smcd = !__smc->conn.lnk; \ | |
130 | if (is_smcd) \ | |
194730a9 | 131 | SMC_STAT_PAYLOAD_SUB(_smc_stats, SMC_TYPE_D, rx, _len, _rc); \ |
e0e4b8fa | 132 | else \ |
194730a9 | 133 | SMC_STAT_PAYLOAD_SUB(_smc_stats, SMC_TYPE_R, rx, _len, _rc); \ |
e0e4b8fa GG |
134 | } \ |
135 | while (0) | |
136 | ||
194730a9 | 137 | #define SMC_STAT_RMB_SIZE_SUB(_smc_stats, _tech, k, _len) \ |
e0e4b8fa GG |
138 | do { \ |
139 | typeof(_len) _l = (_len); \ | |
140 | typeof(_tech) t = (_tech); \ | |
141 | int _pos = fls((_l) >> 13); \ | |
142 | int m = SMC_BUF_MAX - 1; \ | |
143 | _pos = (_pos < m) ? ((_l == 1 << (_pos + 12)) ? _pos - 1 : _pos) : m; \ | |
194730a9 | 144 | this_cpu_inc((*(_smc_stats)).smc[t].k ## _rmbsize.buf[_pos]); \ |
e0e4b8fa GG |
145 | } \ |
146 | while (0) | |
147 | ||
194730a9 GG |
148 | #define SMC_STAT_RMB_SUB(_smc_stats, type, t, key) \ |
149 | this_cpu_inc((*(_smc_stats)).smc[t].rmb ## _ ## key.type ## _cnt) | |
e0e4b8fa | 150 | |
194730a9 | 151 | #define SMC_STAT_RMB_SIZE(_smc, _is_smcd, _is_rx, _len) \ |
e0e4b8fa | 152 | do { \ |
194730a9 GG |
153 | struct net *_net = sock_net(&(_smc)->sk); \ |
154 | struct smc_stats __percpu *_smc_stats = _net->smc.smc_stats; \ | |
e0e4b8fa GG |
155 | typeof(_is_smcd) is_d = (_is_smcd); \ |
156 | typeof(_is_rx) is_r = (_is_rx); \ | |
157 | typeof(_len) l = (_len); \ | |
158 | if ((is_d) && (is_r)) \ | |
194730a9 | 159 | SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_D, rx, l); \ |
e0e4b8fa | 160 | if ((is_d) && !(is_r)) \ |
194730a9 | 161 | SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_D, tx, l); \ |
e0e4b8fa | 162 | if (!(is_d) && (is_r)) \ |
194730a9 | 163 | SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_R, rx, l); \ |
e0e4b8fa | 164 | if (!(is_d) && !(is_r)) \ |
194730a9 | 165 | SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_R, tx, l); \ |
e0e4b8fa GG |
166 | } \ |
167 | while (0) | |
168 | ||
194730a9 | 169 | #define SMC_STAT_RMB(_smc, type, _is_smcd, _is_rx) \ |
e0e4b8fa | 170 | do { \ |
194730a9 GG |
171 | struct net *net = sock_net(&(_smc)->sk); \ |
172 | struct smc_stats __percpu *_smc_stats = net->smc.smc_stats; \ | |
e0e4b8fa GG |
173 | typeof(_is_smcd) is_d = (_is_smcd); \ |
174 | typeof(_is_rx) is_r = (_is_rx); \ | |
175 | if ((is_d) && (is_r)) \ | |
194730a9 | 176 | SMC_STAT_RMB_SUB(_smc_stats, type, SMC_TYPE_D, rx); \ |
e0e4b8fa | 177 | if ((is_d) && !(is_r)) \ |
194730a9 | 178 | SMC_STAT_RMB_SUB(_smc_stats, type, SMC_TYPE_D, tx); \ |
e0e4b8fa | 179 | if (!(is_d) && (is_r)) \ |
194730a9 | 180 | SMC_STAT_RMB_SUB(_smc_stats, type, SMC_TYPE_R, rx); \ |
e0e4b8fa | 181 | if (!(is_d) && !(is_r)) \ |
194730a9 | 182 | SMC_STAT_RMB_SUB(_smc_stats, type, SMC_TYPE_R, tx); \ |
e0e4b8fa GG |
183 | } \ |
184 | while (0) | |
185 | ||
194730a9 GG |
186 | #define SMC_STAT_BUF_REUSE(smc, is_smcd, is_rx) \ |
187 | SMC_STAT_RMB(smc, reuse, is_smcd, is_rx) | |
e0e4b8fa | 188 | |
194730a9 GG |
189 | #define SMC_STAT_RMB_ALLOC(smc, is_smcd, is_rx) \ |
190 | SMC_STAT_RMB(smc, alloc, is_smcd, is_rx) | |
e0e4b8fa | 191 | |
194730a9 GG |
192 | #define SMC_STAT_RMB_DOWNGRADED(smc, is_smcd, is_rx) \ |
193 | SMC_STAT_RMB(smc, dgrade, is_smcd, is_rx) | |
e0e4b8fa | 194 | |
194730a9 GG |
195 | #define SMC_STAT_RMB_TX_PEER_FULL(smc, is_smcd) \ |
196 | SMC_STAT_RMB(smc, buf_full_peer, is_smcd, false) | |
e0e4b8fa | 197 | |
194730a9 GG |
198 | #define SMC_STAT_RMB_TX_FULL(smc, is_smcd) \ |
199 | SMC_STAT_RMB(smc, buf_full, is_smcd, false) | |
e0e4b8fa | 200 | |
194730a9 GG |
201 | #define SMC_STAT_RMB_TX_PEER_SIZE_SMALL(smc, is_smcd) \ |
202 | SMC_STAT_RMB(smc, buf_size_small_peer, is_smcd, false) | |
e0e4b8fa | 203 | |
194730a9 GG |
204 | #define SMC_STAT_RMB_TX_SIZE_SMALL(smc, is_smcd) \ |
205 | SMC_STAT_RMB(smc, buf_size_small, is_smcd, false) | |
e0e4b8fa | 206 | |
194730a9 GG |
207 | #define SMC_STAT_RMB_RX_SIZE_SMALL(smc, is_smcd) \ |
208 | SMC_STAT_RMB(smc, buf_size_small, is_smcd, true) | |
e0e4b8fa | 209 | |
194730a9 GG |
210 | #define SMC_STAT_RMB_RX_FULL(smc, is_smcd) \ |
211 | SMC_STAT_RMB(smc, buf_full, is_smcd, true) | |
e0e4b8fa | 212 | |
194730a9 | 213 | #define SMC_STAT_INC(_smc, type) \ |
e0e4b8fa | 214 | do { \ |
194730a9 GG |
215 | typeof(_smc) __smc = _smc; \ |
216 | bool is_smcd = !(__smc)->conn.lnk; \ | |
217 | struct net *net = sock_net(&(__smc)->sk); \ | |
218 | struct smc_stats __percpu *smc_stats = net->smc.smc_stats; \ | |
e0e4b8fa GG |
219 | if ((is_smcd)) \ |
220 | this_cpu_inc(smc_stats->smc[SMC_TYPE_D].type); \ | |
221 | else \ | |
222 | this_cpu_inc(smc_stats->smc[SMC_TYPE_R].type); \ | |
223 | } \ | |
224 | while (0) | |
225 | ||
194730a9 | 226 | #define SMC_STAT_CLNT_SUCC_INC(net, _aclc) \ |
e0e4b8fa GG |
227 | do { \ |
228 | typeof(_aclc) acl = (_aclc); \ | |
229 | bool is_v2 = (acl->hdr.version == SMC_V2); \ | |
230 | bool is_smcd = (acl->hdr.typev1 == SMC_TYPE_D); \ | |
194730a9 | 231 | struct smc_stats __percpu *smc_stats = (net)->smc.smc_stats; \ |
e0e4b8fa GG |
232 | if (is_v2 && is_smcd) \ |
233 | this_cpu_inc(smc_stats->smc[SMC_TYPE_D].clnt_v2_succ_cnt); \ | |
234 | else if (is_v2 && !is_smcd) \ | |
235 | this_cpu_inc(smc_stats->smc[SMC_TYPE_R].clnt_v2_succ_cnt); \ | |
236 | else if (!is_v2 && is_smcd) \ | |
237 | this_cpu_inc(smc_stats->smc[SMC_TYPE_D].clnt_v1_succ_cnt); \ | |
238 | else if (!is_v2 && !is_smcd) \ | |
239 | this_cpu_inc(smc_stats->smc[SMC_TYPE_R].clnt_v1_succ_cnt); \ | |
240 | } \ | |
241 | while (0) | |
242 | ||
194730a9 | 243 | #define SMC_STAT_SERV_SUCC_INC(net, _ini) \ |
e0e4b8fa GG |
244 | do { \ |
245 | typeof(_ini) i = (_ini); \ | |
e0e4b8fa | 246 | bool is_smcd = (i->is_smcd); \ |
6912e724 GW |
247 | u8 version = is_smcd ? i->smcd_version : i->smcr_version; \ |
248 | bool is_v2 = (version & SMC_V2); \ | |
194730a9 | 249 | typeof(net->smc.smc_stats) smc_stats = (net)->smc.smc_stats; \ |
e0e4b8fa GG |
250 | if (is_v2 && is_smcd) \ |
251 | this_cpu_inc(smc_stats->smc[SMC_TYPE_D].srv_v2_succ_cnt); \ | |
252 | else if (is_v2 && !is_smcd) \ | |
253 | this_cpu_inc(smc_stats->smc[SMC_TYPE_R].srv_v2_succ_cnt); \ | |
254 | else if (!is_v2 && is_smcd) \ | |
255 | this_cpu_inc(smc_stats->smc[SMC_TYPE_D].srv_v1_succ_cnt); \ | |
256 | else if (!is_v2 && !is_smcd) \ | |
257 | this_cpu_inc(smc_stats->smc[SMC_TYPE_R].srv_v1_succ_cnt); \ | |
258 | } \ | |
259 | while (0) | |
260 | ||
8c40602b | 261 | int smc_nl_get_stats(struct sk_buff *skb, struct netlink_callback *cb); |
f0dd7bf5 | 262 | int smc_nl_get_fback_stats(struct sk_buff *skb, struct netlink_callback *cb); |
194730a9 GG |
263 | int smc_stats_init(struct net *net); |
264 | void smc_stats_exit(struct net *net); | |
e0e4b8fa GG |
265 | |
266 | #endif /* NET_SMC_SMC_STATS_H_ */ |