[PATCH] drm/sched: Re-queue run job worker when drm_sched_entity_pop_job() returns NULL

Luben Tuikov ltuikov89 at gmail.com
Tue Feb 6 00:45:32 UTC 2024


On 2024-01-29 22:04, Matthew Brost wrote:
> Rather then loop over entities until one with a ready job is found,
> re-queue the run job worker when drm_sched_entity_pop_job() returns NULL.
> 
> Fixes: 6dbd9004a55 ("drm/sched: Drain all entities in DRM sched run job worker")
> Signed-off-by: Matthew Brost <matthew.brost at intel.com>

Indeed, we cannot have any loops in the GPU scheduler work items, as we need to bounce
between submit and free in the same work queue. (Coming from the original design before
work items/queues were introduced).

Thanks for fixing this, Matt!

Reviewed-by: Luben Tuikov <ltuikov89 at gmail.com>
-- 
Regards,
Luben

> ---
>  drivers/gpu/drm/scheduler/sched_main.c | 15 +++++++++------
>  1 file changed, 9 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c
> index 8acbef7ae53d..7e90c9f95611 100644
> --- a/drivers/gpu/drm/scheduler/sched_main.c
> +++ b/drivers/gpu/drm/scheduler/sched_main.c
> @@ -1178,21 +1178,24 @@ static void drm_sched_run_job_work(struct work_struct *w)
>  	struct drm_sched_entity *entity;
>  	struct dma_fence *fence;
>  	struct drm_sched_fence *s_fence;
> -	struct drm_sched_job *sched_job = NULL;
> +	struct drm_sched_job *sched_job;
>  	int r;
>  
>  	if (READ_ONCE(sched->pause_submit))
>  		return;
>  
>  	/* Find entity with a ready job */
> -	while (!sched_job && (entity = drm_sched_select_entity(sched))) {
> -		sched_job = drm_sched_entity_pop_job(entity);
> -		if (!sched_job)
> -			complete_all(&entity->entity_idle);
> -	}
> +	entity = drm_sched_select_entity(sched);
>  	if (!entity)
>  		return;	/* No more work */
>  
> +	sched_job = drm_sched_entity_pop_job(entity);
> +	if (!sched_job) {
> +		complete_all(&entity->entity_idle);
> +		drm_sched_run_job_queue(sched);
> +		return;
> +	}
> +
>  	s_fence = sched_job->s_fence;
>  
>  	atomic_add(sched_job->credits, &sched->credit_count);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_0x4C15479431A334AF.asc
Type: application/pgp-keys
Size: 664 bytes
Desc: OpenPGP public key
URL: <https://lists.freedesktop.org/archives/dri-devel/attachments/20240205/506f510f/attachment.key>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 236 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/dri-devel/attachments/20240205/506f510f/attachment.sig>


More information about the dri-devel mailing list