qib_debugfs.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /*
  2. * Copyright (c) 2013 - 2017 Intel Corporation. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #include <linux/debugfs.h>
  33. #include <linux/seq_file.h>
  34. #include <linux/kernel.h>
  35. #include <linux/export.h>
  36. #include "qib.h"
  37. #include "qib_verbs.h"
  38. #include "qib_debugfs.h"
  39. static struct dentry *qib_dbg_root;
  40. #define DEBUGFS_FILE(name) \
  41. static const struct seq_operations _##name##_seq_ops = { \
  42. .start = _##name##_seq_start, \
  43. .next = _##name##_seq_next, \
  44. .stop = _##name##_seq_stop, \
  45. .show = _##name##_seq_show \
  46. }; \
  47. static int _##name##_open(struct inode *inode, struct file *s) \
  48. { \
  49. struct seq_file *seq; \
  50. int ret; \
  51. ret = seq_open(s, &_##name##_seq_ops); \
  52. if (ret) \
  53. return ret; \
  54. seq = s->private_data; \
  55. seq->private = inode->i_private; \
  56. return 0; \
  57. } \
  58. static const struct file_operations _##name##_file_ops = { \
  59. .owner = THIS_MODULE, \
  60. .open = _##name##_open, \
  61. .read = seq_read, \
  62. .llseek = seq_lseek, \
  63. .release = seq_release \
  64. };
  65. static void *_opcode_stats_seq_start(struct seq_file *s, loff_t *pos)
  66. {
  67. struct qib_opcode_stats_perctx *opstats;
  68. if (*pos >= ARRAY_SIZE(opstats->stats))
  69. return NULL;
  70. return pos;
  71. }
  72. static void *_opcode_stats_seq_next(struct seq_file *s, void *v, loff_t *pos)
  73. {
  74. struct qib_opcode_stats_perctx *opstats;
  75. ++*pos;
  76. if (*pos >= ARRAY_SIZE(opstats->stats))
  77. return NULL;
  78. return pos;
  79. }
  80. static void _opcode_stats_seq_stop(struct seq_file *s, void *v)
  81. {
  82. /* nothing allocated */
  83. }
  84. static int _opcode_stats_seq_show(struct seq_file *s, void *v)
  85. {
  86. loff_t *spos = v;
  87. loff_t i = *spos, j;
  88. u64 n_packets = 0, n_bytes = 0;
  89. struct qib_ibdev *ibd = (struct qib_ibdev *)s->private;
  90. struct qib_devdata *dd = dd_from_dev(ibd);
  91. for (j = 0; j < dd->first_user_ctxt; j++) {
  92. if (!dd->rcd[j])
  93. continue;
  94. n_packets += dd->rcd[j]->opstats->stats[i].n_packets;
  95. n_bytes += dd->rcd[j]->opstats->stats[i].n_bytes;
  96. }
  97. if (!n_packets && !n_bytes)
  98. return SEQ_SKIP;
  99. seq_printf(s, "%02llx %llu/%llu\n", i,
  100. (unsigned long long) n_packets,
  101. (unsigned long long) n_bytes);
  102. return 0;
  103. }
  104. DEBUGFS_FILE(opcode_stats)
  105. static void *_ctx_stats_seq_start(struct seq_file *s, loff_t *pos)
  106. {
  107. struct qib_ibdev *ibd = (struct qib_ibdev *)s->private;
  108. struct qib_devdata *dd = dd_from_dev(ibd);
  109. if (!*pos)
  110. return SEQ_START_TOKEN;
  111. if (*pos >= dd->first_user_ctxt)
  112. return NULL;
  113. return pos;
  114. }
  115. static void *_ctx_stats_seq_next(struct seq_file *s, void *v, loff_t *pos)
  116. {
  117. struct qib_ibdev *ibd = (struct qib_ibdev *)s->private;
  118. struct qib_devdata *dd = dd_from_dev(ibd);
  119. if (v == SEQ_START_TOKEN)
  120. return pos;
  121. ++*pos;
  122. if (*pos >= dd->first_user_ctxt)
  123. return NULL;
  124. return pos;
  125. }
  126. static void _ctx_stats_seq_stop(struct seq_file *s, void *v)
  127. {
  128. /* nothing allocated */
  129. }
  130. static int _ctx_stats_seq_show(struct seq_file *s, void *v)
  131. {
  132. loff_t *spos;
  133. loff_t i, j;
  134. u64 n_packets = 0;
  135. struct qib_ibdev *ibd = (struct qib_ibdev *)s->private;
  136. struct qib_devdata *dd = dd_from_dev(ibd);
  137. if (v == SEQ_START_TOKEN) {
  138. seq_puts(s, "Ctx:npkts\n");
  139. return 0;
  140. }
  141. spos = v;
  142. i = *spos;
  143. if (!dd->rcd[i])
  144. return SEQ_SKIP;
  145. for (j = 0; j < ARRAY_SIZE(dd->rcd[i]->opstats->stats); j++)
  146. n_packets += dd->rcd[i]->opstats->stats[j].n_packets;
  147. if (!n_packets)
  148. return SEQ_SKIP;
  149. seq_printf(s, " %llu:%llu\n", i, n_packets);
  150. return 0;
  151. }
  152. DEBUGFS_FILE(ctx_stats)
  153. static void *_qp_stats_seq_start(struct seq_file *s, loff_t *pos)
  154. __acquires(RCU)
  155. {
  156. struct rvt_qp_iter *iter;
  157. loff_t n = *pos;
  158. iter = rvt_qp_iter_init(s->private, 0, NULL);
  159. /* stop calls rcu_read_unlock */
  160. rcu_read_lock();
  161. if (!iter)
  162. return NULL;
  163. do {
  164. if (rvt_qp_iter_next(iter)) {
  165. kfree(iter);
  166. return NULL;
  167. }
  168. } while (n--);
  169. return iter;
  170. }
  171. static void *_qp_stats_seq_next(struct seq_file *s, void *iter_ptr,
  172. loff_t *pos)
  173. __must_hold(RCU)
  174. {
  175. struct rvt_qp_iter *iter = iter_ptr;
  176. (*pos)++;
  177. if (rvt_qp_iter_next(iter)) {
  178. kfree(iter);
  179. return NULL;
  180. }
  181. return iter;
  182. }
  183. static void _qp_stats_seq_stop(struct seq_file *s, void *iter_ptr)
  184. __releases(RCU)
  185. {
  186. rcu_read_unlock();
  187. }
  188. static int _qp_stats_seq_show(struct seq_file *s, void *iter_ptr)
  189. {
  190. struct rvt_qp_iter *iter = iter_ptr;
  191. if (!iter)
  192. return 0;
  193. qib_qp_iter_print(s, iter);
  194. return 0;
  195. }
  196. DEBUGFS_FILE(qp_stats)
  197. void qib_dbg_ibdev_init(struct qib_ibdev *ibd)
  198. {
  199. struct dentry *root;
  200. char name[10];
  201. snprintf(name, sizeof(name), "qib%d", dd_from_dev(ibd)->unit);
  202. root = debugfs_create_dir(name, qib_dbg_root);
  203. ibd->qib_ibdev_dbg = root;
  204. debugfs_create_file("opcode_stats", 0400, root, ibd,
  205. &_opcode_stats_file_ops);
  206. debugfs_create_file("ctx_stats", 0400, root, ibd, &_ctx_stats_file_ops);
  207. debugfs_create_file("qp_stats", 0400, root, ibd, &_qp_stats_file_ops);
  208. }
  209. void qib_dbg_ibdev_exit(struct qib_ibdev *ibd)
  210. {
  211. if (!qib_dbg_root)
  212. goto out;
  213. debugfs_remove_recursive(ibd->qib_ibdev_dbg);
  214. out:
  215. ibd->qib_ibdev_dbg = NULL;
  216. }
  217. void qib_dbg_init(void)
  218. {
  219. qib_dbg_root = debugfs_create_dir(QIB_DRV_NAME, NULL);
  220. }
  221. void qib_dbg_exit(void)
  222. {
  223. debugfs_remove_recursive(qib_dbg_root);
  224. qib_dbg_root = NULL;
  225. }