Skip to contentSkip to conversation

drm/sched: Add callback to mark if sched is ready to work.

PATCH Superseded Andrey Grodzovsky 6 participants 10 messages Oct 18, 2018 – Oct 19, 2018 5 messages not in the archive

Subsystems (6)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 drm/sched: Add callback to mark if sched is ready to work.

Problem:
A particular scheduler may become unsuable (underlying HW) after some event (e.g. GPU reset). If it's later chosen by the get free sched. policy a command will fail to be submitted.

Fix:
Add a driver specific callback to report the sced. status so rq with bad sched. can be avoided in favor of working one or none in which case job init will fail.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c |  9 ++++++++-
 drivers/gpu/drm/etnaviv/etnaviv_sched.c   |  3 ++-
 drivers/gpu/drm/scheduler/sched_entity.c  | 11 ++++++++++-
 drivers/gpu/drm/scheduler/sched_main.c    |  8 +++++++-
 drivers/gpu/drm/v3d/v3d_sched.c           |  3 ++-
 include/drm/gpu_scheduler.h               |  5 ++++-
 6 files changed, 33 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +8 -1
index 5448cf2..bbfe7f501 100644
@@ -404,6 +404,13 @@ int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,
 	return 0;
 }
 
+static bool amdgpu_ring_ready(struct drm_gpu_scheduler *sched)
+{
+	struct amdgpu_ring *ring = to_amdgpu_ring(sched);
+
+	return ring->ready;
+}
+
 /**
  * amdgpu_fence_driver_init_ring - init the fence driver
  * for the requested ring.
@@ -450,7 +457,7 @@ int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
 
 		r = drm_sched_init(&ring->sched, &amdgpu_sched_ops,
 				   num_hw_submission, amdgpu_job_hang_limit,
-				   timeout, ring->name);
+				   timeout, ring->name, amdgpu_ring_ready);
 		if (r) {
 			DRM_ERROR("Failed to create scheduler on ring %s.\n",
 				  ring->name);
drivers/gpu/drm/etnaviv/etnaviv_sched.c +2 -1
index f8c5f1e..5094013 100644
@@ -178,7 +178,8 @@ int etnaviv_sched_init(struct etnaviv_gpu *gpu)
 
 	ret = drm_sched_init(&gpu->sched, &etnaviv_sched_ops,
 			     etnaviv_hw_jobs_limit, etnaviv_job_hang_limit,
-			     msecs_to_jiffies(500), dev_name(gpu->dev));
+			     msecs_to_jiffies(500), dev_name(gpu->dev),
+				 NULL);
 	if (ret)
 		return ret;
 
drivers/gpu/drm/scheduler/sched_entity.c +10 -1
index 3e22a54..320c77a 100644
@@ -130,7 +130,16 @@ drm_sched_entity_get_free_sched(struct drm_sched_entity *entity)
 	int i;
 
 	for (i = 0; i < entity->num_rq_list; ++i) {
-		num_jobs = atomic_read(&entity->rq_list[i]->sched->num_jobs);
+		struct drm_gpu_scheduler *sched = entity->rq_list[i]->sched;
+
+		if (entity->rq_list[i]->sched->ready &&
+				!entity->rq_list[i]->sched->ready(sched)) {
+			DRM_WARN("sched%s is not ready, skipping", sched->name);
+
+			continue;
+		}
+
+		num_jobs = atomic_read(&sched->num_jobs);
 		if (num_jobs < min_jobs) {
 			min_jobs = num_jobs;
 			rq = entity->rq_list[i];
drivers/gpu/drm/scheduler/sched_main.c +7 -1
index 63b997d..6b151f2 100644
@@ -420,6 +420,9 @@ int drm_sched_job_init(struct drm_sched_job *job,
 	struct drm_gpu_scheduler *sched;
 
 	drm_sched_entity_select_rq(entity);
+	if (!entity->rq)
+		return -ENOENT;
+
 	sched = entity->rq->sched;
 
 	job->sched = sched;
@@ -606,7 +609,8 @@ int drm_sched_init(struct drm_gpu_scheduler *sched,
 		   unsigned hw_submission,
 		   unsigned hang_limit,
 		   long timeout,
-		   const char *name)
+		   const char *name,
+		   bool (*ready)(struct drm_gpu_scheduler *sched))
 {
 	int i;
 	sched->ops = ops;
@@ -633,6 +637,8 @@ int drm_sched_init(struct drm_gpu_scheduler *sched,
 		return PTR_ERR(sched->thread);
 	}
 
+	sched->ready = ready;
+
 	return 0;
 }
 EXPORT_SYMBOL(drm_sched_init);
drivers/gpu/drm/v3d/v3d_sched.c +2 -1
index 80b641f..e06cc0d 100644
@@ -212,7 +212,8 @@ v3d_sched_init(struct v3d_dev *v3d)
 			     &v3d_sched_ops,
 			     hw_jobs_limit, job_hang_limit,
 			     msecs_to_jiffies(hang_limit_ms),
-			     "v3d_bin");
+			     "v3d_bin",
+				 NULL);
 	if (ret) {
 		dev_err(v3d->dev, "Failed to create bin scheduler: %d.", ret);
 		return ret;
include/drm/gpu_scheduler.h +4 -1
index 0684dcd..a6e18fe 100644
@@ -283,12 +283,15 @@ struct drm_gpu_scheduler {
 	spinlock_t			job_list_lock;
 	int				hang_limit;
 	atomic_t                        num_jobs;
+
+	bool 			(*ready)(struct drm_gpu_scheduler *sched);
 };
 
 int drm_sched_init(struct drm_gpu_scheduler *sched,
 		   const struct drm_sched_backend_ops *ops,
 		   uint32_t hw_submission, unsigned hang_limit, long timeout,
-		   const char *name);
+		   const char *name,
+		   bool (*ready)(struct drm_gpu_scheduler *sched));
 void drm_sched_fini(struct drm_gpu_scheduler *sched);
 int drm_sched_job_init(struct drm_sched_job *job,
 		       struct drm_sched_entity *entity,
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#1 lore raw

PATCH 2/3 drm/sched: Expose drm_sched_entity_select_rq to use in drivers.

---
 drivers/gpu/drm/scheduler/sched_entity.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/scheduler/sched_entity.c +1 -0
index 320c77a..426606c 100644
@@ -492,6 +492,7 @@ void drm_sched_entity_select_rq(struct drm_sched_entity *entity)
 	entity->rq = rq;
 	spin_unlock(&entity->rq_lock);
 }
+EXPORT_SYMBOL(drm_sched_entity_select_rq);
 
 /**
  * drm_sched_entity_push_job - Submit a job to the entity's job queue
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

A message that is not in the archive (sent off-list or not yet received): 1539888261-331-1-git-send-email-andrey.grodzovsky-5C7GfCeVMHo@public.gmane.org

#3 lore raw

PATCH 3/3 drm/amdgpu: Refresh rq selection for job after ASIC reset

A ring might become unusable after reset, if that the case drm_sched_entity_select_rq will choose another, working rq to run the job if there is one.
Also, skip recovery of ring which is not ready.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +15 -1
index d11489e..3124ca1 100644
@@ -3355,10 +3355,24 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
 	else
 		r = amdgpu_device_reset(adev);
 
+	/*
+	 * After reboot a ring might fail in which case this will
+	 * move the job to different rq if possible
+	 */
+	if (job) {
+		drm_sched_entity_select_rq(job->base.entity);
+		if (job->base.entity->rq) {
+			job->base.sched = job->base.entity->rq->sched;
+		} else {
+			job->base.sched = NULL;
+			r = -ENOENT;
+		}
+	}
+
 	for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
 		struct amdgpu_ring *ring = adev->rings[i];
 
