smc_stats.h 7.4 KB

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