0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef NET_SMC_SMC_STATS_H_
0013 #define NET_SMC_SMC_STATS_H_
0014 #include <linux/init.h>
0015 #include <linux/mutex.h>
0016 #include <linux/percpu.h>
0017 #include <linux/ctype.h>
0018 #include <linux/smc.h>
0019
0020 #include "smc_clc.h"
0021
0022 #define SMC_MAX_FBACK_RSN_CNT 30
0023
0024 enum {
0025 SMC_BUF_8K,
0026 SMC_BUF_16K,
0027 SMC_BUF_32K,
0028 SMC_BUF_64K,
0029 SMC_BUF_128K,
0030 SMC_BUF_256K,
0031 SMC_BUF_512K,
0032 SMC_BUF_1024K,
0033 SMC_BUF_G_1024K,
0034 SMC_BUF_MAX,
0035 };
0036
0037 struct smc_stats_fback {
0038 int fback_code;
0039 u16 count;
0040 };
0041
0042 struct smc_stats_rsn {
0043 struct smc_stats_fback srv[SMC_MAX_FBACK_RSN_CNT];
0044 struct smc_stats_fback clnt[SMC_MAX_FBACK_RSN_CNT];
0045 u64 srv_fback_cnt;
0046 u64 clnt_fback_cnt;
0047 };
0048
0049 struct smc_stats_rmbcnt {
0050 u64 buf_size_small_peer_cnt;
0051 u64 buf_size_small_cnt;
0052 u64 buf_full_peer_cnt;
0053 u64 buf_full_cnt;
0054 u64 reuse_cnt;
0055 u64 alloc_cnt;
0056 u64 dgrade_cnt;
0057 };
0058
0059 struct smc_stats_memsize {
0060 u64 buf[SMC_BUF_MAX];
0061 };
0062
0063 struct smc_stats_tech {
0064 struct smc_stats_memsize tx_rmbsize;
0065 struct smc_stats_memsize rx_rmbsize;
0066 struct smc_stats_memsize tx_pd;
0067 struct smc_stats_memsize rx_pd;
0068 struct smc_stats_rmbcnt rmb_tx;
0069 struct smc_stats_rmbcnt rmb_rx;
0070 u64 clnt_v1_succ_cnt;
0071 u64 clnt_v2_succ_cnt;
0072 u64 srv_v1_succ_cnt;
0073 u64 srv_v2_succ_cnt;
0074 u64 sendpage_cnt;
0075 u64 urg_data_cnt;
0076 u64 splice_cnt;
0077 u64 cork_cnt;
0078 u64 ndly_cnt;
0079 u64 rx_bytes;
0080 u64 tx_bytes;
0081 u64 rx_cnt;
0082 u64 tx_cnt;
0083 };
0084
0085 struct smc_stats {
0086 struct smc_stats_tech smc[2];
0087 u64 clnt_hshake_err_cnt;
0088 u64 srv_hshake_err_cnt;
0089 };
0090
0091 #define SMC_STAT_PAYLOAD_SUB(_smc_stats, _tech, key, _len, _rc) \
0092 do { \
0093 typeof(_smc_stats) stats = (_smc_stats); \
0094 typeof(_tech) t = (_tech); \
0095 typeof(_len) l = (_len); \
0096 int _pos = fls64((l) >> 13); \
0097 typeof(_rc) r = (_rc); \
0098 int m = SMC_BUF_MAX - 1; \
0099 this_cpu_inc((*stats).smc[t].key ## _cnt); \
0100 if (r <= 0) \
0101 break; \
0102 _pos = (_pos < m) ? ((l == 1 << (_pos + 12)) ? _pos - 1 : _pos) : m; \
0103 this_cpu_inc((*stats).smc[t].key ## _pd.buf[_pos]); \
0104 this_cpu_add((*stats).smc[t].key ## _bytes, r); \
0105 } \
0106 while (0)
0107
0108 #define SMC_STAT_TX_PAYLOAD(_smc, length, rcode) \
0109 do { \
0110 typeof(_smc) __smc = _smc; \
0111 struct net *_net = sock_net(&__smc->sk); \
0112 struct smc_stats __percpu *_smc_stats = _net->smc.smc_stats; \
0113 typeof(length) _len = (length); \
0114 typeof(rcode) _rc = (rcode); \
0115 bool is_smcd = !__smc->conn.lnk; \
0116 if (is_smcd) \
0117 SMC_STAT_PAYLOAD_SUB(_smc_stats, SMC_TYPE_D, tx, _len, _rc); \
0118 else \
0119 SMC_STAT_PAYLOAD_SUB(_smc_stats, SMC_TYPE_R, tx, _len, _rc); \
0120 } \
0121 while (0)
0122
0123 #define SMC_STAT_RX_PAYLOAD(_smc, length, rcode) \
0124 do { \
0125 typeof(_smc) __smc = _smc; \
0126 struct net *_net = sock_net(&__smc->sk); \
0127 struct smc_stats __percpu *_smc_stats = _net->smc.smc_stats; \
0128 typeof(length) _len = (length); \
0129 typeof(rcode) _rc = (rcode); \
0130 bool is_smcd = !__smc->conn.lnk; \
0131 if (is_smcd) \
0132 SMC_STAT_PAYLOAD_SUB(_smc_stats, SMC_TYPE_D, rx, _len, _rc); \
0133 else \
0134 SMC_STAT_PAYLOAD_SUB(_smc_stats, SMC_TYPE_R, rx, _len, _rc); \
0135 } \
0136 while (0)
0137
0138 #define SMC_STAT_RMB_SIZE_SUB(_smc_stats, _tech, k, _len) \
0139 do { \
0140 typeof(_len) _l = (_len); \
0141 typeof(_tech) t = (_tech); \
0142 int _pos = fls((_l) >> 13); \
0143 int m = SMC_BUF_MAX - 1; \
0144 _pos = (_pos < m) ? ((_l == 1 << (_pos + 12)) ? _pos - 1 : _pos) : m; \
0145 this_cpu_inc((*(_smc_stats)).smc[t].k ## _rmbsize.buf[_pos]); \
0146 } \
0147 while (0)
0148
0149 #define SMC_STAT_RMB_SUB(_smc_stats, type, t, key) \
0150 this_cpu_inc((*(_smc_stats)).smc[t].rmb ## _ ## key.type ## _cnt)
0151
0152 #define SMC_STAT_RMB_SIZE(_smc, _is_smcd, _is_rx, _len) \
0153 do { \
0154 struct net *_net = sock_net(&(_smc)->sk); \
0155 struct smc_stats __percpu *_smc_stats = _net->smc.smc_stats; \
0156 typeof(_is_smcd) is_d = (_is_smcd); \
0157 typeof(_is_rx) is_r = (_is_rx); \
0158 typeof(_len) l = (_len); \
0159 if ((is_d) && (is_r)) \
0160 SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_D, rx, l); \
0161 if ((is_d) && !(is_r)) \
0162 SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_D, tx, l); \
0163 if (!(is_d) && (is_r)) \
0164 SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_R, rx, l); \
0165 if (!(is_d) && !(is_r)) \
0166 SMC_STAT_RMB_SIZE_SUB(_smc_stats, SMC_TYPE_R, tx, l); \
0167 } \
0168 while (0)
0169
0170 #define SMC_STAT_RMB(_smc, type, _is_smcd, _is_rx) \
0171 do { \
0172 struct net *net = sock_net(&(_smc)->sk); \
0173 struct smc_stats __percpu *_smc_stats = net->smc.smc_stats; \
0174 typeof(_is_smcd) is_d = (_is_smcd); \
0175 typeof(_is_rx) is_r = (_is_rx); \
0176 if ((is_d) && (is_r)) \
0177 SMC_STAT_RMB_SUB(_smc_stats, type, SMC_TYPE_D, rx); \
0178 if ((is_d) && !(is_r)) \
0179 SMC_STAT_RMB_SUB(_smc_stats, type, SMC_TYPE_D, tx); \
0180 if (!(is_d) && (is_r)) \
0181 SMC_STAT_RMB_SUB(_smc_stats, type, SMC_TYPE_R, rx); \
0182 if (!(is_d) && !(is_r)) \
0183 SMC_STAT_RMB_SUB(_smc_stats, type, SMC_TYPE_R, tx); \
0184 } \
0185 while (0)
0186
0187 #define SMC_STAT_BUF_REUSE(smc, is_smcd, is_rx) \
0188 SMC_STAT_RMB(smc, reuse, is_smcd, is_rx)
0189
0190 #define SMC_STAT_RMB_ALLOC(smc, is_smcd, is_rx) \
0191 SMC_STAT_RMB(smc, alloc, is_smcd, is_rx)
0192
0193 #define SMC_STAT_RMB_DOWNGRADED(smc, is_smcd, is_rx) \
0194 SMC_STAT_RMB(smc, dgrade, is_smcd, is_rx)
0195
0196 #define SMC_STAT_RMB_TX_PEER_FULL(smc, is_smcd) \
0197 SMC_STAT_RMB(smc, buf_full_peer, is_smcd, false)
0198
0199 #define SMC_STAT_RMB_TX_FULL(smc, is_smcd) \
0200 SMC_STAT_RMB(smc, buf_full, is_smcd, false)
0201
0202 #define SMC_STAT_RMB_TX_PEER_SIZE_SMALL(smc, is_smcd) \
0203 SMC_STAT_RMB(smc, buf_size_small_peer, is_smcd, false)
0204
0205 #define SMC_STAT_RMB_TX_SIZE_SMALL(smc, is_smcd) \
0206 SMC_STAT_RMB(smc, buf_size_small, is_smcd, false)
0207
0208 #define SMC_STAT_RMB_RX_SIZE_SMALL(smc, is_smcd) \
0209 SMC_STAT_RMB(smc, buf_size_small, is_smcd, true)
0210
0211 #define SMC_STAT_RMB_RX_FULL(smc, is_smcd) \
0212 SMC_STAT_RMB(smc, buf_full, is_smcd, true)
0213
0214 #define SMC_STAT_INC(_smc, type) \
0215 do { \
0216 typeof(_smc) __smc = _smc; \
0217 bool is_smcd = !(__smc)->conn.lnk; \
0218 struct net *net = sock_net(&(__smc)->sk); \
0219 struct smc_stats __percpu *smc_stats = net->smc.smc_stats; \
0220 if ((is_smcd)) \
0221 this_cpu_inc(smc_stats->smc[SMC_TYPE_D].type); \
0222 else \
0223 this_cpu_inc(smc_stats->smc[SMC_TYPE_R].type); \
0224 } \
0225 while (0)
0226
0227 #define SMC_STAT_CLNT_SUCC_INC(net, _aclc) \
0228 do { \
0229 typeof(_aclc) acl = (_aclc); \
0230 bool is_v2 = (acl->hdr.version == SMC_V2); \
0231 bool is_smcd = (acl->hdr.typev1 == SMC_TYPE_D); \
0232 struct smc_stats __percpu *smc_stats = (net)->smc.smc_stats; \
0233 if (is_v2 && is_smcd) \
0234 this_cpu_inc(smc_stats->smc[SMC_TYPE_D].clnt_v2_succ_cnt); \
0235 else if (is_v2 && !is_smcd) \
0236 this_cpu_inc(smc_stats->smc[SMC_TYPE_R].clnt_v2_succ_cnt); \
0237 else if (!is_v2 && is_smcd) \
0238 this_cpu_inc(smc_stats->smc[SMC_TYPE_D].clnt_v1_succ_cnt); \
0239 else if (!is_v2 && !is_smcd) \
0240 this_cpu_inc(smc_stats->smc[SMC_TYPE_R].clnt_v1_succ_cnt); \
0241 } \
0242 while (0)
0243
0244 #define SMC_STAT_SERV_SUCC_INC(net, _ini) \
0245 do { \
0246 typeof(_ini) i = (_ini); \
0247 bool is_v2 = (i->smcd_version & SMC_V2); \
0248 bool is_smcd = (i->is_smcd); \
0249 typeof(net->smc.smc_stats) smc_stats = (net)->smc.smc_stats; \
0250 if (is_v2 && is_smcd) \
0251 this_cpu_inc(smc_stats->smc[SMC_TYPE_D].srv_v2_succ_cnt); \
0252 else if (is_v2 && !is_smcd) \
0253 this_cpu_inc(smc_stats->smc[SMC_TYPE_R].srv_v2_succ_cnt); \
0254 else if (!is_v2 && is_smcd) \
0255 this_cpu_inc(smc_stats->smc[SMC_TYPE_D].srv_v1_succ_cnt); \
0256 else if (!is_v2 && !is_smcd) \
0257 this_cpu_inc(smc_stats->smc[SMC_TYPE_R].srv_v1_succ_cnt); \
0258 } \
0259 while (0)
0260
0261 int smc_nl_get_stats(struct sk_buff *skb, struct netlink_callback *cb);
0262 int smc_nl_get_fback_stats(struct sk_buff *skb, struct netlink_callback *cb);
0263 int smc_stats_init(struct net *net);
0264 void smc_stats_exit(struct net *net);
0265
0266 #endif