-		if (!ring || !ring->sched.thread)
+		if (!ring || !ring->ready || !ring->sched.thread)
 			continue;
 
 		/* only need recovery sched of the given job's ring
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1539888261-331-3-git-send-email-andrey.grodzovsky-5C7GfCeVMHo@public.gmane.org

#5 lore raw

Re: [PATCH 3/3] drm/amdgpu: Refresh rq selection for job after ASIC reset

Am 18.10.18 um 20:44 schrieb Andrey Grodzovsky:

Quoted 4 lines

A ring might become unusable after reset, if that the case drm_sched_entity_select_rq will choose another, working rq to run the job if there is one.
Also, skip recovery of ring which is not ready.

Well that is not even remotely sufficient.

If we can't bring up a ring any more after a reset we would need to move all jobs which where previously scheduled on it and all of its entities to a different instance.

What you do here breaks dependencies between jobs and can result in unforeseen consequences including random memory writes.

As far as I can see that can't be done correctly with the current scheduler design.

Additional to that when we can't restart one instance of a ring we usually can't restart all others either. So the whole approach is rather pointless.

Regards,
Christian.

Quoted 26 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 16 +++++++++++++++-
  1 file changed, 15 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +12 -0
index d11489e..3124ca1 100644
@@ -3355,10 +3355,24 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
  	else
  		r = amdgpu_device_reset(adev);
 
+	/*
+	 * After reboot a ring might fail in which case this will
+	 * move the job to different rq if possible
+	 */
+	if (job) {
+		drm_sched_entity_select_rq(job->base.entity);
+		if (job->base.entity->rq) {
+			job->base.sched = job->base.entity->rq->sched;
+		} else {
+			job->base.sched = NULL;
+			r = -ENOENT;
+		}

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct amdgpu_device *adev, · line 3378

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -1
+	}
+
  	for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
  		struct amdgpu_ring *ring = adev->rings[i];
 
