drivers/gpu/drm/amd/amdkfd/kfd_events.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/amd/amdkfd/kfd_events.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/amd/amdkfd/kfd_events.c- Extension
.c- Size
- 37658 bytes
- Lines
- 1428
- Domain
- Driver Families
- Bucket
- drivers/gpu
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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/mm_types.hlinux/slab.hlinux/types.hlinux/sched/signal.hlinux/sched/mm.hlinux/uaccess.hlinux/mman.hlinux/memory.hkfd_priv.hkfd_events.hkfd_device_queue_manager.hlinux/device.h
Detected Declarations
struct kfd_event_waiterstruct kfd_signal_pagefunction allocate_event_notification_slotfunction create_signal_eventfunction create_other_eventfunction kfd_event_init_processfunction destroy_eventfunction destroy_eventsfunction shutdown_signal_pagefunction kfd_event_free_processfunction event_can_be_gpu_signaledfunction event_can_be_cpu_signaledfunction kfd_event_page_setfunction kfd_kmap_event_pagefunction kfd_event_createfunction kfd_criu_restore_eventfunction kfd_criu_checkpoint_eventsfunction idr_for_each_entryfunction kfd_get_num_eventsfunction kfd_event_destroyfunction set_eventfunction kfd_set_eventfunction reset_eventfunction kfd_reset_eventfunction acknowledge_signalfunction set_event_from_interruptfunction kfd_signal_event_interruptfunction init_event_waiterfunction allfunction copy_signaled_event_datafunction user_timeout_to_jiffiesfunction free_waitersfunction kfd_wait_on_eventsfunction kfd_event_mmapfunction get_orderfunction lookup_events_by_type_and_signalfunction kfd_signal_hw_exception_eventfunction kfd_signal_vm_fault_event_with_userptrfunction kfd_signal_vm_fault_eventfunction kfd_signal_reset_eventfunction idr_for_each_entry_continuefunction kfd_signal_poison_consumed_eventfunction idr_for_each_entry_continuefunction kfd_signal_process_terminate_event
Annotated Snippet
struct kfd_event_waiter {
wait_queue_entry_t wait;
struct kfd_event *event; /* Event to wait for */
bool activated; /* Becomes true when event is signaled */
bool event_age_enabled; /* set to true when last_event_age is non-zero */
};
/*
* Each signal event needs a 64-bit signal slot where the signaler will write
* a 1 before sending an interrupt. (This is needed because some interrupts
* do not contain enough spare data bits to identify an event.)
* We get whole pages and map them to the process VA.
* Individual signal events use their event_id as slot index.
*/
struct kfd_signal_page {
uint64_t *kernel_address;
uint64_t __user *user_address;
bool need_to_free_pages;
};
static uint64_t *page_slots(struct kfd_signal_page *page)
{
return page->kernel_address;
}
static struct kfd_signal_page *allocate_signal_page(struct kfd_process *p)
{
void *backing_store;
struct kfd_signal_page *page;
page = kzalloc_obj(*page);
if (!page)
return NULL;
backing_store = (void *) __get_free_pages(GFP_KERNEL,
get_order(KFD_SIGNAL_EVENT_LIMIT * 8));
if (!backing_store)
goto fail_alloc_signal_store;
/* Initialize all events to unsignaled */
memset(backing_store, (uint8_t) UNSIGNALED_EVENT_SLOT,
KFD_SIGNAL_EVENT_LIMIT * 8);
page->kernel_address = backing_store;
page->need_to_free_pages = true;
pr_debug("Allocated new event signal page at %p, for process %p\n",
page, p);
return page;
fail_alloc_signal_store:
kfree(page);
return NULL;
}
static int allocate_event_notification_slot(struct kfd_process *p,
struct kfd_event *ev,
const int *restore_id)
{
int id;
if (!p->signal_page) {
p->signal_page = allocate_signal_page(p);
if (!p->signal_page)
return -ENOMEM;
/* Oldest user mode expects 256 event slots */
p->signal_mapped_size = 256*8;
}
if (restore_id) {
id = idr_alloc(&p->event_idr, ev, *restore_id, *restore_id + 1,
GFP_KERNEL);
} else {
/*
* Compatibility with old user mode: Only use signal slots
* user mode has mapped, may be less than
* KFD_SIGNAL_EVENT_LIMIT. This also allows future increase
* of the event limit without breaking user mode.
*/
id = idr_alloc(&p->event_idr, ev, 0, p->signal_mapped_size / 8,
GFP_KERNEL);
}
if (id < 0)
return id;
ev->event_id = id;
page_slots(p->signal_page)[id] = UNSIGNALED_EVENT_SLOT;
return 0;
}
Annotation
- Immediate include surface: `linux/mm_types.h`, `linux/slab.h`, `linux/types.h`, `linux/sched/signal.h`, `linux/sched/mm.h`, `linux/uaccess.h`, `linux/mman.h`, `linux/memory.h`.
- Detected declarations: `struct kfd_event_waiter`, `struct kfd_signal_page`, `function allocate_event_notification_slot`, `function create_signal_event`, `function create_other_event`, `function kfd_event_init_process`, `function destroy_event`, `function destroy_events`, `function shutdown_signal_page`, `function kfd_event_free_process`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: source 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.