drivers/gpu/drm/scheduler/sched_main.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/scheduler/sched_main.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/scheduler/sched_main.c- Extension
.c- Size
- 38449 bytes
- Lines
- 1274
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/export.hlinux/wait.hlinux/sched.hlinux/completion.hlinux/dma-resv.huapi/linux/sched/types.hdrm/drm_print.hdrm/drm_gem.hdrm/drm_syncobj.hdrm/gpu_scheduler.hdrm/spsc_queue.hsched_internal.hgpu_scheduler_trace.h
Detected Declarations
function executedfunction drm_sched_can_queuefunction drm_sched_run_job_queuefunction drm_sched_run_free_queuefunction drm_sched_job_donefunction drm_sched_job_done_cbfunction drm_sched_start_timeoutfunction drm_sched_start_timeout_unlockedfunction drm_sched_tdr_queue_immfunction drm_sched_faultfunction drm_sched_suspend_timeoutfunction drm_sched_resume_timeoutfunction drm_sched_job_beginfunction drm_sched_job_reinsert_on_false_timeoutfunction drm_sched_job_timedoutfunction recoveryfunction recoveryfunction drm_sched_for_each_pending_jobfunction list_for_each_entry_safefunction drm_sched_entity_push_jobfunction drm_sched_entity_push_jobfunction drm_sched_job_add_dependencyfunction drm_sched_job_add_syncobj_dependencyfunction drm_sched_job_add_resv_dependenciesfunction dma_resv_for_each_fencefunction drm_gem_lock_reservationsfunction drm_sched_job_has_dependencyfunction xa_for_eachfunction drm_sched_job_initfunction xa_for_eachfunction drm_sched_wakeupfunction listfunction drm_sched_pick_bestfunction drm_sched_free_job_workfunction drm_sched_run_job_workfunction drm_sched_initfunction drm_sched_cancel_remaining_jobsfunction drm_sched_finifunction drm_sched_increase_karmafunction drm_sched_wqueue_readyfunction drm_sched_wqueue_stopfunction drm_sched_wqueue_stopfunction drm_sched_is_stoppedfunction drm_sched_job_is_signaledexport drm_sched_tdr_queue_immexport drm_sched_faultexport drm_sched_suspend_timeoutexport drm_sched_resume_timeout
Annotated Snippet
if (sched->free_guilty) {
job->sched->ops->free_job(job);
sched->free_guilty = false;
}
if (status == DRM_GPU_SCHED_STAT_NO_HANG)
drm_sched_job_reinsert_on_false_timeout(sched, job);
} else {
spin_unlock(&sched->job_list_lock);
}
if (status != DRM_GPU_SCHED_STAT_ENODEV)
drm_sched_start_timeout_unlocked(sched);
}
/**
* drm_sched_stop - stop the scheduler
*
* @sched: scheduler instance
* @bad: job which caused the time out
*
* Stop the scheduler and also removes and frees all completed jobs.
* Note: bad job will not be freed as it might be used later and so it's
* callers responsibility to release it manually if it's not part of the
* pending list any more.
*
* This function is typically used for reset recovery (see the docu of
* drm_sched_backend_ops.timedout_job() for details). Do not call it for
* scheduler teardown, i.e., before calling drm_sched_fini().
*
* As it's only used for reset recovery, drivers must not call this function
* in their &struct drm_sched_backend_ops.timedout_job callback when they
* skip a reset using &enum drm_gpu_sched_stat.DRM_GPU_SCHED_STAT_NO_HANG.
*/
void drm_sched_stop(struct drm_gpu_scheduler *sched, struct drm_sched_job *bad)
{
struct drm_sched_job *s_job, *tmp;
drm_sched_wqueue_stop(sched);
/*
* Reinsert back the bad job here - now it's safe as
* drm_sched_get_finished_job() cannot race against us and release the
* bad job at this point - we parked (waited for) any in progress
* (earlier) cleanups and drm_sched_get_finished_job() will not be
* called now until the scheduler's work items are submitted again.
*/
if (bad && bad->sched == sched)
/*
* Add at the head of the queue to reflect it was the earliest
* job extracted.
*/
list_add(&bad->list, &sched->pending_list);
/*
* Iterate the job list from later to earlier one and either deactive
* their HW callbacks or remove them from pending list if they already
* signaled.
* This iteration is thread safe as the scheduler's work items have been
* cancelled.
*/
list_for_each_entry_safe_reverse(s_job, tmp, &sched->pending_list,
list) {
if (s_job->s_fence->parent &&
dma_fence_remove_callback(s_job->s_fence->parent,
&s_job->cb)) {
dma_fence_put(s_job->s_fence->parent);
s_job->s_fence->parent = NULL;
atomic_sub(s_job->credits, &sched->credit_count);
} else {
/*
* remove job from pending_list.
* Locking here is for concurrent resume timeout
*/
spin_lock(&sched->job_list_lock);
list_del_init(&s_job->list);
spin_unlock(&sched->job_list_lock);
/*
* Wait for job's HW fence callback to finish using s_job
* before releasing it.
*
* Job is still alive so fence refcount at least 1
*/
dma_fence_wait(&s_job->s_fence->finished, false);
/*
* We must keep bad job alive for later use during
* recovery by some of the drivers but leave a hint
* that the guilty job must be released.
Annotation
- Immediate include surface: `linux/export.h`, `linux/wait.h`, `linux/sched.h`, `linux/completion.h`, `linux/dma-resv.h`, `uapi/linux/sched/types.h`, `drm/drm_print.h`, `drm/drm_gem.h`.
- Detected declarations: `function executed`, `function drm_sched_can_queue`, `function drm_sched_run_job_queue`, `function drm_sched_run_free_queue`, `function drm_sched_job_done`, `function drm_sched_job_done_cb`, `function drm_sched_start_timeout`, `function drm_sched_start_timeout_unlocked`, `function drm_sched_tdr_queue_imm`, `function drm_sched_fault`.
- 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.