-		if (!ring || !ring->sched.thread)
+		if (!ring || !ring->ready || !ring->sched.thread)
  			continue;
 
  		/* only need recovery sched of the given job's ring

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 92efce5c-f9ad-847b-09b3-e7c6f7f13ff6-5C7GfCeVMHo@public.gmane.org

#7 lore raw

Re: [PATCH 3/3] drm/amdgpu: Refresh rq selection for job after ASIC reset

Quoted 10 lines · Christian

Am 18.10.18 um 20:44 schrieb Andrey Grodzovsky:

Quoted 4 lines

A ring might become unusable after reset, if that the case drm_sched_entity_select_rq will choose another, working rq to run the job if there is one.
Also, skip recovery of ring which is not ready.

Well that is not even remotely sufficient.

If we can't bring up a ring any more after a reset we would need to move all jobs which where previously scheduled on it and all of its entities to a different instance.

That one should be easy to add inside amdgpu_device_gpu_recover in case ring is dead, we just do the same for all the jobs in sched->ring_mirror_list of the dead ring
before doing recovery for them, no?

Quoted 3 lines

What you do here breaks dependencies between jobs and can result in unforeseen consequences including random memory writes.

Can you explain this a bit more ? AFAIK any job dependent on this job will still wait for it's completion
before running regardless of did this job moved to a different ring. What am I missing ?

Quoted 7 lines

As far as I can see that can't be done correctly with the current scheduler design.

Additional to that when we can't restart one instance of a ring we usually can't restart all others either. So the whole approach is rather pointless.

From my testing looks like we can, compute ring 0 is dead but IB tests
pass on other compute rings.

Andrey

Quoted 38 lines

Regards,
Christian.

Quoted 34 lines
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 16 +++++++++++++++-
   1 file changed, 15 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +15 -1
index d11489e..3124ca1 100644
@@ -3355,10 +3355,24 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
   	else
   		r = amdgpu_device_reset(adev);
 
+	/*
+	 * After reboot a ring might fail in which case this will
+	 * move the job to different rq if possible
+	 */
+	if (job) {
+		drm_sched_entity_select_rq(job->base.entity);
+		if (job->base.entity->rq) {
+			job->base.sched = job->base.entity->rq->sched;
+		} else {
+			job->base.sched = NULL;
+			r = -ENOENT;
+		}
+	}
+
   	for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
   		struct amdgpu_ring *ring = adev->rings[i];
 
-		if (!ring || !ring->sched.thread)
+		if (!ring || !ring->ready || !ring->sched.thread)
   			continue;
 
