1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#include <linux/debugfs.h>
24#include <linux/uaccess.h>
25
26#include "kfd_priv.h"
27
28static struct dentry *debugfs_root;
29
30static int kfd_debugfs_open(struct inode *inode, struct file *file)
31{
32 int (*show)(struct seq_file *, void *) = inode->i_private;
33
34 return single_open(file, show, NULL);
35}
36static int kfd_debugfs_hang_hws_read(struct seq_file *m, void *data)
37{
38 seq_printf(m, "echo gpu_id > hang_hws\n");
39 return 0;
40}
41
42static ssize_t kfd_debugfs_hang_hws_write(struct file *file,
43 const char __user *user_buf, size_t size, loff_t *ppos)
44{
45 struct kfd_dev *dev;
46 char tmp[16];
47 uint32_t gpu_id;
48 int ret = -EINVAL;
49
50 memset(tmp, 0, 16);
51 if (size >= 16) {
52 pr_err("Invalid input for gpu id.\n");
53 goto out;
54 }
55 if (copy_from_user(tmp, user_buf, size)) {
56 ret = -EFAULT;
57 goto out;
58 }
59 if (kstrtoint(tmp, 10, &gpu_id)) {
60 pr_err("Invalid input for gpu id.\n");
61 goto out;
62 }
63 dev = kfd_device_by_id(gpu_id);
64 if (dev) {
65 kfd_debugfs_hang_hws(dev);
66 ret = size;
67 } else
68 pr_err("Cannot find device %d.\n", gpu_id);
69
70out:
71 return ret;
72}
73
74static const struct file_operations kfd_debugfs_fops = {
75 .owner = THIS_MODULE,
76 .open = kfd_debugfs_open,
77 .read = seq_read,
78 .llseek = seq_lseek,
79 .release = single_release,
80};
81
82static const struct file_operations kfd_debugfs_hang_hws_fops = {
83 .owner = THIS_MODULE,
84 .open = kfd_debugfs_open,
85 .read = seq_read,
86 .write = kfd_debugfs_hang_hws_write,
87 .llseek = seq_lseek,
88 .release = single_release,
89};
90
91void kfd_debugfs_init(void)
92{
93 debugfs_root = debugfs_create_dir("kfd", NULL);
94
95 debugfs_create_file("mqds", S_IFREG | 0444, debugfs_root,
96 kfd_debugfs_mqds_by_process, &kfd_debugfs_fops);
97 debugfs_create_file("hqds", S_IFREG | 0444, debugfs_root,
98 kfd_debugfs_hqds_by_device, &kfd_debugfs_fops);
99 debugfs_create_file("rls", S_IFREG | 0444, debugfs_root,
100 kfd_debugfs_rls_by_device, &kfd_debugfs_fops);
101 debugfs_create_file("hang_hws", S_IFREG | 0200, debugfs_root,
102 kfd_debugfs_hang_hws_read, &kfd_debugfs_hang_hws_fops);
103}
104
105void kfd_debugfs_fini(void)
106{
107 debugfs_remove_recursive(debugfs_root);
108}
109