Skip to content

Commit fe88fb3

Browse files
Tvrtko UrsulinPhilipp Stanner
authored andcommitted
drm/sched: Consolidate drm_sched_rq_select_entity_rr
Extract out two copies of the identical code to drm_sched_rq_select_entity_rr()'s epilogue to make it smaller and more readable. Signed-off-by: Tvrtko Ursulin <[email protected]> Cc: Christian König <[email protected]> Cc: Danilo Krummrich <[email protected]> Cc: Matthew Brost <[email protected]> Cc: Philipp Stanner <[email protected]> Reviewed-by: Matthew Brost <[email protected]> [phasta: commit message] Signed-off-by: Philipp Stanner <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 602d565 commit fe88fb3

File tree

1 file changed

+20
-28
lines changed

1 file changed

+20
-28
lines changed

drivers/gpu/drm/scheduler/sched_main.c

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -263,38 +263,14 @@ drm_sched_rq_select_entity_rr(struct drm_gpu_scheduler *sched,
263263
entity = rq->current_entity;
264264
if (entity) {
265265
list_for_each_entry_continue(entity, &rq->entities, list) {
266-
if (drm_sched_entity_is_ready(entity)) {
267-
/* If we can't queue yet, preserve the current
268-
* entity in terms of fairness.
269-
*/
270-
if (!drm_sched_can_queue(sched, entity)) {
271-
spin_unlock(&rq->lock);
272-
return ERR_PTR(-ENOSPC);
273-
}
274-
275-
rq->current_entity = entity;
276-
reinit_completion(&entity->entity_idle);
277-
spin_unlock(&rq->lock);
278-
return entity;
279-
}
266+
if (drm_sched_entity_is_ready(entity))
267+
goto found;
280268
}
281269
}
282270

283271
list_for_each_entry(entity, &rq->entities, list) {
284-
if (drm_sched_entity_is_ready(entity)) {
285-
/* If we can't queue yet, preserve the current entity in
286-
* terms of fairness.
287-
*/
288-
if (!drm_sched_can_queue(sched, entity)) {
289-
spin_unlock(&rq->lock);
290-
return ERR_PTR(-ENOSPC);
291-
}
292-
293-
rq->current_entity = entity;
294-
reinit_completion(&entity->entity_idle);
295-
spin_unlock(&rq->lock);
296-
return entity;
297-
}
272+
if (drm_sched_entity_is_ready(entity))
273+
goto found;
298274

299275
if (entity == rq->current_entity)
300276
break;
@@ -303,6 +279,22 @@ drm_sched_rq_select_entity_rr(struct drm_gpu_scheduler *sched,
303279
spin_unlock(&rq->lock);
304280

305281
return NULL;
282+
283+
found:
284+
if (!drm_sched_can_queue(sched, entity)) {
285+
/*
286+
* If scheduler cannot take more jobs signal the caller to not
287+
* consider lower priority queues.
288+
*/
289+
entity = ERR_PTR(-ENOSPC);
290+
} else {
291+
rq->current_entity = entity;
292+
reinit_completion(&entity->entity_idle);
293+
}
294+
295+
spin_unlock(&rq->lock);
296+
297+
return entity;
306298
}
307299

308300
/**

0 commit comments

Comments
 (0)