kfd_debugfs.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Copyright 2016-2017 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. */
  22. #include <linux/debugfs.h>
  23. #include <linux/uaccess.h>
  24. #include "kfd_priv.h"
  25. static struct dentry *debugfs_root;
  26. static int kfd_debugfs_open(struct inode *inode, struct file *file)
  27. {
  28. int (*show)(struct seq_file *, void *) = inode->i_private;
  29. return single_open(file, show, NULL);
  30. }
  31. static ssize_t kfd_debugfs_hang_hws_write(struct file *file,
  32. const char __user *user_buf, size_t size, loff_t *ppos)
  33. {
  34. struct kfd_dev *dev;
  35. char tmp[16];
  36. uint32_t gpu_id;
  37. int ret = -EINVAL;
  38. memset(tmp, 0, 16);
  39. if (size >= 16) {
  40. pr_err("Invalid input for gpu id.\n");
  41. goto out;
  42. }
  43. if (copy_from_user(tmp, user_buf, size)) {
  44. ret = -EFAULT;
  45. goto out;
  46. }
  47. if (kstrtoint(tmp, 10, &gpu_id)) {
  48. pr_err("Invalid input for gpu id.\n");
  49. goto out;
  50. }
  51. dev = kfd_device_by_id(gpu_id);
  52. if (dev) {
  53. kfd_debugfs_hang_hws(dev);
  54. ret = size;
  55. } else
  56. pr_err("Cannot find device %d.\n", gpu_id);
  57. out:
  58. return ret;
  59. }
  60. static const struct file_operations kfd_debugfs_fops = {
  61. .owner = THIS_MODULE,
  62. .open = kfd_debugfs_open,
  63. .read = seq_read,
  64. .llseek = seq_lseek,
  65. .release = single_release,
  66. };
  67. static const struct file_operations kfd_debugfs_hang_hws_fops = {
  68. .owner = THIS_MODULE,
  69. .open = kfd_debugfs_open,
  70. .read = seq_read,
  71. .write = kfd_debugfs_hang_hws_write,
  72. .llseek = seq_lseek,
  73. .release = single_release,
  74. };
  75. void kfd_debugfs_init(void)
  76. {
  77. struct dentry *ent;
  78. debugfs_root = debugfs_create_dir("kfd", NULL);
  79. if (!debugfs_root || debugfs_root == ERR_PTR(-ENODEV)) {
  80. pr_warn("Failed to create kfd debugfs dir\n");
  81. return;
  82. }
  83. ent = debugfs_create_file("mqds", S_IFREG | 0444, debugfs_root,
  84. kfd_debugfs_mqds_by_process,
  85. &kfd_debugfs_fops);
  86. if (!ent)
  87. pr_warn("Failed to create mqds in kfd debugfs\n");
  88. ent = debugfs_create_file("hqds", S_IFREG | 0444, debugfs_root,
  89. kfd_debugfs_hqds_by_device,
  90. &kfd_debugfs_fops);
  91. if (!ent)
  92. pr_warn("Failed to create hqds in kfd debugfs\n");
  93. ent = debugfs_create_file("rls", S_IFREG | 0444, debugfs_root,
  94. kfd_debugfs_rls_by_device,
  95. &kfd_debugfs_fops);
  96. ent = debugfs_create_file("hang_hws", S_IFREG | 0644, debugfs_root,
  97. NULL,
  98. &kfd_debugfs_hang_hws_fops);
  99. if (!ent)
  100. pr_warn("Failed to create rls in kfd debugfs\n");
  101. }
  102. void kfd_debugfs_fini(void)
  103. {
  104. debugfs_remove_recursive(debugfs_root);
  105. }