drivers/gpu/drm/amd/amdkfd/kfd_debugfs.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/amd/amdkfd/kfd_debugfs.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/amd/amdkfd/kfd_debugfs.c- Extension
.c- Size
- 5274 bytes
- Lines
- 188
- Domain
- Driver Families
- Bucket
- drivers/gpu
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/debugfs.hlinux/uaccess.hkfd_priv.h
Detected Declarations
struct debugfs_proc_entryfunction kfd_debugfs_openfunction kfd_debugfs_hang_hws_readfunction kfd_debugfs_hang_hws_writefunction kfd_debugfs_initfunction kfd_debugfs_finifunction kfd_debugfs_pasid_readfunction kfd_debugfs_add_processfunction kfd_debugfs_remove_process
Annotated Snippet
static const struct file_operations kfd_debugfs_fops = {
.owner = THIS_MODULE,
.open = kfd_debugfs_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
static const struct file_operations kfd_debugfs_hang_hws_fops = {
.owner = THIS_MODULE,
.open = kfd_debugfs_open,
.read = seq_read,
.write = kfd_debugfs_hang_hws_write,
.llseek = seq_lseek,
.release = single_release,
};
void kfd_debugfs_init(void)
{
debugfs_root = debugfs_create_dir("kfd", NULL);
debugfs_proc = debugfs_create_dir("proc", debugfs_root);
INIT_LIST_HEAD(&procs);
debugfs_create_file("mqds", S_IFREG | 0444, debugfs_root,
kfd_debugfs_mqds_by_process, &kfd_debugfs_fops);
debugfs_create_file("hqds", S_IFREG | 0444, debugfs_root,
kfd_debugfs_hqds_by_device, &kfd_debugfs_fops);
debugfs_create_file("rls", S_IFREG | 0444, debugfs_root,
kfd_debugfs_rls_by_device, &kfd_debugfs_fops);
debugfs_create_file("hang_hws", S_IFREG | 0200, debugfs_root,
kfd_debugfs_hang_hws_read, &kfd_debugfs_hang_hws_fops);
debugfs_create_file("mem_limit", S_IFREG | 0200, debugfs_root,
kfd_debugfs_kfd_mem_limits, &kfd_debugfs_fops);
}
void kfd_debugfs_fini(void)
{
debugfs_remove_recursive(debugfs_proc);
debugfs_remove_recursive(debugfs_root);
}
static ssize_t kfd_debugfs_pasid_read(struct file *file, char __user *buf,
size_t count, loff_t *ppos)
{
struct kfd_process_device *pdd = file_inode(file)->i_private;
char tmp[32];
int len;
len = snprintf(tmp, sizeof(tmp), "%u\n", pdd->pasid);
return simple_read_from_buffer(buf, count, ppos, tmp, len);
}
static const struct file_operations kfd_debugfs_pasid_fops = {
.owner = THIS_MODULE,
.read = kfd_debugfs_pasid_read,
};
void kfd_debugfs_add_process(struct kfd_process *p)
{
int i;
char name[MAX_DEBUGFS_FILENAME_LEN];
struct debugfs_proc_entry *entry;
entry = kzalloc_obj(*entry);
if (!entry)
return;
list_add(&entry->list, &procs);
entry->pid = p->lead_thread->pid;
snprintf(name, MAX_DEBUGFS_FILENAME_LEN, "%d",
(int)entry->pid);
entry->proc_dentry = debugfs_create_dir(name, debugfs_proc);
/* Create debugfs files for each GPU:
* - proc/<pid>/pasid_<gpuid>
*/
for (i = 0; i < p->n_pdds; i++) {
struct kfd_process_device *pdd = p->pdds[i];
snprintf(name, MAX_DEBUGFS_FILENAME_LEN, "pasid_%u",
pdd->dev->id);
debugfs_create_file((const char *)name, S_IFREG | 0444,
entry->proc_dentry, pdd,
&kfd_debugfs_pasid_fops);
}
}
void kfd_debugfs_remove_process(struct kfd_process *p)
{
Annotation
- Immediate include surface: `linux/debugfs.h`, `linux/uaccess.h`, `kfd_priv.h`.
- Detected declarations: `struct debugfs_proc_entry`, `function kfd_debugfs_open`, `function kfd_debugfs_hang_hws_read`, `function kfd_debugfs_hang_hws_write`, `function kfd_debugfs_init`, `function kfd_debugfs_fini`, `function kfd_debugfs_pasid_read`, `function kfd_debugfs_add_process`, `function kfd_debugfs_remove_process`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.