drm/scheduler re-insert Bailing job to avoid memleak
Subsystems (5)
PATCH v2 1/1 drm/scheduler re-insert Bailing job to avoid memleak
re-insert Bailing jobs to avoid memory leak.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 4 +++- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 8 ++++++-- drivers/gpu/drm/panfrost/panfrost_job.c | 2 +- drivers/gpu/drm/scheduler/sched_main.c | 8 +++++++- include/drm/gpu_scheduler.h | 1 + 5 files changed, 18 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -1
@@ -4815,8 +4815,10 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev, job ? job->base.id : -1);/* even we skipped this reset, still need to set the job to guilty */ -if (job) +if (job) {drm_sched_increase_karma (&job->base); + r =DRM_GPU_SCHED_STAT_BAILING ; + } goto skip_recovery; }
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +6 -2
@@ -34,6 +34,7 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)struct amdgpu_job *job =to_amdgpu_job (s_job);struct amdgpu_task_info ti;struct amdgpu_device *adev = ring->adev; +int ret;memset (&ti,0 ,sizeof (struct amdgpu_task_info ));
@@ -52,8 +53,11 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job) ti.process_name, ti.tgid, ti.task_name, ti.pid);if (amdgpu_device_should_recover_gpu (ring->adev)) { -amdgpu_device_gpu_recover (ring->adev, job); -return DRM_GPU_SCHED_STAT_NOMINAL ; + ret =amdgpu_device_gpu_recover (ring->adev, job); +if (ret ==DRM_GPU_SCHED_STAT_BAILING ) +return DRM_GPU_SCHED_STAT_BAILING ; +else +return DRM_GPU_SCHED_STAT_NOMINAL ; }else {drm_sched_suspend_timeout (&ring->sched);if (amdgpu_sriov_vf (adev))
drivers/gpu/drm/panfrost/panfrost_job.c +1 -1
@@ -456,7 +456,7 @@ static enum drm_gpu_sched_stat panfrost_job_timedout(struct drm_sched_job/* Scheduler is already stopped, nothing to do. */ if (!panfrost_scheduler_stop (&pfdev->js->queue[js], sched_job)) -return DRM_GPU_SCHED_STAT_NOMINAL ; +return DRM_GPU_SCHED_STAT_BAILING ;/* Schedule a reset if there's no reset in progress. */ if (!atomic_xchg (&pfdev->reset.pending,1 ))
drivers/gpu/drm/scheduler/sched_main.c +7 -1
@@ -314,6 +314,7 @@ static void drm_sched_job_timedout(struct work_struct *work) {struct drm_gpu_scheduler *sched;struct drm_sched_job *job; +int ret; sched = container_of(work, struct drm_gpu_scheduler, work_tdr.work);
@@ -331,8 +332,13 @@ static void drm_sched_job_timedout(struct work_struct *work)list_del_init (&job->list);spin_unlock (&sched->job_list_lock); - job->sched->ops->timedout_job (job); + ret = job->sched->ops->timedout_job (job); +if (ret ==DRM_GPU_SCHED_STAT_BAILING ) { +spin_lock (&sched->job_list_lock); +list_add (&job->node, &sched->ring_mirror_list); +spin_unlock (&sched->job_list_lock); + }/* * Guilty job did complete and hence needs to be manually removed * See drm_sched_stop doc.
include/drm/gpu_scheduler.h +1 -0
@@ -210,6 +210,7 @@ enum drm_gpu_sched_stat {DRM_GPU_SCHED_STAT_NONE ,/* Reserve 0 */ DRM_GPU_SCHED_STAT_NOMINAL ,DRM_GPU_SCHED_STAT_ENODEV , + DRM_GPU_SCHED_STAT_BAILING, };/**
Signature · 6 lines
2.25.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 1 line · Jack Zhang
re-insert Bailing jobs to avoid memory leak.
Usually we put a v2:"Blha blha blha" here to explain what was modified in v2
Also - since you make changes to another driver you should add their maintainer and mailing list probably (use ./scripts/get_maintainer.pl) for this
Quoted 57 lines
Signed-off-by Jack Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 4 +++- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 8 ++++++-- drivers/gpu/drm/panfrost/panfrost_job.c | 2 +- drivers/gpu/drm/scheduler/sched_main.c | 8 +++++++- include/drm/gpu_scheduler.h | 1 + 5 files changed, 18 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3
-1@@ -4815,8 +4815,10 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev, job ? job->base.id : -1);/* even we skipped this reset, still need to set the job to guilty */ -if (job) +if (job) {drm_sched_increase_karma (&job->base); + r =DRM_GPU_SCHED_STAT_BAILING ; + } goto skip_recovery; }drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +6
-2@@ -34,6 +34,7 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)struct amdgpu_job *job =to_amdgpu_job (s_job);struct amdgpu_task_info ti;struct amdgpu_device *adev = ring->adev; +int ret;memset (&ti,0 ,sizeof (struct amdgpu_task_info ));@@ -52,8 +53,11 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job) ti.process_name, ti.tgid, ti.task_name, ti.pid);if (amdgpu_device_should_recover_gpu (ring->adev)) { -amdgpu_device_gpu_recover (ring->adev, job); -return DRM_GPU_SCHED_STAT_NOMINAL ; + ret =amdgpu_device_gpu_recover (ring->adev, job); +if (ret ==DRM_GPU_SCHED_STAT_BAILING ) +return DRM_GPU_SCHED_STAT_BAILING ; +else +return DRM_GPU_SCHED_STAT_NOMINAL ; }else {drm_sched_suspend_timeout (&ring->sched);if (amdgpu_sriov_vf (adev))drivers/gpu/drm/panfrost/panfrost_job.c +0
-0
drivers/gpu/drm/panfrost/panfrost_job.c static enum drm_gpu_sched_stat panfrost_job_timedout(struct drm_sched_job · line 459
Quoted 5 lines
drivers/gpu/drm/panfrost/panfrost_job.c +1
-1@@ -456,7 +456,7 @@ static enum drm_gpu_sched_stat panfrost_job_timedout(struct drm_sched_job/* Scheduler is already stopped, nothing to do. */ if (!panfrost_scheduler_stop (&pfdev->js->queue[js], sched_job)) -return DRM_GPU_SCHED_STAT_NOMINAL ; +return DRM_GPU_SCHED_STAT_BAILING ;
Note that there is another early termination in panfrost
at https://elixir.bootlin.com/linux/v5.11.1/source/drivers/gpu/drm/panfrost/panfrost_job.c#L445
So probably should also add there.
Quoted 17 lines
drivers/gpu/drm/panfrost/panfrost_job.c +0
-0/* Schedule a reset if there's no reset in progress. */ if (!atomic_xchg (&pfdev->reset.pending,1 ))drivers/gpu/drm/scheduler/sched_main.c +1
-0@@ -314,6 +314,7 @@ static void drm_sched_job_timedout(struct work_struct *work) {struct drm_gpu_scheduler *sched;struct drm_sched_job *job; +int ret; sched = container_of(work, struct drm_gpu_scheduler, work_tdr.work);@@ -331,8 +332,13 @@ static void drm_sched_job_timedout(struct work_struct *work)list_del_init (&job->list);
drivers/gpu/drm/scheduler/sched_main.c static void drm_sched_job_timedout(struct work_struct *work) · line 341
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +6
-1spin_unlock (&sched->job_list_lock); - job->sched->ops->timedout_job (job); + ret = job->sched->ops->timedout_job (job); +if (ret ==DRM_GPU_SCHED_STAT_BAILING ) { +spin_lock (&sched->job_list_lock); +list_add (&job->node, &sched->ring_mirror_list); +spin_unlock (&sched->job_list_lock); + }
Just reiterating my comment from v1 here since u missed it - Problem here that since you already dropped the reset locks you are racing here now against other recovery threads as they process the same mirror list, and yet,I think this solution makes things better then they are now with the leak but still, it's only temporary band-aid until the full solution to be implemented as described earlier by Christian. Probably then worth mentioning here with a comment this it's a temporary fix and that races are possible.
Andrey
Quoted 9 lines
drivers/gpu/drm/scheduler/sched_main.c +0
-0/* * Guilty job did complete and hence needs to be manually removed * See drm_sched_stop doc. include/drm/gpu_scheduler.h +0
-0
include/drm/gpu_scheduler.h enum drm_gpu_sched_stat { · line 216
Quoted 7 lines
include/drm/gpu_scheduler.h +1
-0@@ -210,6 +210,7 @@ enum drm_gpu_sched_stat {DRM_GPU_SCHED_STAT_NONE ,/* Reserve 0 */ DRM_GPU_SCHED_STAT_NOMINAL ,DRM_GPU_SCHED_STAT_ENODEV , + DRM_GPU_SCHED_STAT_BAILING, };/**
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx