drm/amdgpu: delay job free to when it's finished (v2)
authorMonk Liu <Monk.Liu@amd.com>
Thu, 3 Mar 2016 11:00:50 +0000 (19:00 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Mon, 2 May 2016 19:17:41 +0000 (15:17 -0400)
for those jobs submitted through scheduler, do not
free it immediately after scheduled, instead free it
in global workqueue by its sched fence signaling
callback function.

v2:
call uf's bo_undef after job_run()
call job's sync free after job_run()
no static inline __amdgpu_job_free() anymore, just use
kfree(job) to replace it.

Signed-off-by: Monk Liu <Monk.Liu@amd.com>
Reviewed-by: Chunming Zhou <david1.zhou@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu.h
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
drivers/gpu/drm/amd/scheduler/gpu_scheduler.c
drivers/gpu/drm/amd/scheduler/gpu_scheduler.h

index 412fc2f39fa5adffe81919dd15e99d6e0ce0361a..9bf72b24495c39850d60110f4810693880c3a9b5 100644 (file)
@@ -2401,5 +2401,4 @@ amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
                       uint64_t addr, struct amdgpu_bo **bo);
 
 #include "amdgpu_object.h"
-
 #endif
index eb0f7890401abe6b71fb5df79ca659278777792c..23468088a9958e83265e348c790e8a175cfa203b 100644 (file)
 #include "amdgpu.h"
 #include "amdgpu_trace.h"
 
+static void amdgpu_job_free_handler(struct work_struct *ws)
+{
+       struct amdgpu_job *job = container_of(ws, struct amdgpu_job, base.work_free_job);
+       kfree(job);
+}
+
 int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs,
                     struct amdgpu_job **job)
 {
@@ -45,6 +51,7 @@ int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs,
        (*job)->adev = adev;
        (*job)->ibs = (void *)&(*job)[1];
        (*job)->num_ibs = num_ibs;
+       INIT_WORK(&(*job)->base.work_free_job, amdgpu_job_free_handler);
 
        amdgpu_sync_create(&(*job)->sync);
 
@@ -80,7 +87,9 @@ void amdgpu_job_free(struct amdgpu_job *job)
 
        amdgpu_bo_unref(&job->uf.bo);
        amdgpu_sync_free(&job->sync);
-       kfree(job);
+
+       if (!job->base.use_sched)
+               kfree(job);
 }
 
 int amdgpu_job_submit(struct amdgpu_job *job, struct amdgpu_ring *ring,
index b9d5822bece8dd13b375a9191fa891f42ce97ab8..8d49ea2e413439132e1fb42fe068e8a291da737b 100644 (file)
@@ -319,6 +319,11 @@ static bool amd_sched_entity_in(struct amd_sched_job *sched_job)
        return added;
 }
 
+static void amd_sched_free_job(struct fence *f, struct fence_cb *cb) {
+       struct amd_sched_job *job = container_of(cb, struct amd_sched_job, cb_free_job);
+       schedule_work(&job->work_free_job);
+}
+
 /**
  * Submit a job to the job queue
  *
@@ -330,6 +335,9 @@ void amd_sched_entity_push_job(struct amd_sched_job *sched_job)
 {
        struct amd_sched_entity *entity = sched_job->s_entity;
 
+       sched_job->use_sched = 1;
+       fence_add_callback(&sched_job->s_fence->base,
+                                       &sched_job->cb_free_job, amd_sched_free_job);
        trace_amd_sched_job(sched_job);
        wait_event(entity->sched->job_scheduled,
                   amd_sched_entity_in(sched_job));
index 74bbec837f58b7c75debdc29e88335b4eb6a8c9c..ee1e8127f86370a55f59df5767700beae1c131f4 100644 (file)
@@ -37,7 +37,7 @@ extern atomic_t sched_fence_slab_ref;
 
 /**
  * A scheduler entity is a wrapper around a job queue or a group
- * of other entities. Entities take turns emitting jobs from their 
+ * of other entities. Entities take turns emitting jobs from their
  * job queues to corresponding hardware ring based on scheduling
  * policy.
 */
@@ -82,6 +82,9 @@ struct amd_sched_job {
        struct amd_gpu_scheduler        *sched;
        struct amd_sched_entity         *s_entity;
        struct amd_sched_fence          *s_fence;
+       bool    use_sched;      /* true if the job goes to scheduler */
+       struct fence_cb                cb_free_job;
+       struct work_struct             work_free_job;
 };
 
 extern const struct fence_ops amd_sched_fence_ops;