drivers/gpu/drm/scheduler/sched_rq.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/scheduler/sched_rq.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/scheduler/sched_rq.c- Extension
.c- Size
- 10459 bytes
- Lines
- 384
- 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.
- 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/rbtree.hdrm/drm_print.hdrm/gpu_scheduler.hsched_internal.h
Detected Declarations
function drm_sched_entity_compare_beforefunction drm_sched_rq_update_priofunction drm_sched_rq_remove_tree_lockedfunction drm_sched_rq_update_tree_lockedfunction drm_sched_rq_initfunction drm_sched_rq_get_min_vruntimefunction drm_sched_entity_save_vruntimefunction drm_sched_entity_restore_vruntimefunction drm_sched_entity_update_vruntimefunction drm_sched_rq_add_entityfunction drm_sched_rq_remove_entityfunction drm_sched_rq_pop_entityfunction drm_sched_select_entity
Annotated Snippet
if (prio > rq_prio) {
/*
* Lower priority should not overtake higher when re-
* joining at the top of the queue so push it back
* somewhere behind the "middle" of the run-queue,
* proportional to the scheduler and entity average job
* durations.
*/
vruntime = us_to_ktime((1 + avg_us + sched_avg_us) <<
vruntime_shift[prio]);
} else if (prio < rq_prio) {
/*
* Higher priority can go first.
*/
vruntime = -ns_to_ktime(rq_prio - prio);
} else {
/* Favour entity with shorter jobs (interactivity). */
if (avg_us <= sched_avg_us)
vruntime = -ns_to_ktime(1);
else
vruntime = ns_to_ktime(1);
}
}
/*
* Restore saved relative position in the queue.
*/
vruntime = ktime_add(min_vruntime, vruntime);
stats->vruntime = vruntime;
spin_unlock(&stats->lock);
return vruntime;
}
static ktime_t drm_sched_entity_update_vruntime(struct drm_sched_entity *entity)
{
struct drm_sched_entity_stats *stats = entity->stats;
ktime_t runtime, prev;
spin_lock(&stats->lock);
prev = stats->prev_runtime;
runtime = stats->runtime;
stats->prev_runtime = runtime;
runtime = ktime_add_ns(stats->vruntime,
ktime_to_ns(ktime_sub(runtime, prev)) <<
vruntime_shift[entity->priority]);
stats->vruntime = runtime;
spin_unlock(&stats->lock);
return runtime;
}
/**
* drm_sched_rq_add_entity - add an entity
* @entity: scheduler entity
*
* Adds a scheduler entity to the run queue.
*
* Return: DRM scheduler selected to handle this entity or NULL if entity has
* been stopped and cannot be submitted to.
*/
struct drm_gpu_scheduler *
drm_sched_rq_add_entity(struct drm_sched_entity *entity)
{
struct drm_gpu_scheduler *sched;
struct drm_sched_rq *rq;
ktime_t ts;
/* Add the entity to the run queue */
spin_lock(&entity->lock);
if (entity->stopped) {
spin_unlock(&entity->lock);
DRM_ERROR("Trying to push to a killed entity\n");
return NULL;
}
rq = entity->rq;
sched = container_of(rq, typeof(*sched), rq);
spin_lock(&rq->lock);
if (list_empty(&entity->list)) {
atomic_inc(sched->score);
list_add_tail(&entity->list, &rq->entities);
}
ts = drm_sched_rq_get_min_vruntime(rq);
ts = drm_sched_entity_restore_vruntime(entity, ts, rq->head_prio);
drm_sched_rq_update_tree_locked(entity, rq, ts);
Annotation
- Immediate include surface: `linux/rbtree.h`, `drm/drm_print.h`, `drm/gpu_scheduler.h`, `sched_internal.h`.
- Detected declarations: `function drm_sched_entity_compare_before`, `function drm_sched_rq_update_prio`, `function drm_sched_rq_remove_tree_locked`, `function drm_sched_rq_update_tree_locked`, `function drm_sched_rq_init`, `function drm_sched_rq_get_min_vruntime`, `function drm_sched_entity_save_vruntime`, `function drm_sched_entity_restore_vruntime`, `function drm_sched_entity_update_vruntime`, `function drm_sched_rq_add_entity`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: source 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.