0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 #include <linux/debugfs.h>
0025 #include <linux/uaccess.h>
0026
0027 #include "kfd_priv.h"
0028
0029 static struct dentry *debugfs_root;
0030
0031 static int kfd_debugfs_open(struct inode *inode, struct file *file)
0032 {
0033 int (*show)(struct seq_file *, void *) = inode->i_private;
0034
0035 return single_open(file, show, NULL);
0036 }
0037 static int kfd_debugfs_hang_hws_read(struct seq_file *m, void *data)
0038 {
0039 seq_puts(m, "echo gpu_id > hang_hws\n");
0040 return 0;
0041 }
0042
0043 static ssize_t kfd_debugfs_hang_hws_write(struct file *file,
0044 const char __user *user_buf, size_t size, loff_t *ppos)
0045 {
0046 struct kfd_dev *dev;
0047 char tmp[16];
0048 uint32_t gpu_id;
0049 int ret = -EINVAL;
0050
0051 memset(tmp, 0, 16);
0052 if (size >= 16) {
0053 pr_err("Invalid input for gpu id.\n");
0054 goto out;
0055 }
0056 if (copy_from_user(tmp, user_buf, size)) {
0057 ret = -EFAULT;
0058 goto out;
0059 }
0060 if (kstrtoint(tmp, 10, &gpu_id)) {
0061 pr_err("Invalid input for gpu id.\n");
0062 goto out;
0063 }
0064 dev = kfd_device_by_id(gpu_id);
0065 if (dev) {
0066 kfd_debugfs_hang_hws(dev);
0067 ret = size;
0068 } else
0069 pr_err("Cannot find device %d.\n", gpu_id);
0070
0071 out:
0072 return ret;
0073 }
0074
0075 static const struct file_operations kfd_debugfs_fops = {
0076 .owner = THIS_MODULE,
0077 .open = kfd_debugfs_open,
0078 .read = seq_read,
0079 .llseek = seq_lseek,
0080 .release = single_release,
0081 };
0082
0083 static const struct file_operations kfd_debugfs_hang_hws_fops = {
0084 .owner = THIS_MODULE,
0085 .open = kfd_debugfs_open,
0086 .read = seq_read,
0087 .write = kfd_debugfs_hang_hws_write,
0088 .llseek = seq_lseek,
0089 .release = single_release,
0090 };
0091
0092 void kfd_debugfs_init(void)
0093 {
0094 debugfs_root = debugfs_create_dir("kfd", NULL);
0095
0096 debugfs_create_file("mqds", S_IFREG | 0444, debugfs_root,
0097 kfd_debugfs_mqds_by_process, &kfd_debugfs_fops);
0098 debugfs_create_file("hqds", S_IFREG | 0444, debugfs_root,
0099 kfd_debugfs_hqds_by_device, &kfd_debugfs_fops);
0100 debugfs_create_file("rls", S_IFREG | 0444, debugfs_root,
0101 kfd_debugfs_rls_by_device, &kfd_debugfs_fops);
0102 debugfs_create_file("hang_hws", S_IFREG | 0200, debugfs_root,
0103 kfd_debugfs_hang_hws_read, &kfd_debugfs_hang_hws_fops);
0104 debugfs_create_file("mem_limit", S_IFREG | 0200, debugfs_root,
0105 kfd_debugfs_kfd_mem_limits, &kfd_debugfs_fops);
0106 }
0107
0108 void kfd_debugfs_fini(void)
0109 {
0110 debugfs_remove_recursive(debugfs_root);
0111 }