summaryrefslogtreecommitdiffstats
path: root/net/smc/smc_stats.h
blob: e19177ce409230212f0e71046038f2e1138862c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Shared Memory Communications over RDMA (SMC-R) and RoCE
 *
 * Macros for SMC statistics
 *
 * Copyright IBM Corp. 2021
 *
 * Author(s):  Guvenc Gulce
 */

#ifndef NET_SMC_SMC_STATS_H_
#define NET_SMC_SMC_STATS_H_
#include <linux/init.h>
#include <linux/mutex.h>
#include <linux/percpu.h>
#include <linux/ctype.h>
#include <linux/smc.h>

#include "smc_clc.h"

#define SMC_MAX_FBACK_RSN_CNT 36

enum {
	SMC_BUF_8K,
	SMC_BUF_16K,
	SMC_BUF_32K,
	SMC_BUF_64K,
	SMC_BUF_128K,
	SMC_BUF_256K,
	SMC_BUF_512K,
	SMC_BUF_1024K,
	SMC_BUF_G_1024K,
	SMC_BUF_MAX,
};

struct smc_stats_fback {
	int	fback_code;
	u16	count;
};

struct smc_stats_rsn {
	struct	smc_stats_fback srv[SMC_MAX_FBACK_RSN_CNT];
	struct	smc_stats_fback clnt[SMC_MAX_FBACK_RSN_CNT];
	u64			srv_fback_cnt;
	u64			clnt_fback_cnt;
};

struct smc_stats_rmbcnt {
	u64	buf_size_small_peer_cnt;
	u64	buf_size_small_cnt;
	u64	buf_full_peer_cnt;
	u64	buf_full_cnt;
	u64	reuse_cnt;
	u64	alloc_cnt;
	u64	dgrade_cnt;
};

struct smc_stats_memsize {
	u64	buf[SMC_BUF_MAX];
};

struct smc_stats_tech {
	struct smc_stats_memsize tx_rmbsize;
	struct smc_stats_memsize rx_rmbsize;
	struct smc_stats_memsize tx_pd;
	struct smc_stats_memsize rx_pd;
	struct smc_stats_rmbcnt rmb_tx;
	struct smc_stats_rmbcnt rmb_rx;
	u64			clnt_v1_succ_cnt;
	u64			clnt_v2_succ_cnt;
	u64			srv_v1_succ_cnt;
	u64			srv_v2_succ_cnt;
	u64			urg_data_cnt;
	u64			splice_cnt;
	u64			cork_cnt;
	u64			ndly_cnt;
	u64			rx_bytes;
	u64			tx_bytes;
	u64			rx_cnt;
	u64			tx_cnt;
};

struct smc_stats {
	struct smc_stats_tech	smc[2];
	u64			clnt_hshake_err_cnt;
	u64			srv_hshake_err_cnt;
};

