DRM scheduler changes for Xe
Subsystems (12)
Matthew Brost
maintainerv4 cover DRM scheduler changes for Xe
As a prerequisite to merging the new Intel Xe DRM driver [1] [2], we have been asked to merge our common DRM scheduler patches first.
This a continuation of a RFC [3] with all comments addressed, ready for a full review, and hopefully in state which can merged in the near future. More details of this series can found in the cover letter of the RFC [3].
These changes have been tested with the Xe driver.
v2:
- Break run job, free job, and process message in own work items
- This might break other drivers as run job and free job now can run in parallel, can fix up if needed
v3:
- Include missing patch 'drm/sched: Add drm_sched_submit_* helpers'
- Fix issue with setting timestamp to early
- Don't dequeue jobs for single entity after calling entity fini
- Flush pending jobs on entity fini
- Add documentation for entity teardown
- Add Matthew Brost to maintainers of DRM scheduler
v4:
- Drop message interface
- Drop 'Flush pending jobs on entity fini'
- Drop 'Add documentation for entity teardown'
- Address all feedback
Matt
Matthew Brost (10):
drm/sched: Add drm_sched_submit_* helpers
drm/sched: Convert drm scheduler to use a work queue rather than
kthread
drm/sched: Move schedule policy to scheduler
drm/sched: Add DRM_SCHED_POLICY_SINGLE_ENTITY scheduling policy drm/sched: Split free_job into own work item
drm/sched: Add drm_sched_start_timeout_unlocked helper drm/sched: Start submission before TDR in drm_sched_start drm/sched: Submit job before starting TDR
drm/sched: Add helper to queue TDR immediately for current and future
jobs
drm/sched: Update maintainers of GPU scheduler
MAINTAINERS | 1 + .../drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 15 +- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 15 +- drivers/gpu/drm/etnaviv/etnaviv_sched.c | 5 +- drivers/gpu/drm/lima/lima_sched.c | 5 +- drivers/gpu/drm/msm/adreno/adreno_device.c | 6 +- drivers/gpu/drm/msm/msm_ringbuffer.c | 5 +- drivers/gpu/drm/nouveau/nouveau_sched.c | 5 +- drivers/gpu/drm/panfrost/panfrost_job.c | 5 +- drivers/gpu/drm/scheduler/sched_entity.c | 85 ++- drivers/gpu/drm/scheduler/sched_fence.c | 2 +- drivers/gpu/drm/scheduler/sched_main.c | 491 ++++++++++++------ drivers/gpu/drm/v3d/v3d_sched.c | 25 +- include/drm/gpu_scheduler.h | 48 +- 15 files changed, 495 insertions(+), 220 deletions(-)
Signature · 1 line
2.34.1
Matthew Brost
maintainerPATCH v4 1/10 drm/sched: Add drm_sched_submit_* helpers
Add scheduler submit ready, stop, and start helpers to hide the implementation details of the scheduler from the drivers.
--- .../drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 15 +++---- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 12 +++--- drivers/gpu/drm/msm/adreno/adreno_device.c | 6 ++- drivers/gpu/drm/scheduler/sched_main.c | 40 ++++++++++++++++++- include/drm/gpu_scheduler.h | 3 ++ 6 files changed, 60 insertions(+), 18 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c +1 -1
@@ -290,7 +290,7 @@ static int suspend_resume_compute_scheduler(struct amdgpu_device *adev, bool susfor (i =0 ; i < adev->gfx.num_compute_rings; i++) {struct amdgpu_ring *ring = &adev->gfx.compute_ring[i]; -if (!(ring && ring->sched.thread)) +if (!(ring &&drm_sched_submit_ready (&ring->sched)))continue ;/* stop secheduler and drain ring. */
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +8 -7
@@ -1659,9 +1659,9 @@ static int amdgpu_debugfs_test_ib_show(struct seq_file *m, void *unused)for (i =0 ; i <AMDGPU_MAX_RINGS ; i++) {struct amdgpu_ring *ring = adev->rings[i]; -if (!ring || !ring->sched.thread) +if (!ring || !drm_sched_submit_ready (&ring->sched))continue ; -kthread_park (ring->sched.thread); +drm_sched_submit_stop (&ring->sched); }seq_puts (m,"run ib test:\n" );
@@ -1675,9 +1675,9 @@ static int amdgpu_debugfs_test_ib_show(struct seq_file *m, void *unused)for (i =0 ; i <AMDGPU_MAX_RINGS ; i++) {struct amdgpu_ring *ring = adev->rings[i]; -if (!ring || !ring->sched.thread) +if (!ring || !drm_sched_submit_ready (&ring->sched))continue ; -kthread_unpark (ring->sched.thread); +drm_sched_submit_start (&ring->sched); }up_write (&adev->reset_domain->sem);
@@ -1897,7 +1897,8 @@ static int amdgpu_debugfs_ib_preempt(void *data, u64 val) ring = adev->rings[val]; -if (!ring || !ring->funcs->preempt_ib || !ring->sched.thread) +if (!ring || !ring->funcs->preempt_ib || + !drm_sched_submit_ready (&ring->sched))return -EINVAL ;/* the last preemption failed */
@@ -1915,7 +1916,7 @@ static int amdgpu_debugfs_ib_preempt(void *data, u64 val) goto pro_end;/* stop the scheduler */ -kthread_park (ring->sched.thread); +drm_sched_submit_stop (&ring->sched);/* preempt the IB */ r =amdgpu_ring_preempt_ib (ring);
@@ -1949,7 +1950,7 @@ static int amdgpu_debugfs_ib_preempt(void *data, u64 val) failure:/* restart the scheduler */ -kthread_unpark (ring->sched.thread); +drm_sched_submit_start (&ring->sched);up_read (&adev->reset_domain->sem);
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +6 -6
@@ -4588,7 +4588,7 @@ bool amdgpu_device_has_job_running(struct amdgpu_device *adev)for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = adev->rings[i]; -if (!ring || !ring->sched.thread) +if (!ring || !drm_sched_submit_ready (&ring->sched))continue ;spin_lock (&ring->sched.job_list_lock);
@@ -4727,7 +4727,7 @@ int amdgpu_device_pre_asic_reset(struct amdgpu_device *adev,for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = adev->rings[i]; -if (!ring || !ring->sched.thread) +if (!ring || !drm_sched_submit_ready (&ring->sched))continue ;/* Clear job fence from fence drv to avoid force_completion
@@ -5266,7 +5266,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = tmp_adev->rings[i]; -if (!ring || !ring->sched.thread) +if (!ring || !drm_sched_submit_ready (&ring->sched))continue ;drm_sched_stop (&ring->sched, job ? &job->base :NULL );
@@ -5341,7 +5341,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = tmp_adev->rings[i]; -if (!ring || !ring->sched.thread) +if (!ring || !drm_sched_submit_ready (&ring->sched))continue ;drm_sched_start (&ring->sched, true);
@@ -5667,7 +5667,7 @@ pci_ers_result_t amdgpu_pci_error_detected(struct pci_dev *pdev, pci_channel_stafor (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = adev->rings[i]; -if (!ring || !ring->sched.thread) +if (!ring || !drm_sched_submit_ready (&ring->sched))continue ;drm_sched_stop (&ring->sched,NULL );
@@ -5795,7 +5795,7 @@ void amdgpu_pci_resume(struct pci_dev *pdev)for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = adev->rings[i]; -if (!ring || !ring->sched.thread) +if (!ring || !drm_sched_submit_ready (&ring->sched))continue ;drm_sched_start (&ring->sched, true);
drivers/gpu/drm/msm/adreno/adreno_device.c +4 -2
@@ -809,7 +809,8 @@ static void suspend_scheduler(struct msm_gpu *gpu)*/ for (i =0 ; i < gpu->nr_rings; i++) {struct drm_gpu_scheduler *sched = &gpu->rb[i]->sched; -kthread_park (sched->thread); + +drm_sched_submit_stop (sched); } }
@@ -819,7 +820,8 @@ static void resume_scheduler(struct msm_gpu *gpu)for (i =0 ; i < gpu->nr_rings; i++) {struct drm_gpu_scheduler *sched = &gpu->rb[i]->sched; -kthread_unpark (sched->thread); + +drm_sched_submit_start (sched); } }
drivers/gpu/drm/scheduler/sched_main.c +38 -2
@@ -439,7 +439,7 @@ void drm_sched_stop(struct drm_gpu_scheduler *sched, struct drm_sched_job *bad) {struct drm_sched_job *s_job, *tmp; -kthread_park (sched->thread); +drm_sched_submit_stop (sched);/* * Reinsert back the bad job here - now it's safe as
@@ -552,7 +552,7 @@ void drm_sched_start(struct drm_gpu_scheduler *sched, bool full_recovery)spin_unlock (&sched->job_list_lock); } -kthread_unpark (sched->thread); +drm_sched_submit_start (sched); }EXPORT_SYMBOL (drm_sched_start);
@@ -1206,3 +1206,39 @@ void drm_sched_increase_karma(struct drm_sched_job *bad) } }EXPORT_SYMBOL (drm_sched_increase_karma); + +/** +* drm_sched_submit_ready - scheduler ready for submission +* +* @sched: scheduler instance +* +* Returns true if submission is ready +*/ +bool drm_sched_submit_ready (struct drm_gpu_scheduler *sched) +{ +return !!sched->thread; + +} +EXPORT_SYMBOL (drm_sched_submit_ready); + +/** +* drm_sched_submit_stop - stop scheduler submission +* +* @sched: scheduler instance +*/ +void drm_sched_submit_stop (struct drm_gpu_scheduler *sched) +{ +kthread_park (sched->thread); +} +EXPORT_SYMBOL (drm_sched_submit_stop); + +/** +* drm_sched_submit_start - start scheduler submission +* +* @sched: scheduler instance +*/ +void drm_sched_submit_start (struct drm_gpu_scheduler *sched) +{ +kthread_unpark (sched->thread); +} +EXPORT_SYMBOL (drm_sched_submit_start);
include/drm/gpu_scheduler.h +3 -0
@@ -550,6 +550,9 @@ void drm_sched_entity_modify_sched(struct drm_sched_entity *entity,void drm_sched_job_cleanup (struct drm_sched_job *job);void drm_sched_wakeup_if_can_queue (struct drm_gpu_scheduler *sched); +bool drm_sched_submit_ready (struct drm_gpu_scheduler *sched); +void drm_sched_submit_stop (struct drm_gpu_scheduler *sched); +void drm_sched_submit_start (struct drm_gpu_scheduler *sched);void drm_sched_stop (struct drm_gpu_scheduler *sched,struct drm_sched_job *bad);void drm_sched_start (struct drm_gpu_scheduler *sched,bool full_recovery);void drm_sched_resubmit_jobs (struct drm_gpu_scheduler *sched);
Signature · 1 line
2.34.1
Re: [PATCH v4 01/10] drm/sched: Add drm_sched_submit_* helpers
Am 19.09.23 um 07:01 schrieb Matthew Brost:
Quoted 4 lines
Add scheduler submit ready, stop, and start helpers to hide the implementation details of the scheduler from the drivers.
Signed-off-by Matthew Brost <[email protected]>
No idea when I have time to look into the rest :( But Luben should take a look.
Regards,
Christian
Quoted 236 lines
--- .../drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 15 +++---- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 12 +++--- drivers/gpu/drm/msm/adreno/adreno_device.c | 6 ++- drivers/gpu/drm/scheduler/sched_main.c | 40 ++++++++++++++++++- include/drm/gpu_scheduler.h | 3 ++ 6 files changed, 60 insertions(+), 18 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c +1
-1@@ -290,7 +290,7 @@ static int suspend_resume_compute_scheduler(struct amdgpu_device *adev, bool susfor (i =0 ; i < adev->gfx.num_compute_rings; i++) {struct amdgpu_ring *ring = &adev->gfx.compute_ring[i]; -if (!(ring && ring->sched.thread)) +if (!(ring &&drm_sched_submit_ready (&ring->sched)))continue ;/* stop secheduler and drain ring. */ drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +8
-7@@ -1659,9 +1659,9 @@ static int amdgpu_debugfs_test_ib_show(struct seq_file *m, void *unused)for (i =0 ; i <AMDGPU_MAX_RINGS ; i++) {struct amdgpu_ring *ring = adev->rings[i]; -if (!ring || !ring->sched.thread) +if (!ring || !drm_sched_submit_ready (&ring->sched))continue ; -kthread_park (ring->sched.thread); +drm_sched_submit_stop (&ring->sched); }seq_puts (m,"run ib test:\n" );@@ -1675,9 +1675,9 @@ static int amdgpu_debugfs_test_ib_show(struct seq_file *m, void *unused)for (i =0 ; i <AMDGPU_MAX_RINGS ; i++) {struct amdgpu_ring *ring = adev->rings[i]; -if (!ring || !ring->sched.thread) +if (!ring || !drm_sched_submit_ready (&ring->sched))continue ; -kthread_unpark (ring->sched.thread); +drm_sched_submit_start (&ring->sched); }up_write (&adev->reset_domain->sem);@@ -1897,7 +1897,8 @@ static int amdgpu_debugfs_ib_preempt(void *data, u64 val) ring = adev->rings[val]; -if (!ring || !ring->funcs->preempt_ib || !ring->sched.thread) +if (!ring || !ring->funcs->preempt_ib || + !drm_sched_submit_ready (&ring->sched))return -EINVAL ;/* the last preemption failed */ @@ -1915,7 +1916,7 @@ static int amdgpu_debugfs_ib_preempt(void *data, u64 val) goto pro_end;/* stop the scheduler */ -kthread_park (ring->sched.thread); +drm_sched_submit_stop (&ring->sched);/* preempt the IB */ r =amdgpu_ring_preempt_ib (ring);@@ -1949,7 +1950,7 @@ static int amdgpu_debugfs_ib_preempt(void *data, u64 val) failure:/* restart the scheduler */ -kthread_unpark (ring->sched.thread); +drm_sched_submit_start (&ring->sched);up_read (&adev->reset_domain->sem);drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +6
-6@@ -4588,7 +4588,7 @@ bool amdgpu_device_has_job_running(struct amdgpu_device *adev)for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = adev->rings[i]; -if (!ring || !ring->sched.thread) +if (!ring || !drm_sched_submit_ready (&ring->sched))continue ;spin_lock (&ring->sched.job_list_lock);@@ -4727,7 +4727,7 @@ int amdgpu_device_pre_asic_reset(struct amdgpu_device *adev,for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = adev->rings[i]; -if (!ring || !ring->sched.thread) +if (!ring || !drm_sched_submit_ready (&ring->sched))continue ;/* Clear job fence from fence drv to avoid force_completion @@ -5266,7 +5266,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = tmp_adev->rings[i]; -if (!ring || !ring->sched.thread) +if (!ring || !drm_sched_submit_ready (&ring->sched))continue ;drm_sched_stop (&ring->sched, job ? &job->base :NULL );@@ -5341,7 +5341,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = tmp_adev->rings[i]; -if (!ring || !ring->sched.thread) +if (!ring || !drm_sched_submit_ready (&ring->sched))continue ;drm_sched_start (&ring->sched, true);@@ -5667,7 +5667,7 @@ pci_ers_result_t amdgpu_pci_error_detected(struct pci_dev *pdev, pci_channel_stafor (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = adev->rings[i]; -if (!ring || !ring->sched.thread) +if (!ring || !drm_sched_submit_ready (&ring->sched))continue ;drm_sched_stop (&ring->sched,NULL );@@ -5795,7 +5795,7 @@ void amdgpu_pci_resume(struct pci_dev *pdev)for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = adev->rings[i]; -if (!ring || !ring->sched.thread) +if (!ring || !drm_sched_submit_ready (&ring->sched))continue ;drm_sched_start (&ring->sched, true);drivers/gpu/drm/msm/adreno/adreno_device.c +4
-2@@ -809,7 +809,8 @@ static void suspend_scheduler(struct msm_gpu *gpu)*/ for (i =0 ; i < gpu->nr_rings; i++) {struct drm_gpu_scheduler *sched = &gpu->rb[i]->sched; -kthread_park (sched->thread); + +drm_sched_submit_stop (sched); } }@@ -819,7 +820,8 @@ static void resume_scheduler(struct msm_gpu *gpu)for (i =0 ; i < gpu->nr_rings; i++) {struct drm_gpu_scheduler *sched = &gpu->rb[i]->sched; -kthread_unpark (sched->thread); + +drm_sched_submit_start (sched); } }drivers/gpu/drm/scheduler/sched_main.c +38
-2@@ -439,7 +439,7 @@ void drm_sched_stop(struct drm_gpu_scheduler *sched, struct drm_sched_job *bad) {struct drm_sched_job *s_job, *tmp; -kthread_park (sched->thread); +drm_sched_submit_stop (sched);/* * Reinsert back the bad job here - now it's safe as @@ -552,7 +552,7 @@ void drm_sched_start(struct drm_gpu_scheduler *sched, bool full_recovery)spin_unlock (&sched->job_list_lock); } -kthread_unpark (sched->thread); +drm_sched_submit_start (sched); }EXPORT_SYMBOL (drm_sched_start);@@ -1206,3 +1206,39 @@ void drm_sched_increase_karma(struct drm_sched_job *bad) } }EXPORT_SYMBOL (drm_sched_increase_karma); + +/** +* drm_sched_submit_ready - scheduler ready for submission +* +* @sched: scheduler instance +* +* Returns true if submission is ready +*/ +bool drm_sched_submit_ready (struct drm_gpu_scheduler *sched) +{ +return !!sched->thread; + +} +EXPORT_SYMBOL (drm_sched_submit_ready); + +/** +* drm_sched_submit_stop - stop scheduler submission +* +* @sched: scheduler instance +*/ +void drm_sched_submit_stop (struct drm_gpu_scheduler *sched) +{ +kthread_park (sched->thread); +} +EXPORT_SYMBOL (drm_sched_submit_stop); + +/** +* drm_sched_submit_start - start scheduler submission +* +* @sched: scheduler instance +*/ +void drm_sched_submit_start (struct drm_gpu_scheduler *sched) +{ +kthread_unpark (sched->thread); +} +EXPORT_SYMBOL (drm_sched_submit_start);include/drm/gpu_scheduler.h +3
-0@@ -550,6 +550,9 @@ void drm_sched_entity_modify_sched(struct drm_sched_entity *entity,void drm_sched_job_cleanup (struct drm_sched_job *job);void drm_sched_wakeup_if_can_queue (struct drm_gpu_scheduler *sched); +bool drm_sched_submit_ready (struct drm_gpu_scheduler *sched); +void drm_sched_submit_stop (struct drm_gpu_scheduler *sched); +void drm_sched_submit_start (struct drm_gpu_scheduler *sched);void drm_sched_stop (struct drm_gpu_scheduler *sched,struct drm_sched_job *bad);void drm_sched_start (struct drm_gpu_scheduler *sched,bool full_recovery);void drm_sched_resubmit_jobs (struct drm_gpu_scheduler *sched);
Re: [PATCH v4 01/10] drm/sched: Add drm_sched_submit_* helpers
Quoted 10 lines · Christian König
Am 19.09.23 um 07:01 schrieb Matthew Brost:
Quoted 4 lines
Add scheduler submit ready, stop, and start helpers to hide the implementation details of the scheduler from the drivers.
Signed-off-by Matthew Brost <[email protected]>No idea when I have time to look into the rest :( But Luben should take a look.
Hi Christian,
Yes, I'll finish up with v3 and v4 tomorrow morning and afternoon.
Regards,
Luben
Quoted 241 lines
Regards,
ChristianQuoted 236 lines
--- .../drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 15 +++---- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 12 +++--- drivers/gpu/drm/msm/adreno/adreno_device.c | 6 ++- drivers/gpu/drm/scheduler/sched_main.c | 40 ++++++++++++++++++- include/drm/gpu_scheduler.h | 3 ++ 6 files changed, 60 insertions(+), 18 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c +1
-1@@ -290,7 +290,7 @@ static int suspend_resume_compute_scheduler(struct amdgpu_device *adev, bool susfor (i =0 ; i < adev->gfx.num_compute_rings; i++) {struct amdgpu_ring *ring = &adev->gfx.compute_ring[i]; -if (!(ring && ring->sched.thread)) +if (!(ring &&drm_sched_submit_ready (&ring->sched)))continue ;/* stop secheduler and drain ring. */ drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +8
-7@@ -1659,9 +1659,9 @@ static int amdgpu_debugfs_test_ib_show(struct seq_file *m, void *unused)for (i =0 ; i <AMDGPU_MAX_RINGS ; i++) {struct amdgpu_ring *ring = adev->rings[i]; -if (!ring || !ring->sched.thread) +if (!ring || !drm_sched_submit_ready (&ring->sched))continue ; -kthread_park (ring->sched.thread); +drm_sched_submit_stop (&ring->sched); }seq_puts (m,"run ib test:\n" );@@ -1675,9 +1675,9 @@ static int amdgpu_debugfs_test_ib_show(struct seq_file *m, void *unused)for (i =0 ; i <AMDGPU_MAX_RINGS ; i++) {struct amdgpu_ring *ring = adev->rings[i]; -if (!ring || !ring->sched.thread) +if (!ring || !drm_sched_submit_ready (&ring->sched))continue ; -kthread_unpark (ring->sched.thread); +drm_sched_submit_start (&ring->sched); }up_write (&adev->reset_domain->sem);@@ -1897,7 +1897,8 @@ static int amdgpu_debugfs_ib_preempt(void *data, u64 val) ring = adev->rings[val]; -if (!ring || !ring->funcs->preempt_ib || !ring->sched.thread) +if (!ring || !ring->funcs->preempt_ib || + !drm_sched_submit_ready (&ring->sched))return -EINVAL ;/* the last preemption failed */ @@ -1915,7 +1916,7 @@ static int amdgpu_debugfs_ib_preempt(void *data, u64 val) goto pro_end;/* stop the scheduler */ -kthread_park (ring->sched.thread); +drm_sched_submit_stop (&ring->sched);/* preempt the IB */ r =amdgpu_ring_preempt_ib (ring);@@ -1949,7 +1950,7 @@ static int amdgpu_debugfs_ib_preempt(void *data, u64 val) failure:/* restart the scheduler */ -kthread_unpark (ring->sched.thread); +drm_sched_submit_start (&ring->sched);up_read (&adev->reset_domain->sem);drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +6
-6@@ -4588,7 +4588,7 @@ bool amdgpu_device_has_job_running(struct amdgpu_device *adev)for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = adev->rings[i]; -if (!ring || !ring->sched.thread) +if (!ring || !drm_sched_submit_ready (&ring->sched))continue ;spin_lock (&ring->sched.job_list_lock);@@ -4727,7 +4727,7 @@ int amdgpu_device_pre_asic_reset(struct amdgpu_device *adev,for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = adev->rings[i]; -if (!ring || !ring->sched.thread) +if (!ring || !drm_sched_submit_ready (&ring->sched))continue ;/* Clear job fence from fence drv to avoid force_completion @@ -5266,7 +5266,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = tmp_adev->rings[i]; -if (!ring || !ring->sched.thread) +if (!ring || !drm_sched_submit_ready (&ring->sched))continue ;drm_sched_stop (&ring->sched, job ? &job->base :NULL );@@ -5341,7 +5341,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = tmp_adev->rings[i]; -if (!ring || !ring->sched.thread) +if (!ring || !drm_sched_submit_ready (&ring->sched))continue ;drm_sched_start (&ring->sched, true);@@ -5667,7 +5667,7 @@ pci_ers_result_t amdgpu_pci_error_detected(struct pci_dev *pdev, pci_channel_stafor (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = adev->rings[i]; -if (!ring || !ring->sched.thread) +if (!ring || !drm_sched_submit_ready (&ring->sched))continue ;drm_sched_stop (&ring->sched,NULL );@@ -5795,7 +5795,7 @@ void amdgpu_pci_resume(struct pci_dev *pdev)for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = adev->rings[i]; -if (!ring || !ring->sched.thread) +if (!ring || !drm_sched_submit_ready (&ring->sched))continue ;drm_sched_start (&ring->sched, true);drivers/gpu/drm/msm/adreno/adreno_device.c +4
-2@@ -809,7 +809,8 @@ static void suspend_scheduler(struct msm_gpu *gpu)*/ for (i =0 ; i < gpu->nr_rings; i++) {struct drm_gpu_scheduler *sched = &gpu->rb[i]->sched; -kthread_park (sched->thread); + +drm_sched_submit_stop (sched); } }@@ -819,7 +820,8 @@ static void resume_scheduler(struct msm_gpu *gpu)for (i =0 ; i < gpu->nr_rings; i++) {struct drm_gpu_scheduler *sched = &gpu->rb[i]->sched; -kthread_unpark (sched->thread); + +drm_sched_submit_start (sched); } }drivers/gpu/drm/scheduler/sched_main.c +38
-2@@ -439,7 +439,7 @@ void drm_sched_stop(struct drm_gpu_scheduler *sched, struct drm_sched_job *bad) {struct drm_sched_job *s_job, *tmp; -kthread_park (sched->thread); +drm_sched_submit_stop (sched);/* * Reinsert back the bad job here - now it's safe as @@ -552,7 +552,7 @@ void drm_sched_start(struct drm_gpu_scheduler *sched, bool full_recovery)spin_unlock (&sched->job_list_lock); } -kthread_unpark (sched->thread); +drm_sched_submit_start (sched); }EXPORT_SYMBOL (drm_sched_start);@@ -1206,3 +1206,39 @@ void drm_sched_increase_karma(struct drm_sched_job *bad) } }EXPORT_SYMBOL (drm_sched_increase_karma); + +/** +* drm_sched_submit_ready - scheduler ready for submission +* +* @sched: scheduler instance +* +* Returns true if submission is ready +*/ +bool drm_sched_submit_ready (struct drm_gpu_scheduler *sched) +{ +return !!sched->thread; + +} +EXPORT_SYMBOL (drm_sched_submit_ready); + +/** +* drm_sched_submit_stop - stop scheduler submission +* +* @sched: scheduler instance +*/ +void drm_sched_submit_stop (struct drm_gpu_scheduler *sched) +{ +kthread_park (sched->thread); +} +EXPORT_SYMBOL (drm_sched_submit_stop); + +/** +* drm_sched_submit_start - start scheduler submission +* +* @sched: scheduler instance +*/ +void drm_sched_submit_start (struct drm_gpu_scheduler *sched) +{ +kthread_unpark (sched->thread); +} +EXPORT_SYMBOL (drm_sched_submit_start);include/drm/gpu_scheduler.h +3
-0@@ -550,6 +550,9 @@ void drm_sched_entity_modify_sched(struct drm_sched_entity *entity,void drm_sched_job_cleanup (struct drm_sched_job *job);void drm_sched_wakeup_if_can_queue (struct drm_gpu_scheduler *sched); +bool drm_sched_submit_ready (struct drm_gpu_scheduler *sched); +void drm_sched_submit_stop (struct drm_gpu_scheduler *sched); +void drm_sched_submit_start (struct drm_gpu_scheduler *sched);void drm_sched_stop (struct drm_gpu_scheduler *sched,struct drm_sched_job *bad);void drm_sched_start (struct drm_gpu_scheduler *sched,bool full_recovery);void drm_sched_resubmit_jobs (struct drm_gpu_scheduler *sched);
Signature · 2 lines
Regards, Luben
Re: [PATCH v4 01/10] drm/sched: Add drm_sched_submit_* helpers
In reply to Matthew BrostQuoted 187 lines · Matthew Brost
Add scheduler submit ready, stop, and start helpers to hide the implementation details of the scheduler from the drivers.
Signed-off-by Matthew Brost <[email protected]>--- .../drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 15 +++---- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 12 +++--- drivers/gpu/drm/msm/adreno/adreno_device.c | 6 ++- drivers/gpu/drm/scheduler/sched_main.c | 40 ++++++++++++++++++- include/drm/gpu_scheduler.h | 3 ++ 6 files changed, 60 insertions(+), 18 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c +1
-1@@ -290,7 +290,7 @@ static int suspend_resume_compute_scheduler(struct amdgpu_device *adev, bool susfor (i =0 ; i < adev->gfx.num_compute_rings; i++) {struct amdgpu_ring *ring = &adev->gfx.compute_ring[i]; -if (!(ring && ring->sched.thread)) +if (!(ring &&drm_sched_submit_ready (&ring->sched)))continue ;/* stop secheduler and drain ring. */ drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +8
-7@@ -1659,9 +1659,9 @@ static int amdgpu_debugfs_test_ib_show(struct seq_file *m, void *unused)for (i =0 ; i <AMDGPU_MAX_RINGS ; i++) {struct amdgpu_ring *ring = adev->rings[i]; -if (!ring || !ring->sched.thread) +if (!ring || !drm_sched_submit_ready (&ring->sched))continue ; -kthread_park (ring->sched.thread); +drm_sched_submit_stop (&ring->sched); }seq_puts (m,"run ib test:\n" );@@ -1675,9 +1675,9 @@ static int amdgpu_debugfs_test_ib_show(struct seq_file *m, void *unused)for (i =0 ; i <AMDGPU_MAX_RINGS ; i++) {struct amdgpu_ring *ring = adev->rings[i]; -if (!ring || !ring->sched.thread) +if (!ring || !drm_sched_submit_ready (&ring->sched))continue ; -kthread_unpark (ring->sched.thread); +drm_sched_submit_start (&ring->sched); }up_write (&adev->reset_domain->sem);@@ -1897,7 +1897,8 @@ static int amdgpu_debugfs_ib_preempt(void *data, u64 val) ring = adev->rings[val]; -if (!ring || !ring->funcs->preempt_ib || !ring->sched.thread) +if (!ring || !ring->funcs->preempt_ib || + !drm_sched_submit_ready (&ring->sched))return -EINVAL ;/* the last preemption failed */ @@ -1915,7 +1916,7 @@ static int amdgpu_debugfs_ib_preempt(void *data, u64 val) goto pro_end;/* stop the scheduler */ -kthread_park (ring->sched.thread); +drm_sched_submit_stop (&ring->sched);/* preempt the IB */ r =amdgpu_ring_preempt_ib (ring);@@ -1949,7 +1950,7 @@ static int amdgpu_debugfs_ib_preempt(void *data, u64 val) failure:/* restart the scheduler */ -kthread_unpark (ring->sched.thread); +drm_sched_submit_start (&ring->sched);up_read (&adev->reset_domain->sem);drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +6
-6@@ -4588,7 +4588,7 @@ bool amdgpu_device_has_job_running(struct amdgpu_device *adev)for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = adev->rings[i]; -if (!ring || !ring->sched.thread) +if (!ring || !drm_sched_submit_ready (&ring->sched))continue ;spin_lock (&ring->sched.job_list_lock);@@ -4727,7 +4727,7 @@ int amdgpu_device_pre_asic_reset(struct amdgpu_device *adev,for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = adev->rings[i]; -if (!ring || !ring->sched.thread) +if (!ring || !drm_sched_submit_ready (&ring->sched))continue ;/* Clear job fence from fence drv to avoid force_completion @@ -5266,7 +5266,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = tmp_adev->rings[i]; -if (!ring || !ring->sched.thread) +if (!ring || !drm_sched_submit_ready (&ring->sched))continue ;drm_sched_stop (&ring->sched, job ? &job->base :NULL );@@ -5341,7 +5341,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = tmp_adev->rings[i]; -if (!ring || !ring->sched.thread) +if (!ring || !drm_sched_submit_ready (&ring->sched))continue ;drm_sched_start (&ring->sched, true);@@ -5667,7 +5667,7 @@ pci_ers_result_t amdgpu_pci_error_detected(struct pci_dev *pdev, pci_channel_stafor (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = adev->rings[i]; -if (!ring || !ring->sched.thread) +if (!ring || !drm_sched_submit_ready (&ring->sched))continue ;drm_sched_stop (&ring->sched,NULL );@@ -5795,7 +5795,7 @@ void amdgpu_pci_resume(struct pci_dev *pdev)for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = adev->rings[i]; -if (!ring || !ring->sched.thread) +if (!ring || !drm_sched_submit_ready (&ring->sched))continue ;drm_sched_start (&ring->sched, true);drivers/gpu/drm/msm/adreno/adreno_device.c +4
-2@@ -809,7 +809,8 @@ static void suspend_scheduler(struct msm_gpu *gpu)*/ for (i =0 ; i < gpu->nr_rings; i++) {struct drm_gpu_scheduler *sched = &gpu->rb[i]->sched; -kthread_park (sched->thread); + +drm_sched_submit_stop (sched); } }@@ -819,7 +820,8 @@ static void resume_scheduler(struct msm_gpu *gpu)for (i =0 ; i < gpu->nr_rings; i++) {struct drm_gpu_scheduler *sched = &gpu->rb[i]->sched; -kthread_unpark (sched->thread); + +drm_sched_submit_start (sched); } }drivers/gpu/drm/scheduler/sched_main.c +2
-2@@ -439,7 +439,7 @@ void drm_sched_stop(struct drm_gpu_scheduler *sched, struct drm_sched_job *bad) {struct drm_sched_job *s_job, *tmp; -kthread_park (sched->thread); +drm_sched_submit_stop (sched);/* * Reinsert back the bad job here - now it's safe as @@ -552,7 +552,7 @@ void drm_sched_start(struct drm_gpu_scheduler *sched, bool full_recovery)spin_unlock (&sched->job_list_lock); } -kthread_unpark (sched->thread); +drm_sched_submit_start (sched); }EXPORT_SYMBOL (drm_sched_start);
drivers/gpu/drm/scheduler/sched_main.c void drm_sched_increase_karma(struct drm_sched_job *bad) · line 1211
Quoted 6 lines
drivers/gpu/drm/scheduler/sched_main.c +3
-0@@ -1206,3 +1206,39 @@ void drm_sched_increase_karma(struct drm_sched_job *bad) } }EXPORT_SYMBOL (drm_sched_increase_karma); + +/** +* drm_sched_submit_ready - scheduler ready for submission
"Is the scheduler ready for submission" is so much more clear and approachable. Let's have that go in the kernel, yes?
drivers/gpu/drm/scheduler/sched_main.c void drm_sched_increase_karma(struct drm_sched_job *bad) · line 1221
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +10
-0+* +* @sched: scheduler instance +* +* Returns true if submission is ready +*/ +bool drm_sched_submit_ready (struct drm_gpu_scheduler *sched) +{ +return !!sched->thread; + +}
Remove the extra white line after the return-statement. (Please run your patches through checkpatch.pl to catch those.)
With these two changes this patch is:
Quoted 37 lines
drivers/gpu/drm/scheduler/sched_main.c +23
-0+EXPORT_SYMBOL (drm_sched_submit_ready); + +/** +* drm_sched_submit_stop - stop scheduler submission +* +* @sched: scheduler instance +*/ +void drm_sched_submit_stop (struct drm_gpu_scheduler *sched) +{ +kthread_park (sched->thread); +} +EXPORT_SYMBOL (drm_sched_submit_stop); + +/** +* drm_sched_submit_start - start scheduler submission +* +* @sched: scheduler instance +*/ +void drm_sched_submit_start (struct drm_gpu_scheduler *sched) +{ +kthread_unpark (sched->thread); +} +EXPORT_SYMBOL (drm_sched_submit_start);include/drm/gpu_scheduler.h +3
-0@@ -550,6 +550,9 @@ void drm_sched_entity_modify_sched(struct drm_sched_entity *entity,void drm_sched_job_cleanup (struct drm_sched_job *job);void drm_sched_wakeup_if_can_queue (struct drm_gpu_scheduler *sched); +bool drm_sched_submit_ready (struct drm_gpu_scheduler *sched); +void drm_sched_submit_stop (struct drm_gpu_scheduler *sched); +void drm_sched_submit_start (struct drm_gpu_scheduler *sched);void drm_sched_stop (struct drm_gpu_scheduler *sched,struct drm_sched_job *bad);void drm_sched_start (struct drm_gpu_scheduler *sched,bool full_recovery);void drm_sched_resubmit_jobs (struct drm_gpu_scheduler *sched);
Signature · 2 lines
Regards, Luben
Matthew Brost
maintainerPATCH v4 2/10 drm/sched: Convert drm scheduler to use a work queue rather than kthread
In reply to Matthew BrostIn XE, the new Intel GPU driver, a choice has made to have a 1 to 1 mapping between a drm_gpu_scheduler and drm_sched_entity. At first this seems a bit odd but let us explain the reasoning below.
1. In XE the submission order from multiple drm_sched_entity is not guaranteed to be the same completion even if targeting the same hardware engine. This is because in XE we have a firmware scheduler, the GuC, which allowed to reorder, timeslice, and preempt submissions. If a using shared drm_gpu_scheduler across multiple drm_sched_entity, the TDR falls apart as the TDR expects submission order == completion order. Using a dedicated drm_gpu_scheduler per drm_sched_entity solve this problem.
2. In XE submissions are done via programming a ring buffer (circular buffer), a drm_gpu_scheduler provides a limit on number of jobs, if the limit of number jobs is set to RING_SIZE / MAX_SIZE_PER_JOB we get flow control on the ring for free.
A problem with this design is currently a drm_gpu_scheduler uses a kthread for submission / job cleanup. This doesn't scale if a large number of drm_gpu_scheduler are used. To work around the scaling issue, use a worker rather than kthread for submission / job cleanup.
v2:
- (Rob Clark) Fix msm build
- Pass in run work queue
v3:
- (Boris) don't have loop in worker
v4:
- (Tvrtko) break out submit ready, stop, start helpers into own patch
v5:
- (Boris) default to ordered work queue
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_sched.c | 2 +- drivers/gpu/drm/lima/lima_sched.c | 2 +- drivers/gpu/drm/msm/msm_ringbuffer.c | 2 +- drivers/gpu/drm/nouveau/nouveau_sched.c | 2 +- drivers/gpu/drm/panfrost/panfrost_job.c | 2 +- drivers/gpu/drm/scheduler/sched_main.c | 118 ++++++++++----------- drivers/gpu/drm/v3d/v3d_sched.c | 10 +- include/drm/gpu_scheduler.h | 14 ++- 9 files changed, 79 insertions(+), 75 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
@@ -2279,7 +2279,7 @@ static int amdgpu_device_init_schedulers(struct amdgpu_device *adev)break ; } - r = drm_sched_init(&ring->sched, &amdgpu_sched_ops, + r = drm_sched_init(&ring->sched, &amdgpu_sched_ops, NULL, ring->num_hw_submission, 0, timeout, adev->reset_domain->wq, ring->sched_score, ring->name,
drivers/gpu/drm/etnaviv/etnaviv_sched.c +1 -1
@@ -134,7 +134,7 @@ int etnaviv_sched_init(struct etnaviv_gpu *gpu) {int ret; - ret =drm_sched_init (&gpu->sched, &etnaviv_sched_ops, + ret =drm_sched_init (&gpu->sched, &etnaviv_sched_ops,NULL , etnaviv_hw_jobs_limit, etnaviv_job_hang_limit,msecs_to_jiffies (500 ),NULL ,NULL ,dev_name (gpu->dev), gpu->dev);
drivers/gpu/drm/lima/lima_sched.c +1 -1
@@ -488,7 +488,7 @@ int lima_sched_pipe_init(struct lima_sched_pipe *pipe, const char *name)INIT_WORK (&pipe->recover_work, lima_sched_recover_work); -return drm_sched_init (&pipe->base, &lima_sched_ops,1 , +return drm_sched_init (&pipe->base, &lima_sched_ops,NULL ,1 , lima_job_hang_limit,msecs_to_jiffies (timeout),NULL ,NULL , name, pipe->ldev->dev);
drivers/gpu/drm/msm/msm_ringbuffer.c +1 -1
@@ -94,7 +94,7 @@ struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id,/* currently managing hangcheck ourselves: */ sched_timeout =MAX_SCHEDULE_TIMEOUT ; - ret =drm_sched_init (&ring->sched, &msm_sched_ops, + ret =drm_sched_init (&ring->sched, &msm_sched_ops,NULL , num_hw_submissions,0 , sched_timeout,NULL ,NULL ,to_msm_bo (ring->bo)->name, gpu->dev->dev);if (ret) {
drivers/gpu/drm/nouveau/nouveau_sched.c +1 -1
@@ -429,7 +429,7 @@ int nouveau_sched_init(struct nouveau_drm *drm)if (!drm->sched_wq)return -ENOMEM ; -return drm_sched_init (sched, &nouveau_sched_ops, +return drm_sched_init (sched, &nouveau_sched_ops,NULL ,NOUVEAU_SCHED_HW_SUBMISSIONS ,0 , job_hang_limit,NULL ,NULL ,"nouveau_sched" , drm->dev->dev); }
drivers/gpu/drm/panfrost/panfrost_job.c +1 -1
@@ -831,7 +831,7 @@ int panfrost_job_init(struct panfrost_device *pfdev) js->queue[j].fence_context =dma_fence_context_alloc (1 ); ret = drm_sched_init(&js->queue[j].sched, - &panfrost_sched_ops, + &panfrost_sched_ops, NULL, nentries, 0, msecs_to_jiffies(JOB_TIMEOUT_MS), pfdev->reset.wq,
drivers/gpu/drm/scheduler/sched_main.c +59 -59
231 lines not on this page · raw message
drivers/gpu/drm/v3d/v3d_sched.c +5 -5
@@ -388,7 +388,7 @@ v3d_sched_init(struct v3d_dev *v3d)int ret; ret =drm_sched_init (&v3d->queue[V3D_BIN ].sched, - &v3d_bin_sched_ops, + &v3d_bin_sched_ops,NULL , hw_jobs_limit, job_hang_limit,msecs_to_jiffies (hang_limit_ms),NULL ,NULL ,"v3d_bin" , v3d->drm.dev);
@@ -396,7 +396,7 @@ v3d_sched_init(struct v3d_dev *v3d)return ret; ret =drm_sched_init (&v3d->queue[V3D_RENDER ].sched, - &v3d_render_sched_ops, + &v3d_render_sched_ops,NULL , hw_jobs_limit, job_hang_limit,msecs_to_jiffies (hang_limit_ms),NULL ,NULL ,"v3d_render" , v3d->drm.dev);
@@ -404,7 +404,7 @@ v3d_sched_init(struct v3d_dev *v3d) goto fail; ret =drm_sched_init (&v3d->queue[V3D_TFU ].sched, - &v3d_tfu_sched_ops, + &v3d_tfu_sched_ops,NULL , hw_jobs_limit, job_hang_limit,msecs_to_jiffies (hang_limit_ms),NULL ,NULL ,"v3d_tfu" , v3d->drm.dev);
@@ -413,7 +413,7 @@ v3d_sched_init(struct v3d_dev *v3d)if (v3d_has_csd (v3d)) { ret =drm_sched_init (&v3d->queue[V3D_CSD ].sched, - &v3d_csd_sched_ops, + &v3d_csd_sched_ops,NULL , hw_jobs_limit, job_hang_limit,msecs_to_jiffies (hang_limit_ms),NULL ,NULL ,"v3d_csd" , v3d->drm.dev);
@@ -421,7 +421,7 @@ v3d_sched_init(struct v3d_dev *v3d) goto fail; ret =drm_sched_init (&v3d->queue[V3D_CACHE_CLEAN ].sched, - &v3d_cache_clean_sched_ops, + &v3d_cache_clean_sched_ops,NULL , hw_jobs_limit, job_hang_limit,msecs_to_jiffies (hang_limit_ms),NULL ,NULL ,"v3d_cache_clean" , v3d->drm.dev);
include/drm/gpu_scheduler.h +9 -5
@@ -473,17 +473,16 @@ struct drm_sched_backend_ops {* @timeout: the time after which a job is removed from the scheduler. * @name: name of the ring for which this scheduler is being used. * @sched_rq: priority wise array of run queues. -* @wake_up_worker: the wait queue on which the scheduler sleeps until a job -* is ready to be scheduled. * @job_scheduled: once @drm_sched_entity_do_release is called the scheduler * waits on this wait queue until all the scheduled jobs are * finished. * @hw_rq_count: the number of jobs currently in the hardware queue. * @job_id_count: used to assign unique id to the each job. +* @submit_wq: workqueue used to queue @work_submit * @timeout_wq: workqueue used to queue @work_tdr +* @work_submit: schedules jobs and cleans up entities * @work_tdr: schedules a delayed call to @drm_sched_job_timedout after the * timeout interval is over. -* @thread: the kthread on which the scheduler which run. * @pending_list: the list of jobs which are currently in the job queue. * @job_list_lock: lock to protect the pending_list. * @hang_limit: once the hangs by a job crosses this limit then it is marked
@@ -492,6 +491,8 @@ struct drm_sched_backend_ops {* @_score: score used when the driver doesn't provide one * @ready: marks if the underlying HW is ready to work * @free_guilty: A hit to time out handler to free the guilty job. +* @pause_submit: pause queuing of @work_submit on @submit_wq +* @alloc_submit_wq: scheduler own allocation of @submit_wq * @dev: system &struct device * * One scheduler is implemented for each hardware ring.
@@ -502,13 +503,13 @@ struct drm_gpu_scheduler {long timeout;const char *name;struct drm_sched_rq sched_rq[DRM_SCHED_PRIORITY_COUNT ]; -wait_queue_head_t wake_up_worker;wait_queue_head_t job_scheduled;atomic_t hw_rq_count;atomic64_t job_id_count; +struct workqueue_struct *submit_wq;struct workqueue_struct *timeout_wq; +struct work_struct work_submit;struct delayed_work work_tdr; -struct task_struct *thread;struct list_head pending_list;spinlock_t job_list_lock;int hang_limit;
@@ -516,11 +517,14 @@ struct drm_gpu_scheduler {atomic_t _score;bool ready;bool free_guilty; +bool pause_submit; +bool alloc_submit_wq;struct device *dev; };int drm_sched_init (struct drm_gpu_scheduler *sched,const struct drm_sched_backend_ops *ops, +struct workqueue_struct *submit_wq,uint32_t hw_submission,unsigned hang_limit,long timeout,struct workqueue_struct *timeout_wq,atomic_t *score,const char *name,struct device *dev);
Signature · 1 line
2.34.1
Re: [PATCH v4 02/10] drm/sched: Convert drm scheduler to use a work queue rather than kthread
Hi,
Quoted 89 lines · Matthew Brost
In XE, the new Intel GPU driver, a choice has made to have a 1 to 1 mapping between a
drm_gpu_scheduleranddrm_sched_entity. At first this seems a bit odd but let us explain the reasoning below.1. In XE the submission order from multiple
drm_sched_entityis not guaranteed to be the same completion even if targeting the same hardware engine. This is because in XE we have a firmware scheduler, the GuC, which allowed to reorder, timeslice, and preempt submissions. If a using shareddrm_gpu_scheduleracross multipledrm_sched_entity, the TDR falls apart as the TDR expects submission order == completion order. Using a dedicateddrm_gpu_schedulerperdrm_sched_entitysolve this problem.2. In XE submissions are done via programming a ring buffer (circular buffer), a
drm_gpu_schedulerprovides a limit on number of jobs, if the limit of number jobs is set toRING_SIZE/MAX_SIZE_PER_JOBwe get flow control on the ring for free.A problem with this design is currently a
drm_gpu_scheduleruses a kthread for submission / job cleanup. This doesn't scale if a large number ofdrm_gpu_schedulerare used. To work around the scaling issue, use a worker rather than kthread for submission / job cleanup.v2:
- (Rob Clark) Fix msm build
- Pass in run work queue
v3:
- (Boris) don't have loop in worker
v4:
- (Tvrtko) break out submit ready, stop, start helpers into own patch
v5:
- (Boris) default to ordered work queueSigned-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_sched.c | 2 +- drivers/gpu/drm/lima/lima_sched.c | 2 +- drivers/gpu/drm/msm/msm_ringbuffer.c | 2 +- drivers/gpu/drm/nouveau/nouveau_sched.c | 2 +- drivers/gpu/drm/panfrost/panfrost_job.c | 2 +- drivers/gpu/drm/scheduler/sched_main.c | 118 ++++++++++----------- drivers/gpu/drm/v3d/v3d_sched.c | 10 +- include/drm/gpu_scheduler.h | 14 ++- 9 files changed, 79 insertions(+), 75 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-1@@ -2279,7 +2279,7 @@ static int amdgpu_device_init_schedulers(struct amdgpu_device *adev)break ; } - r = drm_sched_init(&ring->sched, &amdgpu_sched_ops, + r = drm_sched_init(&ring->sched, &amdgpu_sched_ops, NULL, ring->num_hw_submission, 0, timeout, adev->reset_domain->wq, ring->sched_score, ring->name,drivers/gpu/drm/etnaviv/etnaviv_sched.c +1
-1@@ -134,7 +134,7 @@ int etnaviv_sched_init(struct etnaviv_gpu *gpu) {int ret; - ret =drm_sched_init (&gpu->sched, &etnaviv_sched_ops, + ret =drm_sched_init (&gpu->sched, &etnaviv_sched_ops,NULL , etnaviv_hw_jobs_limit, etnaviv_job_hang_limit,msecs_to_jiffies (500 ),NULL ,NULL ,dev_name (gpu->dev), gpu->dev);drivers/gpu/drm/lima/lima_sched.c +1
-1@@ -488,7 +488,7 @@ int lima_sched_pipe_init(struct lima_sched_pipe *pipe, const char *name)INIT_WORK (&pipe->recover_work, lima_sched_recover_work); -return drm_sched_init (&pipe->base, &lima_sched_ops,1 , +return drm_sched_init (&pipe->base, &lima_sched_ops,NULL ,1 , lima_job_hang_limit,msecs_to_jiffies (timeout),NULL ,NULL , name, pipe->ldev->dev);drivers/gpu/drm/msm/msm_ringbuffer.c +0
-0
drivers/gpu/drm/msm/msm_ringbuffer.c struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id, · line 99
Quoted 7 lines
drivers/gpu/drm/msm/msm_ringbuffer.c +1
-1@@ -94,7 +94,7 @@ struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id,/* currently managing hangcheck ourselves: */ sched_timeout =MAX_SCHEDULE_TIMEOUT ; - ret =drm_sched_init (&ring->sched, &msm_sched_ops, + ret =drm_sched_init (&ring->sched, &msm_sched_ops,NULL , num_hw_submissions,0 , sched_timeout,NULL ,NULL ,to_msm_bo (ring->bo)->name, gpu->dev->dev);
checkpatch.pl complains here about unmatched open parens.
Quoted 40 lines
drivers/gpu/drm/msm/msm_ringbuffer.c +0
-0if (ret) {drivers/gpu/drm/nouveau/nouveau_sched.c +1
-1@@ -429,7 +429,7 @@ int nouveau_sched_init(struct nouveau_drm *drm)if (!drm->sched_wq)return -ENOMEM ; -return drm_sched_init (sched, &nouveau_sched_ops, +return drm_sched_init (sched, &nouveau_sched_ops,NULL ,NOUVEAU_SCHED_HW_SUBMISSIONS ,0 , job_hang_limit,NULL ,NULL ,"nouveau_sched" , drm->dev->dev); }drivers/gpu/drm/panfrost/panfrost_job.c +1
-1@@ -831,7 +831,7 @@ int panfrost_job_init(struct panfrost_device *pfdev) js->queue[j].fence_context =dma_fence_context_alloc (1 ); ret = drm_sched_init(&js->queue[j].sched, - &panfrost_sched_ops, + &panfrost_sched_ops, NULL, nentries, 0, msecs_to_jiffies(JOB_TIMEOUT_MS), pfdev->reset.wq,drivers/gpu/drm/scheduler/sched_main.c +0
-1@@ -48,7 +48,6 @@* through the jobs entity pointer. */ -#include <linux/kthread.h> #include <linux/wait.h> #include <linux/sched.h> #include <linux/completion.h>
drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) · line 259
Quoted 5 lines
drivers/gpu/drm/scheduler/sched_main.c +2
-0@@ -256,6 +255,16 @@ drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) return rb ? rb_entry(rb, struct drm_sched_entity, rb_tree_node) : NULL; } +/** +* drm_sched_submit_queue - scheduler queue submission
There is no verb in the description, and is not clear what this function does unless one reads the code. Given that this is DOC, this should be clearer here. Something like "queue scheduler work to be executed" or something to that effect.
Coming back to this from reading the patch below, it was somewhat unclear what "drm_sched_submit_queue()" does, since when reading below, "submit" was being read by my mind as an adjective, as opposed to a verb. Perhaps something like:
drm_sched_queue_submit(), ordrm_sched_queue_exec(), ordrm_sched_queue_push(), or something to that effect. You pick. :-)
Note that it doesn't have to be 100% reflective of the fact that we're putting this on a workqueue and it would be executed sooner or later, so long as it conveys the fact that we're executing this scheduler queue.
Quoted 145 lines
drivers/gpu/drm/scheduler/sched_main.c +37
-43+* @sched: scheduler instance +*/ +static void drm_sched_submit_queue (struct drm_gpu_scheduler *sched) +{ +if (!READ_ONCE (sched->pause_submit)) +queue_work (sched->submit_wq, &sched->work_submit); +} +/** * drm_sched_job_done - complete a job * @s_job: pointer to the job which is done @@ -275,7 +284,7 @@ static void drm_sched_job_done(struct drm_sched_job *s_job, int result)dma_fence_get (&s_fence->finished);drm_sched_fence_finished (s_fence, result);dma_fence_put (&s_fence->finished); -wake_up_interruptible (&sched->wake_up_worker); +drm_sched_submit_queue (sched); }/** @@ -868,7 +877,7 @@ static bool drm_sched_can_queue(struct drm_gpu_scheduler *sched)void drm_sched_wakeup_if_can_queue (struct drm_gpu_scheduler *sched) {if (drm_sched_can_queue (sched)) -wake_up_interruptible (&sched->wake_up_worker); +drm_sched_submit_queue (sched); }/** @@ -978,61 +987,42 @@ drm_sched_pick_best(struct drm_gpu_scheduler **sched_list, }EXPORT_SYMBOL (drm_sched_pick_best); -/** -* drm_sched_blocked - check if the scheduler is blocked -* -* @sched: scheduler instance -* -* Returns true if blocked, otherwise false. -*/ -static bool drm_sched_blocked (struct drm_gpu_scheduler *sched) -{ -if (kthread_should_park ()) { -kthread_parkme (); -return true; - } - -return false; -} -/** * drm_sched_main - main scheduler thread * * @param: scheduler instance -* -* Returns 0. */ -static int drm_sched_main (void *param) +static void drm_sched_main (struct work_struct *w) { -struct drm_gpu_scheduler *sched = (struct drm_gpu_scheduler *)param; +struct drm_gpu_scheduler *sched = + container_of(w, struct drm_gpu_scheduler, work_submit); +struct drm_sched_entity *entity; +struct drm_sched_job *cleanup_job;int r; -sched_set_fifo_low (current); +if (READ_ONCE (sched->pause_submit)) +return ; -while (!kthread_should_stop ()) { -struct drm_sched_entity *entity =NULL ; -struct drm_sched_fence *s_fence; -struct drm_sched_job *sched_job; -struct dma_fence *fence; -struct drm_sched_job *cleanup_job =NULL ; + cleanup_job =drm_sched_get_cleanup_job (sched); + entity =drm_sched_select_entity (sched); -wait_event_interruptible (sched->wake_up_worker, - (cleanup_job =drm_sched_get_cleanup_job (sched)) || - (!drm_sched_blocked (sched) && - (entity =drm_sched_select_entity (sched))) || -kthread_should_stop ()); +if (!entity && !cleanup_job) +return ;/* No more work */ -if (cleanup_job) - sched->ops->free_job (cleanup_job); +if (cleanup_job) + sched->ops->free_job (cleanup_job); -if (!entity) -continue ; +if (entity) { +struct dma_fence *fence; +struct drm_sched_fence *s_fence; +struct drm_sched_job *sched_job; sched_job =drm_sched_entity_pop_job (entity); -if (!sched_job) {complete_all (&entity->entity_idle); -continue ; +if (!cleanup_job) +return ;/* No more work */ + goto again; } s_fence = sched_job->s_fence;@@ -1063,7 +1053,9 @@ static int drm_sched_main(void *param)wake_up (&sched->job_scheduled); } -return 0 ; + +again: +drm_sched_submit_queue (sched); }/** @@ -1071,6 +1063,8 @@ static int drm_sched_main(void *param)* * @sched: scheduler instance * @ops: backend operations for this scheduler +* @submit_wq: workqueue to use for submission. If NULL, an ordered wq is +* allocated and used * @hw_submission: number of hw submissions that can be in flight * @hang_limit: number of times to allow a job to hang before dropping it * @timeout: timeout value in jiffies for the scheduler @@ -1084,14 +1078,25 @@ static int drm_sched_main(void *param)*/ int drm_sched_init (struct drm_gpu_scheduler *sched,const struct drm_sched_backend_ops *ops, +struct workqueue_struct *submit_wq,unsigned hw_submission,unsigned hang_limit,long timeout,struct workqueue_struct *timeout_wq,atomic_t *score,const char *name,struct device *dev) { -int i, ret; +int i; sched->ops = ops; sched->hw_submission_limit = hw_submission; sched->name = name;
drivers/gpu/drm/scheduler/sched_main.c static int drm_sched_main(void *param) · line 1099
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +10
-0+if (!submit_wq) { + sched->submit_wq =alloc_ordered_workqueue (name,0 ); +if (!sched->submit_wq) +return -ENOMEM ; + + sched->alloc_submit_wq = true; + }else { + sched->submit_wq = submit_wq; + sched->alloc_submit_wq = false; + }
This if-conditional, I would've written:
if (submit_wq) {
sched->submit_wq = submit_wq;
sched->alloc_submit_wq = false;
} else {
sched->submit_wq = alloc_ordered_workqueue(name, 0);
if (!sched->submit_wq)
return -ENOMEM;
sched->alloc_submit_wq = true;
}It's easier to understand testing for positivity, than negativity.
Quoted 175 lines
drivers/gpu/drm/scheduler/sched_main.c +10
-15sched->timeout = timeout; sched->timeout_wq = timeout_wq ? : system_wq; sched->hang_limit = hang_limit;@@ -1100,23 +1105,15 @@ int drm_sched_init(struct drm_gpu_scheduler *sched,for (i =DRM_SCHED_PRIORITY_MIN ; i <DRM_SCHED_PRIORITY_COUNT ; i++)drm_sched_rq_init (sched, &sched->sched_rq[i]); -init_waitqueue_head (&sched->wake_up_worker);init_waitqueue_head (&sched->job_scheduled);INIT_LIST_HEAD (&sched->pending_list);spin_lock_init (&sched->job_list_lock);atomic_set (&sched->hw_rq_count,0 );INIT_DELAYED_WORK (&sched->work_tdr, drm_sched_job_timedout); +INIT_WORK (&sched->work_submit, drm_sched_main);atomic_set (&sched->_score,0 );atomic64_set (&sched->job_id_count,0 ); - -/* Each scheduler will run on a seperate kernel thread */ - sched->thread =kthread_run (drm_sched_main, sched, sched->name); -if (IS_ERR (sched->thread)) { - ret =PTR_ERR (sched->thread); - sched->thread =NULL ; -DRM_DEV_ERROR (sched->dev,"Failed to create scheduler for %s.\n" , name); -return ret; - } + sched->pause_submit = false; sched->ready = true;return 0 ;@@ -1135,8 +1132,7 @@ void drm_sched_fini(struct drm_gpu_scheduler *sched)struct drm_sched_entity *s_entity;int i; -if (sched->thread) -kthread_stop (sched->thread); +drm_sched_submit_stop (sched);for (i =DRM_SCHED_PRIORITY_COUNT -1 ; i >=DRM_SCHED_PRIORITY_MIN ; i--) {struct drm_sched_rq *rq = &sched->sched_rq[i];@@ -1159,6 +1155,8 @@ void drm_sched_fini(struct drm_gpu_scheduler *sched)/* Confirm no work left behind accessing device structures */ cancel_delayed_work_sync (&sched->work_tdr); +if (sched->alloc_submit_wq) +destroy_workqueue (sched->submit_wq); sched->ready = false; }EXPORT_SYMBOL (drm_sched_fini);@@ -1216,7 +1214,7 @@ EXPORT_SYMBOL(drm_sched_increase_karma);*/ bool drm_sched_submit_ready (struct drm_gpu_scheduler *sched) { -return !!sched->thread; +return sched->ready; }EXPORT_SYMBOL (drm_sched_submit_ready);@@ -1228,7 +1226,8 @@ EXPORT_SYMBOL(drm_sched_submit_ready);*/ void drm_sched_submit_stop (struct drm_gpu_scheduler *sched) { -kthread_park (sched->thread); +WRITE_ONCE (sched->pause_submit, true); +cancel_work_sync (&sched->work_submit); }EXPORT_SYMBOL (drm_sched_submit_stop);@@ -1239,6 +1238,7 @@ EXPORT_SYMBOL(drm_sched_submit_stop);*/ void drm_sched_submit_start (struct drm_gpu_scheduler *sched) { -kthread_unpark (sched->thread); +WRITE_ONCE (sched->pause_submit, false); +queue_work (sched->submit_wq, &sched->work_submit); }EXPORT_SYMBOL (drm_sched_submit_start);drivers/gpu/drm/v3d/v3d_sched.c +5
-5@@ -388,7 +388,7 @@ v3d_sched_init(struct v3d_dev *v3d)int ret; ret =drm_sched_init (&v3d->queue[V3D_BIN ].sched, - &v3d_bin_sched_ops, + &v3d_bin_sched_ops,NULL , hw_jobs_limit, job_hang_limit,msecs_to_jiffies (hang_limit_ms),NULL ,NULL ,"v3d_bin" , v3d->drm.dev);@@ -396,7 +396,7 @@ v3d_sched_init(struct v3d_dev *v3d)return ret; ret =drm_sched_init (&v3d->queue[V3D_RENDER ].sched, - &v3d_render_sched_ops, + &v3d_render_sched_ops,NULL , hw_jobs_limit, job_hang_limit,msecs_to_jiffies (hang_limit_ms),NULL ,NULL ,"v3d_render" , v3d->drm.dev);@@ -404,7 +404,7 @@ v3d_sched_init(struct v3d_dev *v3d) goto fail; ret =drm_sched_init (&v3d->queue[V3D_TFU ].sched, - &v3d_tfu_sched_ops, + &v3d_tfu_sched_ops,NULL , hw_jobs_limit, job_hang_limit,msecs_to_jiffies (hang_limit_ms),NULL ,NULL ,"v3d_tfu" , v3d->drm.dev);@@ -413,7 +413,7 @@ v3d_sched_init(struct v3d_dev *v3d)if (v3d_has_csd (v3d)) { ret =drm_sched_init (&v3d->queue[V3D_CSD ].sched, - &v3d_csd_sched_ops, + &v3d_csd_sched_ops,NULL , hw_jobs_limit, job_hang_limit,msecs_to_jiffies (hang_limit_ms),NULL ,NULL ,"v3d_csd" , v3d->drm.dev);@@ -421,7 +421,7 @@ v3d_sched_init(struct v3d_dev *v3d) goto fail; ret =drm_sched_init (&v3d->queue[V3D_CACHE_CLEAN ].sched, - &v3d_cache_clean_sched_ops, + &v3d_cache_clean_sched_ops,NULL , hw_jobs_limit, job_hang_limit,msecs_to_jiffies (hang_limit_ms),NULL ,NULL ,"v3d_cache_clean" , v3d->drm.dev);include/drm/gpu_scheduler.h +6
-5@@ -473,17 +473,16 @@ struct drm_sched_backend_ops {* @timeout: the time after which a job is removed from the scheduler. * @name: name of the ring for which this scheduler is being used. * @sched_rq: priority wise array of run queues. -* @wake_up_worker: the wait queue on which the scheduler sleeps until a job -* is ready to be scheduled. * @job_scheduled: once @drm_sched_entity_do_release is called the scheduler * waits on this wait queue until all the scheduled jobs are * finished. * @hw_rq_count: the number of jobs currently in the hardware queue. * @job_id_count: used to assign unique id to the each job. +* @submit_wq: workqueue used to queue @work_submit * @timeout_wq: workqueue used to queue @work_tdr +* @work_submit: schedules jobs and cleans up entities * @work_tdr: schedules a delayed call to @drm_sched_job_timedout after the * timeout interval is over. -* @thread: the kthread on which the scheduler which run. * @pending_list: the list of jobs which are currently in the job queue. * @job_list_lock: lock to protect the pending_list. * @hang_limit: once the hangs by a job crosses this limit then it is marked @@ -492,6 +491,8 @@ struct drm_sched_backend_ops {* @_score: score used when the driver doesn't provide one * @ready: marks if the underlying HW is ready to work * @free_guilty: A hit to time out handler to free the guilty job. +* @pause_submit: pause queuing of @work_submit on @submit_wq +* @alloc_submit_wq: scheduler own allocation of @submit_wq * @dev: system &struct device * * One scheduler is implemented for each hardware ring. @@ -502,13 +503,13 @@ struct drm_gpu_scheduler {long timeout;const char *name;struct drm_sched_rq sched_rq[DRM_SCHED_PRIORITY_COUNT ]; -wait_queue_head_t wake_up_worker;wait_queue_head_t job_scheduled;atomic_t hw_rq_count;atomic64_t job_id_count; +struct workqueue_struct *submit_wq;struct workqueue_struct *timeout_wq; +struct work_struct work_submit;struct delayed_work work_tdr; -struct task_struct *thread;struct list_head pending_list;spinlock_t job_list_lock;int hang_limit;
include/drm/gpu_scheduler.h struct drm_gpu_scheduler { · line 521
Quoted 5 lines
include/drm/gpu_scheduler.h +2
-0@@ -516,11 +517,14 @@ struct drm_gpu_scheduler {atomic_t _score;bool ready;bool free_guilty; +bool pause_submit; +bool alloc_submit_wq;
Please rename it to what it actually describes:
alloc_submit_wq --> own_submit_wq
to mean "do we own the submit wq". Then the check becomes the intuitive,
if (sched->own_submit_wq) destroy_workqueue(sched->submit_wq);
include/drm/gpu_scheduler.h struct drm_gpu_scheduler { · line 530
Quoted 9 lines
include/drm/gpu_scheduler.h +1
-0struct device *dev; };int drm_sched_init (struct drm_gpu_scheduler *sched,const struct drm_sched_backend_ops *ops, +struct workqueue_struct *submit_wq,uint32_t hw_submission,unsigned hang_limit,long timeout,struct workqueue_struct *timeout_wq,atomic_t *score,const char *name,struct device *dev);
This is a good patch.
Signature · 2 lines
Regards, Luben
Matthew Brost
maintainerRe: [PATCH v4 02/10] drm/sched: Convert drm scheduler to use a work queue rather than kthread
Quoted 95 lines · Luben Tuikov
Hi,
Quoted 92 lines · Matthew Brost
In XE, the new Intel GPU driver, a choice has made to have a 1 to 1 mapping between a
drm_gpu_scheduleranddrm_sched_entity. At first this seems a bit odd but let us explain the reasoning below.1. In XE the submission order from multiple
drm_sched_entityis not guaranteed to be the same completion even if targeting the same hardware engine. This is because in XE we have a firmware scheduler, the GuC, which allowed to reorder, timeslice, and preempt submissions. If a using shareddrm_gpu_scheduleracross multipledrm_sched_entity, the TDR falls apart as the TDR expects submission order == completion order. Using a dedicateddrm_gpu_schedulerperdrm_sched_entitysolve this problem.2. In XE submissions are done via programming a ring buffer (circular buffer), a
drm_gpu_schedulerprovides a limit on number of jobs, if the limit of number jobs is set toRING_SIZE/MAX_SIZE_PER_JOBwe get flow control on the ring for free.A problem with this design is currently a
drm_gpu_scheduleruses a kthread for submission / job cleanup. This doesn't scale if a large number ofdrm_gpu_schedulerare used. To work around the scaling issue, use a worker rather than kthread for submission / job cleanup.v2:
- (Rob Clark) Fix msm build
- Pass in run work queue
v3:
- (Boris) don't have loop in worker
v4:
- (Tvrtko) break out submit ready, stop, start helpers into own patch
v5:
- (Boris) default to ordered work queueSigned-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_sched.c | 2 +- drivers/gpu/drm/lima/lima_sched.c | 2 +- drivers/gpu/drm/msm/msm_ringbuffer.c | 2 +- drivers/gpu/drm/nouveau/nouveau_sched.c | 2 +- drivers/gpu/drm/panfrost/panfrost_job.c | 2 +- drivers/gpu/drm/scheduler/sched_main.c | 118 ++++++++++----------- drivers/gpu/drm/v3d/v3d_sched.c | 10 +- include/drm/gpu_scheduler.h | 14 ++- 9 files changed, 79 insertions(+), 75 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-1@@ -2279,7 +2279,7 @@ static int amdgpu_device_init_schedulers(struct amdgpu_device *adev)break ; } - r = drm_sched_init(&ring->sched, &amdgpu_sched_ops, + r = drm_sched_init(&ring->sched, &amdgpu_sched_ops, NULL, ring->num_hw_submission, 0, timeout, adev->reset_domain->wq, ring->sched_score, ring->name,drivers/gpu/drm/etnaviv/etnaviv_sched.c +1
-1@@ -134,7 +134,7 @@ int etnaviv_sched_init(struct etnaviv_gpu *gpu) {int ret; - ret =drm_sched_init (&gpu->sched, &etnaviv_sched_ops, + ret =drm_sched_init (&gpu->sched, &etnaviv_sched_ops,NULL , etnaviv_hw_jobs_limit, etnaviv_job_hang_limit,msecs_to_jiffies (500 ),NULL ,NULL ,dev_name (gpu->dev), gpu->dev);drivers/gpu/drm/lima/lima_sched.c +1
-1@@ -488,7 +488,7 @@ int lima_sched_pipe_init(struct lima_sched_pipe *pipe, const char *name)INIT_WORK (&pipe->recover_work, lima_sched_recover_work); -return drm_sched_init (&pipe->base, &lima_sched_ops,1 , +return drm_sched_init (&pipe->base, &lima_sched_ops,NULL ,1 , lima_job_hang_limit,msecs_to_jiffies (timeout),NULL ,NULL , name, pipe->ldev->dev);drivers/gpu/drm/msm/msm_ringbuffer.c +0
-0@@ -94,7 +94,7 @@ struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id,/* currently managing hangcheck ourselves: */ sched_timeout =MAX_SCHEDULE_TIMEOUT ;
Quoted 7 lines
drivers/gpu/drm/msm/msm_ringbuffer.c struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id, · line 99
Quoted 4 lines
drivers/gpu/drm/msm/msm_ringbuffer.c +1
-1- ret =drm_sched_init (&ring->sched, &msm_sched_ops, + ret =drm_sched_init (&ring->sched, &msm_sched_ops,NULL , num_hw_submissions,0 , sched_timeout,NULL ,NULL ,to_msm_bo (ring->bo)->name, gpu->dev->dev);checkpatch.pl complains here about unmatched open parens.
Will fix and run checkpatch before posting next rev.
Quoted 43 lines
Quoted 43 lines
drivers/gpu/drm/msm/msm_ringbuffer.c +0
-0if (ret) {drivers/gpu/drm/nouveau/nouveau_sched.c +1
-1@@ -429,7 +429,7 @@ int nouveau_sched_init(struct nouveau_drm *drm)if (!drm->sched_wq)return -ENOMEM ; -return drm_sched_init (sched, &nouveau_sched_ops, +return drm_sched_init (sched, &nouveau_sched_ops,NULL ,NOUVEAU_SCHED_HW_SUBMISSIONS ,0 , job_hang_limit,NULL ,NULL ,"nouveau_sched" , drm->dev->dev); }drivers/gpu/drm/panfrost/panfrost_job.c +1
-1@@ -831,7 +831,7 @@ int panfrost_job_init(struct panfrost_device *pfdev) js->queue[j].fence_context =dma_fence_context_alloc (1 ); ret = drm_sched_init(&js->queue[j].sched, - &panfrost_sched_ops, + &panfrost_sched_ops, NULL, nentries, 0, msecs_to_jiffies(JOB_TIMEOUT_MS), pfdev->reset.wq,drivers/gpu/drm/scheduler/sched_main.c +0
-1@@ -48,7 +48,6 @@* through the jobs entity pointer. */ -#include <linux/kthread.h> #include <linux/wait.h> #include <linux/sched.h> #include <linux/completion.h> @@ -256,6 +255,16 @@ drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) return rb ? rb_entry(rb, struct drm_sched_entity, rb_tree_node) : NULL; }
Quoted 8 lines
drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) · line 259
Quoted 2 lines
drivers/gpu/drm/scheduler/sched_main.c +2
-0+/** +* drm_sched_submit_queue - scheduler queue submission There is no verb in the description, and is not clear what this function does unless one reads the code. Given that this is DOC, this should be clearer here. Something like "queue scheduler work to be executed" or something to that effect.
Will fix.
Quoted 9 lines
Coming back to this from reading the patch below, it was somewhat unclear what "
drm_sched_submit_queue()" does, since when reading below, "submit" was being read by my mind as an adjective, as opposed to a verb. Perhaps something like:
drm_sched_queue_submit(), ordrm_sched_queue_exec(), ordrm_sched_queue_push(), or something to that effect. You pick. :-)
I prefer the name as is. In this patch we have:
drm_sched_submit_queue()drm_sched_submit_start)drm_sched_submit_stop()drm_sched_submit_ready()
I like all these functions start with 'drm_sched_submit' which allows for easy searching for the functions that touch the DRM scheduler submission state.
With a little better doc are you fine with the names as is.
Quoted 174 lines
Note that it doesn't have to be 100% reflective of the fact that we're putting this on a workqueue and it would be executed sooner or later, so long as it conveys the fact that we're executing this scheduler queue.
Quoted 145 lines
drivers/gpu/drm/scheduler/sched_main.c +37
-43+* @sched: scheduler instance +*/ +static void drm_sched_submit_queue (struct drm_gpu_scheduler *sched) +{ +if (!READ_ONCE (sched->pause_submit)) +queue_work (sched->submit_wq, &sched->work_submit); +} +/** * drm_sched_job_done - complete a job * @s_job: pointer to the job which is done @@ -275,7 +284,7 @@ static void drm_sched_job_done(struct drm_sched_job *s_job, int result)dma_fence_get (&s_fence->finished);drm_sched_fence_finished (s_fence, result);dma_fence_put (&s_fence->finished); -wake_up_interruptible (&sched->wake_up_worker); +drm_sched_submit_queue (sched); }/** @@ -868,7 +877,7 @@ static bool drm_sched_can_queue(struct drm_gpu_scheduler *sched)void drm_sched_wakeup_if_can_queue (struct drm_gpu_scheduler *sched) {if (drm_sched_can_queue (sched)) -wake_up_interruptible (&sched->wake_up_worker); +drm_sched_submit_queue (sched); }/** @@ -978,61 +987,42 @@ drm_sched_pick_best(struct drm_gpu_scheduler **sched_list, }EXPORT_SYMBOL (drm_sched_pick_best); -/** -* drm_sched_blocked - check if the scheduler is blocked -* -* @sched: scheduler instance -* -* Returns true if blocked, otherwise false. -*/ -static bool drm_sched_blocked (struct drm_gpu_scheduler *sched) -{ -if (kthread_should_park ()) { -kthread_parkme (); -return true; - } - -return false; -} -/** * drm_sched_main - main scheduler thread * * @param: scheduler instance -* -* Returns 0. */ -static int drm_sched_main (void *param) +static void drm_sched_main (struct work_struct *w) { -struct drm_gpu_scheduler *sched = (struct drm_gpu_scheduler *)param; +struct drm_gpu_scheduler *sched = + container_of(w, struct drm_gpu_scheduler, work_submit); +struct drm_sched_entity *entity; +struct drm_sched_job *cleanup_job;int r; -sched_set_fifo_low (current); +if (READ_ONCE (sched->pause_submit)) +return ; -while (!kthread_should_stop ()) { -struct drm_sched_entity *entity =NULL ; -struct drm_sched_fence *s_fence; -struct drm_sched_job *sched_job; -struct dma_fence *fence; -struct drm_sched_job *cleanup_job =NULL ; + cleanup_job =drm_sched_get_cleanup_job (sched); + entity =drm_sched_select_entity (sched); -wait_event_interruptible (sched->wake_up_worker, - (cleanup_job =drm_sched_get_cleanup_job (sched)) || - (!drm_sched_blocked (sched) && - (entity =drm_sched_select_entity (sched))) || -kthread_should_stop ()); +if (!entity && !cleanup_job) +return ;/* No more work */ -if (cleanup_job) - sched->ops->free_job (cleanup_job); +if (cleanup_job) + sched->ops->free_job (cleanup_job); -if (!entity) -continue ; +if (entity) { +struct dma_fence *fence; +struct drm_sched_fence *s_fence; +struct drm_sched_job *sched_job; sched_job =drm_sched_entity_pop_job (entity); -if (!sched_job) {complete_all (&entity->entity_idle); -continue ; +if (!cleanup_job) +return ;/* No more work */ + goto again; } s_fence = sched_job->s_fence;@@ -1063,7 +1053,9 @@ static int drm_sched_main(void *param)wake_up (&sched->job_scheduled); } -return 0 ; + +again: +drm_sched_submit_queue (sched); }/** @@ -1071,6 +1063,8 @@ static int drm_sched_main(void *param)* * @sched: scheduler instance * @ops: backend operations for this scheduler +* @submit_wq: workqueue to use for submission. If NULL, an ordered wq is +* allocated and used * @hw_submission: number of hw submissions that can be in flight * @hang_limit: number of times to allow a job to hang before dropping it * @timeout: timeout value in jiffies for the scheduler @@ -1084,14 +1078,25 @@ static int drm_sched_main(void *param)*/ int drm_sched_init (struct drm_gpu_scheduler *sched,const struct drm_sched_backend_ops *ops, +struct workqueue_struct *submit_wq,unsigned hw_submission,unsigned hang_limit,long timeout,struct workqueue_struct *timeout_wq,atomic_t *score,const char *name,struct device *dev) { -int i, ret; +int i; sched->ops = ops; sched->hw_submission_limit = hw_submission; sched->name = name;drivers/gpu/drm/scheduler/sched_main.c static int drm_sched_main(void *param) · line 1099
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +10
-0+if (!submit_wq) { + sched->submit_wq =alloc_ordered_workqueue (name,0 ); +if (!sched->submit_wq) +return -ENOMEM ; + + sched->alloc_submit_wq = true; + }else { + sched->submit_wq = submit_wq; + sched->alloc_submit_wq = false; + }This if-conditional, I would've written:
if (submit_wq) { sched->submit_wq = submit_wq; sched->alloc_submit_wq = false; } else { sched->submit_wq = alloc_ordered_workqueue(name, 0); if (!sched->submit_wq) return -ENOMEM; sched->alloc_submit_wq = true; }
Quoted 2 lines
It's easier to understand testing for positivity, than negativity.
+1, will do this all in future patches.
Quoted 184 lines
Quoted 176 lines
drivers/gpu/drm/scheduler/sched_main.c +10
-15sched->timeout = timeout; sched->timeout_wq = timeout_wq ? : system_wq; sched->hang_limit = hang_limit;@@ -1100,23 +1105,15 @@ int drm_sched_init(struct drm_gpu_scheduler *sched,for (i =DRM_SCHED_PRIORITY_MIN ; i <DRM_SCHED_PRIORITY_COUNT ; i++)drm_sched_rq_init (sched, &sched->sched_rq[i]); -init_waitqueue_head (&sched->wake_up_worker);init_waitqueue_head (&sched->job_scheduled);INIT_LIST_HEAD (&sched->pending_list);spin_lock_init (&sched->job_list_lock);atomic_set (&sched->hw_rq_count,0 );INIT_DELAYED_WORK (&sched->work_tdr, drm_sched_job_timedout); +INIT_WORK (&sched->work_submit, drm_sched_main);atomic_set (&sched->_score,0 );atomic64_set (&sched->job_id_count,0 ); - -/* Each scheduler will run on a seperate kernel thread */ - sched->thread =kthread_run (drm_sched_main, sched, sched->name); -if (IS_ERR (sched->thread)) { - ret =PTR_ERR (sched->thread); - sched->thread =NULL ; -DRM_DEV_ERROR (sched->dev,"Failed to create scheduler for %s.\n" , name); -return ret; - } + sched->pause_submit = false; sched->ready = true;return 0 ;@@ -1135,8 +1132,7 @@ void drm_sched_fini(struct drm_gpu_scheduler *sched)struct drm_sched_entity *s_entity;int i; -if (sched->thread) -kthread_stop (sched->thread); +drm_sched_submit_stop (sched);for (i =DRM_SCHED_PRIORITY_COUNT -1 ; i >=DRM_SCHED_PRIORITY_MIN ; i--) {struct drm_sched_rq *rq = &sched->sched_rq[i];@@ -1159,6 +1155,8 @@ void drm_sched_fini(struct drm_gpu_scheduler *sched)/* Confirm no work left behind accessing device structures */ cancel_delayed_work_sync (&sched->work_tdr); +if (sched->alloc_submit_wq) +destroy_workqueue (sched->submit_wq); sched->ready = false; }EXPORT_SYMBOL (drm_sched_fini);@@ -1216,7 +1214,7 @@ EXPORT_SYMBOL(drm_sched_increase_karma);*/ bool drm_sched_submit_ready (struct drm_gpu_scheduler *sched) { -return !!sched->thread; +return sched->ready; }EXPORT_SYMBOL (drm_sched_submit_ready);@@ -1228,7 +1226,8 @@ EXPORT_SYMBOL(drm_sched_submit_ready);*/ void drm_sched_submit_stop (struct drm_gpu_scheduler *sched) { -kthread_park (sched->thread); +WRITE_ONCE (sched->pause_submit, true); +cancel_work_sync (&sched->work_submit); }EXPORT_SYMBOL (drm_sched_submit_stop);@@ -1239,6 +1238,7 @@ EXPORT_SYMBOL(drm_sched_submit_stop);*/ void drm_sched_submit_start (struct drm_gpu_scheduler *sched) { -kthread_unpark (sched->thread); +WRITE_ONCE (sched->pause_submit, false); +queue_work (sched->submit_wq, &sched->work_submit); }EXPORT_SYMBOL (drm_sched_submit_start);drivers/gpu/drm/v3d/v3d_sched.c +5
-5@@ -388,7 +388,7 @@ v3d_sched_init(struct v3d_dev *v3d)int ret; ret =drm_sched_init (&v3d->queue[V3D_BIN ].sched, - &v3d_bin_sched_ops, + &v3d_bin_sched_ops,NULL , hw_jobs_limit, job_hang_limit,msecs_to_jiffies (hang_limit_ms),NULL ,NULL ,"v3d_bin" , v3d->drm.dev);@@ -396,7 +396,7 @@ v3d_sched_init(struct v3d_dev *v3d)return ret; ret =drm_sched_init (&v3d->queue[V3D_RENDER ].sched, - &v3d_render_sched_ops, + &v3d_render_sched_ops,NULL , hw_jobs_limit, job_hang_limit,msecs_to_jiffies (hang_limit_ms),NULL ,NULL ,"v3d_render" , v3d->drm.dev);@@ -404,7 +404,7 @@ v3d_sched_init(struct v3d_dev *v3d) goto fail; ret =drm_sched_init (&v3d->queue[V3D_TFU ].sched, - &v3d_tfu_sched_ops, + &v3d_tfu_sched_ops,NULL , hw_jobs_limit, job_hang_limit,msecs_to_jiffies (hang_limit_ms),NULL ,NULL ,"v3d_tfu" , v3d->drm.dev);@@ -413,7 +413,7 @@ v3d_sched_init(struct v3d_dev *v3d)if (v3d_has_csd (v3d)) { ret =drm_sched_init (&v3d->queue[V3D_CSD ].sched, - &v3d_csd_sched_ops, + &v3d_csd_sched_ops,NULL , hw_jobs_limit, job_hang_limit,msecs_to_jiffies (hang_limit_ms),NULL ,NULL ,"v3d_csd" , v3d->drm.dev);@@ -421,7 +421,7 @@ v3d_sched_init(struct v3d_dev *v3d) goto fail; ret =drm_sched_init (&v3d->queue[V3D_CACHE_CLEAN ].sched, - &v3d_cache_clean_sched_ops, + &v3d_cache_clean_sched_ops,NULL , hw_jobs_limit, job_hang_limit,msecs_to_jiffies (hang_limit_ms),NULL ,NULL ,"v3d_cache_clean" , v3d->drm.dev);include/drm/gpu_scheduler.h +6
-5@@ -473,17 +473,16 @@ struct drm_sched_backend_ops {* @timeout: the time after which a job is removed from the scheduler. * @name: name of the ring for which this scheduler is being used. * @sched_rq: priority wise array of run queues. -* @wake_up_worker: the wait queue on which the scheduler sleeps until a job -* is ready to be scheduled. * @job_scheduled: once @drm_sched_entity_do_release is called the scheduler * waits on this wait queue until all the scheduled jobs are * finished. * @hw_rq_count: the number of jobs currently in the hardware queue. * @job_id_count: used to assign unique id to the each job. +* @submit_wq: workqueue used to queue @work_submit * @timeout_wq: workqueue used to queue @work_tdr +* @work_submit: schedules jobs and cleans up entities * @work_tdr: schedules a delayed call to @drm_sched_job_timedout after the * timeout interval is over. -* @thread: the kthread on which the scheduler which run. * @pending_list: the list of jobs which are currently in the job queue. * @job_list_lock: lock to protect the pending_list. * @hang_limit: once the hangs by a job crosses this limit then it is marked @@ -492,6 +491,8 @@ struct drm_sched_backend_ops {* @_score: score used when the driver doesn't provide one * @ready: marks if the underlying HW is ready to work * @free_guilty: A hit to time out handler to free the guilty job. +* @pause_submit: pause queuing of @work_submit on @submit_wq +* @alloc_submit_wq: scheduler own allocation of @submit_wq * @dev: system &struct device * * One scheduler is implemented for each hardware ring. @@ -502,13 +503,13 @@ struct drm_gpu_scheduler {long timeout;const char *name;struct drm_sched_rq sched_rq[DRM_SCHED_PRIORITY_COUNT ]; -wait_queue_head_t wake_up_worker;wait_queue_head_t job_scheduled;atomic_t hw_rq_count;atomic64_t job_id_count; +struct workqueue_struct *submit_wq;struct workqueue_struct *timeout_wq; +struct work_struct work_submit;struct delayed_work work_tdr; -struct task_struct *thread;struct list_head pending_list;spinlock_t job_list_lock;int hang_limit;include/drm/gpu_scheduler.h struct drm_gpu_scheduler { · line 521
Quoted 5 lines
include/drm/gpu_scheduler.h +2
-0@@ -516,11 +517,14 @@ struct drm_gpu_scheduler {atomic_t _score;bool ready;bool free_guilty; +bool pause_submit; +bool alloc_submit_wq;Please rename it to what it actually describes:
Quoted 7 lines
alloc_submit_wq-->own_submit_wqto mean "do we own the submit wq". Then the check becomes the intuitive,
if (sched->own_submit_wq) destroy_workqueue(sched->submit_wq);
Got it, agree.
Quoted 11 lines
include/drm/gpu_scheduler.h struct drm_gpu_scheduler { · line 530
Quoted 9 lines
include/drm/gpu_scheduler.h +1
-0struct device *dev; };int drm_sched_init (struct drm_gpu_scheduler *sched,const struct drm_sched_backend_ops *ops, +struct workqueue_struct *submit_wq,uint32_t hw_submission,unsigned hang_limit,long timeout,struct workqueue_struct *timeout_wq,atomic_t *score,const char *name,struct device *dev);This is a good patch.
Thanks for the review.
Matt
Quoted 4 lines
Signature · 2 lines
Regards, Luben
Re: [PATCH v4 02/10] drm/sched: Convert drm scheduler to use a work queue rather than kthread
Quoted 177 lines · Matthew Brost
Quoted 95 lines · Luben Tuikov
Hi,
Quoted 92 lines · Matthew Brost
In XE, the new Intel GPU driver, a choice has made to have a 1 to 1 mapping between a
drm_gpu_scheduleranddrm_sched_entity. At first this seems a bit odd but let us explain the reasoning below.1. In XE the submission order from multiple
drm_sched_entityis not guaranteed to be the same completion even if targeting the same hardware engine. This is because in XE we have a firmware scheduler, the GuC, which allowed to reorder, timeslice, and preempt submissions. If a using shareddrm_gpu_scheduleracross multipledrm_sched_entity, the TDR falls apart as the TDR expects submission order == completion order. Using a dedicateddrm_gpu_schedulerperdrm_sched_entitysolve this problem.2. In XE submissions are done via programming a ring buffer (circular buffer), a
drm_gpu_schedulerprovides a limit on number of jobs, if the limit of number jobs is set toRING_SIZE/MAX_SIZE_PER_JOBwe get flow control on the ring for free.A problem with this design is currently a
drm_gpu_scheduleruses a kthread for submission / job cleanup. This doesn't scale if a large number ofdrm_gpu_schedulerare used. To work around the scaling issue, use a worker rather than kthread for submission / job cleanup.v2:
- (Rob Clark) Fix msm build
- Pass in run work queue
v3:
- (Boris) don't have loop in worker
v4:
- (Tvrtko) break out submit ready, stop, start helpers into own patch
v5:
- (Boris) default to ordered work queueSigned-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_sched.c | 2 +- drivers/gpu/drm/lima/lima_sched.c | 2 +- drivers/gpu/drm/msm/msm_ringbuffer.c | 2 +- drivers/gpu/drm/nouveau/nouveau_sched.c | 2 +- drivers/gpu/drm/panfrost/panfrost_job.c | 2 +- drivers/gpu/drm/scheduler/sched_main.c | 118 ++++++++++----------- drivers/gpu/drm/v3d/v3d_sched.c | 10 +- include/drm/gpu_scheduler.h | 14 ++- 9 files changed, 79 insertions(+), 75 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-1@@ -2279,7 +2279,7 @@ static int amdgpu_device_init_schedulers(struct amdgpu_device *adev)break ; } - r = drm_sched_init(&ring->sched, &amdgpu_sched_ops, + r = drm_sched_init(&ring->sched, &amdgpu_sched_ops, NULL, ring->num_hw_submission, 0, timeout, adev->reset_domain->wq, ring->sched_score, ring->name,drivers/gpu/drm/etnaviv/etnaviv_sched.c +1
-1@@ -134,7 +134,7 @@ int etnaviv_sched_init(struct etnaviv_gpu *gpu) {int ret; - ret =drm_sched_init (&gpu->sched, &etnaviv_sched_ops, + ret =drm_sched_init (&gpu->sched, &etnaviv_sched_ops,NULL , etnaviv_hw_jobs_limit, etnaviv_job_hang_limit,msecs_to_jiffies (500 ),NULL ,NULL ,dev_name (gpu->dev), gpu->dev);drivers/gpu/drm/lima/lima_sched.c +1
-1@@ -488,7 +488,7 @@ int lima_sched_pipe_init(struct lima_sched_pipe *pipe, const char *name)INIT_WORK (&pipe->recover_work, lima_sched_recover_work); -return drm_sched_init (&pipe->base, &lima_sched_ops,1 , +return drm_sched_init (&pipe->base, &lima_sched_ops,NULL ,1 , lima_job_hang_limit,msecs_to_jiffies (timeout),NULL ,NULL , name, pipe->ldev->dev);drivers/gpu/drm/msm/msm_ringbuffer.c +0
-0@@ -94,7 +94,7 @@ struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id,/* currently managing hangcheck ourselves: */ sched_timeout =MAX_SCHEDULE_TIMEOUT ;Quoted 7 lines
drivers/gpu/drm/msm/msm_ringbuffer.c struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id, · line 99
Quoted 4 lines
drivers/gpu/drm/msm/msm_ringbuffer.c +1
-1- ret =drm_sched_init (&ring->sched, &msm_sched_ops, + ret =drm_sched_init (&ring->sched, &msm_sched_ops,NULL , num_hw_submissions,0 , sched_timeout,NULL ,NULL ,to_msm_bo (ring->bo)->name, gpu->dev->dev);checkpatch.pl complains here about unmatched open parens.
Will fix and run checkpatch before posting next rev.
Quoted 43 lines
Quoted 43 lines
drivers/gpu/drm/msm/msm_ringbuffer.c +0
-0if (ret) {drivers/gpu/drm/nouveau/nouveau_sched.c +1
-1@@ -429,7 +429,7 @@ int nouveau_sched_init(struct nouveau_drm *drm)if (!drm->sched_wq)return -ENOMEM ; -return drm_sched_init (sched, &nouveau_sched_ops, +return drm_sched_init (sched, &nouveau_sched_ops,NULL ,NOUVEAU_SCHED_HW_SUBMISSIONS ,0 , job_hang_limit,NULL ,NULL ,"nouveau_sched" , drm->dev->dev); }drivers/gpu/drm/panfrost/panfrost_job.c +1
-1@@ -831,7 +831,7 @@ int panfrost_job_init(struct panfrost_device *pfdev) js->queue[j].fence_context =dma_fence_context_alloc (1 ); ret = drm_sched_init(&js->queue[j].sched, - &panfrost_sched_ops, + &panfrost_sched_ops, NULL, nentries, 0, msecs_to_jiffies(JOB_TIMEOUT_MS), pfdev->reset.wq,drivers/gpu/drm/scheduler/sched_main.c +0
-1@@ -48,7 +48,6 @@* through the jobs entity pointer. */ -#include <linux/kthread.h> #include <linux/wait.h> #include <linux/sched.h> #include <linux/completion.h> @@ -256,6 +255,16 @@ drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) return rb ? rb_entry(rb, struct drm_sched_entity, rb_tree_node) : NULL; }Quoted 8 lines
drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) · line 259
Quoted 2 lines
drivers/gpu/drm/scheduler/sched_main.c +2
-0+/** +* drm_sched_submit_queue - scheduler queue submission There is no verb in the description, and is not clear what this function does unless one reads the code. Given that this is DOC, this should be clearer here. Something like "queue scheduler work to be executed" or something to that effect.
Will fix.
Quoted 9 lines
Coming back to this from reading the patch below, it was somewhat unclear what "
drm_sched_submit_queue()" does, since when reading below, "submit" was being read by my mind as an adjective, as opposed to a verb. Perhaps something like:
drm_sched_queue_submit(), ordrm_sched_queue_exec(), ordrm_sched_queue_push(), or something to that effect. You pick. :-)I prefer the name as is. In this patch we have:
drm_sched_submit_queue()drm_sched_submit_start)drm_sched_submit_stop()drm_sched_submit_ready()
Quoted 5 lines
I like all these functions start with '
drm_sched_submit' which allows for easy searching for the functions that touch the DRM scheduler submission state.With a little better doc are you fine with the names as is.
Notice the following scheme in the naming,
drm_sched_submit_queue()drm_sched_submit_start)drm_sched_submit_stop()drm_sched_submit_ready()
\---+---/ \--+-/ \-+-/
| | +---> a verb
| +---------> should be a noun (something in the component)
+------------------> the kernel/software componentAnd although "queue" can technically be used as a verb too, I'd rather it be "enqueue", like this:
drm_sched_submit_enqueue()
And using "submit" as the noun of the component is a bit cringy, since "submit" is really a verb, and it's cringy to make it a "state" or an "object" we operate on in the DRM Scheduler. "Submission" is a noun, but "submission enqueue/start/stop/ready" doesn't sound very well thought out. "Submission" really is what the work-queue does.
I'd rather it be a real object, like for instance,
drm_sched_wqueue_enqueue()drm_sched_wqueue_start)drm_sched_wqueue_stop()drm_sched_wqueue_ready()
Which tells me that the component is the DRM Scheduler, the object is a/the work-queue, and the last word as the verb, is the action we're performing on the object, i.e. the work-queue. Plus, all these functions actually do operate on work-queues, directly or indirectly, are new, so it's a win-win naming scheme.
I think that that would be most likeable.
Signature · 2 lines
Regards, Luben
Matthew Brost
maintainerRe: [PATCH v4 02/10] drm/sched: Convert drm scheduler to use a work queue rather than kthread
Quoted 214 lines · Luben Tuikov
Quoted 177 lines · Matthew Brost
Quoted 95 lines · Luben Tuikov
Hi,
Quoted 92 lines · Matthew Brost
In XE, the new Intel GPU driver, a choice has made to have a 1 to 1 mapping between a
drm_gpu_scheduleranddrm_sched_entity. At first this seems a bit odd but let us explain the reasoning below.1. In XE the submission order from multiple
drm_sched_entityis not guaranteed to be the same completion even if targeting the same hardware engine. This is because in XE we have a firmware scheduler, the GuC, which allowed to reorder, timeslice, and preempt submissions. If a using shareddrm_gpu_scheduleracross multipledrm_sched_entity, the TDR falls apart as the TDR expects submission order == completion order. Using a dedicateddrm_gpu_schedulerperdrm_sched_entitysolve this problem.2. In XE submissions are done via programming a ring buffer (circular buffer), a
drm_gpu_schedulerprovides a limit on number of jobs, if the limit of number jobs is set toRING_SIZE/MAX_SIZE_PER_JOBwe get flow control on the ring for free.A problem with this design is currently a
drm_gpu_scheduleruses a kthread for submission / job cleanup. This doesn't scale if a large number ofdrm_gpu_schedulerare used. To work around the scaling issue, use a worker rather than kthread for submission / job cleanup.v2:
- (Rob Clark) Fix msm build
- Pass in run work queue
v3:
- (Boris) don't have loop in worker
v4:
- (Tvrtko) break out submit ready, stop, start helpers into own patch
v5:
- (Boris) default to ordered work queueSigned-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_sched.c | 2 +- drivers/gpu/drm/lima/lima_sched.c | 2 +- drivers/gpu/drm/msm/msm_ringbuffer.c | 2 +- drivers/gpu/drm/nouveau/nouveau_sched.c | 2 +- drivers/gpu/drm/panfrost/panfrost_job.c | 2 +- drivers/gpu/drm/scheduler/sched_main.c | 118 ++++++++++----------- drivers/gpu/drm/v3d/v3d_sched.c | 10 +- include/drm/gpu_scheduler.h | 14 ++- 9 files changed, 79 insertions(+), 75 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-1@@ -2279,7 +2279,7 @@ static int amdgpu_device_init_schedulers(struct amdgpu_device *adev)break ; } - r = drm_sched_init(&ring->sched, &amdgpu_sched_ops, + r = drm_sched_init(&ring->sched, &amdgpu_sched_ops, NULL, ring->num_hw_submission, 0, timeout, adev->reset_domain->wq, ring->sched_score, ring->name,drivers/gpu/drm/etnaviv/etnaviv_sched.c +1
-1@@ -134,7 +134,7 @@ int etnaviv_sched_init(struct etnaviv_gpu *gpu) {int ret; - ret =drm_sched_init (&gpu->sched, &etnaviv_sched_ops, + ret =drm_sched_init (&gpu->sched, &etnaviv_sched_ops,NULL , etnaviv_hw_jobs_limit, etnaviv_job_hang_limit,msecs_to_jiffies (500 ),NULL ,NULL ,dev_name (gpu->dev), gpu->dev);drivers/gpu/drm/lima/lima_sched.c +1
-1@@ -488,7 +488,7 @@ int lima_sched_pipe_init(struct lima_sched_pipe *pipe, const char *name)INIT_WORK (&pipe->recover_work, lima_sched_recover_work); -return drm_sched_init (&pipe->base, &lima_sched_ops,1 , +return drm_sched_init (&pipe->base, &lima_sched_ops,NULL ,1 , lima_job_hang_limit,msecs_to_jiffies (timeout),NULL ,NULL , name, pipe->ldev->dev);drivers/gpu/drm/msm/msm_ringbuffer.c +0
-0@@ -94,7 +94,7 @@ struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id,/* currently managing hangcheck ourselves: */ sched_timeout =MAX_SCHEDULE_TIMEOUT ;Quoted 7 lines
drivers/gpu/drm/msm/msm_ringbuffer.c struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id, · line 99
Quoted 4 lines
drivers/gpu/drm/msm/msm_ringbuffer.c +1
-1- ret =drm_sched_init (&ring->sched, &msm_sched_ops, + ret =drm_sched_init (&ring->sched, &msm_sched_ops,NULL , num_hw_submissions,0 , sched_timeout,NULL ,NULL ,to_msm_bo (ring->bo)->name, gpu->dev->dev);checkpatch.pl complains here about unmatched open parens.
Will fix and run checkpatch before posting next rev.
Quoted 43 lines
Quoted 43 lines
drivers/gpu/drm/msm/msm_ringbuffer.c +0
-0if (ret) {drivers/gpu/drm/nouveau/nouveau_sched.c +1
-1@@ -429,7 +429,7 @@ int nouveau_sched_init(struct nouveau_drm *drm)if (!drm->sched_wq)return -ENOMEM ; -return drm_sched_init (sched, &nouveau_sched_ops, +return drm_sched_init (sched, &nouveau_sched_ops,NULL ,NOUVEAU_SCHED_HW_SUBMISSIONS ,0 , job_hang_limit,NULL ,NULL ,"nouveau_sched" , drm->dev->dev); }drivers/gpu/drm/panfrost/panfrost_job.c +1
-1@@ -831,7 +831,7 @@ int panfrost_job_init(struct panfrost_device *pfdev) js->queue[j].fence_context =dma_fence_context_alloc (1 ); ret = drm_sched_init(&js->queue[j].sched, - &panfrost_sched_ops, + &panfrost_sched_ops, NULL, nentries, 0, msecs_to_jiffies(JOB_TIMEOUT_MS), pfdev->reset.wq,drivers/gpu/drm/scheduler/sched_main.c +0
-1@@ -48,7 +48,6 @@* through the jobs entity pointer. */ -#include <linux/kthread.h> #include <linux/wait.h> #include <linux/sched.h> #include <linux/completion.h> @@ -256,6 +255,16 @@ drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) return rb ? rb_entry(rb, struct drm_sched_entity, rb_tree_node) : NULL; }Quoted 8 lines
drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) · line 259
Quoted 2 lines
drivers/gpu/drm/scheduler/sched_main.c +2
-0+/** +* drm_sched_submit_queue - scheduler queue submission There is no verb in the description, and is not clear what this function does unless one reads the code. Given that this is DOC, this should be clearer here. Something like "queue scheduler work to be executed" or something to that effect.
Will fix.
Quoted 9 lines
Coming back to this from reading the patch below, it was somewhat unclear what "
drm_sched_submit_queue()" does, since when reading below, "submit" was being read by my mind as an adjective, as opposed to a verb. Perhaps something like:
drm_sched_queue_submit(), ordrm_sched_queue_exec(), ordrm_sched_queue_push(), or something to that effect. You pick. :-)I prefer the name as is. In this patch we have:
drm_sched_submit_queue()drm_sched_submit_start)drm_sched_submit_stop()drm_sched_submit_ready()Quoted 5 lines
I like all these functions start with '
drm_sched_submit' which allows for easy searching for the functions that touch the DRM scheduler submission state.With a little better doc are you fine with the names as is.
Notice the following scheme in the naming,
drm_sched_submit_queue()drm_sched_submit_start)drm_sched_submit_stop()drm_sched_submit_ready()
\---+---/ \--+-/ \-+-/| | +---> a verb | +---------> should be a noun (something in the component) +------------------> the kernel/software componentAnd although "queue" can technically be used as a verb too, I'd rather it be "enqueue", like this:
drm_sched_submit_enqueue()And using "submit" as the noun of the component is a bit cringy, since "submit" is really a verb, and it's cringy to make it a "state" or an "object" we operate on in the DRM Scheduler. "Submission" is a noun, but "submission enqueue/start/stop/ready" doesn't sound very well thought out. "Submission" really is what the work-queue does.
I'd rather it be a real object, like for instance,
drm_sched_wqueue_enqueue()drm_sched_wqueue_start)drm_sched_wqueue_stop()drm_sched_wqueue_ready()
Quoted 6 lines
Which tells me that the component is the DRM Scheduler, the object is a/the work-queue, and the last word as the verb, is the action we're performing on the object, i.e. the work-queue. Plus, all these functions actually do operate on work-queues, directly or indirectly, are new, so it's a win-win naming scheme.
I think that that would be most likeable.
Thanks for the detailed explaination. I can adjust the names in the next rev.
Matt
Quoted 4 lines
Signature · 2 lines
Regards, Luben
Re: [PATCH v4 02/10] drm/sched: Convert drm scheduler to use a work queue rather than kthread
In reply to Luben TuikovQuoted 214 lines · Luben Tuikov
Quoted 177 lines · Matthew Brost
Quoted 95 lines · Luben Tuikov
Hi,
Quoted 92 lines · Matthew Brost
In XE, the new Intel GPU driver, a choice has made to have a 1 to 1 mapping between a
drm_gpu_scheduleranddrm_sched_entity. At first this seems a bit odd but let us explain the reasoning below.1. In XE the submission order from multiple
drm_sched_entityis not guaranteed to be the same completion even if targeting the same hardware engine. This is because in XE we have a firmware scheduler, the GuC, which allowed to reorder, timeslice, and preempt submissions. If a using shareddrm_gpu_scheduleracross multipledrm_sched_entity, the TDR falls apart as the TDR expects submission order == completion order. Using a dedicateddrm_gpu_schedulerperdrm_sched_entitysolve this problem.2. In XE submissions are done via programming a ring buffer (circular buffer), a
drm_gpu_schedulerprovides a limit on number of jobs, if the limit of number jobs is set toRING_SIZE/MAX_SIZE_PER_JOBwe get flow control on the ring for free.A problem with this design is currently a
drm_gpu_scheduleruses a kthread for submission / job cleanup. This doesn't scale if a large number ofdrm_gpu_schedulerare used. To work around the scaling issue, use a worker rather than kthread for submission / job cleanup.v2:
- (Rob Clark) Fix msm build
- Pass in run work queue
v3:
- (Boris) don't have loop in worker
v4:
- (Tvrtko) break out submit ready, stop, start helpers into own patch
v5:
- (Boris) default to ordered work queueSigned-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_sched.c | 2 +- drivers/gpu/drm/lima/lima_sched.c | 2 +- drivers/gpu/drm/msm/msm_ringbuffer.c | 2 +- drivers/gpu/drm/nouveau/nouveau_sched.c | 2 +- drivers/gpu/drm/panfrost/panfrost_job.c | 2 +- drivers/gpu/drm/scheduler/sched_main.c | 118 ++++++++++----------- drivers/gpu/drm/v3d/v3d_sched.c | 10 +- include/drm/gpu_scheduler.h | 14 ++- 9 files changed, 79 insertions(+), 75 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-1@@ -2279,7 +2279,7 @@ static int amdgpu_device_init_schedulers(struct amdgpu_device *adev)break ; } - r = drm_sched_init(&ring->sched, &amdgpu_sched_ops, + r = drm_sched_init(&ring->sched, &amdgpu_sched_ops, NULL, ring->num_hw_submission, 0, timeout, adev->reset_domain->wq, ring->sched_score, ring->name,drivers/gpu/drm/etnaviv/etnaviv_sched.c +1
-1@@ -134,7 +134,7 @@ int etnaviv_sched_init(struct etnaviv_gpu *gpu) {int ret; - ret =drm_sched_init (&gpu->sched, &etnaviv_sched_ops, + ret =drm_sched_init (&gpu->sched, &etnaviv_sched_ops,NULL , etnaviv_hw_jobs_limit, etnaviv_job_hang_limit,msecs_to_jiffies (500 ),NULL ,NULL ,dev_name (gpu->dev), gpu->dev);drivers/gpu/drm/lima/lima_sched.c +1
-1@@ -488,7 +488,7 @@ int lima_sched_pipe_init(struct lima_sched_pipe *pipe, const char *name)INIT_WORK (&pipe->recover_work, lima_sched_recover_work); -return drm_sched_init (&pipe->base, &lima_sched_ops,1 , +return drm_sched_init (&pipe->base, &lima_sched_ops,NULL ,1 , lima_job_hang_limit,msecs_to_jiffies (timeout),NULL ,NULL , name, pipe->ldev->dev);drivers/gpu/drm/msm/msm_ringbuffer.c +0
-0@@ -94,7 +94,7 @@ struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id,/* currently managing hangcheck ourselves: */ sched_timeout =MAX_SCHEDULE_TIMEOUT ;Quoted 7 lines
drivers/gpu/drm/msm/msm_ringbuffer.c struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id, · line 99
Quoted 4 lines
drivers/gpu/drm/msm/msm_ringbuffer.c +1
-1- ret =drm_sched_init (&ring->sched, &msm_sched_ops, + ret =drm_sched_init (&ring->sched, &msm_sched_ops,NULL , num_hw_submissions,0 , sched_timeout,NULL ,NULL ,to_msm_bo (ring->bo)->name, gpu->dev->dev);checkpatch.pl complains here about unmatched open parens.
Will fix and run checkpatch before posting next rev.
Quoted 43 lines
Quoted 43 lines
drivers/gpu/drm/msm/msm_ringbuffer.c +0
-0if (ret) {drivers/gpu/drm/nouveau/nouveau_sched.c +1
-1@@ -429,7 +429,7 @@ int nouveau_sched_init(struct nouveau_drm *drm)if (!drm->sched_wq)return -ENOMEM ; -return drm_sched_init (sched, &nouveau_sched_ops, +return drm_sched_init (sched, &nouveau_sched_ops,NULL ,NOUVEAU_SCHED_HW_SUBMISSIONS ,0 , job_hang_limit,NULL ,NULL ,"nouveau_sched" , drm->dev->dev); }drivers/gpu/drm/panfrost/panfrost_job.c +1
-1@@ -831,7 +831,7 @@ int panfrost_job_init(struct panfrost_device *pfdev) js->queue[j].fence_context =dma_fence_context_alloc (1 ); ret = drm_sched_init(&js->queue[j].sched, - &panfrost_sched_ops, + &panfrost_sched_ops, NULL, nentries, 0, msecs_to_jiffies(JOB_TIMEOUT_MS), pfdev->reset.wq,drivers/gpu/drm/scheduler/sched_main.c +0
-1@@ -48,7 +48,6 @@* through the jobs entity pointer. */ -#include <linux/kthread.h> #include <linux/wait.h> #include <linux/sched.h> #include <linux/completion.h> @@ -256,6 +255,16 @@ drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) return rb ? rb_entry(rb, struct drm_sched_entity, rb_tree_node) : NULL; }Quoted 8 lines
drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) · line 259
Quoted 2 lines
drivers/gpu/drm/scheduler/sched_main.c +2
-0+/** +* drm_sched_submit_queue - scheduler queue submission There is no verb in the description, and is not clear what this function does unless one reads the code. Given that this is DOC, this should be clearer here. Something like "queue scheduler work to be executed" or something to that effect.
Will fix.
Quoted 9 lines
Coming back to this from reading the patch below, it was somewhat unclear what "
drm_sched_submit_queue()" does, since when reading below, "submit" was being read by my mind as an adjective, as opposed to a verb. Perhaps something like:
drm_sched_queue_submit(), ordrm_sched_queue_exec(), ordrm_sched_queue_push(), or something to that effect. You pick. :-)I prefer the name as is. In this patch we have:
drm_sched_submit_queue()drm_sched_submit_start)drm_sched_submit_stop()drm_sched_submit_ready()Quoted 5 lines
I like all these functions start with '
drm_sched_submit' which allows for easy searching for the functions that touch the DRM scheduler submission state.With a little better doc are you fine with the names as is.
Notice the following scheme in the naming,
drm_sched_submit_queue()drm_sched_submit_start)drm_sched_submit_stop()drm_sched_submit_ready()
\---+---/ \--+-/ \-+-/| | +---> a verb | +---------> should be a noun (something in the component) +------------------> the kernel/software componentAnd although "queue" can technically be used as a verb too, I'd rather it be "enqueue", like this:
drm_sched_submit_enqueue()And using "submit" as the noun of the component is a bit cringy, since "submit" is really a verb, and it's cringy to make it a "state" or an "object" we operate on in the DRM Scheduler. "Submission" is a noun, but "submission enqueue/start/stop/ready" doesn't sound very well thought out. "Submission" really is what the work-queue does.
I'd rather it be a real object, like for instance,
drm_sched_wqueue_enqueue()drm_sched_wqueue_start)drm_sched_wqueue_stop()drm_sched_wqueue_ready()
Quoted 6 lines
Which tells me that the component is the DRM Scheduler, the object is a/the work-queue, and the last word as the verb, is the action we're performing on the object, i.e. the work-queue. Plus, all these functions actually do operate on work-queues, directly or indirectly, are new, so it's a win-win naming scheme.
I think that that would be most likeable.
FWIW I was suggesting not to encode the fact submit queue is implemented with a workqueue in the API name. IMO it would be nicer and less maintenance churn should something channge if the external components can be isolated from that detail.
drm_sched_submit_queue_$verb? If not viewed as too verbose...
Regards,
Tvrtko
Matthew Brost
maintainerRe: [PATCH v4 02/10] drm/sched: Convert drm scheduler to use a work queue rather than kthread
Quoted 199 lines · Tvrtko Ursulin
Quoted 197 lines · Luben Tuikov
Quoted 167 lines · Matthew Brost
Quoted 88 lines · Luben Tuikov
Hi,
Quoted 85 lines · Matthew Brost
In XE, the new Intel GPU driver, a choice has made to have a 1 to 1 mapping between a
drm_gpu_scheduleranddrm_sched_entity. At first this seems a bit odd but let us explain the reasoning below.1. In XE the submission order from multiple
drm_sched_entityis not guaranteed to be the same completion even if targeting the same hardware engine. This is because in XE we have a firmware scheduler, the GuC, which allowed to reorder, timeslice, and preempt submissions. If a using shareddrm_gpu_scheduleracross multipledrm_sched_entity, the TDR falls apart as the TDR expects submission order == completion order. Using a dedicateddrm_gpu_schedulerperdrm_sched_entitysolve this problem.2. In XE submissions are done via programming a ring buffer (circular buffer), a
drm_gpu_schedulerprovides a limit on number of jobs, if the limit of number jobs is set toRING_SIZE/MAX_SIZE_PER_JOBwe get flow control on the ring for free.A problem with this design is currently a
drm_gpu_scheduleruses a kthread for submission / job cleanup. This doesn't scale if a large number ofdrm_gpu_schedulerare used. To work around the scaling issue, use a worker rather than kthread for submission / job cleanup.v2:
- (Rob Clark) Fix msm build
- Pass in run work queue
v3:
- (Boris) don't have loop in worker
v4:
- (Tvrtko) break out submit ready, stop, start helpers into own patch
v5:
- (Boris) default to ordered work queueSigned-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_sched.c | 2 +- drivers/gpu/drm/lima/lima_sched.c | 2 +- drivers/gpu/drm/msm/msm_ringbuffer.c | 2 +- drivers/gpu/drm/nouveau/nouveau_sched.c | 2 +- drivers/gpu/drm/panfrost/panfrost_job.c | 2 +- drivers/gpu/drm/scheduler/sched_main.c | 118 ++++++++++----------- drivers/gpu/drm/v3d/v3d_sched.c | 10 +- include/drm/gpu_scheduler.h | 14 ++- 9 files changed, 79 insertions(+), 75 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-1@@ -2279,7 +2279,7 @@ static int amdgpu_device_init_schedulers(struct amdgpu_device *adev)break ; } - r = drm_sched_init(&ring->sched, &amdgpu_sched_ops, + r = drm_sched_init(&ring->sched, &amdgpu_sched_ops, NULL, ring->num_hw_submission, 0, timeout, adev->reset_domain->wq, ring->sched_score, ring->name,drivers/gpu/drm/etnaviv/etnaviv_sched.c +1
-1@@ -134,7 +134,7 @@ int etnaviv_sched_init(struct etnaviv_gpu *gpu) {int ret; - ret =drm_sched_init (&gpu->sched, &etnaviv_sched_ops, + ret =drm_sched_init (&gpu->sched, &etnaviv_sched_ops,NULL , etnaviv_hw_jobs_limit, etnaviv_job_hang_limit,msecs_to_jiffies (500 ),NULL ,NULL ,dev_name (gpu->dev), gpu->dev);drivers/gpu/drm/lima/lima_sched.c +1
-1@@ -488,7 +488,7 @@ int lima_sched_pipe_init(struct lima_sched_pipe *pipe, const char *name)INIT_WORK (&pipe->recover_work, lima_sched_recover_work); -return drm_sched_init (&pipe->base, &lima_sched_ops,1 , +return drm_sched_init (&pipe->base, &lima_sched_ops,NULL ,1 , lima_job_hang_limit,msecs_to_jiffies (timeout),NULL ,NULL , name, pipe->ldev->dev);drivers/gpu/drm/msm/msm_ringbuffer.c +0
-0@@ -94,7 +94,7 @@ struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id,Quoted 9 lines
drivers/gpu/drm/msm/msm_ringbuffer.c struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id, · line 99
Quoted 6 lines
drivers/gpu/drm/msm/msm_ringbuffer.c +1
-1/* currently managing hangcheck ourselves: */ sched_timeout =MAX_SCHEDULE_TIMEOUT ; - ret =drm_sched_init (&ring->sched, &msm_sched_ops, + ret =drm_sched_init (&ring->sched, &msm_sched_ops,NULL , num_hw_submissions,0 , sched_timeout,NULL ,NULL ,to_msm_bo (ring->bo)->name, gpu->dev->dev);checkpatch.pl complains here about unmatched open parens.
Will fix and run checkpatch before posting next rev.
Quoted 38 lines
Quoted 38 lines
drivers/gpu/drm/msm/msm_ringbuffer.c +0
-0if (ret) {drivers/gpu/drm/nouveau/nouveau_sched.c +1
-1@@ -429,7 +429,7 @@ int nouveau_sched_init(struct nouveau_drm *drm)if (!drm->sched_wq)return -ENOMEM ; -return drm_sched_init (sched, &nouveau_sched_ops, +return drm_sched_init (sched, &nouveau_sched_ops,NULL ,NOUVEAU_SCHED_HW_SUBMISSIONS ,0 , job_hang_limit,NULL ,NULL ,"nouveau_sched" , drm->dev->dev); }drivers/gpu/drm/panfrost/panfrost_job.c +1
-1@@ -831,7 +831,7 @@ int panfrost_job_init(struct panfrost_device *pfdev) js->queue[j].fence_context =dma_fence_context_alloc (1 ); ret = drm_sched_init(&js->queue[j].sched, - &panfrost_sched_ops, + &panfrost_sched_ops, NULL, nentries, 0, msecs_to_jiffies(JOB_TIMEOUT_MS), pfdev->reset.wq,drivers/gpu/drm/scheduler/sched_main.c +0
-1@@ -48,7 +48,6 @@* through the jobs entity pointer. */ -#include <linux/kthread.h> #include <linux/wait.h> #include <linux/sched.h> #include <linux/completion.h> @@ -256,6 +255,16 @@ drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) return rb ? rb_entry(rb, struct drm_sched_entity, rb_tree_node) : NULL;Quoted 9 lines
drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) · line 259
Quoted 3 lines
drivers/gpu/drm/scheduler/sched_main.c +2
-0} +/** +* drm_sched_submit_queue - scheduler queue submission There is no verb in the description, and is not clear what this function does unless one reads the code. Given that this is DOC, this should be clearer here. Something like "queue scheduler work to be executed" or something to that effect.
Will fix.
Quoted 9 lines
Coming back to this from reading the patch below, it was somewhat unclear what "
drm_sched_submit_queue()" does, since when reading below, "submit" was being read by my mind as an adjective, as opposed to a verb. Perhaps something like:
drm_sched_queue_submit(), ordrm_sched_queue_exec(), ordrm_sched_queue_push(), or something to that effect. You pick. :-)I prefer the name as is. In this patch we have:
drm_sched_submit_queue()drm_sched_submit_start)drm_sched_submit_stop()drm_sched_submit_ready()Quoted 5 lines
I like all these functions start with '
drm_sched_submit' which allows for easy searching for the functions that touch the DRM scheduler submission state.With a little better doc are you fine with the names as is.
Notice the following scheme in the naming,
drm_sched_submit_queue()drm_sched_submit_start)drm_sched_submit_stop()drm_sched_submit_ready()
\---+---/ \--+-/ \-+-/| | +---> a verb | +---------> should be a noun (something in the component) +------------------> the kernel/software componentAnd although "queue" can technically be used as a verb too, I'd rather it be "enqueue", like this:
drm_sched_submit_enqueue()And using "submit" as the noun of the component is a bit cringy, since "submit" is really a verb, and it's cringy to make it a "state" or an "object" we operate on in the DRM Scheduler. "Submission" is a noun, but "submission enqueue/start/stop/ready" doesn't sound very well thought out. "Submission" really is what the work-queue does.
Quoted 7 lines
Quoted 7 lines
I'd rather it be a real object, like for instance,
drm_sched_wqueue_enqueue()drm_sched_wqueue_start)drm_sched_wqueue_stop()drm_sched_wqueue_ready()
How about:
drm_sched_submission_enqueue()drm_sched_submission_start)drm_sched_submission_stop()drm_sched_submission_ready()
Matt
Quoted 17 lines
Quoted 6 lines
Which tells me that the component is the DRM Scheduler, the object is a/the work-queue, and the last word as the verb, is the action we're performing on the object, i.e. the work-queue. Plus, all these functions actually do operate on work-queues, directly or indirectly, are new, so it's a win-win naming scheme.
I think that that would be most likeable.
FWIW I was suggesting not to encode the fact submit queue is implemented with a workqueue in the API name. IMO it would be nicer and less maintenance churn should something channge if the external components can be isolated from that detail.
drm_sched_submit_queue_$verb? If not viewed as too verbose...
Regards,
Tvrtko
Matthew Brost
maintainerRe: [Intel-xe] [PATCH v4 02/10] drm/sched: Convert drm scheduler to use a work queue rather than kthread
Quoted 208 lines · Matthew Brost
Quoted 199 lines · Tvrtko Ursulin
Quoted 197 lines · Luben Tuikov
Quoted 167 lines · Matthew Brost
Quoted 88 lines · Luben Tuikov
Hi,
Quoted 85 lines · Matthew Brost
In XE, the new Intel GPU driver, a choice has made to have a 1 to 1 mapping between a
drm_gpu_scheduleranddrm_sched_entity. At first this seems a bit odd but let us explain the reasoning below.1. In XE the submission order from multiple
drm_sched_entityis not guaranteed to be the same completion even if targeting the same hardware engine. This is because in XE we have a firmware scheduler, the GuC, which allowed to reorder, timeslice, and preempt submissions. If a using shareddrm_gpu_scheduleracross multipledrm_sched_entity, the TDR falls apart as the TDR expects submission order == completion order. Using a dedicateddrm_gpu_schedulerperdrm_sched_entitysolve this problem.2. In XE submissions are done via programming a ring buffer (circular buffer), a
drm_gpu_schedulerprovides a limit on number of jobs, if the limit of number jobs is set toRING_SIZE/MAX_SIZE_PER_JOBwe get flow control on the ring for free.A problem with this design is currently a
drm_gpu_scheduleruses a kthread for submission / job cleanup. This doesn't scale if a large number ofdrm_gpu_schedulerare used. To work around the scaling issue, use a worker rather than kthread for submission / job cleanup.v2:
- (Rob Clark) Fix msm build
- Pass in run work queue
v3:
- (Boris) don't have loop in worker
v4:
- (Tvrtko) break out submit ready, stop, start helpers into own patch
v5:
- (Boris) default to ordered work queueSigned-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_sched.c | 2 +- drivers/gpu/drm/lima/lima_sched.c | 2 +- drivers/gpu/drm/msm/msm_ringbuffer.c | 2 +- drivers/gpu/drm/nouveau/nouveau_sched.c | 2 +- drivers/gpu/drm/panfrost/panfrost_job.c | 2 +- drivers/gpu/drm/scheduler/sched_main.c | 118 ++++++++++----------- drivers/gpu/drm/v3d/v3d_sched.c | 10 +- include/drm/gpu_scheduler.h | 14 ++- 9 files changed, 79 insertions(+), 75 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-1@@ -2279,7 +2279,7 @@ static int amdgpu_device_init_schedulers(struct amdgpu_device *adev)break ; } - r = drm_sched_init(&ring->sched, &amdgpu_sched_ops, + r = drm_sched_init(&ring->sched, &amdgpu_sched_ops, NULL, ring->num_hw_submission, 0, timeout, adev->reset_domain->wq, ring->sched_score, ring->name,drivers/gpu/drm/etnaviv/etnaviv_sched.c +1
-1@@ -134,7 +134,7 @@ int etnaviv_sched_init(struct etnaviv_gpu *gpu) {int ret; - ret =drm_sched_init (&gpu->sched, &etnaviv_sched_ops, + ret =drm_sched_init (&gpu->sched, &etnaviv_sched_ops,NULL , etnaviv_hw_jobs_limit, etnaviv_job_hang_limit,msecs_to_jiffies (500 ),NULL ,NULL ,dev_name (gpu->dev), gpu->dev);drivers/gpu/drm/lima/lima_sched.c +1
-1@@ -488,7 +488,7 @@ int lima_sched_pipe_init(struct lima_sched_pipe *pipe, const char *name)INIT_WORK (&pipe->recover_work, lima_sched_recover_work); -return drm_sched_init (&pipe->base, &lima_sched_ops,1 , +return drm_sched_init (&pipe->base, &lima_sched_ops,NULL ,1 , lima_job_hang_limit,msecs_to_jiffies (timeout),NULL ,NULL , name, pipe->ldev->dev);drivers/gpu/drm/msm/msm_ringbuffer.c +0
-0@@ -94,7 +94,7 @@ struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id,Quoted 9 lines
drivers/gpu/drm/msm/msm_ringbuffer.c struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id, · line 99
Quoted 6 lines
drivers/gpu/drm/msm/msm_ringbuffer.c +1
-1/* currently managing hangcheck ourselves: */ sched_timeout =MAX_SCHEDULE_TIMEOUT ; - ret =drm_sched_init (&ring->sched, &msm_sched_ops, + ret =drm_sched_init (&ring->sched, &msm_sched_ops,NULL , num_hw_submissions,0 , sched_timeout,NULL ,NULL ,to_msm_bo (ring->bo)->name, gpu->dev->dev);checkpatch.pl complains here about unmatched open parens.
Will fix and run checkpatch before posting next rev.
Quoted 38 lines
Quoted 38 lines
drivers/gpu/drm/msm/msm_ringbuffer.c +0
-0if (ret) {drivers/gpu/drm/nouveau/nouveau_sched.c +1
-1@@ -429,7 +429,7 @@ int nouveau_sched_init(struct nouveau_drm *drm)if (!drm->sched_wq)return -ENOMEM ; -return drm_sched_init (sched, &nouveau_sched_ops, +return drm_sched_init (sched, &nouveau_sched_ops,NULL ,NOUVEAU_SCHED_HW_SUBMISSIONS ,0 , job_hang_limit,NULL ,NULL ,"nouveau_sched" , drm->dev->dev); }drivers/gpu/drm/panfrost/panfrost_job.c +1
-1@@ -831,7 +831,7 @@ int panfrost_job_init(struct panfrost_device *pfdev) js->queue[j].fence_context =dma_fence_context_alloc (1 ); ret = drm_sched_init(&js->queue[j].sched, - &panfrost_sched_ops, + &panfrost_sched_ops, NULL, nentries, 0, msecs_to_jiffies(JOB_TIMEOUT_MS), pfdev->reset.wq,drivers/gpu/drm/scheduler/sched_main.c +0
-1@@ -48,7 +48,6 @@* through the jobs entity pointer. */ -#include <linux/kthread.h> #include <linux/wait.h> #include <linux/sched.h> #include <linux/completion.h> @@ -256,6 +255,16 @@ drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) return rb ? rb_entry(rb, struct drm_sched_entity, rb_tree_node) : NULL;Quoted 9 lines
drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) · line 259
Quoted 3 lines
drivers/gpu/drm/scheduler/sched_main.c +2
-0} +/** +* drm_sched_submit_queue - scheduler queue submission There is no verb in the description, and is not clear what this function does unless one reads the code. Given that this is DOC, this should be clearer here. Something like "queue scheduler work to be executed" or something to that effect.
Will fix.
Quoted 9 lines
Coming back to this from reading the patch below, it was somewhat unclear what "
drm_sched_submit_queue()" does, since when reading below, "submit" was being read by my mind as an adjective, as opposed to a verb. Perhaps something like:
drm_sched_queue_submit(), ordrm_sched_queue_exec(), ordrm_sched_queue_push(), or something to that effect. You pick. :-)I prefer the name as is. In this patch we have:
drm_sched_submit_queue()drm_sched_submit_start)drm_sched_submit_stop()drm_sched_submit_ready()Quoted 5 lines
I like all these functions start with '
drm_sched_submit' which allows for easy searching for the functions that touch the DRM scheduler submission state.With a little better doc are you fine with the names as is.
Notice the following scheme in the naming,
drm_sched_submit_queue()drm_sched_submit_start)drm_sched_submit_stop()drm_sched_submit_ready()
\---+---/ \--+-/ \-+-/| | +---> a verb | +---------> should be a noun (something in the component) +------------------> the kernel/software componentAnd although "queue" can technically be used as a verb too, I'd rather it be "enqueue", like this:
drm_sched_submit_enqueue()And using "submit" as the noun of the component is a bit cringy, since "submit" is really a verb, and it's cringy to make it a "state" or an "object" we operate on in the DRM Scheduler. "Submission" is a noun, but "submission enqueue/start/stop/ready" doesn't sound very well thought out. "Submission" really is what the work-queue does.
Quoted 7 lines
Quoted 7 lines
I'd rather it be a real object, like for instance,
drm_sched_wqueue_enqueue()drm_sched_wqueue_start)drm_sched_wqueue_stop()drm_sched_wqueue_ready()
Quoted 8 lines
How about:
drm_sched_submission_enqueue()drm_sched_submission_start)drm_sched_submission_stop()drm_sched_submission_ready()Matt
Ignore this, read Tvrtko commnt and not Luben's fully.
I prefer drm_sched_wqueue over drm_sched_submit_queue as submit queue is a made of thing. drm_sched_submission would be my top choice but if Luben is opposed will go with drm_sched_wqueue in next rev.
Matt
Quoted 18 lines
Quoted 18 lines
Quoted 7 lines
Which tells me that the component is the DRM Scheduler, the object is a/the work-queue, and the last word as the verb, is the action we're performing on the object, i.e. the work-queue. Plus, all these functions actually do operate on work-queues, directly or indirectly, are new, so it's a win-win naming scheme.
I think that that would be most likeable.
FWIW I was suggesting not to encode the fact submit queue is implemented with a workqueue in the API name. IMO it would be nicer and less maintenance churn should something channge if the external components can be isolated from that detail.
drm_sched_submit_queue_$verb? If not viewed as too verbose...
Regards,
Tvrtko
Re: [Intel-xe] [PATCH v4 02/10] drm/sched: Convert drm scheduler to use a work queue rather than kthread
Quoted 216 lines · Matthew Brost
Quoted 215 lines · Matthew Brost
Quoted 199 lines · Tvrtko Ursulin
Quoted 197 lines · Luben Tuikov
Quoted 167 lines · Matthew Brost
Quoted 88 lines · Luben Tuikov
Hi,
Quoted 85 lines · Matthew Brost
In XE, the new Intel GPU driver, a choice has made to have a 1 to 1 mapping between a
drm_gpu_scheduleranddrm_sched_entity. At first this seems a bit odd but let us explain the reasoning below.1. In XE the submission order from multiple
drm_sched_entityis not guaranteed to be the same completion even if targeting the same hardware engine. This is because in XE we have a firmware scheduler, the GuC, which allowed to reorder, timeslice, and preempt submissions. If a using shareddrm_gpu_scheduleracross multipledrm_sched_entity, the TDR falls apart as the TDR expects submission order == completion order. Using a dedicateddrm_gpu_schedulerperdrm_sched_entitysolve this problem.2. In XE submissions are done via programming a ring buffer (circular buffer), a
drm_gpu_schedulerprovides a limit on number of jobs, if the limit of number jobs is set toRING_SIZE/MAX_SIZE_PER_JOBwe get flow control on the ring for free.A problem with this design is currently a
drm_gpu_scheduleruses a kthread for submission / job cleanup. This doesn't scale if a large number ofdrm_gpu_schedulerare used. To work around the scaling issue, use a worker rather than kthread for submission / job cleanup.v2:
- (Rob Clark) Fix msm build
- Pass in run work queue
v3:
- (Boris) don't have loop in worker
v4:
- (Tvrtko) break out submit ready, stop, start helpers into own patch
v5:
- (Boris) default to ordered work queueSigned-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_sched.c | 2 +- drivers/gpu/drm/lima/lima_sched.c | 2 +- drivers/gpu/drm/msm/msm_ringbuffer.c | 2 +- drivers/gpu/drm/nouveau/nouveau_sched.c | 2 +- drivers/gpu/drm/panfrost/panfrost_job.c | 2 +- drivers/gpu/drm/scheduler/sched_main.c | 118 ++++++++++----------- drivers/gpu/drm/v3d/v3d_sched.c | 10 +- include/drm/gpu_scheduler.h | 14 ++- 9 files changed, 79 insertions(+), 75 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-1@@ -2279,7 +2279,7 @@ static int amdgpu_device_init_schedulers(struct amdgpu_device *adev)break ; } - r = drm_sched_init(&ring->sched, &amdgpu_sched_ops, + r = drm_sched_init(&ring->sched, &amdgpu_sched_ops, NULL, ring->num_hw_submission, 0, timeout, adev->reset_domain->wq, ring->sched_score, ring->name,drivers/gpu/drm/etnaviv/etnaviv_sched.c +1
-1@@ -134,7 +134,7 @@ int etnaviv_sched_init(struct etnaviv_gpu *gpu) {int ret; - ret =drm_sched_init (&gpu->sched, &etnaviv_sched_ops, + ret =drm_sched_init (&gpu->sched, &etnaviv_sched_ops,NULL , etnaviv_hw_jobs_limit, etnaviv_job_hang_limit,msecs_to_jiffies (500 ),NULL ,NULL ,dev_name (gpu->dev), gpu->dev);drivers/gpu/drm/lima/lima_sched.c +1
-1@@ -488,7 +488,7 @@ int lima_sched_pipe_init(struct lima_sched_pipe *pipe, const char *name)INIT_WORK (&pipe->recover_work, lima_sched_recover_work); -return drm_sched_init (&pipe->base, &lima_sched_ops,1 , +return drm_sched_init (&pipe->base, &lima_sched_ops,NULL ,1 , lima_job_hang_limit,msecs_to_jiffies (timeout),NULL ,NULL , name, pipe->ldev->dev);drivers/gpu/drm/msm/msm_ringbuffer.c +0
-0@@ -94,7 +94,7 @@ struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id,Quoted 9 lines
drivers/gpu/drm/msm/msm_ringbuffer.c struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id, · line 98
Quoted 6 lines
drivers/gpu/drm/msm/msm_ringbuffer.c +1
-1/* currently managing hangcheck ourselves: */ sched_timeout =MAX_SCHEDULE_TIMEOUT ; - ret =drm_sched_init (&ring->sched, &msm_sched_ops, + ret =drm_sched_init (&ring->sched, &msm_sched_ops,NULL , num_hw_submissions,0 , sched_timeout,NULL ,NULL ,to_msm_bo (ring->bo)->name, gpu->dev->dev);checkpatch.pl complains here about unmatched open parens.
Will fix and run checkpatch before posting next rev.
Quoted 38 lines
Quoted 38 lines
drivers/gpu/drm/msm/msm_ringbuffer.c +0
-0if (ret) {drivers/gpu/drm/nouveau/nouveau_sched.c +1
-1@@ -429,7 +429,7 @@ int nouveau_sched_init(struct nouveau_drm *drm)if (!drm->sched_wq)return -ENOMEM ; -return drm_sched_init (sched, &nouveau_sched_ops, +return drm_sched_init (sched, &nouveau_sched_ops,NULL ,NOUVEAU_SCHED_HW_SUBMISSIONS ,0 , job_hang_limit,NULL ,NULL ,"nouveau_sched" , drm->dev->dev); }drivers/gpu/drm/panfrost/panfrost_job.c +1
-1@@ -831,7 +831,7 @@ int panfrost_job_init(struct panfrost_device *pfdev) js->queue[j].fence_context =dma_fence_context_alloc (1 ); ret = drm_sched_init(&js->queue[j].sched, - &panfrost_sched_ops, + &panfrost_sched_ops, NULL, nentries, 0, msecs_to_jiffies(JOB_TIMEOUT_MS), pfdev->reset.wq,drivers/gpu/drm/scheduler/sched_main.c +0
-1@@ -48,7 +48,6 @@* through the jobs entity pointer. */ -#include <linux/kthread.h> #include <linux/wait.h> #include <linux/sched.h> #include <linux/completion.h> @@ -256,6 +255,16 @@ drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) return rb ? rb_entry(rb, struct drm_sched_entity, rb_tree_node) : NULL;Quoted 9 lines
drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) · line 258
Quoted 3 lines
drivers/gpu/drm/scheduler/sched_main.c +2
-0} +/** +* drm_sched_submit_queue - scheduler queue submission There is no verb in the description, and is not clear what this function does unless one reads the code. Given that this is DOC, this should be clearer here. Something like "queue scheduler work to be executed" or something to that effect.
Will fix.
Quoted 9 lines
Coming back to this from reading the patch below, it was somewhat unclear what "
drm_sched_submit_queue()" does, since when reading below, "submit" was being read by my mind as an adjective, as opposed to a verb. Perhaps something like:
drm_sched_queue_submit(), ordrm_sched_queue_exec(), ordrm_sched_queue_push(), or something to that effect. You pick. :-)I prefer the name as is. In this patch we have:
drm_sched_submit_queue()drm_sched_submit_start)drm_sched_submit_stop()drm_sched_submit_ready()Quoted 5 lines
I like all these functions start with '
drm_sched_submit' which allows for easy searching for the functions that touch the DRM scheduler submission state.With a little better doc are you fine with the names as is.
Notice the following scheme in the naming,
drm_sched_submit_queue()drm_sched_submit_start)drm_sched_submit_stop()drm_sched_submit_ready()
\---+---/ \--+-/ \-+-/| | +---> a verb | +---------> should be a noun (something in the component) +------------------> the kernel/software componentAnd although "queue" can technically be used as a verb too, I'd rather it be "enqueue", like this:
drm_sched_submit_enqueue()And using "submit" as the noun of the component is a bit cringy, since "submit" is really a verb, and it's cringy to make it a "state" or an "object" we operate on in the DRM Scheduler. "Submission" is a noun, but "submission enqueue/start/stop/ready" doesn't sound very well thought out. "Submission" really is what the work-queue does.
Quoted 7 lines
Quoted 7 lines
I'd rather it be a real object, like for instance,
drm_sched_wqueue_enqueue()drm_sched_wqueue_start)drm_sched_wqueue_stop()drm_sched_wqueue_ready()How about:
drm_sched_submission_enqueue()drm_sched_submission_start)drm_sched_submission_stop()drm_sched_submission_ready()
Quoted 7 lines
Quoted 1 line
Matt
Ignore this, read Tvrtko commnt and not Luben's fully.
I prefer
drm_sched_wqueueoverdrm_sched_submit_queueas submit queue is a made of thing.drm_sched_submissionwould be my top choice but if Luben is opposed will go withdrm_sched_wqueuein next rev.
I suppose you meant "made up"? All the verbs are also then made up so I don't really see that as an argument why implementation detail should be encoded into the API naming but your call folks.
Regards,
Tvrtko
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 6 lines
Which tells me that the component is the DRM Scheduler, the object is a/the work-queue, and the last word as the verb, is the action we're performing on the object, i.e. the work-queue. Plus, all these functions actually do operate on work-queues, directly or indirectly, are new, so it's a win-win naming scheme.
I think that that would be most likeable.
FWIW I was suggesting not to encode the fact submit queue is implemented with a workqueue in the API name. IMO it would be nicer and less maintenance churn should something channge if the external components can be isolated from that detail.
drm_sched_submit_queue_$verb? If not viewed as too verbose...
Regards,
Tvrtko
Re: [Intel-xe] [PATCH v4 02/10] drm/sched: Convert drm scheduler to use a work queue rather than kthread
In reply to Matthew BrostQuoted 192 lines · Matthew Brost
Quoted 191 lines · Matthew Brost
Quoted 190 lines · Tvrtko Ursulin
Quoted 188 lines · Luben Tuikov
Quoted 167 lines · Matthew Brost
Quoted 88 lines · Luben Tuikov
Hi,
Quoted 85 lines · Matthew Brost
In XE, the new Intel GPU driver, a choice has made to have a 1 to 1 mapping between a
drm_gpu_scheduleranddrm_sched_entity. At first this seems a bit odd but let us explain the reasoning below.1. In XE the submission order from multiple
drm_sched_entityis not guaranteed to be the same completion even if targeting the same hardware engine. This is because in XE we have a firmware scheduler, the GuC, which allowed to reorder, timeslice, and preempt submissions. If a using shareddrm_gpu_scheduleracross multipledrm_sched_entity, the TDR falls apart as the TDR expects submission order == completion order. Using a dedicateddrm_gpu_schedulerperdrm_sched_entitysolve this problem.2. In XE submissions are done via programming a ring buffer (circular buffer), a
drm_gpu_schedulerprovides a limit on number of jobs, if the limit of number jobs is set toRING_SIZE/MAX_SIZE_PER_JOBwe get flow control on the ring for free.A problem with this design is currently a
drm_gpu_scheduleruses a kthread for submission / job cleanup. This doesn't scale if a large number ofdrm_gpu_schedulerare used. To work around the scaling issue, use a worker rather than kthread for submission / job cleanup.v2:
- (Rob Clark) Fix msm build
- Pass in run work queue
v3:
- (Boris) don't have loop in worker
v4:
- (Tvrtko) break out submit ready, stop, start helpers into own patch
v5:
- (Boris) default to ordered work queueSigned-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_sched.c | 2 +- drivers/gpu/drm/lima/lima_sched.c | 2 +- drivers/gpu/drm/msm/msm_ringbuffer.c | 2 +- drivers/gpu/drm/nouveau/nouveau_sched.c | 2 +- drivers/gpu/drm/panfrost/panfrost_job.c | 2 +- drivers/gpu/drm/scheduler/sched_main.c | 118 ++++++++++----------- drivers/gpu/drm/v3d/v3d_sched.c | 10 +- include/drm/gpu_scheduler.h | 14 ++- 9 files changed, 79 insertions(+), 75 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-1@@ -2279,7 +2279,7 @@ static int amdgpu_device_init_schedulers(struct amdgpu_device *adev)break ; } - r = drm_sched_init(&ring->sched, &amdgpu_sched_ops, + r = drm_sched_init(&ring->sched, &amdgpu_sched_ops, NULL, ring->num_hw_submission, 0, timeout, adev->reset_domain->wq, ring->sched_score, ring->name,drivers/gpu/drm/etnaviv/etnaviv_sched.c +1
-1@@ -134,7 +134,7 @@ int etnaviv_sched_init(struct etnaviv_gpu *gpu) {int ret; - ret =drm_sched_init (&gpu->sched, &etnaviv_sched_ops, + ret =drm_sched_init (&gpu->sched, &etnaviv_sched_ops,NULL , etnaviv_hw_jobs_limit, etnaviv_job_hang_limit,msecs_to_jiffies (500 ),NULL ,NULL ,dev_name (gpu->dev), gpu->dev);drivers/gpu/drm/lima/lima_sched.c +1
-1@@ -488,7 +488,7 @@ int lima_sched_pipe_init(struct lima_sched_pipe *pipe, const char *name)INIT_WORK (&pipe->recover_work, lima_sched_recover_work); -return drm_sched_init (&pipe->base, &lima_sched_ops,1 , +return drm_sched_init (&pipe->base, &lima_sched_ops,NULL ,1 , lima_job_hang_limit,msecs_to_jiffies (timeout),NULL ,NULL , name, pipe->ldev->dev);drivers/gpu/drm/msm/msm_ringbuffer.c +0
-0@@ -94,7 +94,7 @@ struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id,Quoted 9 lines
drivers/gpu/drm/msm/msm_ringbuffer.c struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id, · line 98
Quoted 6 lines
drivers/gpu/drm/msm/msm_ringbuffer.c +1
-1/* currently managing hangcheck ourselves: */ sched_timeout =MAX_SCHEDULE_TIMEOUT ; - ret =drm_sched_init (&ring->sched, &msm_sched_ops, + ret =drm_sched_init (&ring->sched, &msm_sched_ops,NULL , num_hw_submissions,0 , sched_timeout,NULL ,NULL ,to_msm_bo (ring->bo)->name, gpu->dev->dev);checkpatch.pl complains here about unmatched open parens.
Will fix and run checkpatch before posting next rev.
Quoted 38 lines
Quoted 38 lines
drivers/gpu/drm/msm/msm_ringbuffer.c +0
-0if (ret) {drivers/gpu/drm/nouveau/nouveau_sched.c +1
-1@@ -429,7 +429,7 @@ int nouveau_sched_init(struct nouveau_drm *drm)if (!drm->sched_wq)return -ENOMEM ; -return drm_sched_init (sched, &nouveau_sched_ops, +return drm_sched_init (sched, &nouveau_sched_ops,NULL ,NOUVEAU_SCHED_HW_SUBMISSIONS ,0 , job_hang_limit,NULL ,NULL ,"nouveau_sched" , drm->dev->dev); }drivers/gpu/drm/panfrost/panfrost_job.c +1
-1@@ -831,7 +831,7 @@ int panfrost_job_init(struct panfrost_device *pfdev) js->queue[j].fence_context =dma_fence_context_alloc (1 ); ret = drm_sched_init(&js->queue[j].sched, - &panfrost_sched_ops, + &panfrost_sched_ops, NULL, nentries, 0, msecs_to_jiffies(JOB_TIMEOUT_MS), pfdev->reset.wq,drivers/gpu/drm/scheduler/sched_main.c +0
-1@@ -48,7 +48,6 @@* through the jobs entity pointer. */ -#include <linux/kthread.h> #include <linux/wait.h> #include <linux/sched.h> #include <linux/completion.h> @@ -256,6 +255,16 @@ drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) return rb ? rb_entry(rb, struct drm_sched_entity, rb_tree_node) : NULL;Quoted 9 lines
drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) · line 258
Quoted 3 lines
drivers/gpu/drm/scheduler/sched_main.c +2
-0} +/** +* drm_sched_submit_queue - scheduler queue submission There is no verb in the description, and is not clear what this function does unless one reads the code. Given that this is DOC, this should be clearer here. Something like "queue scheduler work to be executed" or something to that effect.
Will fix.
Quoted 9 lines
Coming back to this from reading the patch below, it was somewhat unclear what "
drm_sched_submit_queue()" does, since when reading below, "submit" was being read by my mind as an adjective, as opposed to a verb. Perhaps something like:
drm_sched_queue_submit(), ordrm_sched_queue_exec(), ordrm_sched_queue_push(), or something to that effect. You pick. :-)I prefer the name as is. In this patch we have:
drm_sched_submit_queue()drm_sched_submit_start)drm_sched_submit_stop()drm_sched_submit_ready()Quoted 5 lines
I like all these functions start with '
drm_sched_submit' which allows for easy searching for the functions that touch the DRM scheduler submission state.With a little better doc are you fine with the names as is.
Notice the following scheme in the naming,
drm_sched_submit_queue()drm_sched_submit_start)drm_sched_submit_stop()drm_sched_submit_ready()
\---+---/ \--+-/ \-+-/| | +---> a verb | +---------> should be a noun (something in the component) +------------------> the kernel/software componentAnd although "queue" can technically be used as a verb too, I'd rather it be "enqueue", like this:
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drm_sched_submit_enqueue()And using "submit" as the noun of the component is a bit cringy, since "submit" is really a verb, and it's cringy to make it a "state" or an "object" we operate on in the DRM Scheduler. "Submission" is a noun, but "submission enqueue/start/stop/ready" doesn't sound very well thought out. "Submission" really is what the work-queue does.
^^^^^^^^^^^^^^^^^^^ Here ^^^^^^^^^^^^^^^^^^^^^^^^^^
Quoted 16 lines
Quoted 16 lines
Quoted 8 lines
Quoted 8 lines
I'd rather it be a real object, like for instance,
drm_sched_wqueue_enqueue()drm_sched_wqueue_start)drm_sched_wqueue_stop()drm_sched_wqueue_ready()How about:
drm_sched_submission_enqueue()drm_sched_submission_start)drm_sched_submission_stop()drm_sched_submission_ready()
Quoted 7 lines
Quoted 1 line
Matt
Ignore this, read Tvrtko commnt and not Luben's fully.
I prefer
drm_sched_wqueueoverdrm_sched_submit_queueas submit queue is a made of thing.drm_sched_submissionwould be my top choice but if Luben is opposed will go withdrm_sched_wqueuein next rev.
You had me at "opposed."
I think I've explained why up there.
drm_sched_wqueue_[verb]() is clear and clean. We don't need yet another abstraction, to the abstraction, to the naming.
If we ever implement anything different than work-queue in the future, we may split the code and decide to keep both, maybe depending on what a driver would like to use, etc., so it's cleanest to convey what it means.
"drm_sched_submission_[verb]()" is really cringy.
Plus, it's a good reminder to know that's it's a work-queue. Keeps driver writers informed. There is no reason to obfuscate the code.
Signature · 2 lines
Regards, Luben
Re: [PATCH v4 02/10] drm/sched: Convert drm scheduler to use a work queue rather than kthread
In reply to Matthew BrostQuoted 208 lines · Matthew Brost
Quoted 199 lines · Tvrtko Ursulin
Quoted 197 lines · Luben Tuikov
Quoted 167 lines · Matthew Brost
Quoted 88 lines · Luben Tuikov
Hi,
Quoted 85 lines · Matthew Brost
In XE, the new Intel GPU driver, a choice has made to have a 1 to 1 mapping between a
drm_gpu_scheduleranddrm_sched_entity. At first this seems a bit odd but let us explain the reasoning below.1. In XE the submission order from multiple
drm_sched_entityis not guaranteed to be the same completion even if targeting the same hardware engine. This is because in XE we have a firmware scheduler, the GuC, which allowed to reorder, timeslice, and preempt submissions. If a using shareddrm_gpu_scheduleracross multipledrm_sched_entity, the TDR falls apart as the TDR expects submission order == completion order. Using a dedicateddrm_gpu_schedulerperdrm_sched_entitysolve this problem.2. In XE submissions are done via programming a ring buffer (circular buffer), a
drm_gpu_schedulerprovides a limit on number of jobs, if the limit of number jobs is set toRING_SIZE/MAX_SIZE_PER_JOBwe get flow control on the ring for free.A problem with this design is currently a
drm_gpu_scheduleruses a kthread for submission / job cleanup. This doesn't scale if a large number ofdrm_gpu_schedulerare used. To work around the scaling issue, use a worker rather than kthread for submission / job cleanup.v2:
- (Rob Clark) Fix msm build
- Pass in run work queue
v3:
- (Boris) don't have loop in worker
v4:
- (Tvrtko) break out submit ready, stop, start helpers into own patch
v5:
- (Boris) default to ordered work queueSigned-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_sched.c | 2 +- drivers/gpu/drm/lima/lima_sched.c | 2 +- drivers/gpu/drm/msm/msm_ringbuffer.c | 2 +- drivers/gpu/drm/nouveau/nouveau_sched.c | 2 +- drivers/gpu/drm/panfrost/panfrost_job.c | 2 +- drivers/gpu/drm/scheduler/sched_main.c | 118 ++++++++++----------- drivers/gpu/drm/v3d/v3d_sched.c | 10 +- include/drm/gpu_scheduler.h | 14 ++- 9 files changed, 79 insertions(+), 75 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-1@@ -2279,7 +2279,7 @@ static int amdgpu_device_init_schedulers(struct amdgpu_device *adev)break ; } - r = drm_sched_init(&ring->sched, &amdgpu_sched_ops, + r = drm_sched_init(&ring->sched, &amdgpu_sched_ops, NULL, ring->num_hw_submission, 0, timeout, adev->reset_domain->wq, ring->sched_score, ring->name,drivers/gpu/drm/etnaviv/etnaviv_sched.c +1
-1@@ -134,7 +134,7 @@ int etnaviv_sched_init(struct etnaviv_gpu *gpu) {int ret; - ret =drm_sched_init (&gpu->sched, &etnaviv_sched_ops, + ret =drm_sched_init (&gpu->sched, &etnaviv_sched_ops,NULL , etnaviv_hw_jobs_limit, etnaviv_job_hang_limit,msecs_to_jiffies (500 ),NULL ,NULL ,dev_name (gpu->dev), gpu->dev);drivers/gpu/drm/lima/lima_sched.c +1
-1@@ -488,7 +488,7 @@ int lima_sched_pipe_init(struct lima_sched_pipe *pipe, const char *name)INIT_WORK (&pipe->recover_work, lima_sched_recover_work); -return drm_sched_init (&pipe->base, &lima_sched_ops,1 , +return drm_sched_init (&pipe->base, &lima_sched_ops,NULL ,1 , lima_job_hang_limit,msecs_to_jiffies (timeout),NULL ,NULL , name, pipe->ldev->dev);drivers/gpu/drm/msm/msm_ringbuffer.c +0
-0@@ -94,7 +94,7 @@ struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id,Quoted 9 lines
drivers/gpu/drm/msm/msm_ringbuffer.c struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id, · line 99
Quoted 6 lines
drivers/gpu/drm/msm/msm_ringbuffer.c +1
-1/* currently managing hangcheck ourselves: */ sched_timeout =MAX_SCHEDULE_TIMEOUT ; - ret =drm_sched_init (&ring->sched, &msm_sched_ops, + ret =drm_sched_init (&ring->sched, &msm_sched_ops,NULL , num_hw_submissions,0 , sched_timeout,NULL ,NULL ,to_msm_bo (ring->bo)->name, gpu->dev->dev);checkpatch.pl complains here about unmatched open parens.
Will fix and run checkpatch before posting next rev.
Quoted 38 lines
Quoted 38 lines
drivers/gpu/drm/msm/msm_ringbuffer.c +0
-0if (ret) {drivers/gpu/drm/nouveau/nouveau_sched.c +1
-1@@ -429,7 +429,7 @@ int nouveau_sched_init(struct nouveau_drm *drm)if (!drm->sched_wq)return -ENOMEM ; -return drm_sched_init (sched, &nouveau_sched_ops, +return drm_sched_init (sched, &nouveau_sched_ops,NULL ,NOUVEAU_SCHED_HW_SUBMISSIONS ,0 , job_hang_limit,NULL ,NULL ,"nouveau_sched" , drm->dev->dev); }drivers/gpu/drm/panfrost/panfrost_job.c +1
-1@@ -831,7 +831,7 @@ int panfrost_job_init(struct panfrost_device *pfdev) js->queue[j].fence_context =dma_fence_context_alloc (1 ); ret = drm_sched_init(&js->queue[j].sched, - &panfrost_sched_ops, + &panfrost_sched_ops, NULL, nentries, 0, msecs_to_jiffies(JOB_TIMEOUT_MS), pfdev->reset.wq,drivers/gpu/drm/scheduler/sched_main.c +0
-1@@ -48,7 +48,6 @@* through the jobs entity pointer. */ -#include <linux/kthread.h> #include <linux/wait.h> #include <linux/sched.h> #include <linux/completion.h> @@ -256,6 +255,16 @@ drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) return rb ? rb_entry(rb, struct drm_sched_entity, rb_tree_node) : NULL;Quoted 9 lines
drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) · line 259
Quoted 3 lines
drivers/gpu/drm/scheduler/sched_main.c +2
-0} +/** +* drm_sched_submit_queue - scheduler queue submission There is no verb in the description, and is not clear what this function does unless one reads the code. Given that this is DOC, this should be clearer here. Something like "queue scheduler work to be executed" or something to that effect.
Will fix.
Quoted 9 lines
Coming back to this from reading the patch below, it was somewhat unclear what "
drm_sched_submit_queue()" does, since when reading below, "submit" was being read by my mind as an adjective, as opposed to a verb. Perhaps something like:
drm_sched_queue_submit(), ordrm_sched_queue_exec(), ordrm_sched_queue_push(), or something to that effect. You pick. :-)I prefer the name as is. In this patch we have:
drm_sched_submit_queue()drm_sched_submit_start)drm_sched_submit_stop()drm_sched_submit_ready()Quoted 5 lines
I like all these functions start with '
drm_sched_submit' which allows for easy searching for the functions that touch the DRM scheduler submission state.With a little better doc are you fine with the names as is.
Notice the following scheme in the naming,
drm_sched_submit_queue()drm_sched_submit_start)drm_sched_submit_stop()drm_sched_submit_ready()
\---+---/ \--+-/ \-+-/| | +---> a verb | +---------> should be a noun (something in the component) +------------------> the kernel/software componentAnd although "queue" can technically be used as a verb too, I'd rather it be "enqueue", like this:
drm_sched_submit_enqueue()And using "submit" as the noun of the component is a bit cringy, since "submit" is really a verb, and it's cringy to make it a "state" or an "object" we operate on in the DRM Scheduler. "Submission" is a noun, but "submission enqueue/start/stop/ready" doesn't sound very well thought out. "Submission" really is what the work-queue does.
Quoted 7 lines
Quoted 7 lines
I'd rather it be a real object, like for instance,
drm_sched_wqueue_enqueue()drm_sched_wqueue_start)drm_sched_wqueue_stop()drm_sched_wqueue_ready()
Quoted 6 lines
How about:
drm_sched_submission_enqueue()drm_sched_submission_start)drm_sched_submission_stop()drm_sched_submission_ready()
No.
Signature · 2 lines
Regards, Luben
Re: [PATCH v4 02/10] drm/sched: Convert drm scheduler to use a work queue rather than kthread
In reply to Tvrtko UrsulinQuoted 216 lines · Tvrtko Ursulin
Quoted 214 lines · Luben Tuikov
Quoted 177 lines · Matthew Brost
Quoted 95 lines · Luben Tuikov
Hi,
Quoted 92 lines · Matthew Brost
In XE, the new Intel GPU driver, a choice has made to have a 1 to 1 mapping between a
drm_gpu_scheduleranddrm_sched_entity. At first this seems a bit odd but let us explain the reasoning below.1. In XE the submission order from multiple
drm_sched_entityis not guaranteed to be the same completion even if targeting the same hardware engine. This is because in XE we have a firmware scheduler, the GuC, which allowed to reorder, timeslice, and preempt submissions. If a using shareddrm_gpu_scheduleracross multipledrm_sched_entity, the TDR falls apart as the TDR expects submission order == completion order. Using a dedicateddrm_gpu_schedulerperdrm_sched_entitysolve this problem.2. In XE submissions are done via programming a ring buffer (circular buffer), a
drm_gpu_schedulerprovides a limit on number of jobs, if the limit of number jobs is set toRING_SIZE/MAX_SIZE_PER_JOBwe get flow control on the ring for free.A problem with this design is currently a
drm_gpu_scheduleruses a kthread for submission / job cleanup. This doesn't scale if a large number ofdrm_gpu_schedulerare used. To work around the scaling issue, use a worker rather than kthread for submission / job cleanup.v2:
- (Rob Clark) Fix msm build
- Pass in run work queue
v3:
- (Boris) don't have loop in worker
v4:
- (Tvrtko) break out submit ready, stop, start helpers into own patch
v5:
- (Boris) default to ordered work queueSigned-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_sched.c | 2 +- drivers/gpu/drm/lima/lima_sched.c | 2 +- drivers/gpu/drm/msm/msm_ringbuffer.c | 2 +- drivers/gpu/drm/nouveau/nouveau_sched.c | 2 +- drivers/gpu/drm/panfrost/panfrost_job.c | 2 +- drivers/gpu/drm/scheduler/sched_main.c | 118 ++++++++++----------- drivers/gpu/drm/v3d/v3d_sched.c | 10 +- include/drm/gpu_scheduler.h | 14 ++- 9 files changed, 79 insertions(+), 75 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-1@@ -2279,7 +2279,7 @@ static int amdgpu_device_init_schedulers(struct amdgpu_device *adev)break ; } - r = drm_sched_init(&ring->sched, &amdgpu_sched_ops, + r = drm_sched_init(&ring->sched, &amdgpu_sched_ops, NULL, ring->num_hw_submission, 0, timeout, adev->reset_domain->wq, ring->sched_score, ring->name,drivers/gpu/drm/etnaviv/etnaviv_sched.c +1
-1@@ -134,7 +134,7 @@ int etnaviv_sched_init(struct etnaviv_gpu *gpu) {int ret; - ret =drm_sched_init (&gpu->sched, &etnaviv_sched_ops, + ret =drm_sched_init (&gpu->sched, &etnaviv_sched_ops,NULL , etnaviv_hw_jobs_limit, etnaviv_job_hang_limit,msecs_to_jiffies (500 ),NULL ,NULL ,dev_name (gpu->dev), gpu->dev);drivers/gpu/drm/lima/lima_sched.c +1
-1@@ -488,7 +488,7 @@ int lima_sched_pipe_init(struct lima_sched_pipe *pipe, const char *name)INIT_WORK (&pipe->recover_work, lima_sched_recover_work); -return drm_sched_init (&pipe->base, &lima_sched_ops,1 , +return drm_sched_init (&pipe->base, &lima_sched_ops,NULL ,1 , lima_job_hang_limit,msecs_to_jiffies (timeout),NULL ,NULL , name, pipe->ldev->dev);drivers/gpu/drm/msm/msm_ringbuffer.c +0
-0@@ -94,7 +94,7 @@ struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id,/* currently managing hangcheck ourselves: */ sched_timeout =MAX_SCHEDULE_TIMEOUT ;Quoted 7 lines
drivers/gpu/drm/msm/msm_ringbuffer.c struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id, · line 99
Quoted 4 lines
drivers/gpu/drm/msm/msm_ringbuffer.c +1
-1- ret =drm_sched_init (&ring->sched, &msm_sched_ops, + ret =drm_sched_init (&ring->sched, &msm_sched_ops,NULL , num_hw_submissions,0 , sched_timeout,NULL ,NULL ,to_msm_bo (ring->bo)->name, gpu->dev->dev);checkpatch.pl complains here about unmatched open parens.
Will fix and run checkpatch before posting next rev.
Quoted 43 lines
Quoted 43 lines
drivers/gpu/drm/msm/msm_ringbuffer.c +0
-0if (ret) {drivers/gpu/drm/nouveau/nouveau_sched.c +1
-1@@ -429,7 +429,7 @@ int nouveau_sched_init(struct nouveau_drm *drm)if (!drm->sched_wq)return -ENOMEM ; -return drm_sched_init (sched, &nouveau_sched_ops, +return drm_sched_init (sched, &nouveau_sched_ops,NULL ,NOUVEAU_SCHED_HW_SUBMISSIONS ,0 , job_hang_limit,NULL ,NULL ,"nouveau_sched" , drm->dev->dev); }drivers/gpu/drm/panfrost/panfrost_job.c +1
-1@@ -831,7 +831,7 @@ int panfrost_job_init(struct panfrost_device *pfdev) js->queue[j].fence_context =dma_fence_context_alloc (1 ); ret = drm_sched_init(&js->queue[j].sched, - &panfrost_sched_ops, + &panfrost_sched_ops, NULL, nentries, 0, msecs_to_jiffies(JOB_TIMEOUT_MS), pfdev->reset.wq,drivers/gpu/drm/scheduler/sched_main.c +0
-1@@ -48,7 +48,6 @@* through the jobs entity pointer. */ -#include <linux/kthread.h> #include <linux/wait.h> #include <linux/sched.h> #include <linux/completion.h> @@ -256,6 +255,16 @@ drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) return rb ? rb_entry(rb, struct drm_sched_entity, rb_tree_node) : NULL; }Quoted 8 lines
drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) · line 259
Quoted 2 lines
drivers/gpu/drm/scheduler/sched_main.c +2
-0+/** +* drm_sched_submit_queue - scheduler queue submission There is no verb in the description, and is not clear what this function does unless one reads the code. Given that this is DOC, this should be clearer here. Something like "queue scheduler work to be executed" or something to that effect.
Will fix.
Quoted 9 lines
Coming back to this from reading the patch below, it was somewhat unclear what "
drm_sched_submit_queue()" does, since when reading below, "submit" was being read by my mind as an adjective, as opposed to a verb. Perhaps something like:
drm_sched_queue_submit(), ordrm_sched_queue_exec(), ordrm_sched_queue_push(), or something to that effect. You pick. :-)I prefer the name as is. In this patch we have:
drm_sched_submit_queue()drm_sched_submit_start)drm_sched_submit_stop()drm_sched_submit_ready()Quoted 5 lines
I like all these functions start with '
drm_sched_submit' which allows for easy searching for the functions that touch the DRM scheduler submission state.With a little better doc are you fine with the names as is.
Notice the following scheme in the naming,
drm_sched_submit_queue()drm_sched_submit_start)drm_sched_submit_stop()drm_sched_submit_ready()
\---+---/ \--+-/ \-+-/| | +---> a verb | +---------> should be a noun (something in the component) +------------------> the kernel/software componentAnd although "queue" can technically be used as a verb too, I'd rather it be "enqueue", like this:
drm_sched_submit_enqueue()And using "submit" as the noun of the component is a bit cringy, since "submit" is really a verb, and it's cringy to make it a "state" or an "object" we operate on in the DRM Scheduler. "Submission" is a noun, but "submission enqueue/start/stop/ready" doesn't sound very well thought out. "Submission" really is what the work-queue does.
I'd rather it be a real object, like for instance,
drm_sched_wqueue_enqueue()drm_sched_wqueue_start)drm_sched_wqueue_stop()drm_sched_wqueue_ready()
Quoted 8 lines
Quoted 6 lines
Which tells me that the component is the DRM Scheduler, the object is a/the work-queue, and the last word as the verb, is the action we're performing on the object, i.e. the work-queue. Plus, all these functions actually do operate on work-queues, directly or indirectly, are new, so it's a win-win naming scheme.
I think that that would be most likeable.
FWIW I was suggesting not to encode the fact submit queue is implemented
No. Overengineering.
Quoted 5 lines
with a workqueue in the API name. IMO it would be nicer and less maintenance churn should something channge if the external components can be isolated from that detail.
drm_sched_submit_queue_$verb? If not viewed as too verbose...
No.
That sounds like an unnecessary overengineering: "what if". No.
Signature · 2 lines
Regards, Luben
Matthew Brost
maintainerPATCH v4 3/10 drm/sched: Move schedule policy to scheduler
In reply to Matthew BrostRather than a global modparam for scheduling policy, move the scheduling policy to scheduler so user can control each scheduler policy.
v2:
- s/DRM_SCHED_POLICY_MAX/DRM_SCHED_POLICY_COUNT (Luben)
- Only include policy in scheduler (Luben)
v3:
- use a ternary operator as opposed to an if-control (Luben)
- s/DRM_SCHED_POLICY_DEFAULT/DRM_SCHED_POLICY_UNSET/ (Luben)
- s/default_drm_sched_policy/drm_sched_policy_default/ (Luben)
- Update commit message (Boris)
- Fix v3d build (CI)
- s/bad_policies/drm_sched_policy_mismatch/ (Luben)
- Don't update modparam doc (Luben)
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 1 + drivers/gpu/drm/etnaviv/etnaviv_sched.c | 3 ++- drivers/gpu/drm/lima/lima_sched.c | 3 ++- drivers/gpu/drm/msm/msm_ringbuffer.c | 3 ++- drivers/gpu/drm/nouveau/nouveau_sched.c | 3 ++- drivers/gpu/drm/panfrost/panfrost_job.c | 3 ++- drivers/gpu/drm/scheduler/sched_entity.c | 24 ++++++++++++++++++---- drivers/gpu/drm/scheduler/sched_main.c | 19 ++++++++++++----- drivers/gpu/drm/v3d/v3d_sched.c | 15 +++++++++----- include/drm/gpu_scheduler.h | 20 ++++++++++++------ 10 files changed, 69 insertions(+), 25 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -0
@@ -2283,6 +2283,7 @@ static int amdgpu_device_init_schedulers(struct amdgpu_device *adev) ring->num_hw_submission,0 , timeout, adev->reset_domain->wq, ring->sched_score, ring->name, +DRM_SCHED_POLICY_UNSET , adev->dev);if (r) { DRM_ERROR("Failed to create scheduler on ring %s.\n",
drivers/gpu/drm/etnaviv/etnaviv_sched.c +2 -1
@@ -137,7 +137,8 @@ int etnaviv_sched_init(struct etnaviv_gpu *gpu) ret =drm_sched_init (&gpu->sched, &etnaviv_sched_ops,NULL , etnaviv_hw_jobs_limit, etnaviv_job_hang_limit,msecs_to_jiffies (500 ),NULL ,NULL , -dev_name (gpu->dev), gpu->dev); +dev_name (gpu->dev),DRM_SCHED_POLICY_UNSET , + gpu->dev);if (ret)return ret;
drivers/gpu/drm/lima/lima_sched.c +2 -1
@@ -491,7 +491,8 @@ int lima_sched_pipe_init(struct lima_sched_pipe *pipe, const char *name)return drm_sched_init (&pipe->base, &lima_sched_ops,NULL ,1 , lima_job_hang_limit,msecs_to_jiffies (timeout),NULL , -NULL , name, pipe->ldev->dev); +NULL , name,DRM_SCHED_POLICY_UNSET , + pipe->ldev->dev); }void lima_sched_pipe_fini (struct lima_sched_pipe *pipe)
drivers/gpu/drm/msm/msm_ringbuffer.c +2 -1
@@ -96,7 +96,8 @@ struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id, ret =drm_sched_init (&ring->sched, &msm_sched_ops,NULL , num_hw_submissions,0 , sched_timeout, -NULL ,NULL ,to_msm_bo (ring->bo)->name, gpu->dev->dev); +NULL ,NULL ,to_msm_bo (ring->bo)->name, +DRM_SCHED_POLICY_UNSET , gpu->dev->dev);if (ret) { goto fail; }
drivers/gpu/drm/nouveau/nouveau_sched.c +2 -1
@@ -431,7 +431,8 @@ int nouveau_sched_init(struct nouveau_drm *drm)return drm_sched_init (sched, &nouveau_sched_ops,NULL ,NOUVEAU_SCHED_HW_SUBMISSIONS ,0 , job_hang_limit, -NULL ,NULL ,"nouveau_sched" , drm->dev->dev); +NULL ,NULL ,"nouveau_sched" , +DRM_SCHED_POLICY_UNSET , drm->dev->dev); }void nouveau_sched_fini (struct nouveau_drm *drm)
drivers/gpu/drm/panfrost/panfrost_job.c +2 -1
@@ -835,7 +835,8 @@ int panfrost_job_init(struct panfrost_device *pfdev) nentries,0 ,msecs_to_jiffies (JOB_TIMEOUT_MS ), pfdev->reset.wq, - NULL, "pan_js", pfdev->dev); +NULL ,"pan_js" ,DRM_SCHED_POLICY_UNSET , + pfdev->dev);if (ret) {dev_err (pfdev->dev,"Failed to create scheduler: %d." , ret); goto err_sched;
drivers/gpu/drm/scheduler/sched_entity.c +20 -4
@@ -33,6 +33,20 @@#define to_drm_sched_job (sched_job) \ container_of((sched_job), struct drm_sched_job, queue_node) +static bool drm_sched_policy_mismatch (struct drm_gpu_scheduler **sched_list, +unsigned int num_sched_list) +{ +enum drm_sched_policy sched_policy = sched_list[0 ]->sched_policy; +unsigned int i; + +/* All schedule policies must match */ +for (i =1 ; i < num_sched_list; ++i) +if (sched_policy != sched_list[i]->sched_policy) +return true; + +return false; +} +/** * drm_sched_entity_init - Init a context entity used by scheduler when * submit to HW ring.
@@ -62,7 +76,8 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, unsigned int num_sched_list, atomic_t *guilty) { -if (!(entity && sched_list && (num_sched_list ==0 || sched_list[0 ]))) +if (!(entity && sched_list && (num_sched_list ==0 || sched_list[0 ])) || +drm_sched_policy_mismatch (sched_list, num_sched_list))return -EINVAL ;memset (entity,0 ,sizeof (struct drm_sched_entity ));
@@ -486,7 +501,7 @@ struct drm_sched_job *drm_sched_entity_pop_job(struct drm_sched_entity *entity)* Update the entity's location in the min heap according to * the timestamp of the next job, if any. */ -if (drm_sched_policy ==DRM_SCHED_POLICY_FIFO ) { +if (entity->rq->sched->sched_policy ==DRM_SCHED_POLICY_FIFO ) {struct drm_sched_job *next; next =to_drm_sched_job (spsc_queue_peek (&entity->job_queue));
@@ -558,7 +573,8 @@ void drm_sched_entity_select_rq(struct drm_sched_entity *entity)void drm_sched_entity_push_job (struct drm_sched_job *sched_job) {struct drm_sched_entity *entity = sched_job->entity; -bool first; +bool first, fifo = entity->rq->sched->sched_policy == +DRM_SCHED_POLICY_FIFO ;ktime_t submit_ts;trace_drm_sched_job (sched_job, entity);
@@ -587,7 +603,7 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)drm_sched_rq_add_entity (entity->rq, entity);spin_unlock (&entity->rq_lock); -if (drm_sched_policy ==DRM_SCHED_POLICY_FIFO ) +if (fifo)drm_sched_rq_update_fifo (entity, submit_ts);drm_sched_wakeup_if_can_queue (entity->rq->sched);
drivers/gpu/drm/scheduler/sched_main.c +14 -5
@@ -66,14 +66,14 @@#define to_drm_sched_job (sched_job) \ container_of((sched_job), struct drm_sched_job, queue_node) -int drm_sched_policy =DRM_SCHED_POLICY_FIFO ; +int drm_sched_policy_default =DRM_SCHED_POLICY_FIFO ;/** * DOC: sched_policy (int) * Used to override default entities scheduling policy in a run queue. */ MODULE_PARM_DESC(sched_policy, "Specify the scheduling policy for entities on a run-queue, " __stringify(DRM_SCHED_POLICY_RR) " = Round Robin, " __stringify(DRM_SCHED_POLICY_FIFO) " = FIFO (default)."); -module_param_named (sched_policy, drm_sched_policy, int,0444 ); +module_param_named (sched_policy, drm_sched_policy_default, int,0444 ); static __always_inline bool drm_sched_entity_compare_before(struct rb_node *a,const struct rb_node *b)
@@ -177,7 +177,7 @@ void drm_sched_rq_remove_entity(struct drm_sched_rq *rq,if (rq->current_entity == entity) rq->current_entity =NULL ; -if (drm_sched_policy ==DRM_SCHED_POLICY_FIFO ) +if (rq->sched->sched_policy ==DRM_SCHED_POLICY_FIFO )drm_sched_rq_remove_fifo_locked (entity);spin_unlock (&rq->lock);
@@ -898,7 +898,7 @@ drm_sched_select_entity(struct drm_gpu_scheduler *sched)/* Kernel run queue has higher priority than normal run queue*/ for (i =DRM_SCHED_PRIORITY_COUNT -1 ; i >=DRM_SCHED_PRIORITY_MIN ; i--) { - entity = drm_sched_policy ==DRM_SCHED_POLICY_FIFO ? + entity = sched->sched_policy ==DRM_SCHED_POLICY_FIFO ?drm_sched_rq_select_entity_fifo (&sched->sched_rq[i]) :drm_sched_rq_select_entity_rr (&sched->sched_rq[i]);if (entity)
@@ -1072,6 +1072,7 @@ static void drm_sched_main(struct work_struct *w)* used * @score: optional score atomic shared with other schedulers * @name: name used for debugging +* @sched_policy: schedule policy * @dev: target &struct device * * Return 0 on success, otherwise error code.
@@ -1081,9 +1082,15 @@ int drm_sched_init(struct drm_gpu_scheduler *sched,struct workqueue_struct *submit_wq, unsigned hw_submission, unsigned hang_limit, long timeout, struct workqueue_struct *timeout_wq, - atomic_t *score, const char *name, struct device *dev) + atomic_t *score, const char *name, + enum drm_sched_policy sched_policy, + struct device *dev) { int i; + +if (sched_policy >=DRM_SCHED_POLICY_COUNT ) +return -EINVAL ; + sched->ops = ops; sched->hw_submission_limit = hw_submission; sched->name = name;
@@ -1102,6 +1109,8 @@ int drm_sched_init(struct drm_gpu_scheduler *sched, sched->hang_limit = hang_limit; sched->score = score ? score : &sched->_score; sched->dev = dev; + sched->sched_policy = sched_policy ==DRM_SCHED_POLICY_UNSET ? + drm_sched_policy_default : sched_policy;for (i =DRM_SCHED_PRIORITY_MIN ; i <DRM_SCHED_PRIORITY_COUNT ; i++)drm_sched_rq_init (sched, &sched->sched_rq[i]);
drivers/gpu/drm/v3d/v3d_sched.c +10 -5
@@ -391,7 +391,8 @@ v3d_sched_init(struct v3d_dev *v3d) &v3d_bin_sched_ops,NULL , hw_jobs_limit, job_hang_limit,msecs_to_jiffies (hang_limit_ms),NULL , - NULL, "v3d_bin", v3d->drm.dev); +NULL ,"v3d_bin" ,DRM_SCHED_POLICY_UNSET , + v3d->drm.dev);if (ret)return ret;
@@ -399,7 +400,8 @@ v3d_sched_init(struct v3d_dev *v3d) &v3d_render_sched_ops,NULL , hw_jobs_limit, job_hang_limit,msecs_to_jiffies (hang_limit_ms),NULL , - NULL, "v3d_render", v3d->drm.dev); +NULL ,"v3d_render" ,DRM_SCHED_POLICY_UNSET , + v3d->drm.dev);if (ret) goto fail;
@@ -407,7 +409,8 @@ v3d_sched_init(struct v3d_dev *v3d) &v3d_tfu_sched_ops,NULL , hw_jobs_limit, job_hang_limit,msecs_to_jiffies (hang_limit_ms),NULL , - NULL, "v3d_tfu", v3d->drm.dev); +NULL ,"v3d_tfu" ,DRM_SCHED_POLICY_UNSET , + v3d->drm.dev);if (ret) goto fail;
@@ -416,7 +419,8 @@ v3d_sched_init(struct v3d_dev *v3d) &v3d_csd_sched_ops,NULL , hw_jobs_limit, job_hang_limit,msecs_to_jiffies (hang_limit_ms),NULL , - NULL, "v3d_csd", v3d->drm.dev); +NULL ,"v3d_csd" ,DRM_SCHED_POLICY_UNSET , + v3d->drm.dev);if (ret) goto fail;
@@ -424,7 +428,8 @@ v3d_sched_init(struct v3d_dev *v3d) &v3d_cache_clean_sched_ops,NULL , hw_jobs_limit, job_hang_limit,msecs_to_jiffies (hang_limit_ms),NULL , - NULL, "v3d_cache_clean", v3d->drm.dev); +NULL ,"v3d_cache_clean" , + DRM_SCHED_POLICY_UNSET, v3d->drm.dev);if (ret) goto fail; }
include/drm/gpu_scheduler.h +14 -6
@@ -72,11 +72,15 @@ enum drm_sched_priority { DRM_SCHED_PRIORITY_UNSET = -2 }; -/* Used to chose between FIFO and RR jobs scheduling */ -extern int drm_sched_policy; - -#define DRM_SCHED_POLICY_RR 0 -#define DRM_SCHED_POLICY_FIFO 1 +/* Used to chose default scheduling policy*/ +extern int default_drm_sched_policy; + +enum drm_sched_policy { +DRM_SCHED_POLICY_UNSET , +DRM_SCHED_POLICY_RR , +DRM_SCHED_POLICY_FIFO , +DRM_SCHED_POLICY_COUNT , +};/** * struct drm_sched_entity - A wrapper around a job queue (typically
@@ -489,6 +493,7 @@ struct drm_sched_backend_ops {* guilty and it will no longer be considered for scheduling. * @score: score to help loadbalancer pick a idle sched * @_score: score used when the driver doesn't provide one +* @sched_policy: Schedule policy for scheduler * @ready: marks if the underlying HW is ready to work * @free_guilty: A hit to time out handler to free the guilty job. * @pause_submit: pause queuing of @work_submit on @submit_wq
@@ -515,6 +520,7 @@ struct drm_gpu_scheduler {int hang_limit;atomic_t *score;atomic_t _score; +enum drm_sched_policy sched_policy;bool ready;bool free_guilty;bool pause_submit;
@@ -527,7 +533,9 @@ int drm_sched_init(struct drm_gpu_scheduler *sched,struct workqueue_struct *submit_wq, uint32_t hw_submission, unsigned hang_limit, long timeout, struct workqueue_struct *timeout_wq, - atomic_t *score, const char *name, struct device *dev); + atomic_t *score, const char *name, + enum drm_sched_policy sched_policy, + struct device *dev);void drm_sched_fini (struct drm_gpu_scheduler *sched); int drm_sched_job_init(struct drm_sched_job *job,
Signature · 1 line
2.34.1
kernel test robot
build botRe: [PATCH v4 03/10] drm/sched: Move schedule policy to scheduler
kernel test robot noticed the following build warnings:
Hi Matthew,
kernel test robot noticed the following build warnings:
[auto build test WARNING on drm/drm-next]
[also build test WARNING on drm-exynos/exynos-drm-next drm-intel/for-linux-next drm-intel/for-linux-next-fixes drm-tip/drm-tip linus/master v6.6-rc2 next-20230921] [cannot apply to drm-misc/drm-misc-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Matthew-Brost/drm-sched-Add-drm_sched_submit_-helpers/20230919-130353 base: git://anongit.freedesktop.org/drm/drm drm-next patch link: https://lore.kernel.org/r/20230919050155.2647172-4-matthew.brost%40intel.com patch subject: [PATCH v4 03/10] drm/sched: Move schedule policy to scheduler config: i386-randconfig-063-20230924 (https://download.01.org/0day-ci/archive/20230924/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230924/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
sparse warnings: (new ones prefixed by >>)
>> drivers/gpu/drm/scheduler/sched_main.c:69:5: sparse: sparse: symbol 'drm_sched_policy_default' was not declared. Should it be static?
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH v4 03/10] drm/sched: Move schedule policy to scheduler
In reply to Matthew BrostHi,
Quoted 74 lines · Matthew Brost
Rather than a global modparam for scheduling policy, move the scheduling policy to scheduler so user can control each scheduler policy.
v2:
- s/DRM_SCHED_POLICY_MAX/DRM_SCHED_POLICY_COUNT (Luben)
- Only include policy in scheduler (Luben)
v3:
- use a ternary operator as opposed to an if-control (Luben)
- s/DRM_SCHED_POLICY_DEFAULT/DRM_SCHED_POLICY_UNSET/ (Luben)
- s/default_drm_sched_policy/drm_sched_policy_default/ (Luben)
- Update commit message (Boris)
- Fix v3d build (CI)
- s/bad_policies/drm_sched_policy_mismatch/ (Luben)
- Don't update modparam doc (Luben)Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 1 + drivers/gpu/drm/etnaviv/etnaviv_sched.c | 3 ++- drivers/gpu/drm/lima/lima_sched.c | 3 ++- drivers/gpu/drm/msm/msm_ringbuffer.c | 3 ++- drivers/gpu/drm/nouveau/nouveau_sched.c | 3 ++- drivers/gpu/drm/panfrost/panfrost_job.c | 3 ++- drivers/gpu/drm/scheduler/sched_entity.c | 24 ++++++++++++++++++---- drivers/gpu/drm/scheduler/sched_main.c | 19 ++++++++++++----- drivers/gpu/drm/v3d/v3d_sched.c | 15 +++++++++----- include/drm/gpu_scheduler.h | 20 ++++++++++++------ 10 files changed, 69 insertions(+), 25 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-0@@ -2283,6 +2283,7 @@ static int amdgpu_device_init_schedulers(struct amdgpu_device *adev) ring->num_hw_submission,0 , timeout, adev->reset_domain->wq, ring->sched_score, ring->name, +DRM_SCHED_POLICY_UNSET , adev->dev);if (r) { DRM_ERROR("Failed to create scheduler on ring %s.\n",drivers/gpu/drm/etnaviv/etnaviv_sched.c +2
-1@@ -137,7 +137,8 @@ int etnaviv_sched_init(struct etnaviv_gpu *gpu) ret =drm_sched_init (&gpu->sched, &etnaviv_sched_ops,NULL , etnaviv_hw_jobs_limit, etnaviv_job_hang_limit,msecs_to_jiffies (500 ),NULL ,NULL , -dev_name (gpu->dev), gpu->dev); +dev_name (gpu->dev),DRM_SCHED_POLICY_UNSET , + gpu->dev);if (ret)return ret;drivers/gpu/drm/lima/lima_sched.c +2
-1@@ -491,7 +491,8 @@ int lima_sched_pipe_init(struct lima_sched_pipe *pipe, const char *name)return drm_sched_init (&pipe->base, &lima_sched_ops,NULL ,1 , lima_job_hang_limit,msecs_to_jiffies (timeout),NULL , -NULL , name, pipe->ldev->dev); +NULL , name,DRM_SCHED_POLICY_UNSET , + pipe->ldev->dev); }void lima_sched_pipe_fini (struct lima_sched_pipe *pipe)drivers/gpu/drm/msm/msm_ringbuffer.c +0
-0
drivers/gpu/drm/msm/msm_ringbuffer.c struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id, · line 100
Quoted 6 lines
drivers/gpu/drm/msm/msm_ringbuffer.c +2
-1@@ -96,7 +96,8 @@ struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id, ret =drm_sched_init (&ring->sched, &msm_sched_ops,NULL , num_hw_submissions,0 , sched_timeout, -NULL ,NULL ,to_msm_bo (ring->bo)->name, gpu->dev->dev); +NULL ,NULL ,to_msm_bo (ring->bo)->name, +DRM_SCHED_POLICY_UNSET , gpu->dev->dev);
Align to the open brace. This should come from the fixes to patch 2. (Please use scripts/checkpatch.pl to check patches for common fixes.) With this fix, this patch is:
Signature · 2 lines
Regards, Luben
Quoted 273 lines
drivers/gpu/drm/msm/msm_ringbuffer.c +0
-0if (ret) { goto fail; }drivers/gpu/drm/nouveau/nouveau_sched.c +2
-1@@ -431,7 +431,8 @@ int nouveau_sched_init(struct nouveau_drm *drm)return drm_sched_init (sched, &nouveau_sched_ops,NULL ,NOUVEAU_SCHED_HW_SUBMISSIONS ,0 , job_hang_limit, -NULL ,NULL ,"nouveau_sched" , drm->dev->dev); +NULL ,NULL ,"nouveau_sched" , +DRM_SCHED_POLICY_UNSET , drm->dev->dev); }void nouveau_sched_fini (struct nouveau_drm *drm)drivers/gpu/drm/panfrost/panfrost_job.c +2
-1@@ -835,7 +835,8 @@ int panfrost_job_init(struct panfrost_device *pfdev) nentries,0 ,msecs_to_jiffies (JOB_TIMEOUT_MS ), pfdev->reset.wq, - NULL, "pan_js", pfdev->dev); +NULL ,"pan_js" ,DRM_SCHED_POLICY_UNSET , + pfdev->dev);if (ret) {dev_err (pfdev->dev,"Failed to create scheduler: %d." , ret); goto err_sched;drivers/gpu/drm/scheduler/sched_entity.c +20
-4@@ -33,6 +33,20 @@#define to_drm_sched_job (sched_job) \ container_of((sched_job), struct drm_sched_job, queue_node) +static bool drm_sched_policy_mismatch (struct drm_gpu_scheduler **sched_list, +unsigned int num_sched_list) +{ +enum drm_sched_policy sched_policy = sched_list[0 ]->sched_policy; +unsigned int i; + +/* All schedule policies must match */ +for (i =1 ; i < num_sched_list; ++i) +if (sched_policy != sched_list[i]->sched_policy) +return true; + +return false; +} +/** * drm_sched_entity_init - Init a context entity used by scheduler when * submit to HW ring. @@ -62,7 +76,8 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, unsigned int num_sched_list, atomic_t *guilty) { -if (!(entity && sched_list && (num_sched_list ==0 || sched_list[0 ]))) +if (!(entity && sched_list && (num_sched_list ==0 || sched_list[0 ])) || +drm_sched_policy_mismatch (sched_list, num_sched_list))return -EINVAL ;memset (entity,0 ,sizeof (struct drm_sched_entity ));@@ -486,7 +501,7 @@ struct drm_sched_job *drm_sched_entity_pop_job(struct drm_sched_entity *entity)* Update the entity's location in the min heap according to * the timestamp of the next job, if any. */ -if (drm_sched_policy ==DRM_SCHED_POLICY_FIFO ) { +if (entity->rq->sched->sched_policy ==DRM_SCHED_POLICY_FIFO ) {struct drm_sched_job *next; next =to_drm_sched_job (spsc_queue_peek (&entity->job_queue));@@ -558,7 +573,8 @@ void drm_sched_entity_select_rq(struct drm_sched_entity *entity)void drm_sched_entity_push_job (struct drm_sched_job *sched_job) {struct drm_sched_entity *entity = sched_job->entity; -bool first; +bool first, fifo = entity->rq->sched->sched_policy == +DRM_SCHED_POLICY_FIFO ;ktime_t submit_ts;trace_drm_sched_job (sched_job, entity);@@ -587,7 +603,7 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)drm_sched_rq_add_entity (entity->rq, entity);spin_unlock (&entity->rq_lock); -if (drm_sched_policy ==DRM_SCHED_POLICY_FIFO ) +if (fifo)drm_sched_rq_update_fifo (entity, submit_ts);drm_sched_wakeup_if_can_queue (entity->rq->sched);drivers/gpu/drm/scheduler/sched_main.c +14
-5@@ -66,14 +66,14 @@#define to_drm_sched_job (sched_job) \ container_of((sched_job), struct drm_sched_job, queue_node) -int drm_sched_policy =DRM_SCHED_POLICY_FIFO ; +int drm_sched_policy_default =DRM_SCHED_POLICY_FIFO ;/** * DOC: sched_policy (int) * Used to override default entities scheduling policy in a run queue. */ MODULE_PARM_DESC(sched_policy, "Specify the scheduling policy for entities on a run-queue, " __stringify(DRM_SCHED_POLICY_RR) " = Round Robin, " __stringify(DRM_SCHED_POLICY_FIFO) " = FIFO (default)."); -module_param_named (sched_policy, drm_sched_policy, int,0444 ); +module_param_named (sched_policy, drm_sched_policy_default, int,0444 ); static __always_inline bool drm_sched_entity_compare_before(struct rb_node *a,const struct rb_node *b)@@ -177,7 +177,7 @@ void drm_sched_rq_remove_entity(struct drm_sched_rq *rq,if (rq->current_entity == entity) rq->current_entity =NULL ; -if (drm_sched_policy ==DRM_SCHED_POLICY_FIFO ) +if (rq->sched->sched_policy ==DRM_SCHED_POLICY_FIFO )drm_sched_rq_remove_fifo_locked (entity);spin_unlock (&rq->lock);@@ -898,7 +898,7 @@ drm_sched_select_entity(struct drm_gpu_scheduler *sched)/* Kernel run queue has higher priority than normal run queue*/ for (i =DRM_SCHED_PRIORITY_COUNT -1 ; i >=DRM_SCHED_PRIORITY_MIN ; i--) { - entity = drm_sched_policy ==DRM_SCHED_POLICY_FIFO ? + entity = sched->sched_policy ==DRM_SCHED_POLICY_FIFO ?drm_sched_rq_select_entity_fifo (&sched->sched_rq[i]) :drm_sched_rq_select_entity_rr (&sched->sched_rq[i]);if (entity)@@ -1072,6 +1072,7 @@ static void drm_sched_main(struct work_struct *w)* used * @score: optional score atomic shared with other schedulers * @name: name used for debugging +* @sched_policy: schedule policy * @dev: target &struct device * * Return 0 on success, otherwise error code. @@ -1081,9 +1082,15 @@ int drm_sched_init(struct drm_gpu_scheduler *sched,struct workqueue_struct *submit_wq, unsigned hw_submission, unsigned hang_limit, long timeout, struct workqueue_struct *timeout_wq, - atomic_t *score, const char *name, struct device *dev) + atomic_t *score, const char *name, + enum drm_sched_policy sched_policy, + struct device *dev) { int i; + +if (sched_policy >=DRM_SCHED_POLICY_COUNT ) +return -EINVAL ; + sched->ops = ops; sched->hw_submission_limit = hw_submission; sched->name = name;@@ -1102,6 +1109,8 @@ int drm_sched_init(struct drm_gpu_scheduler *sched, sched->hang_limit = hang_limit; sched->score = score ? score : &sched->_score; sched->dev = dev; + sched->sched_policy = sched_policy ==DRM_SCHED_POLICY_UNSET ? + drm_sched_policy_default : sched_policy;for (i =DRM_SCHED_PRIORITY_MIN ; i <DRM_SCHED_PRIORITY_COUNT ; i++)drm_sched_rq_init (sched, &sched->sched_rq[i]);drivers/gpu/drm/v3d/v3d_sched.c +10
-5@@ -391,7 +391,8 @@ v3d_sched_init(struct v3d_dev *v3d) &v3d_bin_sched_ops,NULL , hw_jobs_limit, job_hang_limit,msecs_to_jiffies (hang_limit_ms),NULL , - NULL, "v3d_bin", v3d->drm.dev); +NULL ,"v3d_bin" ,DRM_SCHED_POLICY_UNSET , + v3d->drm.dev);if (ret)return ret;@@ -399,7 +400,8 @@ v3d_sched_init(struct v3d_dev *v3d) &v3d_render_sched_ops,NULL , hw_jobs_limit, job_hang_limit,msecs_to_jiffies (hang_limit_ms),NULL , - NULL, "v3d_render", v3d->drm.dev); +NULL ,"v3d_render" ,DRM_SCHED_POLICY_UNSET , + v3d->drm.dev);if (ret) goto fail;@@ -407,7 +409,8 @@ v3d_sched_init(struct v3d_dev *v3d) &v3d_tfu_sched_ops,NULL , hw_jobs_limit, job_hang_limit,msecs_to_jiffies (hang_limit_ms),NULL , - NULL, "v3d_tfu", v3d->drm.dev); +NULL ,"v3d_tfu" ,DRM_SCHED_POLICY_UNSET , + v3d->drm.dev);if (ret) goto fail;@@ -416,7 +419,8 @@ v3d_sched_init(struct v3d_dev *v3d) &v3d_csd_sched_ops,NULL , hw_jobs_limit, job_hang_limit,msecs_to_jiffies (hang_limit_ms),NULL , - NULL, "v3d_csd", v3d->drm.dev); +NULL ,"v3d_csd" ,DRM_SCHED_POLICY_UNSET , + v3d->drm.dev);if (ret) goto fail;@@ -424,7 +428,8 @@ v3d_sched_init(struct v3d_dev *v3d) &v3d_cache_clean_sched_ops,NULL , hw_jobs_limit, job_hang_limit,msecs_to_jiffies (hang_limit_ms),NULL , - NULL, "v3d_cache_clean", v3d->drm.dev); +NULL ,"v3d_cache_clean" , + DRM_SCHED_POLICY_UNSET, v3d->drm.dev);if (ret) goto fail; }include/drm/gpu_scheduler.h +14
-6@@ -72,11 +72,15 @@ enum drm_sched_priority { DRM_SCHED_PRIORITY_UNSET = -2 }; -/* Used to chose between FIFO and RR jobs scheduling */ -extern int drm_sched_policy; - -#define DRM_SCHED_POLICY_RR 0 -#define DRM_SCHED_POLICY_FIFO 1 +/* Used to chose default scheduling policy*/ +extern int default_drm_sched_policy; + +enum drm_sched_policy { +DRM_SCHED_POLICY_UNSET , +DRM_SCHED_POLICY_RR , +DRM_SCHED_POLICY_FIFO , +DRM_SCHED_POLICY_COUNT , +};/** * struct drm_sched_entity - A wrapper around a job queue (typically @@ -489,6 +493,7 @@ struct drm_sched_backend_ops {* guilty and it will no longer be considered for scheduling. * @score: score to help loadbalancer pick a idle sched * @_score: score used when the driver doesn't provide one +* @sched_policy: Schedule policy for scheduler * @ready: marks if the underlying HW is ready to work * @free_guilty: A hit to time out handler to free the guilty job. * @pause_submit: pause queuing of @work_submit on @submit_wq @@ -515,6 +520,7 @@ struct drm_gpu_scheduler {int hang_limit;atomic_t *score;atomic_t _score; +enum drm_sched_policy sched_policy;bool ready;bool free_guilty;bool pause_submit;@@ -527,7 +533,9 @@ int drm_sched_init(struct drm_gpu_scheduler *sched,struct workqueue_struct *submit_wq, uint32_t hw_submission, unsigned hang_limit, long timeout, struct workqueue_struct *timeout_wq, - atomic_t *score, const char *name, struct device *dev); + atomic_t *score, const char *name, + enum drm_sched_policy sched_policy, + struct device *dev);void drm_sched_fini (struct drm_gpu_scheduler *sched); int drm_sched_job_init(struct drm_sched_job *job,
Matthew Brost
maintainerPATCH v4 4/10 drm/sched: Add DRM_SCHED_POLICY_SINGLE_ENTITY scheduling policy
In reply to Matthew BrostDRM_SCHED_POLICY_SINGLE_ENTITY creates a 1 to 1 relationship between scheduler and entity. No priorities or run queue used in this mode. Intended for devices with firmware schedulers.
v2:
- Drop sched / rq union (Luben)
v3:
- Don't pick entity if stopped in drm_sched_select_entity (Danilo)
--- drivers/gpu/drm/scheduler/sched_entity.c | 69 ++++++++++++++++++------ drivers/gpu/drm/scheduler/sched_fence.c | 2 +- drivers/gpu/drm/scheduler/sched_main.c | 64 +++++++++++++++++++--- include/drm/gpu_scheduler.h | 8 +++ 4 files changed, 120 insertions(+), 23 deletions(-)
drivers/gpu/drm/scheduler/sched_entity.c +54 -15
@@ -83,6 +83,7 @@ int drm_sched_entity_init(struct drm_sched_entity *entity,memset (entity,0 ,sizeof (struct drm_sched_entity ));INIT_LIST_HEAD (&entity->list); entity->rq =NULL ; + entity->single_sched =NULL ; entity->guilty = guilty; entity->num_sched_list = num_sched_list; entity->priority = priority;
@@ -90,8 +91,17 @@ int drm_sched_entity_init(struct drm_sched_entity *entity,RCU_INIT_POINTER (entity->last_scheduled,NULL );RB_CLEAR_NODE (&entity->rb_tree_node); -if (num_sched_list) - entity->rq = &sched_list[0 ]->sched_rq[entity->priority]; +if (num_sched_list) { +if (sched_list[0 ]->sched_policy != +DRM_SCHED_POLICY_SINGLE_ENTITY ) { + entity->rq = &sched_list[0 ]->sched_rq[entity->priority]; + }else { +if (num_sched_list !=1 || sched_list[0 ]->single_entity) +return -EINVAL ; + sched_list[0 ]->single_entity = entity; + entity->single_sched = sched_list[0 ]; + } + }init_completion (&entity->entity_idle);
@@ -124,7 +134,8 @@ void drm_sched_entity_modify_sched(struct drm_sched_entity *entity,struct drm_gpu_scheduler **sched_list, unsigned int num_sched_list) { - WARN_ON(!num_sched_list || !sched_list); + WARN_ON(!num_sched_list || !sched_list || + !!entity->single_sched); entity->sched_list = sched_list; entity->num_sched_list = num_sched_list;
@@ -231,13 +242,15 @@ static void drm_sched_entity_kill(struct drm_sched_entity *entity) {struct drm_sched_job *job;struct dma_fence *prev; +bool single_entity = !!entity->single_sched; -if (!entity->rq) +if (!entity->rq && !single_entity)return ;spin_lock (&entity->rq_lock); entity->stopped = true; -drm_sched_rq_remove_entity (entity->rq, entity); +if (!single_entity) +drm_sched_rq_remove_entity (entity->rq, entity);spin_unlock (&entity->rq_lock);/* Make sure this entity is not used by the scheduler at the moment */
@@ -259,6 +272,20 @@ static void drm_sched_entity_kill(struct drm_sched_entity *entity)dma_fence_put (prev); } +/** +* drm_sched_entity_to_scheduler - Schedule entity to GPU scheduler +* @entity: scheduler entity +* +* Returns GPU scheduler for the entity +*/ +struct drm_gpu_scheduler * +drm_sched_entity_to_scheduler (struct drm_sched_entity *entity) +{ +bool single_entity = !!entity->single_sched; + +return single_entity ? entity->single_sched : entity->rq->sched; +} +/** * drm_sched_entity_flush - Flush a context entity *
@@ -276,11 +303,12 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout)struct drm_gpu_scheduler *sched;struct task_struct *last_user;long ret = timeout; +bool single_entity = !!entity->single_sched; -if (!entity->rq) +if (!entity->rq && !single_entity)return 0 ; - sched = entity->rq->sched; + sched =drm_sched_entity_to_scheduler (entity);/** * The client will not queue more IBs during this fini, consume existing * queued IBs or discard them on SIGKILL
@@ -373,7 +401,7 @@ static void drm_sched_entity_wakeup(struct dma_fence *f, container_of(cb, struct drm_sched_entity, cb);drm_sched_entity_clear_dep (f, cb); -drm_sched_wakeup_if_can_queue (entity->rq->sched); +drm_sched_wakeup_if_can_queue (drm_sched_entity_to_scheduler (entity)); }/**
@@ -387,6 +415,8 @@ static void drm_sched_entity_wakeup(struct dma_fence *f,void drm_sched_entity_set_priority (struct drm_sched_entity *entity,enum drm_sched_priority priority) { +WARN_ON (!!entity->single_sched); +spin_lock (&entity->rq_lock); entity->priority = priority;spin_unlock (&entity->rq_lock);
@@ -399,7 +429,7 @@ EXPORT_SYMBOL(drm_sched_entity_set_priority);*/ static bool drm_sched_entity_add_dependency_cb (struct drm_sched_entity *entity) { -struct drm_gpu_scheduler *sched = entity->rq->sched; +struct drm_gpu_scheduler *sched =drm_sched_entity_to_scheduler (entity);struct dma_fence *fence = entity->dependency;struct drm_sched_fence *s_fence;
@@ -501,7 +531,8 @@ struct drm_sched_job *drm_sched_entity_pop_job(struct drm_sched_entity *entity)* Update the entity's location in the min heap according to * the timestamp of the next job, if any. */ -if (entity->rq->sched->sched_policy ==DRM_SCHED_POLICY_FIFO ) { +if (drm_sched_entity_to_scheduler (entity)->sched_policy == +DRM_SCHED_POLICY_FIFO ) {struct drm_sched_job *next; next =to_drm_sched_job (spsc_queue_peek (&entity->job_queue));
@@ -524,6 +555,8 @@ void drm_sched_entity_select_rq(struct drm_sched_entity *entity)struct drm_gpu_scheduler *sched;struct drm_sched_rq *rq; +WARN_ON (!!entity->single_sched); +/* single possible engine and already selected */ if (!entity->sched_list)return ;
@@ -573,12 +606,13 @@ void drm_sched_entity_select_rq(struct drm_sched_entity *entity)void drm_sched_entity_push_job (struct drm_sched_job *sched_job) {struct drm_sched_entity *entity = sched_job->entity; -bool first, fifo = entity->rq->sched->sched_policy == -DRM_SCHED_POLICY_FIFO ; +bool single_entity = !!entity->single_sched; +bool first;ktime_t submit_ts;trace_drm_sched_job (sched_job, entity); -atomic_inc (entity->rq->sched->score); +if (!single_entity) +atomic_inc (entity->rq->sched->score);WRITE_ONCE (entity->last_user, current->group_leader);/*
@@ -591,6 +625,10 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)/* first job wakes up scheduler */ if (first) { +struct drm_gpu_scheduler *sched = +drm_sched_entity_to_scheduler (entity); +bool fifo = sched->sched_policy ==DRM_SCHED_POLICY_FIFO ; +/* Add the entity to the run queue */ spin_lock (&entity->rq_lock);if (entity->stopped) {
@@ -600,13 +638,14 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)return ; } -drm_sched_rq_add_entity (entity->rq, entity); +if (!single_entity) +drm_sched_rq_add_entity (entity->rq, entity);spin_unlock (&entity->rq_lock);if (fifo)drm_sched_rq_update_fifo (entity, submit_ts); -drm_sched_wakeup_if_can_queue (entity->rq->sched); +drm_sched_wakeup_if_can_queue (sched); } }EXPORT_SYMBOL (drm_sched_entity_push_job);
drivers/gpu/drm/scheduler/sched_fence.c +1 -1
@@ -225,7 +225,7 @@ void drm_sched_fence_init(struct drm_sched_fence *fence, {unsigned seq; - fence->sched = entity->rq->sched; + fence->sched =drm_sched_entity_to_scheduler (entity); seq =atomic_inc_return (&entity->fence_seq);dma_fence_init (&fence->scheduled, &drm_sched_fence_ops_scheduled, &fence->lock, entity->fence_context, seq);
drivers/gpu/drm/scheduler/sched_main.c +57 -7
146 lines not on this page · raw message
include/drm/gpu_scheduler.h +8 -0
@@ -79,6 +79,7 @@ enum drm_sched_policy {DRM_SCHED_POLICY_UNSET ,DRM_SCHED_POLICY_RR ,DRM_SCHED_POLICY_FIFO , +DRM_SCHED_POLICY_SINGLE_ENTITY , DRM_SCHED_POLICY_COUNT, };
@@ -112,6 +113,9 @@ struct drm_sched_entity {*/ struct drm_sched_rq *rq; +/** @single_sched: Single scheduler */ +struct drm_gpu_scheduler *single_sched; +/** * @sched_list: *
@@ -473,6 +477,7 @@ struct drm_sched_backend_ops {* struct drm_gpu_scheduler - scheduler instance-specific data * * @ops: backend operations provided by the driver. +* @single_entity: Single entity for the scheduler * @hw_submission_limit: the max size of the hardware queue. * @timeout: the time after which a job is removed from the scheduler. * @name: name of the ring for which this scheduler is being used.
@@ -504,6 +509,7 @@ struct drm_sched_backend_ops {*/ struct drm_gpu_scheduler {const struct drm_sched_backend_ops *ops; +struct drm_sched_entity *single_entity;uint32_t hw_submission_limit;long timeout;const char *name;
@@ -587,6 +593,8 @@ int drm_sched_entity_init(struct drm_sched_entity *entity,struct drm_gpu_scheduler **sched_list, unsigned int num_sched_list, atomic_t *guilty); +struct drm_gpu_scheduler * +drm_sched_entity_to_scheduler (struct drm_sched_entity *entity);long drm_sched_entity_flush (struct drm_sched_entity *entity,long timeout);void drm_sched_entity_fini (struct drm_sched_entity *entity);void drm_sched_entity_destroy (struct drm_sched_entity *entity);
Signature · 1 line
2.34.1
Re: [PATCH v4 04/10] drm/sched: Add DRM_SCHED_POLICY_SINGLE_ENTITY scheduling policy
Hi,
Quoted 36 lines · Matthew Brost
DRM_SCHED_POLICY_SINGLE_ENTITYcreates a 1 to 1 relationship between scheduler and entity. No priorities or run queue used in this mode. Intended for devices with firmware schedulers.v2:
- Drop sched / rq union (Luben)
v3:
- Don't pick entity if stopped indrm_sched_select_entity(Danilo)Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/scheduler/sched_entity.c | 69 ++++++++++++++++++------ drivers/gpu/drm/scheduler/sched_fence.c | 2 +- drivers/gpu/drm/scheduler/sched_main.c | 64 +++++++++++++++++++--- include/drm/gpu_scheduler.h | 8 +++ 4 files changed, 120 insertions(+), 23 deletions(-)drivers/gpu/drm/scheduler/sched_entity.c +2
-2@@ -83,6 +83,7 @@ int drm_sched_entity_init(struct drm_sched_entity *entity,memset (entity,0 ,sizeof (struct drm_sched_entity ));INIT_LIST_HEAD (&entity->list); entity->rq =NULL ; + entity->single_sched =NULL ; entity->guilty = guilty; entity->num_sched_list = num_sched_list; entity->priority = priority;@@ -90,8 +91,17 @@ int drm_sched_entity_init(struct drm_sched_entity *entity,RCU_INIT_POINTER (entity->last_scheduled,NULL );RB_CLEAR_NODE (&entity->rb_tree_node); -if (num_sched_list) - entity->rq = &sched_list[0 ]->sched_rq[entity->priority]; +if (num_sched_list) {
drivers/gpu/drm/scheduler/sched_entity.c int drm_sched_entity_init(struct drm_sched_entity *entity, · line 104
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_entity.c +10
-0+if (sched_list[0 ]->sched_policy != +DRM_SCHED_POLICY_SINGLE_ENTITY ) { + entity->rq = &sched_list[0 ]->sched_rq[entity->priority]; + }else { +if (num_sched_list !=1 || sched_list[0 ]->single_entity) +return -EINVAL ; + sched_list[0 ]->single_entity = entity; + entity->single_sched = sched_list[0 ]; + } + }
So much (checking for) negativity...:-)
Perhaps the simplified form below?
if (num_sched_list) {
if (sched_list[0]->sched_policy !=
DRM_SCHED_POLICY_SINGLE_ENTITY) {
entity->rq = &sched_list[0]->sched_rq[entity->priority];
} else if (num_sched_list == 1 && !sched_list[0]->single_entity) {
sched_list[0]->single_entity = entity;
entity->single_sched = sched_list[0];
} else {
return -EINVAL;
}
}Quoted 32 lines
drivers/gpu/drm/scheduler/sched_entity.c +6
-3init_completion (&entity->entity_idle);@@ -124,7 +134,8 @@ void drm_sched_entity_modify_sched(struct drm_sched_entity *entity,struct drm_gpu_scheduler **sched_list, unsigned int num_sched_list) { - WARN_ON(!num_sched_list || !sched_list); + WARN_ON(!num_sched_list || !sched_list || + !!entity->single_sched); entity->sched_list = sched_list; entity->num_sched_list = num_sched_list;@@ -231,13 +242,15 @@ static void drm_sched_entity_kill(struct drm_sched_entity *entity) {struct drm_sched_job *job;struct dma_fence *prev; +bool single_entity = !!entity->single_sched; -if (!entity->rq) +if (!entity->rq && !single_entity)return ;spin_lock (&entity->rq_lock); entity->stopped = true; -drm_sched_rq_remove_entity (entity->rq, entity); +if (!single_entity) +drm_sched_rq_remove_entity (entity->rq, entity);spin_unlock (&entity->rq_lock);/* Make sure this entity is not used by the scheduler at the moment */
drivers/gpu/drm/scheduler/sched_entity.c static void drm_sched_entity_kill(struct drm_sched_entity *entity) · line 276
Quoted 5 lines
drivers/gpu/drm/scheduler/sched_entity.c +2
-0@@ -259,6 +272,20 @@ static void drm_sched_entity_kill(struct drm_sched_entity *entity)dma_fence_put (prev); } +/** +* drm_sched_entity_to_scheduler - Schedule entity to GPU scheduler
Please use verbs. Please?
Fix:
/**
* drm_sched_entity_to_scheduler - Map a schedule entity to a GPU scheduler
drivers/gpu/drm/scheduler/sched_entity.c static void drm_sched_entity_kill(struct drm_sched_entity *entity) · line 279
Quoted 3 lines
drivers/gpu/drm/scheduler/sched_entity.c +3
-0+* @entity: scheduler entity +* +* Returns GPU scheduler for the entity
Fix:
* Given an entity, return its GPU scheduler.
Quoted 136 lines
drivers/gpu/drm/scheduler/sched_entity.c +31
-10+*/ +struct drm_gpu_scheduler * +drm_sched_entity_to_scheduler (struct drm_sched_entity *entity) +{ +bool single_entity = !!entity->single_sched; + +return single_entity ? entity->single_sched : entity->rq->sched; +} +/** * drm_sched_entity_flush - Flush a context entity * @@ -276,11 +303,12 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout)struct drm_gpu_scheduler *sched;struct task_struct *last_user;long ret = timeout; +bool single_entity = !!entity->single_sched; -if (!entity->rq) +if (!entity->rq && !single_entity)return 0 ; - sched = entity->rq->sched; + sched =drm_sched_entity_to_scheduler (entity);/** * The client will not queue more IBs during this fini, consume existing * queued IBs or discard them on SIGKILL @@ -373,7 +401,7 @@ static void drm_sched_entity_wakeup(struct dma_fence *f, container_of(cb, struct drm_sched_entity, cb);drm_sched_entity_clear_dep (f, cb); -drm_sched_wakeup_if_can_queue (entity->rq->sched); +drm_sched_wakeup_if_can_queue (drm_sched_entity_to_scheduler (entity)); }/** @@ -387,6 +415,8 @@ static void drm_sched_entity_wakeup(struct dma_fence *f,void drm_sched_entity_set_priority (struct drm_sched_entity *entity,enum drm_sched_priority priority) { +WARN_ON (!!entity->single_sched); +spin_lock (&entity->rq_lock); entity->priority = priority;spin_unlock (&entity->rq_lock);@@ -399,7 +429,7 @@ EXPORT_SYMBOL(drm_sched_entity_set_priority);*/ static bool drm_sched_entity_add_dependency_cb (struct drm_sched_entity *entity) { -struct drm_gpu_scheduler *sched = entity->rq->sched; +struct drm_gpu_scheduler *sched =drm_sched_entity_to_scheduler (entity);struct dma_fence *fence = entity->dependency;struct drm_sched_fence *s_fence;@@ -501,7 +531,8 @@ struct drm_sched_job *drm_sched_entity_pop_job(struct drm_sched_entity *entity)* Update the entity's location in the min heap according to * the timestamp of the next job, if any. */ -if (entity->rq->sched->sched_policy ==DRM_SCHED_POLICY_FIFO ) { +if (drm_sched_entity_to_scheduler (entity)->sched_policy == +DRM_SCHED_POLICY_FIFO ) {struct drm_sched_job *next; next =to_drm_sched_job (spsc_queue_peek (&entity->job_queue));@@ -524,6 +555,8 @@ void drm_sched_entity_select_rq(struct drm_sched_entity *entity)struct drm_gpu_scheduler *sched;struct drm_sched_rq *rq; +WARN_ON (!!entity->single_sched); +/* single possible engine and already selected */ if (!entity->sched_list)return ;@@ -573,12 +606,13 @@ void drm_sched_entity_select_rq(struct drm_sched_entity *entity)void drm_sched_entity_push_job (struct drm_sched_job *sched_job) {struct drm_sched_entity *entity = sched_job->entity; -bool first, fifo = entity->rq->sched->sched_policy == -DRM_SCHED_POLICY_FIFO ; +bool single_entity = !!entity->single_sched; +bool first;ktime_t submit_ts;trace_drm_sched_job (sched_job, entity); -atomic_inc (entity->rq->sched->score); +if (!single_entity) +atomic_inc (entity->rq->sched->score);WRITE_ONCE (entity->last_user, current->group_leader);/* @@ -591,6 +625,10 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)/* first job wakes up scheduler */ if (first) { +struct drm_gpu_scheduler *sched = +drm_sched_entity_to_scheduler (entity); +bool fifo = sched->sched_policy ==DRM_SCHED_POLICY_FIFO ; +/* Add the entity to the run queue */ spin_lock (&entity->rq_lock);if (entity->stopped) {@@ -600,13 +638,14 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)return ; } -drm_sched_rq_add_entity (entity->rq, entity); +if (!single_entity) +drm_sched_rq_add_entity (entity->rq, entity);spin_unlock (&entity->rq_lock);if (fifo)drm_sched_rq_update_fifo (entity, submit_ts); -drm_sched_wakeup_if_can_queue (entity->rq->sched); +drm_sched_wakeup_if_can_queue (sched); } }EXPORT_SYMBOL (drm_sched_entity_push_job);drivers/gpu/drm/scheduler/sched_fence.c +1
-1@@ -225,7 +225,7 @@ void drm_sched_fence_init(struct drm_sched_fence *fence, {unsigned seq; - fence->sched = entity->rq->sched; + fence->sched =drm_sched_entity_to_scheduler (entity); seq =atomic_inc_return (&entity->fence_seq);dma_fence_init (&fence->scheduled, &drm_sched_fence_ops_scheduled, &fence->lock, entity->fence_context, seq);drivers/gpu/drm/scheduler/sched_main.c +0
-0
drivers/gpu/drm/scheduler/sched_main.c line 36
Quoted 6 lines
drivers/gpu/drm/scheduler/sched_main.c +2
-1@@ -32,7 +32,8 @@* backend operations to the scheduler like submitting a job to hardware run queue, * returning the dependencies of a job etc. * -* The organisation of the scheduler is the following: +* The organisation of the scheduler is the following for scheduling policies +* DRM_SCHED_POLICY_RR and DRM_SCHED_POLICY_FIFO:
Yes, so this was badly written to begin with. If we're adding more information, I'd write:
* For scheduling policies DRM_SCHED_POLICY_RR and DRM_SCHED_POLICY_FIFO,
* the scheduler organization is,
drivers/gpu/drm/scheduler/sched_main.c line 48
Quoted 9 lines
drivers/gpu/drm/scheduler/sched_main.c +2
-0* * 1. Each hw run queue has one scheduler * 2. Each scheduler has multiple run queues with different priorities @@ -43,6 +44,23 @@* * The jobs in a entity are always scheduled in the order that they were pushed. * +* The organisation of the scheduler is the following for scheduling policy +* DRM_SCHED_POLICY_SINGLE_ENTITY:
Remember, it's a list, on large enough scale, thus,
* For DRM_SCHED_POLICY_SINGLE_ENTITY, the organization of the scheduler is,
drivers/gpu/drm/scheduler/sched_main.c line 54
Quoted 6 lines
drivers/gpu/drm/scheduler/sched_main.c +6
-0+* +* 1. One to one relationship between scheduler and entity +* 2. No priorities implemented per scheduler (single job queue) +* 3. No run queues in scheduler rather jobs are directly dequeued from entity +* 4. The entity maintains a queue of jobs that will be scheduled on the +* hardware
Good! But please fix,
4. The entity maintains a queue of jobs that will be scheduler _to_ the hardware.
drivers/gpu/drm/scheduler/sched_main.c line 57
Quoted 3 lines
drivers/gpu/drm/scheduler/sched_main.c +3
-0+* +* The jobs in a entity are always scheduled in the order that they were pushed +* regardless of scheduling policy.
Please add here,
Single-entity scheduling is essentially a FIFO for jobs.
drivers/gpu/drm/scheduler/sched_main.c line 59
Quoted 2 lines
drivers/gpu/drm/scheduler/sched_main.c +2
-0+* +* A policy of DRM_SCHED_POLICY_RR or DRM_SCHED_POLICY_FIFO is expected to used
"... is expected to _be_ used ..."
drivers/gpu/drm/scheduler/sched_main.c line 60
Quoted 1 line
drivers/gpu/drm/scheduler/sched_main.c +1
-0+* when the KMD is scheduling directly on the hardware while a scheduling policy
I'd spell out "kernel-mode driver" since it makes it terse when reading a processed DOC format, and having a three-letter abbreviation spelled out makes for an easier reading experience. (There are too many three-letter abbreviations as is...)
"... directly _to_ the hardware ..." since, ultimately, the DRM scheduler just pushes jobs to be executed to the hardware by the hardware and doesn't support or control hardware preemption of jobs _on_ the hardware. (See what I did there? :-) )
drivers/gpu/drm/scheduler/sched_main.c line 63
Quoted 3 lines
drivers/gpu/drm/scheduler/sched_main.c +3
-0+* of DRM_SCHED_POLICY_SINGLE_ENTITY is expected to be used when there is a +* firmware scheduler. +*
Yeah, so that's a good explanation--thanks for writing this.
drivers/gpu/drm/scheduler/sched_main.c line 64
Quoted 1 line
drivers/gpu/drm/scheduler/sched_main.c +0
-0* Note that once a job was taken from the entities queue and pushed to the
Please only use present tense in software documentation. No past, future, or perfect tenses please.
* Note that once a job _is_ taken from the entities queue and pushed to the
drivers/gpu/drm/scheduler/sched_main.c line 66
Quoted 2 lines
drivers/gpu/drm/scheduler/sched_main.c +0
-0* hardware, i.e. the pending queue, the entity must not be referenced anymore * through the jobs entity pointer.
Yeah, another good explanation--thanks for including this.
Quoted 47 lines
drivers/gpu/drm/scheduler/sched_main.c +9
-1@@ -96,6 +114,8 @@ static inline void drm_sched_rq_remove_fifo_locked(struct drm_sched_entity *entivoid drm_sched_rq_update_fifo (struct drm_sched_entity *entity,ktime_t ts) { +WARN_ON (!!entity->single_sched); +/* * Both locks need to be grabbed, one to protect from entity->rq change * for entity from within concurrent drm_sched_entity_select_rq and the @@ -126,6 +146,8 @@ void drm_sched_rq_update_fifo(struct drm_sched_entity *entity, ktime_t ts)static void drm_sched_rq_init (struct drm_gpu_scheduler *sched,struct drm_sched_rq *rq) { +WARN_ON (sched->sched_policy ==DRM_SCHED_POLICY_SINGLE_ENTITY ); +spin_lock_init (&rq->lock);INIT_LIST_HEAD (&rq->entities); rq->rb_tree_root =RB_ROOT_CACHED ;@@ -144,6 +166,8 @@ static void drm_sched_rq_init(struct drm_gpu_scheduler *sched,void drm_sched_rq_add_entity (struct drm_sched_rq *rq,struct drm_sched_entity *entity) { +WARN_ON (!!entity->single_sched); +if (!list_empty (&entity->list))return ;@@ -166,6 +190,8 @@ void drm_sched_rq_add_entity(struct drm_sched_rq *rq,void drm_sched_rq_remove_entity (struct drm_sched_rq *rq,struct drm_sched_entity *entity) { +WARN_ON (!!entity->single_sched); +if (list_empty (&entity->list))return ;@@ -641,7 +667,7 @@ int drm_sched_job_init(struct drm_sched_job *job, struct drm_sched_entity *entity, void *owner) { -if (!entity->rq) +if (!entity->rq && !entity->single_sched)return -ENOENT ; job->entity = entity;@@ -674,13 +700,16 @@ void drm_sched_job_arm(struct drm_sched_job *job) {
drivers/gpu/drm/scheduler/sched_main.c void drm_sched_job_arm(struct drm_sched_job *job) · line 708
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +4
-2struct drm_gpu_scheduler *sched;struct drm_sched_entity *entity = job->entity; +bool single_entity = !!entity->single_sched;BUG_ON (!entity); -drm_sched_entity_select_rq (entity); - sched = entity->rq->sched; +if (!single_entity) +drm_sched_entity_select_rq (entity); + sched =drm_sched_entity_to_scheduler (entity);
So here, I wonder, and I've a tiny exploratory request:
Could we "fake" an rq for the single-entity and thus remove (become unnecessary) all those "if (single-entity)" and "if (!single-entity)".
If we keep adding code peppered with if () everywhere, over the years it'll become hard to read. However, if we use maps to achieve choice and selection, such as entity->rq, then you'd not need much of the "if (single-entity)" and "if (!single-entity)", and the code would naturally stay mostly the same and the sched selection would still be abstracted out via the entity->rq.
What do you think?
Quoted 32 lines
drivers/gpu/drm/scheduler/sched_main.c +11
-1job->sched = sched; - job->s_priority = entity->rq - sched->sched_rq; +if (!single_entity) + job->s_priority = entity->rq - sched->sched_rq; job->id =atomic64_inc_return (&sched->job_id_count);drm_sched_fence_init (job->s_fence, job->entity);@@ -896,6 +925,14 @@ drm_sched_select_entity(struct drm_gpu_scheduler *sched)if (!drm_sched_can_queue (sched))return NULL ; +if (sched->single_entity) { +if (!READ_ONCE (sched->single_entity->stopped) && +drm_sched_entity_is_ready (sched->single_entity)) +return sched->single_entity; + +return NULL ; + } +/* Kernel run queue has higher priority than normal run queue*/ for (i =DRM_SCHED_PRIORITY_COUNT -1 ; i >=DRM_SCHED_PRIORITY_MIN ; i--) { entity = sched->sched_policy == DRM_SCHED_POLICY_FIFO ?@@ -1092,6 +1129,7 @@ int drm_sched_init(struct drm_gpu_scheduler *sched,return -EINVAL ; sched->ops = ops; + sched->single_entity =NULL ; sched->hw_submission_limit = hw_submission; sched->name = name;if (!submit_wq) {
drivers/gpu/drm/scheduler/sched_main.c int drm_sched_init(struct drm_gpu_scheduler *sched, · line 1154
Quoted 7 lines
drivers/gpu/drm/scheduler/sched_main.c +3
-1@@ -1111,7 +1149,9 @@ int drm_sched_init(struct drm_gpu_scheduler *sched, sched->dev = dev; sched->sched_policy = sched_policy ==DRM_SCHED_POLICY_UNSET ? drm_sched_policy_default : sched_policy; -for (i =DRM_SCHED_PRIORITY_MIN ; i <DRM_SCHED_PRIORITY_COUNT ; i++) +for (i =DRM_SCHED_PRIORITY_MIN ; sched_policy != +DRM_SCHED_POLICY_SINGLE_ENTITY && i <DRM_SCHED_PRIORITY_COUNT ; + i++)
So, "sched_policy != DRM_SCHED_POLICY_SINGLE_ENTITY" doesn't seem to be a loop-invariant, since it doesn't cause the loop to exit over iterations. It's just a gate to executing the loop. I am used to seeing only loop invariants in the for-loop conditional.
I wonder if it is clearer to just say what is meant:
if (sched_policy != DRM_SCHED_POLICY_SINGLE_ENTITY) {
for (i = DRM_SCHED_PRIORITY_MIN; i < DRM_SCHED_PRIORITY_COUNT; i++)
...
}On a larger scheme of things, I believe it is a bit presumptuous to say:
struct drm_gpu_scheduler {
...
struct drm_sched_rq sched_rq[DRM_SCHED_PRIORITY_COUNT];
...
};I mean, why does a scheduler have to implement all those priorities? Maybe it wants to implement only one. :-)
Perhaps we can have,
struct drm_gpu_scheduler {
...
u32 num_rqs;
struct drm_sched_rq *sched_rq;
...
};Which might make it easier to fake out an rq for single-entity and then leave the code mostly intact, while also implementing single-entity.
It's not a gating issue, but perhaps it would create a cleaner code in the long run? Maybe we should explore this?
Quoted 8 lines
drivers/gpu/drm/scheduler/sched_main.c +0
-1drm_sched_rq_init (sched, &sched->sched_rq[i]);init_waitqueue_head (&sched->job_scheduled);@@ -1143,7 +1183,15 @@ void drm_sched_fini(struct drm_gpu_scheduler *sched)drm_sched_submit_stop (sched); -for (i =DRM_SCHED_PRIORITY_COUNT -1 ; i >=DRM_SCHED_PRIORITY_MIN ; i--) {
drivers/gpu/drm/scheduler/sched_main.c void drm_sched_fini(struct drm_gpu_scheduler *sched) · line 1195
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +9
-0+if (sched->single_entity) { +spin_lock (&sched->single_entity->rq_lock); + sched->single_entity->stopped = true; +spin_unlock (&sched->single_entity->rq_lock); + } + +for (i =DRM_SCHED_PRIORITY_COUNT -1 ; sched->sched_policy != +DRM_SCHED_POLICY_SINGLE_ENTITY && i >=DRM_SCHED_PRIORITY_MIN ; + i--) {struct drm_sched_rq *rq = &sched->sched_rq[i];
Same sentiment here, as above.
Signature · 2 lines
Regards, Luben
Quoted 58 lines
drivers/gpu/drm/scheduler/sched_main.c +2
-0spin_lock (&rq->lock);@@ -1186,6 +1234,8 @@ void drm_sched_increase_karma(struct drm_sched_job *bad)struct drm_sched_entity *entity;struct drm_gpu_scheduler *sched = bad->sched; +WARN_ON (sched->sched_policy ==DRM_SCHED_POLICY_SINGLE_ENTITY ); +/* don't change @bad's karma if it's from KERNEL RQ, * because sometimes GPU hang would cause kernel jobs (like VM updating jobs) * corrupt but keep in mind that kernel jobs always considered good. include/drm/gpu_scheduler.h +8
-0@@ -79,6 +79,7 @@ enum drm_sched_policy {DRM_SCHED_POLICY_UNSET ,DRM_SCHED_POLICY_RR ,DRM_SCHED_POLICY_FIFO , +DRM_SCHED_POLICY_SINGLE_ENTITY , DRM_SCHED_POLICY_COUNT, };@@ -112,6 +113,9 @@ struct drm_sched_entity {*/ struct drm_sched_rq *rq; +/** @single_sched: Single scheduler */ +struct drm_gpu_scheduler *single_sched; +/** * @sched_list: * @@ -473,6 +477,7 @@ struct drm_sched_backend_ops {* struct drm_gpu_scheduler - scheduler instance-specific data * * @ops: backend operations provided by the driver. +* @single_entity: Single entity for the scheduler * @hw_submission_limit: the max size of the hardware queue. * @timeout: the time after which a job is removed from the scheduler. * @name: name of the ring for which this scheduler is being used. @@ -504,6 +509,7 @@ struct drm_sched_backend_ops {*/ struct drm_gpu_scheduler {const struct drm_sched_backend_ops *ops; +struct drm_sched_entity *single_entity;uint32_t hw_submission_limit;long timeout;const char *name;@@ -587,6 +593,8 @@ int drm_sched_entity_init(struct drm_sched_entity *entity,struct drm_gpu_scheduler **sched_list, unsigned int num_sched_list, atomic_t *guilty); +struct drm_gpu_scheduler * +drm_sched_entity_to_scheduler (struct drm_sched_entity *entity);long drm_sched_entity_flush (struct drm_sched_entity *entity,long timeout);void drm_sched_entity_fini (struct drm_sched_entity *entity);void drm_sched_entity_destroy (struct drm_sched_entity *entity);
Matthew Brost
maintainerRe: [PATCH v4 04/10] drm/sched: Add DRM_SCHED_POLICY_SINGLE_ENTITY scheduling policy
Quoted 53 lines · Luben Tuikov
Hi,
Quoted 36 lines · Matthew Brost
DRM_SCHED_POLICY_SINGLE_ENTITYcreates a 1 to 1 relationship between scheduler and entity. No priorities or run queue used in this mode. Intended for devices with firmware schedulers.v2:
- Drop sched / rq union (Luben)
v3:
- Don't pick entity if stopped indrm_sched_select_entity(Danilo)Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/scheduler/sched_entity.c | 69 ++++++++++++++++++------ drivers/gpu/drm/scheduler/sched_fence.c | 2 +- drivers/gpu/drm/scheduler/sched_main.c | 64 +++++++++++++++++++--- include/drm/gpu_scheduler.h | 8 +++ 4 files changed, 120 insertions(+), 23 deletions(-)drivers/gpu/drm/scheduler/sched_entity.c +2
-2@@ -83,6 +83,7 @@ int drm_sched_entity_init(struct drm_sched_entity *entity,memset (entity,0 ,sizeof (struct drm_sched_entity ));INIT_LIST_HEAD (&entity->list); entity->rq =NULL ; + entity->single_sched =NULL ; entity->guilty = guilty; entity->num_sched_list = num_sched_list; entity->priority = priority;@@ -90,8 +91,17 @@ int drm_sched_entity_init(struct drm_sched_entity *entity,RCU_INIT_POINTER (entity->last_scheduled,NULL );RB_CLEAR_NODE (&entity->rb_tree_node); -if (num_sched_list) - entity->rq = &sched_list[0 ]->sched_rq[entity->priority]; +if (num_sched_list) {drivers/gpu/drm/scheduler/sched_entity.c int drm_sched_entity_init(struct drm_sched_entity *entity, · line 104
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_entity.c +10
-0+if (sched_list[0 ]->sched_policy != +DRM_SCHED_POLICY_SINGLE_ENTITY ) { + entity->rq = &sched_list[0 ]->sched_rq[entity->priority]; + }else { +if (num_sched_list !=1 || sched_list[0 ]->single_entity) +return -EINVAL ; + sched_list[0 ]->single_entity = entity; + entity->single_sched = sched_list[0 ]; + } + }So much (checking for) negativity...:-)
Perhaps the simplified form below?
Quoted 12 lines
if (num_sched_list) {
if (sched_list[0]->sched_policy !=
DRM_SCHED_POLICY_SINGLE_ENTITY) {
entity->rq = &sched_list[0]->sched_rq[entity->priority];
} else if (num_sched_list == 1 && !sched_list[0]->single_entity) {
sched_list[0]->single_entity = entity;
entity->single_sched = sched_list[0];
} else {
return -EINVAL;
}
}Will change.
Quoted 44 lines
Quoted 32 lines
drivers/gpu/drm/scheduler/sched_entity.c +6
-3init_completion (&entity->entity_idle);@@ -124,7 +134,8 @@ void drm_sched_entity_modify_sched(struct drm_sched_entity *entity,struct drm_gpu_scheduler **sched_list, unsigned int num_sched_list) { - WARN_ON(!num_sched_list || !sched_list); + WARN_ON(!num_sched_list || !sched_list || + !!entity->single_sched); entity->sched_list = sched_list; entity->num_sched_list = num_sched_list;@@ -231,13 +242,15 @@ static void drm_sched_entity_kill(struct drm_sched_entity *entity) {struct drm_sched_job *job;struct dma_fence *prev; +bool single_entity = !!entity->single_sched; -if (!entity->rq) +if (!entity->rq && !single_entity)return ;spin_lock (&entity->rq_lock); entity->stopped = true; -drm_sched_rq_remove_entity (entity->rq, entity); +if (!single_entity) +drm_sched_rq_remove_entity (entity->rq, entity);spin_unlock (&entity->rq_lock);/* Make sure this entity is not used by the scheduler at the moment */ drivers/gpu/drm/scheduler/sched_entity.c static void drm_sched_entity_kill(struct drm_sched_entity *entity) · line 276
Quoted 5 lines
drivers/gpu/drm/scheduler/sched_entity.c +2
-0@@ -259,6 +272,20 @@ static void drm_sched_entity_kill(struct drm_sched_entity *entity)dma_fence_put (prev); } +/** +* drm_sched_entity_to_scheduler - Schedule entity to GPU scheduler Please use verbs. Please?
Fix:
/**
*drm_sched_entity_to_scheduler- Map a schedule entity to a GPU scheduler
Quoted 7 lines
drivers/gpu/drm/scheduler/sched_entity.c static void drm_sched_entity_kill(struct drm_sched_entity *entity) · line 279
Quoted 3 lines
drivers/gpu/drm/scheduler/sched_entity.c +3
-0+* @entity: scheduler entity +* +* Returns GPU scheduler for the entity Fix:
* Given an entity, return its GPU scheduler.
Yep.
Quoted 146 lines
Quoted 136 lines
drivers/gpu/drm/scheduler/sched_entity.c +31
-10+*/ +struct drm_gpu_scheduler * +drm_sched_entity_to_scheduler (struct drm_sched_entity *entity) +{ +bool single_entity = !!entity->single_sched; + +return single_entity ? entity->single_sched : entity->rq->sched; +} +/** * drm_sched_entity_flush - Flush a context entity * @@ -276,11 +303,12 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout)struct drm_gpu_scheduler *sched;struct task_struct *last_user;long ret = timeout; +bool single_entity = !!entity->single_sched; -if (!entity->rq) +if (!entity->rq && !single_entity)return 0 ; - sched = entity->rq->sched; + sched =drm_sched_entity_to_scheduler (entity);/** * The client will not queue more IBs during this fini, consume existing * queued IBs or discard them on SIGKILL @@ -373,7 +401,7 @@ static void drm_sched_entity_wakeup(struct dma_fence *f, container_of(cb, struct drm_sched_entity, cb);drm_sched_entity_clear_dep (f, cb); -drm_sched_wakeup_if_can_queue (entity->rq->sched); +drm_sched_wakeup_if_can_queue (drm_sched_entity_to_scheduler (entity)); }/** @@ -387,6 +415,8 @@ static void drm_sched_entity_wakeup(struct dma_fence *f,void drm_sched_entity_set_priority (struct drm_sched_entity *entity,enum drm_sched_priority priority) { +WARN_ON (!!entity->single_sched); +spin_lock (&entity->rq_lock); entity->priority = priority;spin_unlock (&entity->rq_lock);@@ -399,7 +429,7 @@ EXPORT_SYMBOL(drm_sched_entity_set_priority);*/ static bool drm_sched_entity_add_dependency_cb (struct drm_sched_entity *entity) { -struct drm_gpu_scheduler *sched = entity->rq->sched; +struct drm_gpu_scheduler *sched =drm_sched_entity_to_scheduler (entity);struct dma_fence *fence = entity->dependency;struct drm_sched_fence *s_fence;@@ -501,7 +531,8 @@ struct drm_sched_job *drm_sched_entity_pop_job(struct drm_sched_entity *entity)* Update the entity's location in the min heap according to * the timestamp of the next job, if any. */ -if (entity->rq->sched->sched_policy ==DRM_SCHED_POLICY_FIFO ) { +if (drm_sched_entity_to_scheduler (entity)->sched_policy == +DRM_SCHED_POLICY_FIFO ) {struct drm_sched_job *next; next =to_drm_sched_job (spsc_queue_peek (&entity->job_queue));@@ -524,6 +555,8 @@ void drm_sched_entity_select_rq(struct drm_sched_entity *entity)struct drm_gpu_scheduler *sched;struct drm_sched_rq *rq; +WARN_ON (!!entity->single_sched); +/* single possible engine and already selected */ if (!entity->sched_list)return ;@@ -573,12 +606,13 @@ void drm_sched_entity_select_rq(struct drm_sched_entity *entity)void drm_sched_entity_push_job (struct drm_sched_job *sched_job) {struct drm_sched_entity *entity = sched_job->entity; -bool first, fifo = entity->rq->sched->sched_policy == -DRM_SCHED_POLICY_FIFO ; +bool single_entity = !!entity->single_sched; +bool first;ktime_t submit_ts;trace_drm_sched_job (sched_job, entity); -atomic_inc (entity->rq->sched->score); +if (!single_entity) +atomic_inc (entity->rq->sched->score);WRITE_ONCE (entity->last_user, current->group_leader);/* @@ -591,6 +625,10 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)/* first job wakes up scheduler */ if (first) { +struct drm_gpu_scheduler *sched = +drm_sched_entity_to_scheduler (entity); +bool fifo = sched->sched_policy ==DRM_SCHED_POLICY_FIFO ; +/* Add the entity to the run queue */ spin_lock (&entity->rq_lock);if (entity->stopped) {@@ -600,13 +638,14 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)return ; } -drm_sched_rq_add_entity (entity->rq, entity); +if (!single_entity) +drm_sched_rq_add_entity (entity->rq, entity);spin_unlock (&entity->rq_lock);if (fifo)drm_sched_rq_update_fifo (entity, submit_ts); -drm_sched_wakeup_if_can_queue (entity->rq->sched); +drm_sched_wakeup_if_can_queue (sched); } }EXPORT_SYMBOL (drm_sched_entity_push_job);drivers/gpu/drm/scheduler/sched_fence.c +1
-1@@ -225,7 +225,7 @@ void drm_sched_fence_init(struct drm_sched_fence *fence, {unsigned seq; - fence->sched = entity->rq->sched; + fence->sched =drm_sched_entity_to_scheduler (entity); seq =atomic_inc_return (&entity->fence_seq);dma_fence_init (&fence->scheduled, &drm_sched_fence_ops_scheduled, &fence->lock, entity->fence_context, seq);drivers/gpu/drm/scheduler/sched_main.c +0
-0drivers/gpu/drm/scheduler/sched_main.c line 36
Quoted 6 lines
drivers/gpu/drm/scheduler/sched_main.c +2
-1@@ -32,7 +32,8 @@* backend operations to the scheduler like submitting a job to hardware run queue, * returning the dependencies of a job etc. * -* The organisation of the scheduler is the following: +* The organisation of the scheduler is the following for scheduling policies +* DRM_SCHED_POLICY_RR and DRM_SCHED_POLICY_FIFO: Yes, so this was badly written to begin with. If we're adding more information, I'd write:
Quoted 2 lines
* For scheduling policies
DRM_SCHED_POLICY_RRandDRM_SCHED_POLICY_FIFO,
* the scheduler organization is,
Yep.
Quoted 59 lines
drivers/gpu/drm/scheduler/sched_main.c line 48
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +2
-0* * 1. Each hw run queue has one scheduler * 2. Each scheduler has multiple run queues with different priorities @@ -43,6 +44,23 @@* * The jobs in a entity are always scheduled in the order that they were pushed. * +* The organisation of the scheduler is the following for scheduling policy +* DRM_SCHED_POLICY_SINGLE_ENTITY: Remember, it's a list, on large enough scale, thus,
* For
DRM_SCHED_POLICY_SINGLE_ENTITY, the organization of the scheduler is,drivers/gpu/drm/scheduler/sched_main.c line 54
Quoted 6 lines
drivers/gpu/drm/scheduler/sched_main.c +6
-0+* +* 1. One to one relationship between scheduler and entity +* 2. No priorities implemented per scheduler (single job queue) +* 3. No run queues in scheduler rather jobs are directly dequeued from entity +* 4. The entity maintains a queue of jobs that will be scheduled on the +* hardware Good! But please fix,
4. The entity maintains a queue of jobs that will be scheduler _to_ the hardware.
drivers/gpu/drm/scheduler/sched_main.c line 57
Quoted 3 lines
drivers/gpu/drm/scheduler/sched_main.c +3
-0+* +* The jobs in a entity are always scheduled in the order that they were pushed +* regardless of scheduling policy. Please add here,
Single-entity scheduling is essentially a FIFO for jobs.drivers/gpu/drm/scheduler/sched_main.c line 59
Quoted 2 lines
drivers/gpu/drm/scheduler/sched_main.c +2
-0+* +* A policy of DRM_SCHED_POLICY_RR or DRM_SCHED_POLICY_FIFO is expected to used "... is expected to _be_ used ..."
drivers/gpu/drm/scheduler/sched_main.c line 60
Quoted 1 line
drivers/gpu/drm/scheduler/sched_main.c +1
-0+* when the KMD is scheduling directly on the hardware while a scheduling policy I'd spell out "kernel-mode driver" since it makes it terse when reading a processed DOC format, and having a three-letter abbreviation spelled out makes for an easier reading experience. (There are too many three-letter abbreviations as is...)
"... directly _to_ the hardware ..." since, ultimately, the DRM scheduler just pushes jobs to be executed to the hardware by the hardware and doesn't support or control hardware preemption of jobs _on_ the hardware. (See what I did there? :-) )
drivers/gpu/drm/scheduler/sched_main.c line 63
Quoted 3 lines
drivers/gpu/drm/scheduler/sched_main.c +3
-0+* of DRM_SCHED_POLICY_SINGLE_ENTITY is expected to be used when there is a +* firmware scheduler. +* Yeah, so that's a good explanation--thanks for writing this.
drivers/gpu/drm/scheduler/sched_main.c line 64
Quoted 1 line
drivers/gpu/drm/scheduler/sched_main.c +0
-0* Note that once a job was taken from the entities queue and pushed to the Please only use present tense in software documentation. No past, future, or perfect tenses please.
Quoted 7 lines
* Note that once a job _is_ taken from the entities queue and pushed to the
drivers/gpu/drm/scheduler/sched_main.c line 66
Quoted 2 lines
drivers/gpu/drm/scheduler/sched_main.c +0
-0* hardware, i.e. the pending queue, the entity must not be referenced anymore * through the jobs entity pointer. Yeah, another good explanation--thanks for including this.
Yes to all the wordin changes.
Quoted 62 lines
Quoted 47 lines
drivers/gpu/drm/scheduler/sched_main.c +9
-1@@ -96,6 +114,8 @@ static inline void drm_sched_rq_remove_fifo_locked(struct drm_sched_entity *entivoid drm_sched_rq_update_fifo (struct drm_sched_entity *entity,ktime_t ts) { +WARN_ON (!!entity->single_sched); +/* * Both locks need to be grabbed, one to protect from entity->rq change * for entity from within concurrent drm_sched_entity_select_rq and the @@ -126,6 +146,8 @@ void drm_sched_rq_update_fifo(struct drm_sched_entity *entity, ktime_t ts)static void drm_sched_rq_init (struct drm_gpu_scheduler *sched,struct drm_sched_rq *rq) { +WARN_ON (sched->sched_policy ==DRM_SCHED_POLICY_SINGLE_ENTITY ); +spin_lock_init (&rq->lock);INIT_LIST_HEAD (&rq->entities); rq->rb_tree_root =RB_ROOT_CACHED ;@@ -144,6 +166,8 @@ static void drm_sched_rq_init(struct drm_gpu_scheduler *sched,void drm_sched_rq_add_entity (struct drm_sched_rq *rq,struct drm_sched_entity *entity) { +WARN_ON (!!entity->single_sched); +if (!list_empty (&entity->list))return ;@@ -166,6 +190,8 @@ void drm_sched_rq_add_entity(struct drm_sched_rq *rq,void drm_sched_rq_remove_entity (struct drm_sched_rq *rq,struct drm_sched_entity *entity) { +WARN_ON (!!entity->single_sched); +if (list_empty (&entity->list))return ;@@ -641,7 +667,7 @@ int drm_sched_job_init(struct drm_sched_job *job, struct drm_sched_entity *entity, void *owner) { -if (!entity->rq) +if (!entity->rq && !entity->single_sched)return -ENOENT ; job->entity = entity;@@ -674,13 +700,16 @@ void drm_sched_job_arm(struct drm_sched_job *job) {drivers/gpu/drm/scheduler/sched_main.c void drm_sched_job_arm(struct drm_sched_job *job) · line 708
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +4
-2struct drm_gpu_scheduler *sched;struct drm_sched_entity *entity = job->entity; +bool single_entity = !!entity->single_sched;BUG_ON (!entity); -drm_sched_entity_select_rq (entity); - sched = entity->rq->sched; +if (!single_entity) +drm_sched_entity_select_rq (entity); + sched =drm_sched_entity_to_scheduler (entity);So here, I wonder, and I've a tiny exploratory request:
Could we "fake" an rq for the single-entity and thus remove (become unnecessary) all those "if (single-entity)" and "if (!single-entity)".
Quoted 8 lines
If we keep adding code peppered with if () everywhere, over the years it'll become hard to read. However, if we use maps to achieve choice and selection, such as
entity->rq, then you'd not need much of the "if (single-entity)" and "if (!single-entity)", and the code would naturally stay mostly the same and the sched selection would still be abstracted out via theentity->rq.What do you think?
I looked into this a little and can't really think of an easy way to do this. Wouldn't we just end up with a similar number of checks in the rq code? I'd say for now let's just live the if / else in a few places. If we start adding more scheduling modes then perhaps we explore another approach.
Quoted 45 lines
Quoted 32 lines
drivers/gpu/drm/scheduler/sched_main.c +11
-1job->sched = sched; - job->s_priority = entity->rq - sched->sched_rq; +if (!single_entity) + job->s_priority = entity->rq - sched->sched_rq; job->id =atomic64_inc_return (&sched->job_id_count);drm_sched_fence_init (job->s_fence, job->entity);@@ -896,6 +925,14 @@ drm_sched_select_entity(struct drm_gpu_scheduler *sched)if (!drm_sched_can_queue (sched))return NULL ; +if (sched->single_entity) { +if (!READ_ONCE (sched->single_entity->stopped) && +drm_sched_entity_is_ready (sched->single_entity)) +return sched->single_entity; + +return NULL ; + } +/* Kernel run queue has higher priority than normal run queue*/ for (i =DRM_SCHED_PRIORITY_COUNT -1 ; i >=DRM_SCHED_PRIORITY_MIN ; i--) { entity = sched->sched_policy == DRM_SCHED_POLICY_FIFO ?@@ -1092,6 +1129,7 @@ int drm_sched_init(struct drm_gpu_scheduler *sched,return -EINVAL ; sched->ops = ops; + sched->single_entity =NULL ; sched->hw_submission_limit = hw_submission; sched->name = name;if (!submit_wq) {drivers/gpu/drm/scheduler/sched_main.c int drm_sched_init(struct drm_gpu_scheduler *sched, · line 1154
Quoted 7 lines
drivers/gpu/drm/scheduler/sched_main.c +3
-1@@ -1111,7 +1149,9 @@ int drm_sched_init(struct drm_gpu_scheduler *sched, sched->dev = dev; sched->sched_policy = sched_policy ==DRM_SCHED_POLICY_UNSET ? drm_sched_policy_default : sched_policy; -for (i =DRM_SCHED_PRIORITY_MIN ; i <DRM_SCHED_PRIORITY_COUNT ; i++) +for (i =DRM_SCHED_PRIORITY_MIN ; sched_policy != +DRM_SCHED_POLICY_SINGLE_ENTITY && i <DRM_SCHED_PRIORITY_COUNT ; + i++)So, "
sched_policy!=DRM_SCHED_POLICY_SINGLE_ENTITY" doesn't seem to be a loop-invariant, since it doesn't cause the loop to exit over iterations. It's just a gate to executing the loop. I am used to seeing only loop invariants in the for-loop conditional.
Quoted 7 lines
I wonder if it is clearer to just say what is meant:
if (sched_policy != DRM_SCHED_POLICY_SINGLE_ENTITY) { for (i = DRM_SCHED_PRIORITY_MIN; i < DRM_SCHED_PRIORITY_COUNT; i++) ... }
Sure, will add if statement.
Quoted 20 lines
On a larger scheme of things, I believe it is a bit presumptuous to say:
struct drm_gpu_scheduler { ... struct drm_sched_rq sched_rq[DRM_SCHED_PRIORITY_COUNT]; ... };I mean, why does a scheduler have to implement all those priorities? Maybe it wants to implement only one. :-)
Perhaps we can have,
struct drm_gpu_scheduler { ... u32 num_rqs; struct drm_sched_rq *sched_rq; ... };
Quoted 6 lines
Which might make it easier to fake out an rq for single-entity and then leave the code mostly intact, while also implementing single-entity.
It's not a gating issue, but perhaps it would create a cleaner code in the long run? Maybe we should explore this?
See above. I'd vote for leave this as is for now.
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/scheduler/sched_main.c +0
-0drm_sched_rq_init (sched, &sched->sched_rq[i]);init_waitqueue_head (&sched->job_scheduled);@@ -1143,7 +1183,15 @@ void drm_sched_fini(struct drm_gpu_scheduler *sched)drm_sched_submit_stop (sched);
Quoted 13 lines
drivers/gpu/drm/scheduler/sched_main.c void drm_sched_fini(struct drm_gpu_scheduler *sched) · line 1195
Quoted 11 lines
drivers/gpu/drm/scheduler/sched_main.c +9
-1-for (i =DRM_SCHED_PRIORITY_COUNT -1 ; i >=DRM_SCHED_PRIORITY_MIN ; i--) { +if (sched->single_entity) { +spin_lock (&sched->single_entity->rq_lock); + sched->single_entity->stopped = true; +spin_unlock (&sched->single_entity->rq_lock); + } + +for (i =DRM_SCHED_PRIORITY_COUNT -1 ; sched->sched_policy != +DRM_SCHED_POLICY_SINGLE_ENTITY && i >=DRM_SCHED_PRIORITY_MIN ; + i--) {struct drm_sched_rq *rq = &sched->sched_rq[i];Same sentiment here, as above.
Got it.
Matt
Quoted 63 lines
Signature · 2 lines
Regards, LubenQuoted 58 lines
drivers/gpu/drm/scheduler/sched_main.c +2
-0spin_lock (&rq->lock);@@ -1186,6 +1234,8 @@ void drm_sched_increase_karma(struct drm_sched_job *bad)struct drm_sched_entity *entity;struct drm_gpu_scheduler *sched = bad->sched; +WARN_ON (sched->sched_policy ==DRM_SCHED_POLICY_SINGLE_ENTITY ); +/* don't change @bad's karma if it's from KERNEL RQ, * because sometimes GPU hang would cause kernel jobs (like VM updating jobs) * corrupt but keep in mind that kernel jobs always considered good. include/drm/gpu_scheduler.h +8
-0@@ -79,6 +79,7 @@ enum drm_sched_policy {DRM_SCHED_POLICY_UNSET ,DRM_SCHED_POLICY_RR ,DRM_SCHED_POLICY_FIFO , +DRM_SCHED_POLICY_SINGLE_ENTITY , DRM_SCHED_POLICY_COUNT, };@@ -112,6 +113,9 @@ struct drm_sched_entity {*/ struct drm_sched_rq *rq; +/** @single_sched: Single scheduler */ +struct drm_gpu_scheduler *single_sched; +/** * @sched_list: * @@ -473,6 +477,7 @@ struct drm_sched_backend_ops {* struct drm_gpu_scheduler - scheduler instance-specific data * * @ops: backend operations provided by the driver. +* @single_entity: Single entity for the scheduler * @hw_submission_limit: the max size of the hardware queue. * @timeout: the time after which a job is removed from the scheduler. * @name: name of the ring for which this scheduler is being used. @@ -504,6 +509,7 @@ struct drm_sched_backend_ops {*/ struct drm_gpu_scheduler {const struct drm_sched_backend_ops *ops; +struct drm_sched_entity *single_entity;uint32_t hw_submission_limit;long timeout;const char *name;@@ -587,6 +593,8 @@ int drm_sched_entity_init(struct drm_sched_entity *entity,struct drm_gpu_scheduler **sched_list, unsigned int num_sched_list, atomic_t *guilty); +struct drm_gpu_scheduler * +drm_sched_entity_to_scheduler (struct drm_sched_entity *entity);long drm_sched_entity_flush (struct drm_sched_entity *entity,long timeout);void drm_sched_entity_fini (struct drm_sched_entity *entity);void drm_sched_entity_destroy (struct drm_sched_entity *entity);
Matthew Brost
maintainerPATCH v4 5/10 drm/sched: Split free_job into own work item
In reply to Matthew BrostRather than call free_job and run_job in same work item have a dedicated work item for each. This aligns with the design and intended use of work queues.
v2:
- Test for DMA_FENCE_FLAG_TIMESTAMP_BIT before setting timestamp in free_job() work item (Danilo)
v3:
- Drop forward dec of drm_sched_select_entity (Boris)
- Return in drm_sched_run_job_work if entity NULL (Boris)
--- drivers/gpu/drm/scheduler/sched_main.c | 290 +++++++++++++++---------- include/drm/gpu_scheduler.h | 8 +- 2 files changed, 182 insertions(+), 116 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +177 -113
@@ -213,11 +213,12 @@ void drm_sched_rq_remove_entity(struct drm_sched_rq *rq,* drm_sched_rq_select_entity_rr - Select an entity which could provide a job to run * * @rq: scheduler run queue to check. +* @dequeue: dequeue selected entity * * Try to find a ready entity, returns NULL if none found. */ static struct drm_sched_entity * -drm_sched_rq_select_entity_rr (struct drm_sched_rq *rq) +drm_sched_rq_select_entity_rr (struct drm_sched_rq *rq,bool dequeue) {struct drm_sched_entity *entity;
@@ -227,8 +228,10 @@ drm_sched_rq_select_entity_rr(struct drm_sched_rq *rq)if (entity) {list_for_each_entry_continue (entity, &rq->entities, list) {if (drm_sched_entity_is_ready (entity)) { - rq->current_entity = entity; -reinit_completion (&entity->entity_idle); +if (dequeue) { + rq->current_entity = entity; +reinit_completion (&entity->entity_idle); + }spin_unlock (&rq->lock);return entity; }
@@ -238,8 +241,10 @@ drm_sched_rq_select_entity_rr(struct drm_sched_rq *rq)list_for_each_entry (entity, &rq->entities, list) {if (drm_sched_entity_is_ready (entity)) { - rq->current_entity = entity; -reinit_completion (&entity->entity_idle); +if (dequeue) { + rq->current_entity = entity; +reinit_completion (&entity->entity_idle); + }spin_unlock (&rq->lock);return entity; }
@@ -257,11 +262,12 @@ drm_sched_rq_select_entity_rr(struct drm_sched_rq *rq)* drm_sched_rq_select_entity_fifo - Select an entity which provides a job to run * * @rq: scheduler run queue to check. +* @dequeue: dequeue selected entity * * Find oldest waiting ready entity, returns NULL if none found. */ static struct drm_sched_entity * -drm_sched_rq_select_entity_fifo (struct drm_sched_rq *rq) +drm_sched_rq_select_entity_fifo (struct drm_sched_rq *rq,bool dequeue) {struct rb_node *rb;
@@ -271,8 +277,10 @@ drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) entity = rb_entry(rb, struct drm_sched_entity, rb_tree_node);if (drm_sched_entity_is_ready (entity)) { - rq->current_entity = entity; -reinit_completion (&entity->entity_idle); +if (dequeue) { + rq->current_entity = entity; +reinit_completion (&entity->entity_idle); + }break ; } }
@@ -282,13 +290,102 @@ drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) }/** -* drm_sched_submit_queue - scheduler queue submission +* drm_sched_run_job_queue - queue job submission +* @sched: scheduler instance +*/ +static void drm_sched_run_job_queue (struct drm_gpu_scheduler *sched) +{ +if (!READ_ONCE (sched->pause_submit)) +queue_work (sched->submit_wq, &sched->work_run_job); +} + +/** +* drm_sched_can_queue -- Can we queue more to the hardware? +* @sched: scheduler instance +* +* Return true if we can push more jobs to the hw, otherwise false. +*/ +static bool drm_sched_can_queue (struct drm_gpu_scheduler *sched) +{ +return atomic_read (&sched->hw_rq_count) < + sched->hw_submission_limit; +} + +/** +* drm_sched_select_entity - Select next entity to process +* +* @sched: scheduler instance +* @dequeue: dequeue selected entity +* +* Returns the entity to process or NULL if none are found. +*/ +static struct drm_sched_entity * +drm_sched_select_entity (struct drm_gpu_scheduler *sched,bool dequeue) +{ +struct drm_sched_entity *entity; +int i; + +if (!drm_sched_can_queue (sched)) +return NULL ; + +if (sched->single_entity) { +if (!READ_ONCE (sched->single_entity->stopped) && +drm_sched_entity_is_ready (sched->single_entity)) +return sched->single_entity; + +return NULL ; + } + +/* Kernel run queue has higher priority than normal run queue*/ +for (i =DRM_SCHED_PRIORITY_COUNT -1 ; i >=DRM_SCHED_PRIORITY_MIN ; i--) { + entity = sched->sched_policy ==DRM_SCHED_POLICY_FIFO ? +drm_sched_rq_select_entity_fifo (&sched->sched_rq[i], + dequeue) : +drm_sched_rq_select_entity_rr (&sched->sched_rq[i], + dequeue); +if (entity) +break ; + } + +return entity; +} + +/** +* drm_sched_run_job_queue_if_ready - queue job submission if ready * @sched: scheduler instance */ -static void drm_sched_submit_queue (struct drm_gpu_scheduler *sched) +static void drm_sched_run_job_queue_if_ready (struct drm_gpu_scheduler *sched) +{ +if (drm_sched_select_entity (sched, false)) +drm_sched_run_job_queue (sched); +} + +/** +* drm_sched_free_job_queue - queue free job +* +* @sched: scheduler instance to queue free job +*/ +static void drm_sched_free_job_queue (struct drm_gpu_scheduler *sched) {if (!READ_ONCE (sched->pause_submit)) -queue_work (sched->submit_wq, &sched->work_submit); +queue_work (sched->submit_wq, &sched->work_free_job); +} + +/** +* drm_sched_free_job_queue_if_ready - queue free job if ready +* +* @sched: scheduler instance to queue free job +*/ +static void drm_sched_free_job_queue_if_ready (struct drm_gpu_scheduler *sched) +{ +struct drm_sched_job *job; + +spin_lock (&sched->job_list_lock); + job =list_first_entry_or_null (&sched->pending_list, + struct drm_sched_job, list); +if (job &&dma_fence_is_signaled (&job->s_fence->finished)) +drm_sched_free_job_queue (sched); +spin_unlock (&sched->job_list_lock); }/**
@@ -310,7 +407,7 @@ static void drm_sched_job_done(struct drm_sched_job *s_job, int result)dma_fence_get (&s_fence->finished);drm_sched_fence_finished (s_fence, result);dma_fence_put (&s_fence->finished); -drm_sched_submit_queue (sched); +drm_sched_free_job_queue (sched); }/**
@@ -885,18 +982,6 @@ void drm_sched_job_cleanup(struct drm_sched_job *job) }EXPORT_SYMBOL (drm_sched_job_cleanup); -/** -* drm_sched_can_queue -- Can we queue more to the hardware? -* @sched: scheduler instance -* -* Return true if we can push more jobs to the hw, otherwise false. -*/ -static bool drm_sched_can_queue (struct drm_gpu_scheduler *sched) -{ -return atomic_read (&sched->hw_rq_count) < - sched->hw_submission_limit; -} -/** * drm_sched_wakeup_if_can_queue - Wake up the scheduler * @sched: scheduler instance
@@ -906,43 +991,7 @@ static bool drm_sched_can_queue(struct drm_gpu_scheduler *sched)void drm_sched_wakeup_if_can_queue (struct drm_gpu_scheduler *sched) {if (drm_sched_can_queue (sched)) -drm_sched_submit_queue (sched); -} - -/** -* drm_sched_select_entity - Select next entity to process -* -* @sched: scheduler instance -* -* Returns the entity to process or NULL if none are found. -*/ -static struct drm_sched_entity * -drm_sched_select_entity (struct drm_gpu_scheduler *sched) -{ -struct drm_sched_entity *entity; -int i; - -if (!drm_sched_can_queue (sched)) -return NULL ; - -if (sched->single_entity) { -if (!READ_ONCE (sched->single_entity->stopped) && -drm_sched_entity_is_ready (sched->single_entity)) -return sched->single_entity; - -return NULL ; - } - -/* Kernel run queue has higher priority than normal run queue*/ -for (i =DRM_SCHED_PRIORITY_COUNT -1 ; i >=DRM_SCHED_PRIORITY_MIN ; i--) { - entity = sched->sched_policy ==DRM_SCHED_POLICY_FIFO ? -drm_sched_rq_select_entity_fifo (&sched->sched_rq[i]) : -drm_sched_rq_select_entity_rr (&sched->sched_rq[i]); -if (entity) -break ; - } - -return entity; +drm_sched_run_job_queue (sched); }/**
@@ -974,8 +1023,10 @@ drm_sched_get_cleanup_job(struct drm_gpu_scheduler *sched) typeof(*next), list);if (next) { - next->s_fence->scheduled.timestamp = - job->s_fence->finished.timestamp; +if (test_bit (DMA_FENCE_FLAG_TIMESTAMP_BIT , + &next->s_fence->scheduled.flags)) + next->s_fence->scheduled.timestamp = + job->s_fence->finished.timestamp;/* start TO timer for next job */ drm_sched_start_timeout (sched); }
@@ -1025,74 +1076,84 @@ drm_sched_pick_best(struct drm_gpu_scheduler **sched_list,EXPORT_SYMBOL (drm_sched_pick_best);/** -* drm_sched_main - main scheduler thread +* drm_sched_free_job_work - worker to call free_job * -* @param: scheduler instance +* @w: free job work */ -static void drm_sched_main (struct work_struct *w) +static void drm_sched_free_job_work (struct work_struct *w) {struct drm_gpu_scheduler *sched = - container_of(w, struct drm_gpu_scheduler, work_submit); -struct drm_sched_entity *entity; + container_of(w, struct drm_gpu_scheduler, work_free_job);struct drm_sched_job *cleanup_job; -int r;if (READ_ONCE (sched->pause_submit))return ; cleanup_job =drm_sched_get_cleanup_job (sched); - entity =drm_sched_select_entity (sched); - -if (!entity && !cleanup_job) -return ;/* No more work */ - -if (cleanup_job) +if (cleanup_job) { sched->ops->free_job (cleanup_job); -if (entity) { -struct dma_fence *fence; -struct drm_sched_fence *s_fence; -struct drm_sched_job *sched_job; - - sched_job =drm_sched_entity_pop_job (entity); -if (!sched_job) { -complete_all (&entity->entity_idle); -if (!cleanup_job) -return ;/* No more work */ - goto again; - } +drm_sched_free_job_queue_if_ready (sched); +drm_sched_run_job_queue_if_ready (sched); + } +} + +/** +* drm_sched_run_job_work - worker to call run_job +* +* @w: run job work +*/ +static void drm_sched_run_job_work (struct work_struct *w) +{ +struct drm_gpu_scheduler *sched = + container_of(w, struct drm_gpu_scheduler, work_run_job); +struct drm_sched_entity *entity; +struct dma_fence *fence; +struct drm_sched_fence *s_fence; +struct drm_sched_job *sched_job; +int r; - s_fence = sched_job->s_fence; +if (READ_ONCE (sched->pause_submit)) +return ; -atomic_inc (&sched->hw_rq_count); -drm_sched_job_begin (sched_job); + entity =drm_sched_select_entity (sched, true); +if (!entity) +return ; -trace_drm_run_job (sched_job, entity); - fence = sched->ops->run_job (sched_job); + sched_job =drm_sched_entity_pop_job (entity); +if (!sched_job) {complete_all (&entity->entity_idle); -drm_sched_fence_scheduled (s_fence, fence); +return ;/* No more work */ + } -if (!IS_ERR_OR_NULL (fence)) { -/* Drop for original kref_init of the fence */ -dma_fence_put (fence); + s_fence = sched_job->s_fence; - r =dma_fence_add_callback (fence, &sched_job->cb, - drm_sched_job_done_cb); -if (r == -ENOENT ) -drm_sched_job_done (sched_job, fence->error); -else if (r) -DRM_DEV_ERROR (sched->dev,"fence add callback failed (%d)\n" , - r); - }else { -drm_sched_job_done (sched_job,IS_ERR (fence) ? -PTR_ERR (fence) :0 ); - } +atomic_inc (&sched->hw_rq_count); +drm_sched_job_begin (sched_job); + +trace_drm_run_job (sched_job, entity); + fence = sched->ops->run_job (sched_job); +complete_all (&entity->entity_idle); +drm_sched_fence_scheduled (s_fence, fence); -wake_up (&sched->job_scheduled); +if (!IS_ERR_OR_NULL (fence)) { +/* Drop for original kref_init of the fence */ +dma_fence_put (fence); + + r =dma_fence_add_callback (fence, &sched_job->cb, + drm_sched_job_done_cb); +if (r == -ENOENT ) +drm_sched_job_done (sched_job, fence->error); +else if (r) +DRM_DEV_ERROR (sched->dev,"fence add callback failed (%d)\n" , + r); + }else { +drm_sched_job_done (sched_job,IS_ERR (fence) ? +PTR_ERR (fence) :0 ); } -again: -drm_sched_submit_queue (sched); +wake_up (&sched->job_scheduled); +drm_sched_run_job_queue_if_ready (sched); }/**
@@ -1159,7 +1220,8 @@ int drm_sched_init(struct drm_gpu_scheduler *sched,spin_lock_init (&sched->job_list_lock);atomic_set (&sched->hw_rq_count,0 );INIT_DELAYED_WORK (&sched->work_tdr, drm_sched_job_timedout); -INIT_WORK (&sched->work_submit, drm_sched_main); +INIT_WORK (&sched->work_run_job, drm_sched_run_job_work); +INIT_WORK (&sched->work_free_job, drm_sched_free_job_work);atomic_set (&sched->_score,0 );atomic64_set (&sched->job_id_count,0 ); sched->pause_submit = false;
@@ -1286,7 +1348,8 @@ EXPORT_SYMBOL(drm_sched_submit_ready);void drm_sched_submit_stop (struct drm_gpu_scheduler *sched) {WRITE_ONCE (sched->pause_submit, true); -cancel_work_sync (&sched->work_submit); +cancel_work_sync (&sched->work_run_job); +cancel_work_sync (&sched->work_free_job); }EXPORT_SYMBOL (drm_sched_submit_stop);
@@ -1298,6 +1361,7 @@ EXPORT_SYMBOL(drm_sched_submit_stop);void drm_sched_submit_start (struct drm_gpu_scheduler *sched) {WRITE_ONCE (sched->pause_submit, false); -queue_work (sched->submit_wq, &sched->work_submit); +queue_work (sched->submit_wq, &sched->work_run_job); +queue_work (sched->submit_wq, &sched->work_free_job); }EXPORT_SYMBOL (drm_sched_submit_start);
include/drm/gpu_scheduler.h +5 -3
@@ -487,9 +487,10 @@ struct drm_sched_backend_ops {* finished. * @hw_rq_count: the number of jobs currently in the hardware queue. * @job_id_count: used to assign unique id to the each job. -* @submit_wq: workqueue used to queue @work_submit +* @submit_wq: workqueue used to queue @work_run_job and @work_free_job * @timeout_wq: workqueue used to queue @work_tdr -* @work_submit: schedules jobs and cleans up entities +* @work_run_job: schedules jobs +* @work_free_job: cleans up jobs * @work_tdr: schedules a delayed call to @drm_sched_job_timedout after the * timeout interval is over. * @pending_list: the list of jobs which are currently in the job queue.
@@ -519,7 +520,8 @@ struct drm_gpu_scheduler {atomic64_t job_id_count;struct workqueue_struct *submit_wq;struct workqueue_struct *timeout_wq; -struct work_struct work_submit; +struct work_struct work_run_job; +struct work_struct work_free_job;struct delayed_work work_tdr;struct list_head pending_list;spinlock_t job_list_lock;
Signature · 1 line
2.34.1
Re: [PATCH v4 05/10] drm/sched: Split free_job into own work item
Quoted 22 lines · Matthew Brost
Rather than call
free_jobandrun_jobin same work item have a dedicated work item for each. This aligns with the design and intended use of work queues.v2:
- Test forDMA_FENCE_FLAG_TIMESTAMP_BITbefore setting timestamp infree_job()work item (Danilo)
v3:
- Drop forward dec ofdrm_sched_select_entity(Boris)
- Return indrm_sched_run_job_workif entity NULL (Boris)Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/scheduler/sched_main.c | 290 +++++++++++++++---------- include/drm/gpu_scheduler.h | 8 +- 2 files changed, 182 insertions(+), 116 deletions(-)drivers/gpu/drm/scheduler/sched_main.c +0
-0
drivers/gpu/drm/scheduler/sched_main.c void drm_sched_rq_remove_entity(struct drm_sched_rq *rq, · line 216
Quoted 4 lines
drivers/gpu/drm/scheduler/sched_main.c +1
-0@@ -213,11 +213,12 @@ void drm_sched_rq_remove_entity(struct drm_sched_rq *rq,* drm_sched_rq_select_entity_rr - Select an entity which could provide a job to run * * @rq: scheduler run queue to check. +* @dequeue: dequeue selected entity
Change this to "peek" as indicated below.
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +1
-1* * Try to find a ready entity, returns NULL if none found. */ static struct drm_sched_entity * -drm_sched_rq_select_entity_rr (struct drm_sched_rq *rq) +drm_sched_rq_select_entity_rr (struct drm_sched_rq *rq,bool dequeue) {struct drm_sched_entity *entity;
drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_rr(struct drm_sched_rq *rq) · line 234
Quoted 9 lines
drivers/gpu/drm/scheduler/sched_main.c +4
-2@@ -227,8 +228,10 @@ drm_sched_rq_select_entity_rr(struct drm_sched_rq *rq)if (entity) {list_for_each_entry_continue (entity, &rq->entities, list) {if (drm_sched_entity_is_ready (entity)) { - rq->current_entity = entity; -reinit_completion (&entity->entity_idle); +if (dequeue) { + rq->current_entity = entity; +reinit_completion (&entity->entity_idle); + }
Please rename "dequeue" or invert its logic, as from this patch it seems that it is hiding (gating out) current behaviour.
Ideally, I'd prefer it be inverted, so that current behaviour, i.e. what people are used to the rq_select_entity_*() to do, is default--preserved.
Perhaps use "peek" as the name of this new variable, to indicate that we're not setting it to be the current entity.
I prefer "peek" to others, as the former tells me "Hey, I'm only peeking at the rq and not really doing the default behaviour I've been doing which you're used to." So, probably use "peek". ("Peek" also has historical significance...).
drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_rr(struct drm_sched_rq *rq) · line 244
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +1
-2spin_unlock (&rq->lock);return entity; }@@ -238,8 +241,10 @@ drm_sched_rq_select_entity_rr(struct drm_sched_rq *rq)list_for_each_entry (entity, &rq->entities, list) {if (drm_sched_entity_is_ready (entity)) { - rq->current_entity = entity; -reinit_completion (&entity->entity_idle); +if (dequeue) {
if (!peek) {drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_rr(struct drm_sched_rq *rq) · line 265
Quoted 11 lines
drivers/gpu/drm/scheduler/sched_main.c +4
-0+ rq->current_entity = entity; +reinit_completion (&entity->entity_idle); + }spin_unlock (&rq->lock);return entity; }@@ -257,11 +262,12 @@ drm_sched_rq_select_entity_rr(struct drm_sched_rq *rq)* drm_sched_rq_select_entity_fifo - Select an entity which provides a job to run * * @rq: scheduler run queue to check. +* @dequeue: dequeue selected entity
* @peek: Just find, don't set to current.
Quoted 9 lines
drivers/gpu/drm/scheduler/sched_main.c +1
-1* * Find oldest waiting ready entity, returns NULL if none found.> */ static struct drm_sched_entity * -drm_sched_rq_select_entity_fifo (struct drm_sched_rq *rq) +drm_sched_rq_select_entity_fifo (struct drm_sched_rq *rq,bool dequeue) {struct rb_node *rb;
drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) · line 280
Quoted 6 lines
drivers/gpu/drm/scheduler/sched_main.c +1
-2@@ -271,8 +277,10 @@ drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) entity = rb_entry(rb, struct drm_sched_entity, rb_tree_node);if (drm_sched_entity_is_ready (entity)) { - rq->current_entity = entity; -reinit_completion (&entity->entity_idle); +if (dequeue) {
if (!peek) {Quoted 7 lines
drivers/gpu/drm/scheduler/sched_main.c +3
-0+ rq->current_entity = entity; +reinit_completion (&entity->entity_idle); + }break ; } }
drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) · line 295
Quoted 7 lines
drivers/gpu/drm/scheduler/sched_main.c +3
-1@@ -282,13 +290,102 @@ drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) }/** -* drm_sched_submit_queue - scheduler queue submission +* drm_sched_run_job_queue - queue job submission +* @sched: scheduler instance +*/
Perhaps it would be clearer to a DOC reader if there were verbs in this function comment? I feel this was mentioned in the review to patch 2...
Quoted 13 lines
drivers/gpu/drm/scheduler/sched_main.c +13
-0+static void drm_sched_run_job_queue (struct drm_gpu_scheduler *sched) +{ +if (!READ_ONCE (sched->pause_submit)) +queue_work (sched->submit_wq, &sched->work_run_job); +} + +/** +* drm_sched_can_queue -- Can we queue more to the hardware? +* @sched: scheduler instance +* +* Return true if we can push more jobs to the hw, otherwise false. +*/ +static bool drm_sched_can_queue (struct drm_gpu_scheduler *sched)
drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) · line 318
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +10
-0+{ +return atomic_read (&sched->hw_rq_count) < + sched->hw_submission_limit; +} + +/** +* drm_sched_select_entity - Select next entity to process +* +* @sched: scheduler instance +* @dequeue: dequeue selected entity
When I see "dequeue" I'm thinking "list_del()". Let's use "peek" here as mentioned above.
drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) · line 323
Quoted 5 lines
drivers/gpu/drm/scheduler/sched_main.c +5
-0+* +* Returns the entity to process or NULL if none are found. +*/ +static struct drm_sched_entity * +drm_sched_select_entity (struct drm_gpu_scheduler *sched,bool dequeue)
drm_sched_select_entity(struct drm_gpu_scheduler *sched, bool peek)
Quoted 32 lines
drivers/gpu/drm/scheduler/sched_main.c +31
-0+{ +struct drm_sched_entity *entity; +int i; + +if (!drm_sched_can_queue (sched)) +return NULL ; + +if (sched->single_entity) { +if (!READ_ONCE (sched->single_entity->stopped) && +drm_sched_entity_is_ready (sched->single_entity)) +return sched->single_entity; + +return NULL ; + } + +/* Kernel run queue has higher priority than normal run queue*/ +for (i =DRM_SCHED_PRIORITY_COUNT -1 ; i >=DRM_SCHED_PRIORITY_MIN ; i--) { + entity = sched->sched_policy ==DRM_SCHED_POLICY_FIFO ? +drm_sched_rq_select_entity_fifo (&sched->sched_rq[i], + dequeue) : +drm_sched_rq_select_entity_rr (&sched->sched_rq[i], + dequeue); +if (entity) +break ; + } + +return entity; +} + +/** +* drm_sched_run_job_queue_if_ready - queue job submission if ready * @sched: scheduler instance
drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) · line 364
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +8
-1*/ -static void drm_sched_submit_queue (struct drm_gpu_scheduler *sched) +static void drm_sched_run_job_queue_if_ready (struct drm_gpu_scheduler *sched) +{ +if (drm_sched_select_entity (sched, false)) +drm_sched_run_job_queue (sched); +} + +/** +* drm_sched_free_job_queue - queue free job
* drm_sched_free_job_queue - enqueue free-job work
drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) · line 366
Quoted 2 lines
drivers/gpu/drm/scheduler/sched_main.c +2
-0+* +* @sched: scheduler instance to queue free job
* @sched: scheduler instance to queue free job work for
drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) · line 375
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +7
-1+*/ +static void drm_sched_free_job_queue (struct drm_gpu_scheduler *sched) {if (!READ_ONCE (sched->pause_submit)) -queue_work (sched->submit_wq, &sched->work_submit); +queue_work (sched->submit_wq, &sched->work_free_job); +} + +/** +* drm_sched_free_job_queue_if_ready - queue free job if ready
* drm_sched_free_job_queue_if_ready - enqueue free-job work if ready
Quoted 212 lines
drivers/gpu/drm/scheduler/sched_main.c +61
-97+* +* @sched: scheduler instance to queue free job +*/ +static void drm_sched_free_job_queue_if_ready (struct drm_gpu_scheduler *sched) +{ +struct drm_sched_job *job; + +spin_lock (&sched->job_list_lock); + job =list_first_entry_or_null (&sched->pending_list, + struct drm_sched_job, list); +if (job &&dma_fence_is_signaled (&job->s_fence->finished)) +drm_sched_free_job_queue (sched); +spin_unlock (&sched->job_list_lock); }/** @@ -310,7 +407,7 @@ static void drm_sched_job_done(struct drm_sched_job *s_job, int result)dma_fence_get (&s_fence->finished);drm_sched_fence_finished (s_fence, result);dma_fence_put (&s_fence->finished); -drm_sched_submit_queue (sched); +drm_sched_free_job_queue (sched); }/** @@ -885,18 +982,6 @@ void drm_sched_job_cleanup(struct drm_sched_job *job) }EXPORT_SYMBOL (drm_sched_job_cleanup); -/** -* drm_sched_can_queue -- Can we queue more to the hardware? -* @sched: scheduler instance -* -* Return true if we can push more jobs to the hw, otherwise false. -*/ -static bool drm_sched_can_queue (struct drm_gpu_scheduler *sched) -{ -return atomic_read (&sched->hw_rq_count) < - sched->hw_submission_limit; -} -/** * drm_sched_wakeup_if_can_queue - Wake up the scheduler * @sched: scheduler instance @@ -906,43 +991,7 @@ static bool drm_sched_can_queue(struct drm_gpu_scheduler *sched)void drm_sched_wakeup_if_can_queue (struct drm_gpu_scheduler *sched) {if (drm_sched_can_queue (sched)) -drm_sched_submit_queue (sched); -} - -/** -* drm_sched_select_entity - Select next entity to process -* -* @sched: scheduler instance -* -* Returns the entity to process or NULL if none are found. -*/ -static struct drm_sched_entity * -drm_sched_select_entity (struct drm_gpu_scheduler *sched) -{ -struct drm_sched_entity *entity; -int i; - -if (!drm_sched_can_queue (sched)) -return NULL ; - -if (sched->single_entity) { -if (!READ_ONCE (sched->single_entity->stopped) && -drm_sched_entity_is_ready (sched->single_entity)) -return sched->single_entity; - -return NULL ; - } - -/* Kernel run queue has higher priority than normal run queue*/ -for (i =DRM_SCHED_PRIORITY_COUNT -1 ; i >=DRM_SCHED_PRIORITY_MIN ; i--) { - entity = sched->sched_policy ==DRM_SCHED_POLICY_FIFO ? -drm_sched_rq_select_entity_fifo (&sched->sched_rq[i]) : -drm_sched_rq_select_entity_rr (&sched->sched_rq[i]); -if (entity) -break ; - } - -return entity; +drm_sched_run_job_queue (sched); }/** @@ -974,8 +1023,10 @@ drm_sched_get_cleanup_job(struct drm_gpu_scheduler *sched) typeof(*next), list);if (next) { - next->s_fence->scheduled.timestamp = - job->s_fence->finished.timestamp; +if (test_bit (DMA_FENCE_FLAG_TIMESTAMP_BIT , + &next->s_fence->scheduled.flags)) + next->s_fence->scheduled.timestamp = + job->s_fence->finished.timestamp;/* start TO timer for next job */ drm_sched_start_timeout (sched); }@@ -1025,74 +1076,84 @@ drm_sched_pick_best(struct drm_gpu_scheduler **sched_list,EXPORT_SYMBOL (drm_sched_pick_best);/** -* drm_sched_main - main scheduler thread +* drm_sched_free_job_work - worker to call free_job * -* @param: scheduler instance +* @w: free job work */ -static void drm_sched_main (struct work_struct *w) +static void drm_sched_free_job_work (struct work_struct *w) {struct drm_gpu_scheduler *sched = - container_of(w, struct drm_gpu_scheduler, work_submit); -struct drm_sched_entity *entity; + container_of(w, struct drm_gpu_scheduler, work_free_job);struct drm_sched_job *cleanup_job; -int r;if (READ_ONCE (sched->pause_submit))return ; cleanup_job =drm_sched_get_cleanup_job (sched); - entity =drm_sched_select_entity (sched); - -if (!entity && !cleanup_job) -return ;/* No more work */ - -if (cleanup_job) +if (cleanup_job) { sched->ops->free_job (cleanup_job); -if (entity) { -struct dma_fence *fence; -struct drm_sched_fence *s_fence; -struct drm_sched_job *sched_job; - - sched_job =drm_sched_entity_pop_job (entity); -if (!sched_job) { -complete_all (&entity->entity_idle); -if (!cleanup_job) -return ;/* No more work */ - goto again; - } +drm_sched_free_job_queue_if_ready (sched); +drm_sched_run_job_queue_if_ready (sched); + } +} + +/** +* drm_sched_run_job_work - worker to call run_job +* +* @w: run job work +*/ +static void drm_sched_run_job_work (struct work_struct *w) +{ +struct drm_gpu_scheduler *sched = + container_of(w, struct drm_gpu_scheduler, work_run_job); +struct drm_sched_entity *entity; +struct dma_fence *fence; +struct drm_sched_fence *s_fence; +struct drm_sched_job *sched_job; +int r; - s_fence = sched_job->s_fence; +if (READ_ONCE (sched->pause_submit)) +return ; -atomic_inc (&sched->hw_rq_count); -drm_sched_job_begin (sched_job); + entity =drm_sched_select_entity (sched, true); +if (!entity) +return ; -trace_drm_run_job (sched_job, entity); - fence = sched->ops->run_job (sched_job); + sched_job =drm_sched_entity_pop_job (entity); +if (!sched_job) {complete_all (&entity->entity_idle); -drm_sched_fence_scheduled (s_fence, fence); +return ;/* No more work */ + } -if (!IS_ERR_OR_NULL (fence)) { -/* Drop for original kref_init of the fence */ -dma_fence_put (fence); + s_fence = sched_job->s_fence; - r =dma_fence_add_callback (fence, &sched_job->cb, - drm_sched_job_done_cb); -if (r == -ENOENT ) -drm_sched_job_done (sched_job, fence->error); -else if (r) -DRM_DEV_ERROR (sched->dev,"fence add callback failed (%d)\n" , - r); - }else { -drm_sched_job_done (sched_job,IS_ERR (fence) ? -PTR_ERR (fence) :0 ); - } +atomic_inc (&sched->hw_rq_count); +drm_sched_job_begin (sched_job); + +trace_drm_run_job (sched_job, entity); + fence = sched->ops->run_job (sched_job); +complete_all (&entity->entity_idle); +drm_sched_fence_scheduled (s_fence, fence); -wake_up (&sched->job_scheduled); +if (!IS_ERR_OR_NULL (fence)) {
drivers/gpu/drm/scheduler/sched_main.c drm_sched_pick_best(struct drm_gpu_scheduler **sched_list, · line 1149
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +10
-0+/* Drop for original kref_init of the fence */ +dma_fence_put (fence); + + r =dma_fence_add_callback (fence, &sched_job->cb, + drm_sched_job_done_cb); +if (r == -ENOENT ) +drm_sched_job_done (sched_job, fence->error); +else if (r) +DRM_DEV_ERROR (sched->dev,"fence add callback failed (%d)\n" , + r);
Please align "r);" to the open brace on the previous line. If you're using Emacs with sane Linux settings, press the "Tab" key anywhere on the line to indent it. (It should run c-indent-line-or-region, usually using leading-tabs-only mode. Pressing it again, over and over, on an already indented line, does nothing. Column indenting--say for columns in 2D/3D/etc., array, usually happens using spaces, which is portable. Also please take an overview with "scrips/checkpatch.pl --strict".)
Wrap-around was bumped to 100 in the Linux kernel so you can put the 'r' on the same line without style problems.
Quoted 59 lines
drivers/gpu/drm/scheduler/sched_main.c +11
-5+ }else { +drm_sched_job_done (sched_job,IS_ERR (fence) ? +PTR_ERR (fence) :0 ); } -again: -drm_sched_submit_queue (sched); +wake_up (&sched->job_scheduled); +drm_sched_run_job_queue_if_ready (sched); }/** @@ -1159,7 +1220,8 @@ int drm_sched_init(struct drm_gpu_scheduler *sched,spin_lock_init (&sched->job_list_lock);atomic_set (&sched->hw_rq_count,0 );INIT_DELAYED_WORK (&sched->work_tdr, drm_sched_job_timedout); -INIT_WORK (&sched->work_submit, drm_sched_main); +INIT_WORK (&sched->work_run_job, drm_sched_run_job_work); +INIT_WORK (&sched->work_free_job, drm_sched_free_job_work);atomic_set (&sched->_score,0 );atomic64_set (&sched->job_id_count,0 ); sched->pause_submit = false;@@ -1286,7 +1348,8 @@ EXPORT_SYMBOL(drm_sched_submit_ready);void drm_sched_submit_stop (struct drm_gpu_scheduler *sched) {WRITE_ONCE (sched->pause_submit, true); -cancel_work_sync (&sched->work_submit); +cancel_work_sync (&sched->work_run_job); +cancel_work_sync (&sched->work_free_job); }EXPORT_SYMBOL (drm_sched_submit_stop);@@ -1298,6 +1361,7 @@ EXPORT_SYMBOL(drm_sched_submit_stop);void drm_sched_submit_start (struct drm_gpu_scheduler *sched) {WRITE_ONCE (sched->pause_submit, false); -queue_work (sched->submit_wq, &sched->work_submit); +queue_work (sched->submit_wq, &sched->work_run_job); +queue_work (sched->submit_wq, &sched->work_free_job); }EXPORT_SYMBOL (drm_sched_submit_start);include/drm/gpu_scheduler.h +3
-2@@ -487,9 +487,10 @@ struct drm_sched_backend_ops {* finished. * @hw_rq_count: the number of jobs currently in the hardware queue. * @job_id_count: used to assign unique id to the each job. -* @submit_wq: workqueue used to queue @work_submit +* @submit_wq: workqueue used to queue @work_run_job and @work_free_job * @timeout_wq: workqueue used to queue @work_tdr -* @work_submit: schedules jobs and cleans up entities +* @work_run_job: schedules jobs +* @work_free_job: cleans up jobs * @work_tdr: schedules a delayed call to @drm_sched_job_timedout after the * timeout interval is over. * @pending_list: the list of jobs which are currently in the job queue.
include/drm/gpu_scheduler.h struct drm_gpu_scheduler { · line 527
Quoted 9 lines
include/drm/gpu_scheduler.h +2
-1@@ -519,7 +520,8 @@ struct drm_gpu_scheduler {atomic64_t job_id_count;struct workqueue_struct *submit_wq;struct workqueue_struct *timeout_wq; -struct work_struct work_submit; +struct work_struct work_run_job; +struct work_struct work_free_job;struct delayed_work work_tdr;struct list_head pending_list;spinlock_t job_list_lock;
Yeah, so this is a good patch. Thanks for doing this!
Signature · 2 lines
Regards, Luben
Matthew Brost
maintainerRe: [PATCH v4 05/10] drm/sched: Split free_job into own work item
Quoted 56 lines · Luben Tuikov
Quoted 22 lines · Matthew Brost
Rather than call
free_jobandrun_jobin same work item have a dedicated work item for each. This aligns with the design and intended use of work queues.v2:
- Test forDMA_FENCE_FLAG_TIMESTAMP_BITbefore setting timestamp infree_job()work item (Danilo)
v3:
- Drop forward dec ofdrm_sched_select_entity(Boris)
- Return indrm_sched_run_job_workif entity NULL (Boris)Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/scheduler/sched_main.c | 290 +++++++++++++++---------- include/drm/gpu_scheduler.h | 8 +- 2 files changed, 182 insertions(+), 116 deletions(-)drivers/gpu/drm/scheduler/sched_main.c +0
-0drivers/gpu/drm/scheduler/sched_main.c void drm_sched_rq_remove_entity(struct drm_sched_rq *rq, · line 216
Quoted 4 lines
drivers/gpu/drm/scheduler/sched_main.c +1
-0@@ -213,11 +213,12 @@ void drm_sched_rq_remove_entity(struct drm_sched_rq *rq,* drm_sched_rq_select_entity_rr - Select an entity which could provide a job to run * * @rq: scheduler run queue to check. +* @dequeue: dequeue selected entity Change this to "peek" as indicated below.
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +1
-1* * Try to find a ready entity, returns NULL if none found. */ static struct drm_sched_entity * -drm_sched_rq_select_entity_rr (struct drm_sched_rq *rq) +drm_sched_rq_select_entity_rr (struct drm_sched_rq *rq,bool dequeue) {struct drm_sched_entity *entity;drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_rr(struct drm_sched_rq *rq) · line 234
Quoted 9 lines
drivers/gpu/drm/scheduler/sched_main.c +4
-2@@ -227,8 +228,10 @@ drm_sched_rq_select_entity_rr(struct drm_sched_rq *rq)if (entity) {list_for_each_entry_continue (entity, &rq->entities, list) {if (drm_sched_entity_is_ready (entity)) { - rq->current_entity = entity; -reinit_completion (&entity->entity_idle); +if (dequeue) { + rq->current_entity = entity; +reinit_completion (&entity->entity_idle); + }Please rename "dequeue" or invert its logic, as from this patch it seems that it is hiding (gating out) current behaviour.
Ideally, I'd prefer it be inverted, so that current behaviour, i.e. what people are used to the rq_select_entity_*() to do, is default--preserved.
Quoted 8 lines
Perhaps use "peek" as the name of this new variable, to indicate that we're not setting it to be the current entity.
I prefer "peek" to others, as the former tells me "Hey, I'm only peeking at the rq and not really doing the default behaviour I've been doing which you're used to." So, probably use "peek". ("Peek" also has historical significance...).
Peek it is. Will change.
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/scheduler/sched_main.c +0
-0spin_unlock (&rq->lock);return entity; }@@ -238,8 +241,10 @@ drm_sched_rq_select_entity_rr(struct drm_sched_rq *rq)list_for_each_entry (entity, &rq->entities, list) {
Quoted 7 lines
drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_rr(struct drm_sched_rq *rq) · line 231
Quoted 4 lines
drivers/gpu/drm/scheduler/sched_main.c +1
-2if (drm_sched_entity_is_ready (entity)) { - rq->current_entity = entity; -reinit_completion (&entity->entity_idle); +if (dequeue) {if (!peek) {
+1
Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/scheduler/sched_main.c +3
-0+ rq->current_entity = entity; +reinit_completion (&entity->entity_idle); + }spin_unlock (&rq->lock);return entity;
Quoted 9 lines
drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_rr(struct drm_sched_rq *rq) · line 265
Quoted 6 lines
drivers/gpu/drm/scheduler/sched_main.c +1
-0}@@ -257,11 +262,12 @@ drm_sched_rq_select_entity_rr(struct drm_sched_rq *rq)* drm_sched_rq_select_entity_fifo - Select an entity which provides a job to run * * @rq: scheduler run queue to check. +* @dequeue: dequeue selected entity * @peek: Just find, don't set to current.
+1
Quoted 64 lines
Quoted 9 lines
drivers/gpu/drm/scheduler/sched_main.c +1
-1* * Find oldest waiting ready entity, returns NULL if none found.> */ static struct drm_sched_entity * -drm_sched_rq_select_entity_fifo (struct drm_sched_rq *rq) +drm_sched_rq_select_entity_fifo (struct drm_sched_rq *rq,bool dequeue) {struct rb_node *rb;drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) · line 280
Quoted 6 lines
drivers/gpu/drm/scheduler/sched_main.c +1
-2@@ -271,8 +277,10 @@ drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) entity = rb_entry(rb, struct drm_sched_entity, rb_tree_node);if (drm_sched_entity_is_ready (entity)) { - rq->current_entity = entity; -reinit_completion (&entity->entity_idle); +if (dequeue) {if (!peek) {Quoted 7 lines
drivers/gpu/drm/scheduler/sched_main.c +3
-0+ rq->current_entity = entity; +reinit_completion (&entity->entity_idle); + }break ; } }drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) · line 295
Quoted 7 lines
drivers/gpu/drm/scheduler/sched_main.c +3
-1@@ -282,13 +290,102 @@ drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) }/** -* drm_sched_submit_queue - scheduler queue submission +* drm_sched_run_job_queue - queue job submission +* @sched: scheduler instance +*/ Perhaps it would be clearer to a DOC reader if there were verbs in this function comment? I feel this was mentioned in the review to patch 2...
Quoted 13 lines
drivers/gpu/drm/scheduler/sched_main.c +13
-0+static void drm_sched_run_job_queue (struct drm_gpu_scheduler *sched) +{ +if (!READ_ONCE (sched->pause_submit)) +queue_work (sched->submit_wq, &sched->work_run_job); +} + +/** +* drm_sched_can_queue -- Can we queue more to the hardware? +* @sched: scheduler instance +* +* Return true if we can push more jobs to the hw, otherwise false. +*/ +static bool drm_sched_can_queue (struct drm_gpu_scheduler *sched)drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) · line 318
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +10
-0+{ +return atomic_read (&sched->hw_rq_count) < + sched->hw_submission_limit; +} + +/** +* drm_sched_select_entity - Select next entity to process +* +* @sched: scheduler instance +* @dequeue: dequeue selected entity When I see "dequeue" I'm thinking "
list_del()". Let's use "peek" here as mentioned above.
Quoted 8 lines
drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) · line 323
Quoted 5 lines
drivers/gpu/drm/scheduler/sched_main.c +5
-0+* +* Returns the entity to process or NULL if none are found. +*/ +static struct drm_sched_entity * +drm_sched_select_entity (struct drm_gpu_scheduler *sched,bool dequeue)
drm_sched_select_entity(struct drm_gpu_scheduler *sched, bool peek)
+1
Quoted 45 lines
Quoted 32 lines
drivers/gpu/drm/scheduler/sched_main.c +31
-0+{ +struct drm_sched_entity *entity; +int i; + +if (!drm_sched_can_queue (sched)) +return NULL ; + +if (sched->single_entity) { +if (!READ_ONCE (sched->single_entity->stopped) && +drm_sched_entity_is_ready (sched->single_entity)) +return sched->single_entity; + +return NULL ; + } + +/* Kernel run queue has higher priority than normal run queue*/ +for (i =DRM_SCHED_PRIORITY_COUNT -1 ; i >=DRM_SCHED_PRIORITY_MIN ; i--) { + entity = sched->sched_policy ==DRM_SCHED_POLICY_FIFO ? +drm_sched_rq_select_entity_fifo (&sched->sched_rq[i], + dequeue) : +drm_sched_rq_select_entity_rr (&sched->sched_rq[i], + dequeue); +if (entity) +break ; + } + +return entity; +} + +/** +* drm_sched_run_job_queue_if_ready - queue job submission if ready * @sched: scheduler instance drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) · line 364
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +8
-1*/ -static void drm_sched_submit_queue (struct drm_gpu_scheduler *sched) +static void drm_sched_run_job_queue_if_ready (struct drm_gpu_scheduler *sched) +{ +if (drm_sched_select_entity (sched, false)) +drm_sched_run_job_queue (sched); +} + +/** +* drm_sched_free_job_queue - queue free job *
drm_sched_free_job_queue- enqueue free-job work
Quoted 6 lines
drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) · line 366
Quoted 2 lines
drivers/gpu/drm/scheduler/sched_main.c +2
-0+* +* @sched: scheduler instance to queue free job * @sched: scheduler instance to queue free job work for
Will change both.
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/scheduler/sched_main.c +2
-0+*/ +static void drm_sched_free_job_queue (struct drm_gpu_scheduler *sched) {if (!READ_ONCE (sched->pause_submit))
Quoted 9 lines
drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) · line 375
Quoted 6 lines
drivers/gpu/drm/scheduler/sched_main.c +5
-1-queue_work (sched->submit_wq, &sched->work_submit); +queue_work (sched->submit_wq, &sched->work_free_job); +} + +/** +* drm_sched_free_job_queue_if_ready - queue free job if ready *
drm_sched_free_job_queue_if_ready- enqueue free-job work if ready
Will change this too.
Quoted 221 lines
Quoted 221 lines
drivers/gpu/drm/scheduler/sched_main.c +70
-97+* +* @sched: scheduler instance to queue free job +*/ +static void drm_sched_free_job_queue_if_ready (struct drm_gpu_scheduler *sched) +{ +struct drm_sched_job *job; + +spin_lock (&sched->job_list_lock); + job =list_first_entry_or_null (&sched->pending_list, + struct drm_sched_job, list); +if (job &&dma_fence_is_signaled (&job->s_fence->finished)) +drm_sched_free_job_queue (sched); +spin_unlock (&sched->job_list_lock); }/** @@ -310,7 +407,7 @@ static void drm_sched_job_done(struct drm_sched_job *s_job, int result)dma_fence_get (&s_fence->finished);drm_sched_fence_finished (s_fence, result);dma_fence_put (&s_fence->finished); -drm_sched_submit_queue (sched); +drm_sched_free_job_queue (sched); }/** @@ -885,18 +982,6 @@ void drm_sched_job_cleanup(struct drm_sched_job *job) }EXPORT_SYMBOL (drm_sched_job_cleanup); -/** -* drm_sched_can_queue -- Can we queue more to the hardware? -* @sched: scheduler instance -* -* Return true if we can push more jobs to the hw, otherwise false. -*/ -static bool drm_sched_can_queue (struct drm_gpu_scheduler *sched) -{ -return atomic_read (&sched->hw_rq_count) < - sched->hw_submission_limit; -} -/** * drm_sched_wakeup_if_can_queue - Wake up the scheduler * @sched: scheduler instance @@ -906,43 +991,7 @@ static bool drm_sched_can_queue(struct drm_gpu_scheduler *sched)void drm_sched_wakeup_if_can_queue (struct drm_gpu_scheduler *sched) {if (drm_sched_can_queue (sched)) -drm_sched_submit_queue (sched); -} - -/** -* drm_sched_select_entity - Select next entity to process -* -* @sched: scheduler instance -* -* Returns the entity to process or NULL if none are found. -*/ -static struct drm_sched_entity * -drm_sched_select_entity (struct drm_gpu_scheduler *sched) -{ -struct drm_sched_entity *entity; -int i; - -if (!drm_sched_can_queue (sched)) -return NULL ; - -if (sched->single_entity) { -if (!READ_ONCE (sched->single_entity->stopped) && -drm_sched_entity_is_ready (sched->single_entity)) -return sched->single_entity; - -return NULL ; - } - -/* Kernel run queue has higher priority than normal run queue*/ -for (i =DRM_SCHED_PRIORITY_COUNT -1 ; i >=DRM_SCHED_PRIORITY_MIN ; i--) { - entity = sched->sched_policy ==DRM_SCHED_POLICY_FIFO ? -drm_sched_rq_select_entity_fifo (&sched->sched_rq[i]) : -drm_sched_rq_select_entity_rr (&sched->sched_rq[i]); -if (entity) -break ; - } - -return entity; +drm_sched_run_job_queue (sched); }/** @@ -974,8 +1023,10 @@ drm_sched_get_cleanup_job(struct drm_gpu_scheduler *sched) typeof(*next), list);if (next) { - next->s_fence->scheduled.timestamp = - job->s_fence->finished.timestamp; +if (test_bit (DMA_FENCE_FLAG_TIMESTAMP_BIT , + &next->s_fence->scheduled.flags)) + next->s_fence->scheduled.timestamp = + job->s_fence->finished.timestamp;/* start TO timer for next job */ drm_sched_start_timeout (sched); }@@ -1025,74 +1076,84 @@ drm_sched_pick_best(struct drm_gpu_scheduler **sched_list,EXPORT_SYMBOL (drm_sched_pick_best);/** -* drm_sched_main - main scheduler thread +* drm_sched_free_job_work - worker to call free_job * -* @param: scheduler instance +* @w: free job work */ -static void drm_sched_main (struct work_struct *w) +static void drm_sched_free_job_work (struct work_struct *w) {struct drm_gpu_scheduler *sched = - container_of(w, struct drm_gpu_scheduler, work_submit); -struct drm_sched_entity *entity; + container_of(w, struct drm_gpu_scheduler, work_free_job);struct drm_sched_job *cleanup_job; -int r;if (READ_ONCE (sched->pause_submit))return ; cleanup_job =drm_sched_get_cleanup_job (sched); - entity =drm_sched_select_entity (sched); - -if (!entity && !cleanup_job) -return ;/* No more work */ - -if (cleanup_job) +if (cleanup_job) { sched->ops->free_job (cleanup_job); -if (entity) { -struct dma_fence *fence; -struct drm_sched_fence *s_fence; -struct drm_sched_job *sched_job; - - sched_job =drm_sched_entity_pop_job (entity); -if (!sched_job) { -complete_all (&entity->entity_idle); -if (!cleanup_job) -return ;/* No more work */ - goto again; - } +drm_sched_free_job_queue_if_ready (sched); +drm_sched_run_job_queue_if_ready (sched); + } +} + +/** +* drm_sched_run_job_work - worker to call run_job +* +* @w: run job work +*/ +static void drm_sched_run_job_work (struct work_struct *w) +{ +struct drm_gpu_scheduler *sched = + container_of(w, struct drm_gpu_scheduler, work_run_job); +struct drm_sched_entity *entity; +struct dma_fence *fence; +struct drm_sched_fence *s_fence; +struct drm_sched_job *sched_job; +int r; - s_fence = sched_job->s_fence; +if (READ_ONCE (sched->pause_submit)) +return ; -atomic_inc (&sched->hw_rq_count); -drm_sched_job_begin (sched_job); + entity =drm_sched_select_entity (sched, true); +if (!entity) +return ; -trace_drm_run_job (sched_job, entity); - fence = sched->ops->run_job (sched_job); + sched_job =drm_sched_entity_pop_job (entity); +if (!sched_job) {complete_all (&entity->entity_idle); -drm_sched_fence_scheduled (s_fence, fence); +return ;/* No more work */ + } -if (!IS_ERR_OR_NULL (fence)) { -/* Drop for original kref_init of the fence */ -dma_fence_put (fence); + s_fence = sched_job->s_fence; - r =dma_fence_add_callback (fence, &sched_job->cb, - drm_sched_job_done_cb); -if (r == -ENOENT ) -drm_sched_job_done (sched_job, fence->error); -else if (r) -DRM_DEV_ERROR (sched->dev,"fence add callback failed (%d)\n" , - r); - }else { -drm_sched_job_done (sched_job,IS_ERR (fence) ? -PTR_ERR (fence) :0 ); - } +atomic_inc (&sched->hw_rq_count); +drm_sched_job_begin (sched_job); + +trace_drm_run_job (sched_job, entity); + fence = sched->ops->run_job (sched_job); +complete_all (&entity->entity_idle); +drm_sched_fence_scheduled (s_fence, fence); -wake_up (&sched->job_scheduled); +if (!IS_ERR_OR_NULL (fence)) { +/* Drop for original kref_init of the fence */ +dma_fence_put (fence); + + r =dma_fence_add_callback (fence, &sched_job->cb, + drm_sched_job_done_cb); +if (r == -ENOENT ) +drm_sched_job_done (sched_job, fence->error); +else if (r) + DRM_DEV_ERROR(sched->dev, "fence add callback failed (%d)\n",
Quoted 9 lines
drivers/gpu/drm/scheduler/sched_main.c drm_sched_pick_best(struct drm_gpu_scheduler **sched_list, · line 1149
Quoted 1 line
drivers/gpu/drm/scheduler/sched_main.c +1
-0+ r);Please align "r);" to the open brace on the previous line. If you're using Emacs with sane Linux settings, press the "Tab" key anywhere on the line to indent it. (It should run c-indent-line-or-region, usually using leading-tabs-only mode. Pressing it again, over and over, on an already indented line, does nothing. Column indenting--say for columns in 2D/3D/etc., array, usually happens using spaces, which is portable. Also please take an overview with "
scrips/checkpatch.pl--strict".)
Will run checkpatch.
Quoted 3 lines
Wrap-around was bumped to 100 in the Linux kernel so you can put the 'r' on the same line without style problems.
Using Vi with wrap around of 80 but know 100 is allowed. Will fix.
Quoted 62 lines
Quoted 62 lines
drivers/gpu/drm/scheduler/sched_main.c +11
-5+ }else { +drm_sched_job_done (sched_job,IS_ERR (fence) ? +PTR_ERR (fence) :0 ); } -again: -drm_sched_submit_queue (sched); +wake_up (&sched->job_scheduled); +drm_sched_run_job_queue_if_ready (sched); }/** @@ -1159,7 +1220,8 @@ int drm_sched_init(struct drm_gpu_scheduler *sched,spin_lock_init (&sched->job_list_lock);atomic_set (&sched->hw_rq_count,0 );INIT_DELAYED_WORK (&sched->work_tdr, drm_sched_job_timedout); -INIT_WORK (&sched->work_submit, drm_sched_main); +INIT_WORK (&sched->work_run_job, drm_sched_run_job_work); +INIT_WORK (&sched->work_free_job, drm_sched_free_job_work);atomic_set (&sched->_score,0 );atomic64_set (&sched->job_id_count,0 ); sched->pause_submit = false;@@ -1286,7 +1348,8 @@ EXPORT_SYMBOL(drm_sched_submit_ready);void drm_sched_submit_stop (struct drm_gpu_scheduler *sched) {WRITE_ONCE (sched->pause_submit, true); -cancel_work_sync (&sched->work_submit); +cancel_work_sync (&sched->work_run_job); +cancel_work_sync (&sched->work_free_job); }EXPORT_SYMBOL (drm_sched_submit_stop);@@ -1298,6 +1361,7 @@ EXPORT_SYMBOL(drm_sched_submit_stop);void drm_sched_submit_start (struct drm_gpu_scheduler *sched) {WRITE_ONCE (sched->pause_submit, false); -queue_work (sched->submit_wq, &sched->work_submit); +queue_work (sched->submit_wq, &sched->work_run_job); +queue_work (sched->submit_wq, &sched->work_free_job); }EXPORT_SYMBOL (drm_sched_submit_start);include/drm/gpu_scheduler.h +3
-2@@ -487,9 +487,10 @@ struct drm_sched_backend_ops {* finished. * @hw_rq_count: the number of jobs currently in the hardware queue. * @job_id_count: used to assign unique id to the each job. -* @submit_wq: workqueue used to queue @work_submit +* @submit_wq: workqueue used to queue @work_run_job and @work_free_job * @timeout_wq: workqueue used to queue @work_tdr -* @work_submit: schedules jobs and cleans up entities +* @work_run_job: schedules jobs +* @work_free_job: cleans up jobs * @work_tdr: schedules a delayed call to @drm_sched_job_timedout after the * timeout interval is over. * @pending_list: the list of jobs which are currently in the job queue. @@ -519,7 +520,8 @@ struct drm_gpu_scheduler {atomic64_t job_id_count;struct workqueue_struct *submit_wq;struct workqueue_struct *timeout_wq;
Quoted 8 lines
include/drm/gpu_scheduler.h struct drm_gpu_scheduler { · line 527
Quoted 6 lines
include/drm/gpu_scheduler.h +2
-1-struct work_struct work_submit; +struct work_struct work_run_job; +struct work_struct work_free_job;struct delayed_work work_tdr;struct list_head pending_list;spinlock_t job_list_lock;Yeah, so this is a good patch. Thanks for doing this!
Thanks for the review.
Matt
Quoted 4 lines
Signature · 2 lines
Regards, Luben
Re: [PATCH v4 05/10] drm/sched: Split free_job into own work item
Quoted 477 lines · Matthew Brost
Quoted 56 lines · Luben Tuikov
Quoted 22 lines · Matthew Brost
Rather than call
free_jobandrun_jobin same work item have a dedicated work item for each. This aligns with the design and intended use of work queues.v2:
- Test forDMA_FENCE_FLAG_TIMESTAMP_BITbefore setting timestamp infree_job()work item (Danilo)
v3:
- Drop forward dec ofdrm_sched_select_entity(Boris)
- Return indrm_sched_run_job_workif entity NULL (Boris)Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/scheduler/sched_main.c | 290 +++++++++++++++---------- include/drm/gpu_scheduler.h | 8 +- 2 files changed, 182 insertions(+), 116 deletions(-)drivers/gpu/drm/scheduler/sched_main.c +0
-0drivers/gpu/drm/scheduler/sched_main.c void drm_sched_rq_remove_entity(struct drm_sched_rq *rq, · line 216
Quoted 4 lines
drivers/gpu/drm/scheduler/sched_main.c +1
-0@@ -213,11 +213,12 @@ void drm_sched_rq_remove_entity(struct drm_sched_rq *rq,* drm_sched_rq_select_entity_rr - Select an entity which could provide a job to run * * @rq: scheduler run queue to check. +* @dequeue: dequeue selected entity Change this to "peek" as indicated below.
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +1
-1* * Try to find a ready entity, returns NULL if none found. */ static struct drm_sched_entity * -drm_sched_rq_select_entity_rr (struct drm_sched_rq *rq) +drm_sched_rq_select_entity_rr (struct drm_sched_rq *rq,bool dequeue) {struct drm_sched_entity *entity;drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_rr(struct drm_sched_rq *rq) · line 234
Quoted 9 lines
drivers/gpu/drm/scheduler/sched_main.c +4
-2@@ -227,8 +228,10 @@ drm_sched_rq_select_entity_rr(struct drm_sched_rq *rq)if (entity) {list_for_each_entry_continue (entity, &rq->entities, list) {if (drm_sched_entity_is_ready (entity)) { - rq->current_entity = entity; -reinit_completion (&entity->entity_idle); +if (dequeue) { + rq->current_entity = entity; +reinit_completion (&entity->entity_idle); + }Please rename "dequeue" or invert its logic, as from this patch it seems that it is hiding (gating out) current behaviour.
Ideally, I'd prefer it be inverted, so that current behaviour, i.e. what people are used to the rq_select_entity_*() to do, is default--preserved.
Quoted 8 lines
Perhaps use "peek" as the name of this new variable, to indicate that we're not setting it to be the current entity.
I prefer "peek" to others, as the former tells me "Hey, I'm only peeking at the rq and not really doing the default behaviour I've been doing which you're used to." So, probably use "peek". ("Peek" also has historical significance...).
Peek it is. Will change.
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/scheduler/sched_main.c +0
-0spin_unlock (&rq->lock);return entity; }@@ -238,8 +241,10 @@ drm_sched_rq_select_entity_rr(struct drm_sched_rq *rq)list_for_each_entry (entity, &rq->entities, list) {Quoted 7 lines
drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_rr(struct drm_sched_rq *rq) · line 231
Quoted 4 lines
drivers/gpu/drm/scheduler/sched_main.c +1
-2if (drm_sched_entity_is_ready (entity)) { - rq->current_entity = entity; -reinit_completion (&entity->entity_idle); +if (dequeue) {if (!peek) {+1
Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/scheduler/sched_main.c +3
-0+ rq->current_entity = entity; +reinit_completion (&entity->entity_idle); + }spin_unlock (&rq->lock);return entity;Quoted 9 lines
drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_rr(struct drm_sched_rq *rq) · line 265
Quoted 6 lines
drivers/gpu/drm/scheduler/sched_main.c +1
-0}@@ -257,11 +262,12 @@ drm_sched_rq_select_entity_rr(struct drm_sched_rq *rq)* drm_sched_rq_select_entity_fifo - Select an entity which provides a job to run * * @rq: scheduler run queue to check. +* @dequeue: dequeue selected entity * @peek: Just find, don't set to current.
+1
Quoted 64 lines
Quoted 9 lines
drivers/gpu/drm/scheduler/sched_main.c +1
-1* * Find oldest waiting ready entity, returns NULL if none found.> */ static struct drm_sched_entity * -drm_sched_rq_select_entity_fifo (struct drm_sched_rq *rq) +drm_sched_rq_select_entity_fifo (struct drm_sched_rq *rq,bool dequeue) {struct rb_node *rb;drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) · line 280
Quoted 6 lines
drivers/gpu/drm/scheduler/sched_main.c +1
-2@@ -271,8 +277,10 @@ drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) entity = rb_entry(rb, struct drm_sched_entity, rb_tree_node);if (drm_sched_entity_is_ready (entity)) { - rq->current_entity = entity; -reinit_completion (&entity->entity_idle); +if (dequeue) {if (!peek) {Quoted 7 lines
drivers/gpu/drm/scheduler/sched_main.c +3
-0+ rq->current_entity = entity; +reinit_completion (&entity->entity_idle); + }break ; } }drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) · line 295
Quoted 7 lines
drivers/gpu/drm/scheduler/sched_main.c +3
-1@@ -282,13 +290,102 @@ drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) }/** -* drm_sched_submit_queue - scheduler queue submission +* drm_sched_run_job_queue - queue job submission +* @sched: scheduler instance +*/ Perhaps it would be clearer to a DOC reader if there were verbs in this function comment? I feel this was mentioned in the review to patch 2...
Quoted 13 lines
drivers/gpu/drm/scheduler/sched_main.c +13
-0+static void drm_sched_run_job_queue (struct drm_gpu_scheduler *sched) +{ +if (!READ_ONCE (sched->pause_submit)) +queue_work (sched->submit_wq, &sched->work_run_job); +} + +/** +* drm_sched_can_queue -- Can we queue more to the hardware? +* @sched: scheduler instance +* +* Return true if we can push more jobs to the hw, otherwise false. +*/ +static bool drm_sched_can_queue (struct drm_gpu_scheduler *sched)drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) · line 318
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +10
-0+{ +return atomic_read (&sched->hw_rq_count) < + sched->hw_submission_limit; +} + +/** +* drm_sched_select_entity - Select next entity to process +* +* @sched: scheduler instance +* @dequeue: dequeue selected entity When I see "dequeue" I'm thinking "
list_del()". Let's use "peek" here as mentioned above.Quoted 8 lines
drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) · line 323
Quoted 5 lines
drivers/gpu/drm/scheduler/sched_main.c +5
-0+* +* Returns the entity to process or NULL if none are found. +*/ +static struct drm_sched_entity * +drm_sched_select_entity (struct drm_gpu_scheduler *sched,bool dequeue)
drm_sched_select_entity(struct drm_gpu_scheduler *sched, bool peek)+1
Quoted 45 lines
Quoted 32 lines
drivers/gpu/drm/scheduler/sched_main.c +31
-0+{ +struct drm_sched_entity *entity; +int i; + +if (!drm_sched_can_queue (sched)) +return NULL ; + +if (sched->single_entity) { +if (!READ_ONCE (sched->single_entity->stopped) && +drm_sched_entity_is_ready (sched->single_entity)) +return sched->single_entity; + +return NULL ; + } + +/* Kernel run queue has higher priority than normal run queue*/ +for (i =DRM_SCHED_PRIORITY_COUNT -1 ; i >=DRM_SCHED_PRIORITY_MIN ; i--) { + entity = sched->sched_policy ==DRM_SCHED_POLICY_FIFO ? +drm_sched_rq_select_entity_fifo (&sched->sched_rq[i], + dequeue) : +drm_sched_rq_select_entity_rr (&sched->sched_rq[i], + dequeue); +if (entity) +break ; + } + +return entity; +} + +/** +* drm_sched_run_job_queue_if_ready - queue job submission if ready * @sched: scheduler instance drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) · line 364
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +8
-1*/ -static void drm_sched_submit_queue (struct drm_gpu_scheduler *sched) +static void drm_sched_run_job_queue_if_ready (struct drm_gpu_scheduler *sched) +{ +if (drm_sched_select_entity (sched, false)) +drm_sched_run_job_queue (sched); +} + +/** +* drm_sched_free_job_queue - queue free job *
drm_sched_free_job_queue- enqueue free-job workQuoted 6 lines
drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) · line 366
Quoted 2 lines
drivers/gpu/drm/scheduler/sched_main.c +2
-0+* +* @sched: scheduler instance to queue free job * @sched: scheduler instance to queue free job work for
Will change both.
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/scheduler/sched_main.c +2
-0+*/ +static void drm_sched_free_job_queue (struct drm_gpu_scheduler *sched) {if (!READ_ONCE (sched->pause_submit))Quoted 9 lines
drivers/gpu/drm/scheduler/sched_main.c drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq) · line 375
Quoted 6 lines
drivers/gpu/drm/scheduler/sched_main.c +5
-1-queue_work (sched->submit_wq, &sched->work_submit); +queue_work (sched->submit_wq, &sched->work_free_job); +} + +/** +* drm_sched_free_job_queue_if_ready - queue free job if ready *
drm_sched_free_job_queue_if_ready- enqueue free-job work if readyWill change this too.
Quoted 221 lines
Quoted 221 lines
drivers/gpu/drm/scheduler/sched_main.c +70
-97+* +* @sched: scheduler instance to queue free job +*/ +static void drm_sched_free_job_queue_if_ready (struct drm_gpu_scheduler *sched) +{ +struct drm_sched_job *job; + +spin_lock (&sched->job_list_lock); + job =list_first_entry_or_null (&sched->pending_list, + struct drm_sched_job, list); +if (job &&dma_fence_is_signaled (&job->s_fence->finished)) +drm_sched_free_job_queue (sched); +spin_unlock (&sched->job_list_lock); }/** @@ -310,7 +407,7 @@ static void drm_sched_job_done(struct drm_sched_job *s_job, int result)dma_fence_get (&s_fence->finished);drm_sched_fence_finished (s_fence, result);dma_fence_put (&s_fence->finished); -drm_sched_submit_queue (sched); +drm_sched_free_job_queue (sched); }/** @@ -885,18 +982,6 @@ void drm_sched_job_cleanup(struct drm_sched_job *job) }EXPORT_SYMBOL (drm_sched_job_cleanup); -/** -* drm_sched_can_queue -- Can we queue more to the hardware? -* @sched: scheduler instance -* -* Return true if we can push more jobs to the hw, otherwise false. -*/ -static bool drm_sched_can_queue (struct drm_gpu_scheduler *sched) -{ -return atomic_read (&sched->hw_rq_count) < - sched->hw_submission_limit; -} -/** * drm_sched_wakeup_if_can_queue - Wake up the scheduler * @sched: scheduler instance @@ -906,43 +991,7 @@ static bool drm_sched_can_queue(struct drm_gpu_scheduler *sched)void drm_sched_wakeup_if_can_queue (struct drm_gpu_scheduler *sched) {if (drm_sched_can_queue (sched)) -drm_sched_submit_queue (sched); -} - -/** -* drm_sched_select_entity - Select next entity to process -* -* @sched: scheduler instance -* -* Returns the entity to process or NULL if none are found. -*/ -static struct drm_sched_entity * -drm_sched_select_entity (struct drm_gpu_scheduler *sched) -{ -struct drm_sched_entity *entity; -int i; - -if (!drm_sched_can_queue (sched)) -return NULL ; - -if (sched->single_entity) { -if (!READ_ONCE (sched->single_entity->stopped) && -drm_sched_entity_is_ready (sched->single_entity)) -return sched->single_entity; - -return NULL ; - } - -/* Kernel run queue has higher priority than normal run queue*/ -for (i =DRM_SCHED_PRIORITY_COUNT -1 ; i >=DRM_SCHED_PRIORITY_MIN ; i--) { - entity = sched->sched_policy ==DRM_SCHED_POLICY_FIFO ? -drm_sched_rq_select_entity_fifo (&sched->sched_rq[i]) : -drm_sched_rq_select_entity_rr (&sched->sched_rq[i]); -if (entity) -break ; - } - -return entity; +drm_sched_run_job_queue (sched); }/** @@ -974,8 +1023,10 @@ drm_sched_get_cleanup_job(struct drm_gpu_scheduler *sched) typeof(*next), list);if (next) { - next->s_fence->scheduled.timestamp = - job->s_fence->finished.timestamp; +if (test_bit (DMA_FENCE_FLAG_TIMESTAMP_BIT , + &next->s_fence->scheduled.flags)) + next->s_fence->scheduled.timestamp = + job->s_fence->finished.timestamp;/* start TO timer for next job */ drm_sched_start_timeout (sched); }@@ -1025,74 +1076,84 @@ drm_sched_pick_best(struct drm_gpu_scheduler **sched_list,EXPORT_SYMBOL (drm_sched_pick_best);/** -* drm_sched_main - main scheduler thread +* drm_sched_free_job_work - worker to call free_job * -* @param: scheduler instance +* @w: free job work */ -static void drm_sched_main (struct work_struct *w) +static void drm_sched_free_job_work (struct work_struct *w) {struct drm_gpu_scheduler *sched = - container_of(w, struct drm_gpu_scheduler, work_submit); -struct drm_sched_entity *entity; + container_of(w, struct drm_gpu_scheduler, work_free_job);struct drm_sched_job *cleanup_job; -int r;if (READ_ONCE (sched->pause_submit))return ; cleanup_job =drm_sched_get_cleanup_job (sched); - entity =drm_sched_select_entity (sched); - -if (!entity && !cleanup_job) -return ;/* No more work */ - -if (cleanup_job) +if (cleanup_job) { sched->ops->free_job (cleanup_job); -if (entity) { -struct dma_fence *fence; -struct drm_sched_fence *s_fence; -struct drm_sched_job *sched_job; - - sched_job =drm_sched_entity_pop_job (entity); -if (!sched_job) { -complete_all (&entity->entity_idle); -if (!cleanup_job) -return ;/* No more work */ - goto again; - } +drm_sched_free_job_queue_if_ready (sched); +drm_sched_run_job_queue_if_ready (sched); + } +} + +/** +* drm_sched_run_job_work - worker to call run_job +* +* @w: run job work +*/ +static void drm_sched_run_job_work (struct work_struct *w) +{ +struct drm_gpu_scheduler *sched = + container_of(w, struct drm_gpu_scheduler, work_run_job); +struct drm_sched_entity *entity; +struct dma_fence *fence; +struct drm_sched_fence *s_fence; +struct drm_sched_job *sched_job; +int r; - s_fence = sched_job->s_fence; +if (READ_ONCE (sched->pause_submit)) +return ; -atomic_inc (&sched->hw_rq_count); -drm_sched_job_begin (sched_job); + entity =drm_sched_select_entity (sched, true); +if (!entity) +return ; -trace_drm_run_job (sched_job, entity); - fence = sched->ops->run_job (sched_job); + sched_job =drm_sched_entity_pop_job (entity); +if (!sched_job) {complete_all (&entity->entity_idle); -drm_sched_fence_scheduled (s_fence, fence); +return ;/* No more work */ + } -if (!IS_ERR_OR_NULL (fence)) { -/* Drop for original kref_init of the fence */ -dma_fence_put (fence); + s_fence = sched_job->s_fence; - r =dma_fence_add_callback (fence, &sched_job->cb, - drm_sched_job_done_cb); -if (r == -ENOENT ) -drm_sched_job_done (sched_job, fence->error); -else if (r) -DRM_DEV_ERROR (sched->dev,"fence add callback failed (%d)\n" , - r); - }else { -drm_sched_job_done (sched_job,IS_ERR (fence) ? -PTR_ERR (fence) :0 ); - } +atomic_inc (&sched->hw_rq_count); +drm_sched_job_begin (sched_job); + +trace_drm_run_job (sched_job, entity); + fence = sched->ops->run_job (sched_job); +complete_all (&entity->entity_idle); +drm_sched_fence_scheduled (s_fence, fence); -wake_up (&sched->job_scheduled); +if (!IS_ERR_OR_NULL (fence)) { +/* Drop for original kref_init of the fence */ +dma_fence_put (fence); + + r =dma_fence_add_callback (fence, &sched_job->cb, + drm_sched_job_done_cb); +if (r == -ENOENT ) +drm_sched_job_done (sched_job, fence->error); +else if (r) + DRM_DEV_ERROR(sched->dev, "fence add callback failed (%d)\n",Quoted 9 lines
drivers/gpu/drm/scheduler/sched_main.c drm_sched_pick_best(struct drm_gpu_scheduler **sched_list, · line 1149
Quoted 1 line
drivers/gpu/drm/scheduler/sched_main.c +1
-0+ r);Please align "r);" to the open brace on the previous line. If you're using Emacs with sane Linux settings, press the "Tab" key anywhere on the line to indent it. (It should run c-indent-line-or-region, usually using leading-tabs-only mode. Pressing it again, over and over, on an already indented line, does nothing. Column indenting--say for columns in 2D/3D/etc., array, usually happens using spaces, which is portable. Also please take an overview with "
scrips/checkpatch.pl--strict".)
Quoted 7 lines
Will run checkpatch.
Quoted 3 lines
Wrap-around was bumped to 100 in the Linux kernel so you can put the 'r' on the same line without style problems.
Using Vi with wrap around of 80 but know 100 is allowed. Will fix.
Ah, yes--I now see where the real problem is. :-D
Signature · 2 lines
Regards, Luben
Matthew Brost
maintainerPATCH v4 6/10 drm/sched: Add drm_sched_start_timeout_unlocked helper
In reply to Matthew BrostAlso add a lockdep assert to drm_sched_start_timeout.
--- drivers/gpu/drm/scheduler/sched_main.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +13 -10
@@ -431,11 +431,20 @@ static void drm_sched_job_done_cb(struct dma_fence *f, struct dma_fence_cb *cb)*/ static void drm_sched_start_timeout (struct drm_gpu_scheduler *sched) { +lockdep_assert_held (&sched->job_list_lock); +if (sched->timeout !=MAX_SCHEDULE_TIMEOUT && !list_empty (&sched->pending_list))queue_delayed_work (sched->timeout_wq, &sched->work_tdr, sched->timeout); } +static void drm_sched_start_timeout_unlocked (struct drm_gpu_scheduler *sched) +{ +spin_lock (&sched->job_list_lock); +drm_sched_start_timeout (sched); +spin_unlock (&sched->job_list_lock); +} +/** * drm_sched_fault - immediately start timeout handler *
@@ -548,11 +557,8 @@ static void drm_sched_job_timedout(struct work_struct *work)spin_unlock (&sched->job_list_lock); } -if (status !=DRM_GPU_SCHED_STAT_ENODEV ) { -spin_lock (&sched->job_list_lock); -drm_sched_start_timeout (sched); -spin_unlock (&sched->job_list_lock); - } +if (status !=DRM_GPU_SCHED_STAT_ENODEV ) +drm_sched_start_timeout_unlocked (sched); }/**
@@ -678,11 +684,8 @@ void drm_sched_start(struct drm_gpu_scheduler *sched, bool full_recovery)drm_sched_job_done (s_job, -ECANCELED ); } -if (full_recovery) { -spin_lock (&sched->job_list_lock); -drm_sched_start_timeout (sched); -spin_unlock (&sched->job_list_lock); - } +if (full_recovery) +drm_sched_start_timeout_unlocked (sched);drm_sched_submit_start (sched); }
Signature · 1 line
2.34.1
Re: [PATCH v4 06/10] drm/sched: Add drm_sched_start_timeout_unlocked helper
Hi,
Quoted 3 lines · Matthew Brost
Also add a lockdep assert to
drm_sched_start_timeout.Signed-off-by Matthew Brost <[email protected]>
Thanks for this patch!
Quoted 57 lines
--- drivers/gpu/drm/scheduler/sched_main.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)drivers/gpu/drm/scheduler/sched_main.c +13
-10@@ -431,11 +431,20 @@ static void drm_sched_job_done_cb(struct dma_fence *f, struct dma_fence_cb *cb)*/ static void drm_sched_start_timeout (struct drm_gpu_scheduler *sched) { +lockdep_assert_held (&sched->job_list_lock); +if (sched->timeout !=MAX_SCHEDULE_TIMEOUT && !list_empty (&sched->pending_list))queue_delayed_work (sched->timeout_wq, &sched->work_tdr, sched->timeout); } +static void drm_sched_start_timeout_unlocked (struct drm_gpu_scheduler *sched) +{ +spin_lock (&sched->job_list_lock); +drm_sched_start_timeout (sched); +spin_unlock (&sched->job_list_lock); +} +/** * drm_sched_fault - immediately start timeout handler * @@ -548,11 +557,8 @@ static void drm_sched_job_timedout(struct work_struct *work)spin_unlock (&sched->job_list_lock); } -if (status !=DRM_GPU_SCHED_STAT_ENODEV ) { -spin_lock (&sched->job_list_lock); -drm_sched_start_timeout (sched); -spin_unlock (&sched->job_list_lock); - } +if (status !=DRM_GPU_SCHED_STAT_ENODEV ) +drm_sched_start_timeout_unlocked (sched); }/** @@ -678,11 +684,8 @@ void drm_sched_start(struct drm_gpu_scheduler *sched, bool full_recovery)drm_sched_job_done (s_job, -ECANCELED ); } -if (full_recovery) { -spin_lock (&sched->job_list_lock); -drm_sched_start_timeout (sched); -spin_unlock (&sched->job_list_lock); - } +if (full_recovery) +drm_sched_start_timeout_unlocked (sched);drm_sched_submit_start (sched); }
Signature · 2 lines
Regards, Luben
Matthew Brost
maintainerPATCH v4 7/10 drm/sched: Start submission before TDR in drm_sched_start
In reply to Matthew BrostIf the TDR is set to a very small value it can fire before the submission is started in the function drm_sched_start. The submission is expected to running when the TDR fires, fix this ordering so this expectation is always met.
--- drivers/gpu/drm/scheduler/sched_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +2 -2
@@ -684,10 +684,10 @@ void drm_sched_start(struct drm_gpu_scheduler *sched, bool full_recovery)drm_sched_job_done (s_job, -ECANCELED ); } +drm_sched_submit_start (sched); +if (full_recovery)drm_sched_start_timeout_unlocked (sched); - -drm_sched_submit_start (sched); }EXPORT_SYMBOL (drm_sched_start);
Signature · 1 line
2.34.1
Re: [PATCH v4 07/10] drm/sched: Start submission before TDR in drm_sched_start
Hi,
Quoted 16 lines · Matthew Brost
If the TDR is set to a very small value it can fire before the submission is started in the function
drm_sched_start. The submission is expected to running when the TDR fires, fix this ordering so this expectation is always met.Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/scheduler/sched_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/scheduler/sched_main.c +0
-0@@ -684,10 +684,10 @@ void drm_sched_start(struct drm_gpu_scheduler *sched, bool full_recovery)drm_sched_job_done (s_job, -ECANCELED );
drivers/gpu/drm/scheduler/sched_main.c void drm_sched_start(struct drm_gpu_scheduler *sched, bool full_recovery) · line 692
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +2
-2} +drm_sched_submit_start (sched); +if (full_recovery)drm_sched_start_timeout_unlocked (sched); - -drm_sched_submit_start (sched); }EXPORT_SYMBOL (drm_sched_start);
No.
A timeout timer should be started before we submit anything down to the hardware. See Message-ID: <[email protected]>,
and Message-ID: <[email protected]>.
You shouldn't start TDR at an arbitrarily late time after job submission to the hardware. To close this, the timer is started before jobs are submitted to the hardware.
One possibility is to increase the timeout timer value.
Signature · 2 lines
Regards, Luben
Re: [PATCH v4 07/10] drm/sched: Start submission before TDR in drm_sched_start
Quoted 36 lines · Luben Tuikov
Hi,
Quoted 16 lines · Matthew Brost
If the TDR is set to a very small value it can fire before the submission is started in the function
drm_sched_start. The submission is expected to running when the TDR fires, fix this ordering so this expectation is always met.Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/scheduler/sched_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/scheduler/sched_main.c +0
-0@@ -684,10 +684,10 @@ void drm_sched_start(struct drm_gpu_scheduler *sched, bool full_recovery)drm_sched_job_done (s_job, -ECANCELED );drivers/gpu/drm/scheduler/sched_main.c void drm_sched_start(struct drm_gpu_scheduler *sched, bool full_recovery) · line 692
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +2
-2} +drm_sched_submit_start (sched); +if (full_recovery)drm_sched_start_timeout_unlocked (sched); - -drm_sched_submit_start (sched); }EXPORT_SYMBOL (drm_sched_start);No.
A timeout timer should be started before we submit anything down to the hardware. See Message-ID: <[email protected]>,
and Message-ID: <[email protected]>.
Quoted 5 lines
You shouldn't start TDR at an arbitrarily late time after job submission to the hardware. To close this, the timer is started before jobs are submitted to the hardware.
One possibility is to increase the timeout timer value.
If we went with this general change as we see here and in the subsequent patch--starting the TDR _after_ submitting jobs for execution to the hardware--this is what generally happens,
1. submit one or many jobs for execution;
2. one or many jobs may execute, complete, hang, etc.;
3. at some arbitrary time in the future, start TDR.
Which means that the timeout doesn't necessarily track the time allotted for a job to finish executing in the hardware. It ends up larger than intended.
Signature · 2 lines
Regards, Luben
Matthew Brost
maintainerRe: [PATCH v4 07/10] drm/sched: Start submission before TDR in drm_sched_start
Quoted 22 lines · Luben Tuikov
Quoted 21 lines · Luben Tuikov
Hi,
Quoted 18 lines · Matthew Brost
If the TDR is set to a very small value it can fire before the submission is started in the function
drm_sched_start. The submission is expected to running when the TDR fires, fix this ordering so this expectation is always met.Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/scheduler/sched_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/scheduler/sched_main.c +0
-0@@ -684,10 +684,10 @@ void drm_sched_start(struct drm_gpu_scheduler *sched, bool full_recovery)drm_sched_job_done (s_job, -ECANCELED ); }
Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/scheduler/sched_main.c void drm_sched_start(struct drm_gpu_scheduler *sched, bool full_recovery) · line 692
Quoted 8 lines
drivers/gpu/drm/scheduler/sched_main.c +2
-2+drm_sched_submit_start (sched); +if (full_recovery)drm_sched_start_timeout_unlocked (sched); - -drm_sched_submit_start (sched); }EXPORT_SYMBOL (drm_sched_start);No.
I don't think we will ever agree on this but I pulled out this patch and the next in Xe. It seems to work without these changes, I believe understand why and think it should actually work without this change. If for some reason it didn't work, I know how I can work around this in the Xe submission backend.
With this, I will drop these in the next rev.
But more on why I disagree below...
Quoted 9 lines
Quoted 9 lines
A timeout timer should be started before we submit anything down to the hardware. See Message-ID: <[email protected]>,
and Message-ID: <[email protected]>.You shouldn't start TDR at an arbitrarily late time after job submission to the hardware. To close this, the timer is started before jobs are submitted to the hardware.
One possibility is to increase the timeout timer value.
No matter what the timeout value is there will always be a race of TDR firing before run_job() is called.
Quoted 8 lines
If we went with this general change as we see here and in the subsequent patch--starting the TDR _after_ submitting jobs for execution to the hardware--this is what generally happens,
1. submit one or many jobs for execution;
2. one or many jobs may execute, complete, hang, etc.;
3. at some arbitrary time in the future, start TDR.
Which means that the timeout doesn't necessarily track the time allotted for a job to finish executing in the hardware. It ends up larger than intended.
Yes, conversely it can be smaller the way it is coded now. Kinda just a matter of opinion on which one to prefer.
Matt
Quoted 4 lines
Signature · 2 lines
Regards, Luben
Re: [PATCH v4 07/10] drm/sched: Start submission before TDR in drm_sched_start
Quoted 49 lines · Matthew Brost
Quoted 22 lines · Luben Tuikov
Quoted 21 lines · Luben Tuikov
Hi,
Quoted 18 lines · Matthew Brost
If the TDR is set to a very small value it can fire before the submission is started in the function
drm_sched_start. The submission is expected to running when the TDR fires, fix this ordering so this expectation is always met.Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/scheduler/sched_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/scheduler/sched_main.c +0
-0@@ -684,10 +684,10 @@ void drm_sched_start(struct drm_gpu_scheduler *sched, bool full_recovery)drm_sched_job_done (s_job, -ECANCELED ); }Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/scheduler/sched_main.c void drm_sched_start(struct drm_gpu_scheduler *sched, bool full_recovery) · line 692
Quoted 8 lines
drivers/gpu/drm/scheduler/sched_main.c +2
-2+drm_sched_submit_start (sched); +if (full_recovery)drm_sched_start_timeout_unlocked (sched); - -drm_sched_submit_start (sched); }EXPORT_SYMBOL (drm_sched_start);No.
I don't think we will ever agree on this but I pulled out this patch and the next in Xe. It seems to work without these changes, I believe understand why and think it should actually work without this change. If for some reason it didn't work, I know how I can work around this in the Xe submission backend.
With this, I will drop these in the next rev.
But more on why I disagree below...
Quoted 4 lines
Quoted 4 lines
A timeout timer should be started before we submit anything down to the hardware. See Message-ID: <[email protected]>,
and Message-ID: <[email protected]>.
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
You shouldn't start TDR at an arbitrarily late time after job submission to the hardware. To close this, the timer is started before jobs are submitted to the hardware.
One possibility is to increase the timeout timer value.
No matter what the timeout value is there will always be a race of TDR firing before
run_job()is called.
It's not a "race".
In all software and firmware I've seen, a timeout timer is started _before_ a command is submitted to firmware or hardware, respectively.
Quoted 10 lines
Quoted 9 lines
If we went with this general change as we see here and in the subsequent patch--starting the TDR _after_ submitting jobs for execution to the hardware--this is what generally happens,
1. submit one or many jobs for execution;
2. one or many jobs may execute, complete, hang, etc.;
3. at some arbitrary time in the future, start TDR.
Which means that the timeout doesn't necessarily track the time allotted for a job to finish executing in the hardware. It ends up larger than intended.
Quoted 2 lines
Yes, conversely it can be smaller the way it is coded now. Kinda just a matter of opinion on which one to prefer.
It should be large enough to contain the command/task/job making it to the hardware. We want to make sure there's no runaway job, _for_ the amount of time allotted to each job.
Signature · 2 lines
Regards, Luben
Matthew Brost
maintainerPATCH v4 8/10 drm/sched: Submit job before starting TDR
In reply to Matthew BrostIf the TDR is set to a value, it can fire before a job is submitted in drm_sched_main. The job should be always be submitted before the TDR fires, fix this ordering.
v2:
- Add to pending list before run_job, start TDR after (Luben, Boris)
--- drivers/gpu/drm/scheduler/sched_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/scheduler/sched_main.c +1 -1
@@ -517,7 +517,6 @@ static void drm_sched_job_begin(struct drm_sched_job *s_job)spin_lock (&sched->job_list_lock);list_add_tail (&s_job->list, &sched->pending_list); -drm_sched_start_timeout (sched);spin_unlock (&sched->job_list_lock); }
@@ -1138,6 +1137,7 @@ static void drm_sched_run_job_work(struct work_struct *w) fence = sched->ops->run_job (sched_job);complete_all (&entity->entity_idle);drm_sched_fence_scheduled (s_fence, fence); +drm_sched_start_timeout_unlocked (sched);if (!IS_ERR_OR_NULL (fence)) {/* Drop for original kref_init of the fence */
Signature · 1 line
2.34.1
Re: [PATCH v4 08/10] drm/sched: Submit job before starting TDR
Hi,
Quoted 25 lines · Matthew Brost
If the TDR is set to a value, it can fire before a job is submitted in
drm_sched_main. The job should be always be submitted before the TDR fires, fix this ordering.v2:
- Add to pending list beforerun_job, start TDR after (Luben, Boris)Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/scheduler/sched_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/scheduler/sched_main.c +0
-1@@ -517,7 +517,6 @@ static void drm_sched_job_begin(struct drm_sched_job *s_job)spin_lock (&sched->job_list_lock);list_add_tail (&s_job->list, &sched->pending_list); -drm_sched_start_timeout (sched);spin_unlock (&sched->job_list_lock); }
drivers/gpu/drm/scheduler/sched_main.c static void drm_sched_run_job_work(struct work_struct *w) · line 1143
Quoted 7 lines
drivers/gpu/drm/scheduler/sched_main.c +1
-0@@ -1138,6 +1137,7 @@ static void drm_sched_run_job_work(struct work_struct *w) fence = sched->ops->run_job (sched_job);complete_all (&entity->entity_idle);drm_sched_fence_scheduled (s_fence, fence); +drm_sched_start_timeout_unlocked (sched);if (!IS_ERR_OR_NULL (fence)) {/* Drop for original kref_init of the fence */
No.
See Message-ID: <[email protected]>, and Message-ID: <[email protected]>, and Message-ID: <[email protected]>.
Signature · 2 lines
Regards, Luben
Matthew Brost
maintainerRe: [PATCH v4 08/10] drm/sched: Submit job before starting TDR
Quoted 33 lines · Luben Tuikov
Hi,
Quoted 30 lines · Matthew Brost
If the TDR is set to a value, it can fire before a job is submitted in
drm_sched_main. The job should be always be submitted before the TDR fires, fix this ordering.v2:
- Add to pending list beforerun_job, start TDR after (Luben, Boris)Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/scheduler/sched_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/scheduler/sched_main.c +1
-1@@ -517,7 +517,6 @@ static void drm_sched_job_begin(struct drm_sched_job *s_job)spin_lock (&sched->job_list_lock);list_add_tail (&s_job->list, &sched->pending_list); -drm_sched_start_timeout (sched);spin_unlock (&sched->job_list_lock); }@@ -1138,6 +1137,7 @@ static void drm_sched_run_job_work(struct work_struct *w) fence = sched->ops->run_job (sched_job);complete_all (&entity->entity_idle);drm_sched_fence_scheduled (s_fence, fence); +drm_sched_start_timeout_unlocked (sched);
Quoted 8 lines
drivers/gpu/drm/scheduler/sched_main.c static void drm_sched_run_job_work(struct work_struct *w) · line 1143
Quoted 2 lines
drivers/gpu/drm/scheduler/sched_main.c +0
-0if (!IS_ERR_OR_NULL (fence)) {/* Drop for original kref_init of the fence */ No.
See Message-ID: <[email protected]>, and Message-ID: <[email protected]>, and Message-ID: <[email protected]>.
See reply to previous patch, will drop this.
Matt
Quoted 4 lines
Signature · 2 lines
Regards, Luben
Matthew Brost
maintainerPATCH v4 9/10 drm/sched: Add helper to queue TDR immediately for current and future jobs
In reply to Matthew BrostAdd helper to queue TDR immediately for current and future jobs. This will be used in XE, new Intel GPU driver, to trigger the TDR to cleanup a drm_scheduler that encounter errors.
v2:
- Drop timeout args, rename function, use mod delayed work (Luben)
--- drivers/gpu/drm/scheduler/sched_main.c | 19 ++++++++++++++++++- include/drm/gpu_scheduler.h | 1 + 2 files changed, 19 insertions(+), 1 deletion(-)
drivers/gpu/drm/scheduler/sched_main.c +18 -1
@@ -435,7 +435,7 @@ static void drm_sched_start_timeout(struct drm_gpu_scheduler *sched)if (sched->timeout !=MAX_SCHEDULE_TIMEOUT && !list_empty (&sched->pending_list)) -queue_delayed_work (sched->timeout_wq, &sched->work_tdr, sched->timeout); +mod_delayed_work (sched->timeout_wq, &sched->work_tdr, sched->timeout); }static void drm_sched_start_timeout_unlocked (struct drm_gpu_scheduler *sched)
@@ -445,6 +445,23 @@ static void drm_sched_start_timeout_unlocked(struct drm_gpu_scheduler *sched)spin_unlock (&sched->job_list_lock); } +/** +* drm_sched_tdr_queue_imm: - immediately start timeout handler including future +* jobs +* +* @sched: scheduler where the timeout handling should be started. +* +* Start timeout handling immediately for current and future jobs +*/ +void drm_sched_tdr_queue_imm (struct drm_gpu_scheduler *sched) +{ +spin_lock (&sched->job_list_lock); + sched->timeout =0 ; +drm_sched_start_timeout (sched); +spin_unlock (&sched->job_list_lock); +} +EXPORT_SYMBOL (drm_sched_tdr_queue_imm); +/** * drm_sched_fault - immediately start timeout handler *
include/drm/gpu_scheduler.h +1 -0
@@ -568,6 +568,7 @@ void drm_sched_entity_modify_sched(struct drm_sched_entity *entity,struct drm_gpu_scheduler **sched_list, unsigned int num_sched_list); +void drm_sched_tdr_queue_imm (struct drm_gpu_scheduler *sched);void drm_sched_job_cleanup (struct drm_sched_job *job);void drm_sched_wakeup_if_can_queue (struct drm_gpu_scheduler *sched);bool drm_sched_submit_ready (struct drm_gpu_scheduler *sched);
Signature · 1 line
2.34.1
Re: [PATCH v4 09/10] drm/sched: Add helper to queue TDR immediately for current and future jobs
Quoted 2 lines · Matthew Brost
Add helper to queue TDR immediately for current and future jobs. This will be used in XE, new Intel GPU driver, to trigger the TDR to cleanup
Please use present tense, "is", in code, comments, commits, etc.
Is it "XE" or is it "Xe"? I always thought it was "Xe".
This is used in Xe, a new Intel GPU driver, to trigger a TDR to clean up
Code, comments, commits, etc., immediately become history, and it's a bit ambitious to use future tense in something which immediately becomes history. It's much better to describe what is happening now, including the patch in question (any patch, ftm) is considered "now"/"current state" as well.
Quoted 24 lines
a
drm_schedulerthat encounter error[.]>
v2:
- Drop timeout args, rename function, use mod delayed work (Luben)Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/scheduler/sched_main.c | 19 ++++++++++++++++++- include/drm/gpu_scheduler.h | 1 + 2 files changed, 19 insertions(+), 1 deletion(-)drivers/gpu/drm/scheduler/sched_main.c +1
-1@@ -435,7 +435,7 @@ static void drm_sched_start_timeout(struct drm_gpu_scheduler *sched)if (sched->timeout !=MAX_SCHEDULE_TIMEOUT && !list_empty (&sched->pending_list)) -queue_delayed_work (sched->timeout_wq, &sched->work_tdr, sched->timeout); +mod_delayed_work (sched->timeout_wq, &sched->work_tdr, sched->timeout); }static void drm_sched_start_timeout_unlocked (struct drm_gpu_scheduler *sched)
drivers/gpu/drm/scheduler/sched_main.c static void drm_sched_start_timeout_unlocked(struct drm_gpu_scheduler *sched) · line 450
Quoted 6 lines
drivers/gpu/drm/scheduler/sched_main.c +3
-0@@ -445,6 +445,23 @@ static void drm_sched_start_timeout_unlocked(struct drm_gpu_scheduler *sched)spin_unlock (&sched->job_list_lock); } +/** +* drm_sched_tdr_queue_imm: - immediately start timeout handler including future +* jobs
Let's not mention "including future jobs", since we don't know the future. But we can sneak "jobs" into the description like this:
* drm_sched_tdr_queue_imm - immediately start job timeout handler
:-)
drivers/gpu/drm/scheduler/sched_main.c static void drm_sched_start_timeout_unlocked(struct drm_gpu_scheduler *sched) · line 452
Quoted 2 lines
drivers/gpu/drm/scheduler/sched_main.c +2
-0+* +* @sched: scheduler where the timeout handling should be started.
"where" --> "for which"
The former denotes a location, like in space-time, and the latter denotes an object, like a scheduler, a spaceship, a bicycle, etc.
drivers/gpu/drm/scheduler/sched_main.c static void drm_sched_start_timeout_unlocked(struct drm_gpu_scheduler *sched) · line 454
Quoted 2 lines
drivers/gpu/drm/scheduler/sched_main.c +2
-0+* +* Start timeout handling immediately for current and future jobs
* Start timeout handling immediately for the named scheduler.
Quoted 18 lines
drivers/gpu/drm/scheduler/sched_main.c +10
-0+*/ +void drm_sched_tdr_queue_imm (struct drm_gpu_scheduler *sched) +{ +spin_lock (&sched->job_list_lock); + sched->timeout =0 ; +drm_sched_start_timeout (sched); +spin_unlock (&sched->job_list_lock); +} +EXPORT_SYMBOL (drm_sched_tdr_queue_imm); +/** * drm_sched_fault - immediately start timeout handler * include/drm/gpu_scheduler.h +0
-0
include/drm/gpu_scheduler.h void drm_sched_entity_modify_sched(struct drm_sched_entity *entity, · line 574
Quoted 7 lines
include/drm/gpu_scheduler.h +1
-0@@ -568,6 +568,7 @@ void drm_sched_entity_modify_sched(struct drm_sched_entity *entity,struct drm_gpu_scheduler **sched_list, unsigned int num_sched_list); +void drm_sched_tdr_queue_imm (struct drm_gpu_scheduler *sched);void drm_sched_job_cleanup (struct drm_sched_job *job);void drm_sched_wakeup_if_can_queue (struct drm_gpu_scheduler *sched);bool drm_sched_submit_ready (struct drm_gpu_scheduler *sched);
Looks good!
Fix the above, for an immediate R-B. :-)
Signature · 2 lines
Regards, Luben
Matthew Brost
maintainerRe: [PATCH v4 09/10] drm/sched: Add helper to queue TDR immediately for current and future jobs
Quoted 8 lines · Luben Tuikov
Quoted 2 lines · Matthew Brost
Add helper to queue TDR immediately for current and future jobs. This will be used in XE, new Intel GPU driver, to trigger the TDR to cleanup
Please use present tense, "is", in code, comments, commits, etc.
Is it "XE" or is it "Xe"? I always thought it was "Xe".
Yea should be 'Xe'.
Quoted 2 lines
This is used in Xe, a new Intel GPU driver, to trigger a TDR to clean up
Will fix.
Quoted 5 lines
Code, comments, commits, etc., immediately become history, and it's a bit ambitious to use future tense in something which immediately becomes history. It's much better to describe what is happening now, including the patch in question (any patch, ftm) is considered "now"/"current state" as well.
Got it.
Quoted 34 lines
Quoted 24 lines
a
drm_schedulerthat encounter error[.]>
v2:
- Drop timeout args, rename function, use mod delayed work (Luben)Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/scheduler/sched_main.c | 19 ++++++++++++++++++- include/drm/gpu_scheduler.h | 1 + 2 files changed, 19 insertions(+), 1 deletion(-)drivers/gpu/drm/scheduler/sched_main.c +1
-1@@ -435,7 +435,7 @@ static void drm_sched_start_timeout(struct drm_gpu_scheduler *sched)if (sched->timeout !=MAX_SCHEDULE_TIMEOUT && !list_empty (&sched->pending_list)) -queue_delayed_work (sched->timeout_wq, &sched->work_tdr, sched->timeout); +mod_delayed_work (sched->timeout_wq, &sched->work_tdr, sched->timeout); }static void drm_sched_start_timeout_unlocked (struct drm_gpu_scheduler *sched)drivers/gpu/drm/scheduler/sched_main.c static void drm_sched_start_timeout_unlocked(struct drm_gpu_scheduler *sched) · line 450
Quoted 6 lines
drivers/gpu/drm/scheduler/sched_main.c +3
-0@@ -445,6 +445,23 @@ static void drm_sched_start_timeout_unlocked(struct drm_gpu_scheduler *sched)spin_unlock (&sched->job_list_lock); } +/** +* drm_sched_tdr_queue_imm: - immediately start timeout handler including future +* jobs Let's not mention "including future jobs", since we don't know the future. But we can sneak "jobs" into the description like this:
Quoted 4 lines
*
drm_sched_tdr_queue_imm- immediately start job timeout handler:-)
Will change.
Quoted 7 lines
drivers/gpu/drm/scheduler/sched_main.c static void drm_sched_start_timeout_unlocked(struct drm_gpu_scheduler *sched) · line 452
Quoted 2 lines
drivers/gpu/drm/scheduler/sched_main.c +2
-0+* +* @sched: scheduler where the timeout handling should be started. "where" --> "for which"
The former denotes a location, like in space-time, and the latter denotes an object, like a scheduler, a spaceship, a bicycle, etc.
+1
Quoted 5 lines
drivers/gpu/drm/scheduler/sched_main.c static void drm_sched_start_timeout_unlocked(struct drm_gpu_scheduler *sched) · line 454
Quoted 2 lines
drivers/gpu/drm/scheduler/sched_main.c +2
-0+* +* Start timeout handling immediately for current and future jobs * Start timeout handling immediately for the named scheduler.
+1
Quoted 21 lines
Quoted 21 lines
drivers/gpu/drm/scheduler/sched_main.c +10
-0+*/ +void drm_sched_tdr_queue_imm (struct drm_gpu_scheduler *sched) +{ +spin_lock (&sched->job_list_lock); + sched->timeout =0 ; +drm_sched_start_timeout (sched); +spin_unlock (&sched->job_list_lock); +} +EXPORT_SYMBOL (drm_sched_tdr_queue_imm); +/** * drm_sched_fault - immediately start timeout handler * include/drm/gpu_scheduler.h +0
-0@@ -568,6 +568,7 @@ void drm_sched_entity_modify_sched(struct drm_sched_entity *entity,struct drm_gpu_scheduler **sched_list, unsigned int num_sched_list);
Quoted 8 lines
include/drm/gpu_scheduler.h void drm_sched_entity_modify_sched(struct drm_sched_entity *entity, · line 574
Quoted 4 lines
include/drm/gpu_scheduler.h +1
-0+void drm_sched_tdr_queue_imm (struct drm_gpu_scheduler *sched);void drm_sched_job_cleanup (struct drm_sched_job *job);void drm_sched_wakeup_if_can_queue (struct drm_gpu_scheduler *sched);bool drm_sched_submit_ready (struct drm_gpu_scheduler *sched);Looks good!
Fix the above, for an immediate R-B. :-)
Thanks for the review, will fix all of this.
Matt
Quoted 4 lines
Signature · 2 lines
Regards, Luben
Matthew Brost
maintainerPATCH v4 10/10 drm/sched: Update maintainers of GPU scheduler
In reply to Matthew BrostAdd Matthew Brost to maintainers of GPU scheduler
--- MAINTAINERS | 1 + 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
@@ -7134,6 +7134,7 @@ F: drivers/gpu/drm/xlnx/ DRM GPU SCHEDULER M: Luben Tuikov <[email protected]> +M: Matthew Brost <[email protected]> L: [email protected] S: Maintained T: git git://anongit.freedesktop.org/drm/drm-misc
Signature · 1 line
2.34.1
Patchwork
CI[Intel-xe] ✗ CI.Patch_applied: failure for DRM scheduler changes for Xe (rev6)
In reply to Matthew Brost== Series Details ==
== Series Details ==
Series: DRM scheduler changes for Xe (rev6)
URL : https://patchwork.freedesktop.org/series/121744/
State : failure
== Summary ==
=== Applying kernel patches on branch 'drm-xe-next' with base: ===
Base commit: 22df933d8 drm/xe: Rename exec_queue_kill_compute to xe_vm_remove_compute_exec_queue === git am output follows ===
error: patch failed: drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c:290
error: drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c: patch does not apply
error: patch failed: drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c:1659
error: drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c: patch does not apply
error: patch failed: drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:4588
error: drivers/gpu/drm/amd/amdgpu/amdgpu_device.c: patch does not apply
error: patch failed: drivers/gpu/drm/msm/adreno/adreno_device.c:809
error: drivers/gpu/drm/msm/adreno/adreno_device.c: patch does not apply
error: patch failed: drivers/gpu/drm/scheduler/sched_main.c:439
error: drivers/gpu/drm/scheduler/sched_main.c: patch does not apply
error: patch failed: include/drm/gpu_scheduler.h:550
error: include/drm/gpu_scheduler.h: patch does not apply
hint: Use 'git am --show-current-patch' to see the failed patch
Applying: drm/sched: Add drm_sched_submit_* helpers
Patch failed at 0001 drm/sched: Add drm_sched_submit_* helpers
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Hi Matt,
Quoted 23 lines · Matthew Brost
As a prerequisite to merging the new Intel Xe DRM driver [1] [2], we have been asked to merge our common DRM scheduler patches first.
This a continuation of a RFC [3] with all comments addressed, ready for a full review, and hopefully in state which can merged in the near future. More details of this series can found in the cover letter of the RFC [3].
These changes have been tested with the Xe driver.
v2:
- Break run job, free job, and process message in own work items
- This might break other drivers as run job and free job now can run in parallel, can fix up if neededv3:
- Include missing patch 'drm/sched: Add drm_sched_submit_* helpers'
- Fix issue with setting timestamp to early
- Don't dequeue jobs for single entity after calling entity fini
- Flush pending jobs on entity fini
- Add documentation for entity teardown
- Add Matthew Brost to maintainers of DRM scheduler
Quoted 5 lines
v4:
- Drop message interface
- Drop 'Flush pending jobs on entity fini'
- Drop 'Add documentation for entity teardown'
- Address all feedback
There is some feedback from V3 that doesn't seem to be addressed yet.
(1) Document tear down of struct drm_gpu_scheduler. [1]
(2) Implement helpers to tear down struct drm_gpu_scheduler. [2]
(3) Document implications of using a workqueue in terms of free_job() being or not being part of the fence signaling path respectively. [3]
I think at least (1) and (3) should be part of this series. I think (2) could also happen subsequently. Christian's idea [2] how to address this is quite interesting, but might exceed the scope of this series.
I will try to rebase my Nouveau changes onto your V4 tomorrow for a quick test.
- Danilo
[1] https://lore.kernel.org/all/[email protected]/T/#m2e8c1c1e68e8127d5dd62509b5e424a12217300b
[2] https://lore.kernel.org/all/[email protected]/T/#m16a0d6fa2e617383776515af45d3c6b9db543d47
[3] https://lore.kernel.org/all/[email protected]/T/#m807ff95284089fdb51985f1c187666772314bd8a
Quoted 34 lines
Matt
Matthew Brost (10):
drm/sched: Add drm_sched_submit_* helpers
drm/sched: Convert drm scheduler to use a work queue rather than
kthread
drm/sched: Move schedule policy to scheduler
drm/sched: AddDRM_SCHED_POLICY_SINGLE_ENTITYscheduling policy drm/sched: Splitfree_jobinto own work item
drm/sched: Adddrm_sched_start_timeout_unlockedhelper drm/sched: Start submission before TDR indrm_sched_startdrm/sched: Submit job before starting TDR
drm/sched: Add helper to queue TDR immediately for current and future
jobs
drm/sched: Update maintainers of GPU schedulerMAINTAINERS | 1 + .../drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 15 +- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 15 +- drivers/gpu/drm/etnaviv/etnaviv_sched.c | 5 +- drivers/gpu/drm/lima/lima_sched.c | 5 +- drivers/gpu/drm/msm/adreno/adreno_device.c | 6 +- drivers/gpu/drm/msm/msm_ringbuffer.c | 5 +- drivers/gpu/drm/nouveau/nouveau_sched.c | 5 +- drivers/gpu/drm/panfrost/panfrost_job.c | 5 +- drivers/gpu/drm/scheduler/sched_entity.c | 85 ++- drivers/gpu/drm/scheduler/sched_fence.c | 2 +- drivers/gpu/drm/scheduler/sched_main.c | 491 ++++++++++++------ drivers/gpu/drm/v3d/v3d_sched.c | 25 +- include/drm/gpu_scheduler.h | 48 +- 15 files changed, 495 insertions(+), 220 deletions(-)
Danilo Krummrich
Tested-byQuoted 39 lines · Danilo Krummrich
Hi Matt,
Quoted 23 lines · Matthew Brost
As a prerequisite to merging the new Intel Xe DRM driver [1] [2], we have been asked to merge our common DRM scheduler patches first.
This a continuation of a RFC [3] with all comments addressed, ready for a full review, and hopefully in state which can merged in the near future. More details of this series can found in the cover letter of the RFC [3].
These changes have been tested with the Xe driver.
v2:
- Break run job, free job, and process message in own work items
- This might break other drivers as run job and free job now can run in parallel, can fix up if neededv3:
- Include missing patch 'drm/sched: Add drm_sched_submit_* helpers'
- Fix issue with setting timestamp to early
- Don't dequeue jobs for single entity after calling entity fini
- Flush pending jobs on entity fini
- Add documentation for entity teardown
- Add Matthew Brost to maintainers of DRM schedulerQuoted 5 lines
v4:
- Drop message interface
- Drop 'Flush pending jobs on entity fini'
- Drop 'Add documentation for entity teardown'
- Address all feedbackThere is some feedback from V3 that doesn't seem to be addressed yet.
(1) Document tear down of struct
drm_gpu_scheduler. [1]
(2) Implement helpers to tear down structdrm_gpu_scheduler. [2]
(3) Document implications of using a workqueue in terms offree_job()being or not being part of the fence signaling path respectively. [3]
Quoted 5 lines
I think at least (1) and (3) should be part of this series. I think (2) could also happen subsequently. Christian's idea [2] how to address this is quite interesting, but might exceed the scope of this series.
I will try to rebase my Nouveau changes onto your V4 tomorrow for a quick test.
Quoted 41 lines
- Danilo
[1] https://lore.kernel.org/all/[email protected]/T/#m2e8c1c1e68e8127d5dd62509b5e424a12217300b
[2] https://lore.kernel.org/all/[email protected]/T/#m16a0d6fa2e617383776515af45d3c6b9db543d47
[3] https://lore.kernel.org/all/[email protected]/T/#m807ff95284089fdb51985f1c187666772314bd8aQuoted 34 lines
Matt
Matthew Brost (10):
drm/sched: Add drm_sched_submit_* helpers
drm/sched: Convert drm scheduler to use a work queue rather than kthread
drm/sched: Move schedule policy to scheduler
drm/sched: AddDRM_SCHED_POLICY_SINGLE_ENTITYscheduling policy drm/sched: Splitfree_jobinto own work item
drm/sched: Adddrm_sched_start_timeout_unlockedhelper drm/sched: Start submission before TDR indrm_sched_startdrm/sched: Submit job before starting TDR
drm/sched: Add helper to queue TDR immediately for current and future jobs
drm/sched: Update maintainers of GPU schedulerMAINTAINERS | 1 + .../drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 15 +- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 15 +- drivers/gpu/drm/etnaviv/etnaviv_sched.c | 5 +- drivers/gpu/drm/lima/lima_sched.c | 5 +- drivers/gpu/drm/msm/adreno/adreno_device.c | 6 +- drivers/gpu/drm/msm/msm_ringbuffer.c | 5 +- drivers/gpu/drm/nouveau/nouveau_sched.c | 5 +- drivers/gpu/drm/panfrost/panfrost_job.c | 5 +- drivers/gpu/drm/scheduler/sched_entity.c | 85 ++- drivers/gpu/drm/scheduler/sched_fence.c | 2 +- drivers/gpu/drm/scheduler/sched_main.c | 491 ++++++++++++------ drivers/gpu/drm/v3d/v3d_sched.c | 25 +- include/drm/gpu_scheduler.h | 48 +-
15 files changed, 495 insertions(+), 220 deletions(-)
Quoted 31 lines · On Mon, 18 Sep 2023 22:01:45 -0700 Matthew Brost <[email protected]>…
As a prerequisite to merging the new Intel Xe DRM driver [1] [2], we have been asked to merge our common DRM scheduler patches first.
This a continuation of a RFC [3] with all comments addressed, ready for a full review, and hopefully in state which can merged in the near future. More details of this series can found in the cover letter of the RFC [3].
These changes have been tested with the Xe driver.
v2:
- Break run job, free job, and process message in own work items
- This might break other drivers as run job and free job now can run in parallel, can fix up if neededv3:
- Include missing patch 'drm/sched: Add drm_sched_submit_* helpers'
- Fix issue with setting timestamp to early
- Don't dequeue jobs for single entity after calling entity fini
- Flush pending jobs on entity fini
- Add documentation for entity teardown
- Add Matthew Brost to maintainers of DRM schedulerv4:
- Drop message interface
- Drop 'Flush pending jobs on entity fini'
- Drop 'Add documentation for entity teardown'
- Address all feedbackMatt
Quoted 13 lines
Matthew Brost (10):
drm/sched: Add drm_sched_submit_* helpers
drm/sched: Convert drm scheduler to use a work queue rather than
kthread
drm/sched: Move schedule policy to scheduler
drm/sched: AddDRM_SCHED_POLICY_SINGLE_ENTITYscheduling policy drm/sched: Splitfree_jobinto own work item
drm/sched: Adddrm_sched_start_timeout_unlockedhelper drm/sched: Start submission before TDR indrm_sched_startdrm/sched: Submit job before starting TDR
drm/sched: Add helper to queue TDR immediately for current and future
jobs
drm/sched: Update maintainers of GPU scheduler
Quoted 18 lines
MAINTAINERS | 1 + .../drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 15 +- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 15 +- drivers/gpu/drm/etnaviv/etnaviv_sched.c | 5 +- drivers/gpu/drm/lima/lima_sched.c | 5 +- drivers/gpu/drm/msm/adreno/adreno_device.c | 6 +- drivers/gpu/drm/msm/msm_ringbuffer.c | 5 +- drivers/gpu/drm/nouveau/nouveau_sched.c | 5 +- drivers/gpu/drm/panfrost/panfrost_job.c | 5 +- drivers/gpu/drm/scheduler/sched_entity.c | 85 ++- drivers/gpu/drm/scheduler/sched_fence.c | 2 +- drivers/gpu/drm/scheduler/sched_main.c | 491 ++++++++++++------ drivers/gpu/drm/v3d/v3d_sched.c | 25 +- include/drm/gpu_scheduler.h | 48 +- 15 files changed, 495 insertions(+), 220 deletions(-)