iaa_crypto_stats.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright(c) 2021 Intel Corporation. All rights rsvd. */
  3. #include <linux/module.h>
  4. #include <linux/kernel.h>
  5. #include <linux/highmem.h>
  6. #include <linux/mm.h>
  7. #include <linux/slab.h>
  8. #include <linux/delay.h>
  9. #include <linux/smp.h>
  10. #include <uapi/linux/idxd.h>
  11. #include <linux/idxd.h>
  12. #include <linux/dmaengine.h>
  13. #include "../../dma/idxd/idxd.h"
  14. #include <linux/debugfs.h>
  15. #include <crypto/internal/acompress.h>
  16. #include "iaa_crypto.h"
  17. #include "iaa_crypto_stats.h"
  18. static atomic64_t total_comp_calls;
  19. static atomic64_t total_decomp_calls;
  20. static atomic64_t total_sw_decomp_calls;
  21. static atomic64_t total_comp_bytes_out;
  22. static atomic64_t total_decomp_bytes_in;
  23. static atomic64_t total_completion_einval_errors;
  24. static atomic64_t total_completion_timeout_errors;
  25. static atomic64_t total_completion_comp_buf_overflow_errors;
  26. static struct dentry *iaa_crypto_debugfs_root;
  27. void update_total_comp_calls(void)
  28. {
  29. atomic64_inc(&total_comp_calls);
  30. }
  31. void update_total_comp_bytes_out(int n)
  32. {
  33. atomic64_add(n, &total_comp_bytes_out);
  34. }
  35. void update_total_decomp_calls(void)
  36. {
  37. atomic64_inc(&total_decomp_calls);
  38. }
  39. void update_total_sw_decomp_calls(void)
  40. {
  41. atomic64_inc(&total_sw_decomp_calls);
  42. }
  43. void update_total_decomp_bytes_in(int n)
  44. {
  45. atomic64_add(n, &total_decomp_bytes_in);
  46. }
  47. void update_completion_einval_errs(void)
  48. {
  49. atomic64_inc(&total_completion_einval_errors);
  50. }
  51. void update_completion_timeout_errs(void)
  52. {
  53. atomic64_inc(&total_completion_timeout_errors);
  54. }
  55. void update_completion_comp_buf_overflow_errs(void)
  56. {
  57. atomic64_inc(&total_completion_comp_buf_overflow_errors);
  58. }
  59. void update_wq_comp_calls(struct idxd_wq *idxd_wq)
  60. {
  61. struct iaa_wq *wq = idxd_wq_get_private(idxd_wq);
  62. atomic64_inc(&wq->comp_calls);
  63. atomic64_inc(&wq->iaa_device->comp_calls);
  64. }
  65. void update_wq_comp_bytes(struct idxd_wq *idxd_wq, int n)
  66. {
  67. struct iaa_wq *wq = idxd_wq_get_private(idxd_wq);
  68. atomic64_add(n, &wq->comp_bytes);
  69. atomic64_add(n, &wq->iaa_device->comp_bytes);
  70. }
  71. void update_wq_decomp_calls(struct idxd_wq *idxd_wq)
  72. {
  73. struct iaa_wq *wq = idxd_wq_get_private(idxd_wq);
  74. atomic64_inc(&wq->decomp_calls);
  75. atomic64_inc(&wq->iaa_device->decomp_calls);
  76. }
  77. void update_wq_decomp_bytes(struct idxd_wq *idxd_wq, int n)
  78. {
  79. struct iaa_wq *wq = idxd_wq_get_private(idxd_wq);
  80. atomic64_add(n, &wq->decomp_bytes);
  81. atomic64_add(n, &wq->iaa_device->decomp_bytes);
  82. }
  83. static void reset_iaa_crypto_stats(void)
  84. {
  85. atomic64_set(&total_comp_calls, 0);
  86. atomic64_set(&total_decomp_calls, 0);
  87. atomic64_set(&total_sw_decomp_calls, 0);
  88. atomic64_set(&total_comp_bytes_out, 0);
  89. atomic64_set(&total_decomp_bytes_in, 0);
  90. atomic64_set(&total_completion_einval_errors, 0);
  91. atomic64_set(&total_completion_timeout_errors, 0);
  92. atomic64_set(&total_completion_comp_buf_overflow_errors, 0);
  93. }
  94. static void reset_wq_stats(struct iaa_wq *wq)
  95. {
  96. atomic64_set(&wq->comp_calls, 0);
  97. atomic64_set(&wq->comp_bytes, 0);
  98. atomic64_set(&wq->decomp_calls, 0);
  99. atomic64_set(&wq->decomp_bytes, 0);
  100. }
  101. static void reset_device_stats(struct iaa_device *iaa_device)
  102. {
  103. struct iaa_wq *iaa_wq;
  104. atomic64_set(&iaa_device->comp_calls, 0);
  105. atomic64_set(&iaa_device->comp_bytes, 0);
  106. atomic64_set(&iaa_device->decomp_calls, 0);
  107. atomic64_set(&iaa_device->decomp_bytes, 0);
  108. list_for_each_entry(iaa_wq, &iaa_device->wqs, list)
  109. reset_wq_stats(iaa_wq);
  110. }
  111. static void wq_show(struct seq_file *m, struct iaa_wq *iaa_wq)
  112. {
  113. seq_printf(m, " name: %s\n", iaa_wq->wq->name);
  114. seq_printf(m, " comp_calls: %llu\n",
  115. atomic64_read(&iaa_wq->comp_calls));
  116. seq_printf(m, " comp_bytes: %llu\n",
  117. atomic64_read(&iaa_wq->comp_bytes));
  118. seq_printf(m, " decomp_calls: %llu\n",
  119. atomic64_read(&iaa_wq->decomp_calls));
  120. seq_printf(m, " decomp_bytes: %llu\n\n",
  121. atomic64_read(&iaa_wq->decomp_bytes));
  122. }
  123. static void device_stats_show(struct seq_file *m, struct iaa_device *iaa_device)
  124. {
  125. struct iaa_wq *iaa_wq;
  126. seq_puts(m, "iaa device:\n");
  127. seq_printf(m, " id: %d\n", iaa_device->idxd->id);
  128. seq_printf(m, " n_wqs: %d\n", iaa_device->n_wq);
  129. seq_printf(m, " comp_calls: %llu\n",
  130. atomic64_read(&iaa_device->comp_calls));
  131. seq_printf(m, " comp_bytes: %llu\n",
  132. atomic64_read(&iaa_device->comp_bytes));
  133. seq_printf(m, " decomp_calls: %llu\n",
  134. atomic64_read(&iaa_device->decomp_calls));
  135. seq_printf(m, " decomp_bytes: %llu\n",
  136. atomic64_read(&iaa_device->decomp_bytes));
  137. seq_puts(m, " wqs:\n");
  138. list_for_each_entry(iaa_wq, &iaa_device->wqs, list)
  139. wq_show(m, iaa_wq);
  140. }
  141. static int global_stats_show(struct seq_file *m, void *v)
  142. {
  143. seq_puts(m, "global stats:\n");
  144. seq_printf(m, " total_comp_calls: %llu\n",
  145. atomic64_read(&total_comp_calls));
  146. seq_printf(m, " total_decomp_calls: %llu\n",
  147. atomic64_read(&total_decomp_calls));
  148. seq_printf(m, " total_sw_decomp_calls: %llu\n",
  149. atomic64_read(&total_sw_decomp_calls));
  150. seq_printf(m, " total_comp_bytes_out: %llu\n",
  151. atomic64_read(&total_comp_bytes_out));
  152. seq_printf(m, " total_decomp_bytes_in: %llu\n",
  153. atomic64_read(&total_decomp_bytes_in));
  154. seq_printf(m, " total_completion_einval_errors: %llu\n",
  155. atomic64_read(&total_completion_einval_errors));
  156. seq_printf(m, " total_completion_timeout_errors: %llu\n",
  157. atomic64_read(&total_completion_timeout_errors));
  158. seq_printf(m, " total_completion_comp_buf_overflow_errors: %llu\n\n",
  159. atomic64_read(&total_completion_comp_buf_overflow_errors));
  160. return 0;
  161. }
  162. static int wq_stats_show(struct seq_file *m, void *v)
  163. {
  164. struct iaa_device *iaa_device;
  165. mutex_lock(&iaa_devices_lock);
  166. list_for_each_entry(iaa_device, &iaa_devices, list)
  167. device_stats_show(m, iaa_device);
  168. mutex_unlock(&iaa_devices_lock);
  169. return 0;
  170. }
  171. static int iaa_crypto_stats_reset(void *data, u64 value)
  172. {
  173. struct iaa_device *iaa_device;
  174. reset_iaa_crypto_stats();
  175. mutex_lock(&iaa_devices_lock);
  176. list_for_each_entry(iaa_device, &iaa_devices, list)
  177. reset_device_stats(iaa_device);
  178. mutex_unlock(&iaa_devices_lock);
  179. return 0;
  180. }
  181. static int wq_stats_open(struct inode *inode, struct file *file)
  182. {
  183. return single_open(file, wq_stats_show, file);
  184. }
  185. static const struct file_operations wq_stats_fops = {
  186. .open = wq_stats_open,
  187. .read = seq_read,
  188. .llseek = seq_lseek,
  189. .release = single_release,
  190. };
  191. static int global_stats_open(struct inode *inode, struct file *file)
  192. {
  193. return single_open(file, global_stats_show, file);
  194. }
  195. static const struct file_operations global_stats_fops = {
  196. .open = global_stats_open,
  197. .read = seq_read,
  198. .llseek = seq_lseek,
  199. .release = single_release,
  200. };
  201. DEFINE_DEBUGFS_ATTRIBUTE(wq_stats_reset_fops, NULL, iaa_crypto_stats_reset, "%llu\n");
  202. int __init iaa_crypto_debugfs_init(void)
  203. {
  204. if (!debugfs_initialized())
  205. return -ENODEV;
  206. iaa_crypto_debugfs_root = debugfs_create_dir("iaa_crypto", NULL);
  207. debugfs_create_file("global_stats", 0644, iaa_crypto_debugfs_root, NULL,
  208. &global_stats_fops);
  209. debugfs_create_file("wq_stats", 0644, iaa_crypto_debugfs_root, NULL,
  210. &wq_stats_fops);
  211. debugfs_create_file("stats_reset", 0644, iaa_crypto_debugfs_root, NULL,
  212. &wq_stats_reset_fops);
  213. return 0;
  214. }
  215. void __exit iaa_crypto_debugfs_cleanup(void)
  216. {
  217. debugfs_remove_recursive(iaa_crypto_debugfs_root);
  218. }
  219. MODULE_LICENSE("GPL");