drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c- Extension
.c- Size
- 11206 bytes
- Lines
- 414
- 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/poll.hlinux/wait.hlinux/anon_inodes.huapi/linux/kfd_ioctl.hamdgpu.hamdgpu_vm.hkfd_priv.hkfd_smi_events.hamdgpu_reset.h
Detected Declarations
struct kfd_smi_clientfunction kfd_smi_ev_pollfunction kfd_smi_ev_readfunction kfd_smi_ev_writefunction kfd_smi_ev_client_freefunction kfd_smi_ev_releasefunction kfd_smi_ev_enabledfunction add_event_to_kfifofunction list_for_each_entry_rcufunction kfd_smi_event_addfunction kfd_smi_event_update_gpu_resetfunction kfd_smi_event_update_thermal_throttlingfunction kfd_smi_event_update_vmfaultfunction kfd_smi_event_page_fault_startfunction kfd_smi_event_page_fault_endfunction kfd_smi_event_migration_startfunction kfd_smi_event_migration_endfunction kfd_smi_event_queue_evictionfunction kfd_smi_event_queue_restorefunction kfd_smi_event_queue_restore_rescheduledfunction kfd_smi_event_unmap_from_gpufunction kfd_smi_event_processfunction kfd_smi_event_open
Annotated Snippet
static const struct file_operations kfd_smi_ev_fops = {
.owner = THIS_MODULE,
.poll = kfd_smi_ev_poll,
.read = kfd_smi_ev_read,
.write = kfd_smi_ev_write,
.release = kfd_smi_ev_release
};
static __poll_t kfd_smi_ev_poll(struct file *filep,
struct poll_table_struct *wait)
{
struct kfd_smi_client *client = filep->private_data;
__poll_t mask = 0;
poll_wait(filep, &client->wait_queue, wait);
spin_lock(&client->lock);
if (!kfifo_is_empty(&client->fifo))
mask = EPOLLIN | EPOLLRDNORM;
spin_unlock(&client->lock);
return mask;
}
static ssize_t kfd_smi_ev_read(struct file *filep, char __user *user,
size_t size, loff_t *offset)
{
int ret;
size_t to_copy;
struct kfd_smi_client *client = filep->private_data;
unsigned char *buf;
size = min_t(size_t, size, KFD_MAX_KFIFO_SIZE);
buf = kmalloc(size, GFP_KERNEL);
if (!buf)
return -ENOMEM;
/* kfifo_to_user can sleep so we can't use spinlock protection around
* it. Instead, we kfifo out as spinlocked then copy them to the user.
*/
spin_lock(&client->lock);
to_copy = kfifo_len(&client->fifo);
if (!to_copy) {
spin_unlock(&client->lock);
ret = -EAGAIN;
goto ret_err;
}
to_copy = min(size, to_copy);
ret = kfifo_out(&client->fifo, buf, to_copy);
spin_unlock(&client->lock);
if (ret <= 0) {
ret = -EAGAIN;
goto ret_err;
}
ret = copy_to_user(user, buf, to_copy);
if (ret) {
ret = -EFAULT;
goto ret_err;
}
kfree(buf);
return to_copy;
ret_err:
kfree(buf);
return ret;
}
static ssize_t kfd_smi_ev_write(struct file *filep, const char __user *user,
size_t size, loff_t *offset)
{
struct kfd_smi_client *client = filep->private_data;
uint64_t events;
if (!access_ok(user, size) || size < sizeof(events))
return -EFAULT;
if (copy_from_user(&events, user, sizeof(events)))
return -EFAULT;
WRITE_ONCE(client->events, events);
return sizeof(events);
}
static void kfd_smi_ev_client_free(struct rcu_head *p)
{
struct kfd_smi_client *ev = container_of(p, struct kfd_smi_client, rcu);
kfifo_free(&ev->fifo);
Annotation
- Immediate include surface: `linux/poll.h`, `linux/wait.h`, `linux/anon_inodes.h`, `uapi/linux/kfd_ioctl.h`, `amdgpu.h`, `amdgpu_vm.h`, `kfd_priv.h`, `kfd_smi_events.h`.
- Detected declarations: `struct kfd_smi_client`, `function kfd_smi_ev_poll`, `function kfd_smi_ev_read`, `function kfd_smi_ev_write`, `function kfd_smi_ev_client_free`, `function kfd_smi_ev_release`, `function kfd_smi_ev_enabled`, `function add_event_to_kfifo`, `function list_for_each_entry_rcu`, `function kfd_smi_event_add`.
- 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.