Quoted 5 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct amdgpu_device *adev, · line 3378

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
   		/* only need recovery sched of the given job's ring

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 0928be66-d606-84b8-4fa8-399e5615f75c-5C7GfCeVMHo@public.gmane.org

#9 lore raw

Re: [PATCH 3/3] drm/amdgpu: Refresh rq selection for job after ASIC reset

Am 19.10.18 um 17:06 schrieb Grodzovsky, Andrey:

Quoted 9 lines · Christian
Quoted 7 lines

Am 18.10.18 um 20:44 schrieb Andrey Grodzovsky:

Quoted 4 lines

A ring might become unusable after reset, if that the case drm_sched_entity_select_rq will choose another, working rq to run the job if there is one.
Also, skip recovery of ring which is not ready.

Well that is not even remotely sufficient.

Quoted 7 lines
Quoted 3 lines

If we can't bring up a ring any more after a reset we would need to move all jobs which where previously scheduled on it and all of its entities to a different instance.

That one should be easy to add inside amdgpu_device_gpu_recover in case ring is dead, we just do the same for all the jobs in sched->ring_mirror_list of the dead ring
before doing recovery for them, no?

Correct, you need to execute all jobs from the ring_mirror_list as well as move all entities to other rqs.

But there are some problem with that see below.

Quoted 6 lines
Quoted 2 lines

What you do here breaks dependencies between jobs and can result in unforeseen consequences including random memory writes.

Can you explain this a bit more ? AFAIK any job dependent on this job will still wait for it's completion
before running regardless of did this job moved to a different ring. What am I missing ?

The stuff dependent on the moving jobs should indeed work correctly.

But you don't necessary have space to execute the ring_mirror_list on another scheduler. And to that the jobs are prepared to run on a specific ring, e.g. UVD jobs are patches, VMIDs assigned etc etc...

So that most likely won't work correctly.

Quoted 8 lines
Quoted 6 lines

As far as I can see that can't be done correctly with the current scheduler design.

Additional to that when we can't restart one instance of a ring we usually can't restart all others either. So the whole approach is rather pointless.

From my testing looks like we can, compute ring 0 is dead but IB tests
pass on other compute rings.

Interesting, but I would rather investigate why compute ring 0 is dead while other still work.

At least some compute rings should be handled by the same engine, so if one is dead all other should be dead as well.

Christian.

Quoted 45 lines

Andrey

Quoted 37 lines

Regards,
Christian.

Quoted 34 lines
---
    drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 16 +++++++++++++++-
    1 file changed, 15 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +15 -1
index d11489e..3124ca1 100644
@@ -3355,10 +3355,24 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
    	else
    		r = amdgpu_device_reset(adev);
 
+	/*
+	 * After reboot a ring might fail in which case this will
+	 * move the job to different rq if possible
+	 */
+	if (job) {
+		drm_sched_entity_select_rq(job->base.entity);
+		if (job->base.entity->rq) {
+			job->base.sched = job->base.entity->rq->sched;
+		} else {
+			job->base.sched = NULL;
+			r = -ENOENT;
+		}
+	}
+
    	for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
    		struct amdgpu_ring *ring = adev->rings[i];
 
-		if (!ring || !ring->sched.thread)
+		if (!ring || !ring->ready || !ring->sched.thread)
    			continue;
 
