kfd_debugfs.c 3.3 KB

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