#define SMC_STAT_PAYLOAD_SUB(_smc_stats, _tech, key, _len, _rc) \
do { \
	typeof(_smc_stats) stats = (_smc_stats); \
	typeof(_tech) t = (_tech); \
	typeof(_len) l = (_len); \
	int _pos; \
	typeof(_rc) r = (_rc); \
	int m = SMC_BUF_MAX - 1; \
	this_cpu_inc((*stats).smc[t].key ## _cnt); \
	if (r <= 0 || l <= 0) \
		break; \
	_pos = fls64((l - 1) >> 13); \
	_pos = (_pos <= m) ? _pos : m; \
	this_cpu_inc((*stats).smc[t].key ## _pd.buf[_pos]); \
	this_cpu_add((*stats).smc[t].key ## _bytes, r); \
} \
while (0)

#define SMC_STAT_TX_PAYLOAD(_smc, length, rcode) \
do { \
	typeof(_smc) __smc = _smc; \
	struct net *_net = sock_net(&__smc->sk); \
	struct smc_stats __percpu *_smc_stats = _net->smc.smc_stats; \
	typeof(length) _len = (length); \
	typeof(rcode) _rc = (rcode); \
	bool is_smcd = !__smc->conn.lnk; \
	if (is_smcd) \
		SMC_STAT_PAYLOAD_SUB(_smc_stats, SMC_TYPE_D, tx, _len, _rc); \
	else \
		SMC_STAT_PAYLOAD_SUB(_smc_stats, SMC_TYPE_R, tx, _len, _rc); \
} \
while (0)

#define SMC_STAT_RX_PAYLOAD(_smc, length, rcode) \
do { \
	typeof(_smc) __smc = _smc; \
	struct net *_net = sock_net(&__smc->sk); \
	struct smc_stats __percpu *_smc_stats = _net->smc.smc_stats; \
	typeof(length) _len = (length); \
	typeof(rcode) _rc = (rcode); \
	bool is_smcd = !__smc->conn.lnk; \
	if (is_smcd) \
		SMC_STAT_PAYLOAD_SUB(_smc_stats, SMC_TYPE_D, rx, _len, _rc); \
	else \
		SMC_STAT_PAYLOAD_SUB(_smc_stats, SMC_TYPE_R, rx, _len, _rc); \
} \
while (0)

#define SMC_STAT_RMB_SIZE_SUB(_smc_stats, _tech, k, _len) \
do { \
	typeof(_len) _l = (_len); \
	typeof(_tech) t = (_tech); \
	int _pos; \
	int m = SMC_BUF_MAX - 1; \
	if (_l <= 0) \
		break; \
	_pos = fls((_l - 1) >> 13); \
	_pos = (_pos <= m) ? _pos : m; \
	this_cpu_inc((*(_smc_stats)).smc[t].k ## _rmbsize.buf[_pos]); \
} \
while (0)

#define SMC_STAT_RMB_SUB(_smc_stats, type, t, key) \
	this_cpu_inc((*(_smc_stats)).smc[t].rmb ## _ ## key.type ## _cnt)

#define SMC_STAT_RMB_SIZE(_smc, _is_smcd, _is_rx, _len) \
do { \
	struct net *_net = sock_net(&(_smc)->sk); \
	struct smc_stats __percpu *_smc_stats = _net->smc.smc_stats; \
	typeof(_is_smcd) is_d = (_is_smcd); \
	typeof(_is_rx) is_r = (_is_rx); \
	typeof(_len) l = (_len); \
	if ((is_d) && (is_r)) \
		SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_D, rx, l); \
	if ((is_d) && !(is_r)) \
		SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_D, tx, l); \
	if (!(is_d) && (is_r)) \
		SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_R, rx, l); \
	if (!(is_d) && !(is_r)) \
		SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_R, tx, l); \
} \
while (0)

#define SMC_STAT_RMB(_smc, type, _is_smcd, _is_rx) \
do { \
	struct net *net = sock_net(&(_smc)->sk); \
	struct smc_stats __percpu *_smc_stats = net->smc.smc_stats; \
	typeof(_is_smcd) is_d = (_is_smcd); \
	typeof(_is_rx) is_r = (_is_rx); \
	if ((is_d) && (is_r)) \
		SMC_STAT_RMB_SUB(_smc_stats, type, SMC_TYPE_D, rx); \
	if ((is_d) && !(is_r)) \
		SMC_STAT_RMB_SUB(_smc_stats, type, SMC_TYPE_D, tx); \
	if (!(is_d) && (is_r)) \
		SMC_STAT_RMB_SUB(_smc_stats, type, SMC_TYPE_R, rx); \
	if (!(is_d) && !(is_r)) \
		SMC_STAT_RMB_SUB(_smc_stats, type, SMC_TYPE_R, tx); \
} \
while (0)

#define SMC_STAT_BUF_REUSE(smc, is_smcd, is_rx) \
	SMC_STAT_RMB(smc, reuse, is_smcd, is_rx)

#define SMC_STAT_RMB_ALLOC(smc, is_smcd, is_rx) \
	SMC_STAT_RMB(smc, alloc, is_smcd, is_rx)

#define SMC_STAT_RMB_DOWNGRADED(smc, is_smcd, is_rx) \
	SMC_STAT_RMB(smc, dgrade, is_smcd, is_rx)

#define SMC_STAT_RMB_TX_PEER_FULL(smc, is_smcd) \
	SMC_STAT_RMB(smc, buf_full_peer, is_smcd, false)

#define SMC_STAT_RMB_TX_FULL(smc, is_smcd) \
	SMC_STAT_RMB(smc, buf_full, is_smcd, false)

#define SMC_STAT_RMB_TX_PEER_SIZE_SMALL(smc, is_smcd) \
	SMC_STAT_RMB(smc, buf_size_small_peer, is_smcd, false)

#define SMC_STAT_RMB_TX_SIZE_SMALL(smc, is_smcd) \
	SMC_STAT_RMB(smc, buf_size_small, is_smcd, false)

#define SMC_STAT_RMB_RX_SIZE_SMALL(smc, is_smcd) \
	SMC_STAT_RMB(smc, buf_size_small, is_smcd, true)

#define SMC_STAT_RMB_RX_FULL(smc, is_smcd) \
	SMC_STAT_RMB(smc, buf_full, is_smcd, true)

#define SMC_STAT_INC(_smc, type) \
do { \
	typeof(_smc) __smc = _smc; \
	bool is_smcd = !(__smc)->conn.lnk; \
	struct net *net = sock_net(&(__smc)->sk); \
	struct smc_stats __percpu *smc_stats = net->smc.smc_stats; \
	if ((is_smcd)) \
		this_cpu_inc(smc_stats->smc[SMC_TYPE_D].type); \
	else \
		this_cpu_inc(smc_stats->smc[SMC_TYPE_R].type); \
} \
while (0)

#define SMC_STAT_CLNT_SUCC_INC(net, _aclc) \
do { \
	typeof(_aclc) acl = (_aclc); \
	bool is_v2 = (acl->hdr.version == SMC_V2); \
	bool is_smcd = (acl->hdr.typev1 == SMC_TYPE_D); \
	struct smc_stats __percpu *smc_stats = (net)->smc.smc_stats; \
	if (is_v2 && is_smcd) \
		this_cpu_inc(smc_stats->smc[SMC_TYPE_D].clnt_v2_succ_cnt); \
	else if (is_v2 && !is_smcd) \
		this_cpu_inc(smc_stats->smc[SMC_TYPE_R].clnt_v2_succ_cnt); \
	else if (!is_v2 && is_smcd) \
		this_cpu_inc(smc_stats->smc[SMC_TYPE_D].clnt_v1_succ_cnt); \
	else if (!is_v2 && !is_smcd) \
		this_cpu_inc(smc_stats->smc[SMC_TYPE_R].clnt_v1_succ_cnt); \
} \
while (0)

#define SMC_STAT_SERV_SUCC_INC(net, _ini) \
do { \
	typeof(_ini) i = (_ini); \
	bool is_smcd = (i->is_smcd); \
	u8 version = is_smcd ? i->smcd_version : i->smcr_version; \
	bool is_v2 = (version & SMC_V2); \
	typeof(net->smc.smc_stats) smc_stats = (net)->smc.smc_stats; \
	if (is_v2 && is_smcd) \
		this_cpu_inc(smc_stats->smc[SMC_TYPE_D].srv_v2_succ_cnt); \
	else if (is_v2 && !is_smcd) \
		this_cpu_inc(smc_stats->smc[SMC_TYPE_R].srv_v2_succ_cnt); \
	else if (!is_v2 && is_smcd) \
		this_cpu_inc(smc_stats->smc[SMC_TYPE_D].srv_v1_succ_cnt); \
	else if (!is_v2 && !is_smcd) \
		this_cpu_inc(smc_stats->smc[SMC_TYPE_R].srv_v1_succ_cnt); \
} \
while (0)

int smc_nl_get_stats(struct sk_buff *skb, struct netlink_callback *cb);
int smc_nl_get_fback_stats(struct sk_buff *skb, struct netlink_callback *cb);
int smc_stats_init(struct net *net);
void smc_stats_exit(struct net *net);

#endif /* NET_SMC_SMC_STATS_H_ */