Quoted 5 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct amdgpu_device *adev, · line 3378

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
    		/* only need recovery sched of the given job's ring

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#10 lore raw

Re: [PATCH 3/3] drm/amdgpu: Refresh rq selection for job after ASIC reset

That my next step.

Andrey

On 10/19/2018 12:28 PM, Christian König wrote:
From my testing looks like we can, compute ring 0 is dead but IB tests
pass on other compute rings.

Interesting, but I would rather investigate why compute ring 0 is dead while other still work.

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#11 lore raw
In reply to a message not in the archive
Quoted 29 lines · Andrey Grodzovsky

Problem:
A particular scheduler may become unsuable (underlying HW) after some event (e.g. GPU reset). If it's later chosen by the get free sched. policy a command will fail to be submitted.

Fix:
Add a driver specific callback to report the sced. status so rq with bad sched. can be avoided in favor of working one or none in which case job init will fail.

[...]

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +1 -1
@@ -450,7 +457,7 @@ int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
 
 		r = drm_sched_init(&ring->sched, &amdgpu_sched_ops,
 				   num_hw_submission, amdgpu_job_hang_limit,
-				   timeout, ring->name);
+				   timeout, ring->name, amdgpu_ring_ready);
 		if (r) {
 			DRM_ERROR("Failed to create scheduler on ring %s.\n",
 				  ring->name);
drivers/gpu/drm/etnaviv/etnaviv_sched.c +0 -0
index f8c5f1e..5094013 100644

drivers/gpu/drm/etnaviv/etnaviv_sched.c int etnaviv_sched_init(struct etnaviv_gpu *gpu) · line 182

Quoted 6 lines
drivers/gpu/drm/etnaviv/etnaviv_sched.c +2 -1
@@ -178,7 +178,8 @@ int etnaviv_sched_init(struct etnaviv_gpu *gpu)
 
 	ret = drm_sched_init(&gpu->sched, &etnaviv_sched_ops,
 			     etnaviv_hw_jobs_limit, etnaviv_job_hang_limit,
-			     msecs_to_jiffies(500), dev_name(gpu->dev));
+			     msecs_to_jiffies(500), dev_name(gpu->dev),
+				 NULL);

Indentation looks wrong for the NULL here...

drivers/gpu/drm/scheduler/sched_entity.c drm_sched_entity_get_free_sched(struct drm_sched_entity *entity) · line 136

Quoted 13 lines
drivers/gpu/drm/scheduler/sched_entity.c +4 -1
index 3e22a54..320c77a 100644
@@ -130,7 +130,16 @@ drm_sched_entity_get_free_sched(struct drm_sched_entity *entity)
 	int i;
 
 	for (i = 0; i < entity->num_rq_list; ++i) {
-		num_jobs = atomic_read(&entity->rq_list[i]->sched->num_jobs);
+		struct drm_gpu_scheduler *sched = entity->rq_list[i]->sched;
+
+		if (entity->rq_list[i]->sched->ready &&
+				!entity->rq_list[i]->sched->ready(sched)) {

... the second line of the if here...

drivers/gpu/drm/v3d/v3d_sched.c v3d_sched_init(struct v3d_dev *v3d) · line 216

Quoted 11 lines
drivers/gpu/drm/v3d/v3d_sched.c +2 -1
index 80b641f..e06cc0d 100644
@@ -212,7 +212,8 @@ v3d_sched_init(struct v3d_dev *v3d)
 			     &v3d_sched_ops,
 			     hw_jobs_limit, job_hang_limit,
 			     msecs_to_jiffies(hang_limit_ms),
-			     "v3d_bin");
+			     "v3d_bin",
+				 NULL);

... the NULL here...

include/drm/gpu_scheduler.h struct drm_gpu_scheduler { · line 288

Quoted 11 lines
include/drm/gpu_scheduler.h +2 -0
index 0684dcd..a6e18fe 100644
@@ -283,12 +283,15 @@ struct drm_gpu_scheduler {
 	spinlock_t			job_list_lock;
 	int				hang_limit;
 	atomic_t                        num_jobs;
+
+	bool 			(*ready)(struct drm_gpu_scheduler *sched);
 };

... and the new line here.

Which editor are you using?

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 567b553a-eef7-9560-a789-f1c8bffe3206-otUistvHUpPR7s880joybQ@public.gmane.org

#14 lore raw
In reply to Andrey Grodzovsky

Am 18.10.18 um 20:44 schrieb Andrey Grodzovsky:

Quoted 10 lines

Problem:
A particular scheduler may become unsuable (underlying HW) after some event (e.g. GPU reset). If it's later chosen by the get free sched. policy a command will fail to be submitted.

Fix:
Add a driver specific callback to report the sced. status so rq with bad sched. can be avoided in favor of working one or none in which case job init will fail.

I would rather go with the approach of moving the ready flag completely into the scheduler instead.

Christian.

Quoted 132 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c |  9 ++++++++-
  drivers/gpu/drm/etnaviv/etnaviv_sched.c   |  3 ++-
  drivers/gpu/drm/scheduler/sched_entity.c  | 11 ++++++++++-
  drivers/gpu/drm/scheduler/sched_main.c    |  8 +++++++-
  drivers/gpu/drm/v3d/v3d_sched.c           |  3 ++-
  include/drm/gpu_scheduler.h               |  5 ++++-
  6 files changed, 33 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +8 -1
index 5448cf2..bbfe7f501 100644
@@ -404,6 +404,13 @@ int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,
  	return 0;
  }
 
+static bool amdgpu_ring_ready(struct drm_gpu_scheduler *sched)
+{
+	struct amdgpu_ring *ring = to_amdgpu_ring(sched);
+
+	return ring->ready;
+}
+
  /**
   * amdgpu_fence_driver_init_ring - init the fence driver
   * for the requested ring.
@@ -450,7 +457,7 @@ int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
 
  		r = drm_sched_init(&ring->sched, &amdgpu_sched_ops,
  				   num_hw_submission, amdgpu_job_hang_limit,
-				   timeout, ring->name);
+				   timeout, ring->name, amdgpu_ring_ready);
  		if (r) {
  			DRM_ERROR("Failed to create scheduler on ring %s.\n",
  				  ring->name);
drivers/gpu/drm/etnaviv/etnaviv_sched.c +2 -1
index f8c5f1e..5094013 100644
@@ -178,7 +178,8 @@ int etnaviv_sched_init(struct etnaviv_gpu *gpu)
 
  	ret = drm_sched_init(&gpu->sched, &etnaviv_sched_ops,
  			     etnaviv_hw_jobs_limit, etnaviv_job_hang_limit,
-			     msecs_to_jiffies(500), dev_name(gpu->dev));
+			     msecs_to_jiffies(500), dev_name(gpu->dev),
+				 NULL);
  	if (ret)
  		return ret;
 
drivers/gpu/drm/scheduler/sched_entity.c +10 -1
index 3e22a54..320c77a 100644
@@ -130,7 +130,16 @@ drm_sched_entity_get_free_sched(struct drm_sched_entity *entity)
  	int i;
 
  	for (i = 0; i < entity->num_rq_list; ++i) {
-		num_jobs = atomic_read(&entity->rq_list[i]->sched->num_jobs);
+		struct drm_gpu_scheduler *sched = entity->rq_list[i]->sched;
+
+		if (entity->rq_list[i]->sched->ready &&
+				!entity->rq_list[i]->sched->ready(sched)) {
+			DRM_WARN("sched%s is not ready, skipping", sched->name);
+
+			continue;
+		}
+
+		num_jobs = atomic_read(&sched->num_jobs);
  		if (num_jobs < min_jobs) {
  			min_jobs = num_jobs;
  			rq = entity->rq_list[i];
drivers/gpu/drm/scheduler/sched_main.c +7 -1
index 63b997d..6b151f2 100644
@@ -420,6 +420,9 @@ int drm_sched_job_init(struct drm_sched_job *job,
  	struct drm_gpu_scheduler *sched;
 
  	drm_sched_entity_select_rq(entity);
+	if (!entity->rq)
+		return -ENOENT;
+
  	sched = entity->rq->sched;
 
  	job->sched = sched;
@@ -606,7 +609,8 @@ int drm_sched_init(struct drm_gpu_scheduler *sched,
  		   unsigned hw_submission,
  		   unsigned hang_limit,
  		   long timeout,
-		   const char *name)
+		   const char *name,
+		   bool (*ready)(struct drm_gpu_scheduler *sched))
  {
  	int i;
  	sched->ops = ops;
@@ -633,6 +637,8 @@ int drm_sched_init(struct drm_gpu_scheduler *sched,
  		return PTR_ERR(sched->thread);
  	}
 
+	sched->ready = ready;
+
  	return 0;
  }
  EXPORT_SYMBOL(drm_sched_init);
drivers/gpu/drm/v3d/v3d_sched.c +2 -1
index 80b641f..e06cc0d 100644
@@ -212,7 +212,8 @@ v3d_sched_init(struct v3d_dev *v3d)
  			     &v3d_sched_ops,
  			     hw_jobs_limit, job_hang_limit,
  			     msecs_to_jiffies(hang_limit_ms),
-			     "v3d_bin");
+			     "v3d_bin",
+				 NULL);
  	if (ret) {
  		dev_err(v3d->dev, "Failed to create bin scheduler: %d.", ret);
  		return ret;
include/drm/gpu_scheduler.h +2 -0
index 0684dcd..a6e18fe 100644
@@ -283,12 +283,15 @@ struct drm_gpu_scheduler {
  	spinlock_t			job_list_lock;
  	int				hang_limit;
  	atomic_t                        num_jobs;
+
+	bool 			(*ready)(struct drm_gpu_scheduler *sched);
  };

include/drm/gpu_scheduler.h struct drm_gpu_scheduler { · line 297

Quoted 10 lines
include/drm/gpu_scheduler.h +2 -1
 
  int drm_sched_init(struct drm_gpu_scheduler *sched,
  		   const struct drm_sched_backend_ops *ops,
  		   uint32_t hw_submission, unsigned hang_limit, long timeout,
-		   const char *name);
+		   const char *name,
+		   bool (*ready)(struct drm_gpu_scheduler *sched));
  void drm_sched_fini(struct drm_gpu_scheduler *sched);
  int drm_sched_job_init(struct drm_sched_job *job,
  		       struct drm_sched_entity *entity,

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel