drivers/gpu/drm/scheduler/sched_entity.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/scheduler/sched_entity.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/scheduler/sched_entity.c- Extension
.c- Size
- 19042 bytes
- Lines
- 641
- Domain
- Driver Families
- Bucket
- drivers/gpu
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/export.hlinux/slab.hlinux/completion.hdrm/drm_print.hdrm/gpu_scheduler.hsched_internal.hgpu_scheduler_trace.h
Detected Declarations
function filesfunction drm_sched_entity_stats_job_add_gpu_timefunction drm_sched_entity_set_priorityfunction drm_sched_job_armfunction drm_sched_entity_is_idlefunction drm_sched_entity_errorfunction drm_sched_entity_kill_jobs_workfunction drm_sched_entity_kill_jobs_cbfunction drm_sched_entity_flushfunction drm_sched_entity_finifunction drm_sched_entity_flushfunction drm_sched_entity_flushfunction drm_sched_entity_wakeupfunction drm_sched_entity_set_priorityfunction drm_sched_entity_add_dependency_cbfunction drm_sched_job_dependencyfunction drm_sched_entity_select_rqfunction drm_sched_job_armexport drm_sched_entity_initexport drm_sched_entity_modify_schedexport drm_sched_entity_errorexport drm_sched_entity_killexport drm_sched_entity_flushexport drm_sched_entity_finiexport drm_sched_entity_destroyexport drm_sched_entity_set_priorityexport drm_sched_entity_push_job
Annotated Snippet
if (s_fence && f == &s_fence->scheduled) {
/* The dependencies array had a reference on the scheduled
* fence, and the finished fence refcount might have
* dropped to zero. Use dma_fence_get_rcu() so we get
* a NULL fence in that case.
*/
f = dma_fence_get_rcu(&s_fence->finished);
/* Now that we have a reference on the finished fence,
* we can release the reference the dependencies array
* had on the scheduled fence.
*/
dma_fence_put(&s_fence->scheduled);
}
xa_erase(&job->dependencies, index);
if (f && !dma_fence_add_callback(f, &job->finish_cb,
drm_sched_entity_kill_jobs_cb))
return;
dma_fence_put(f);
}
drm_sched_fence_scheduled(job->s_fence, NULL);
drm_sched_fence_finished(job->s_fence, -ESRCH);
WARN_ON(job->s_fence->parent);
job->sched->ops->free_job(job);
}
/* Signal the scheduler finished fence when the entity in question is killed. */
static void drm_sched_entity_kill_jobs_cb(struct dma_fence *f,
struct dma_fence_cb *cb)
{
struct drm_sched_job *job = container_of(cb, struct drm_sched_job,
finish_cb);
dma_fence_put(f);
INIT_WORK(&job->work, drm_sched_entity_kill_jobs_work);
schedule_work(&job->work);
}
/**
* drm_sched_entity_kill - kill an entity's pending jobs and remove it
* @entity: the entity to remove
*
* Removes the entity from the scheduler's run queue and kills all pending jobs.
*
* This function should be used over drm_sched_entity_flush() if it is not
* desired to actually wait for all pending jobs to finish.
*/
void drm_sched_entity_kill(struct drm_sched_entity *entity)
{
struct drm_sched_job *job;
struct dma_fence *prev;
if (!entity->rq)
return;
spin_lock(&entity->lock);
entity->stopped = true;
drm_sched_rq_remove_entity(entity->rq, entity);
spin_unlock(&entity->lock);
/* Make sure this entity is not used by the scheduler at the moment */
wait_for_completion(&entity->entity_idle);
/* The entity is guaranteed to not be used by the scheduler */
prev = rcu_dereference_check(entity->last_scheduled, true);
dma_fence_get(prev);
while ((job = drm_sched_entity_queue_pop(entity))) {
struct drm_sched_fence *s_fence = job->s_fence;
dma_fence_get(&s_fence->finished);
if (!prev ||
dma_fence_add_callback(prev, &job->finish_cb,
drm_sched_entity_kill_jobs_cb)) {
/*
* Adding callback above failed.
* dma_fence_put() checks for NULL.
*/
dma_fence_put(prev);
drm_sched_entity_kill_jobs_cb(NULL, &job->finish_cb);
}
prev = &s_fence->finished;
}
dma_fence_put(prev);
}
EXPORT_SYMBOL(drm_sched_entity_kill);
Annotation
- Immediate include surface: `linux/export.h`, `linux/slab.h`, `linux/completion.h`, `drm/drm_print.h`, `drm/gpu_scheduler.h`, `sched_internal.h`, `gpu_scheduler_trace.h`.
- Detected declarations: `function files`, `function drm_sched_entity_stats_job_add_gpu_time`, `function drm_sched_entity_set_priority`, `function drm_sched_job_arm`, `function drm_sched_entity_is_idle`, `function drm_sched_entity_error`, `function drm_sched_entity_kill_jobs_work`, `function drm_sched_entity_kill_jobs_cb`, `function drm_sched_entity_flush`, `function drm_sched_entity_fini`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: integration implementation candidate.
- 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.