Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0 OR MIT
0002 /*
0003  * Copyright 2016-2022 Advanced Micro Devices, Inc.
0004  *
0005  * Permission is hereby granted, free of charge, to any person obtaining a
0006  * copy of this software and associated documentation files (the "Software"),
0007  * to deal in the Software without restriction, including without limitation
0008  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0009  * and/or sell copies of the Software, and to permit persons to whom the
0010  * Software is furnished to do so, subject to the following conditions:
0011  *
0012  * The above copyright notice and this permission notice shall be included in
0013  * all copies or substantial portions of the Software.
0014  *
0015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0016  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0017  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0018  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0019  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0020  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0021  * OTHER DEALINGS IN THE SOFTWARE.
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 }