drm/amdgpu: abstract amdgpu_job for scheduler
Signed-off-by: Chunming Zhou <david1.zhou@amd.com>
Reviewed-by: Christian K?nig <christian.koenig@amd.com>
diff --git a/drivers/gpu/drm/amd/scheduler/gpu_scheduler.c b/drivers/gpu/drm/amd/scheduler/gpu_scheduler.c
index 265d3e2..462c161 100644
--- a/drivers/gpu/drm/amd/scheduler/gpu_scheduler.c
+++ b/drivers/gpu/drm/amd/scheduler/gpu_scheduler.c
@@ -282,30 +282,18 @@
* scheduler consum some queued command.
* -1 other fail.
*/
-int amd_sched_push_job(struct amd_gpu_scheduler *sched,
- struct amd_sched_entity *c_entity,
- void *data,
- struct amd_sched_fence **fence)
+int amd_sched_push_job(struct amd_sched_job *sched_job)
{
- struct amd_sched_job *job;
-
+ struct amd_sched_fence *fence =
+ amd_sched_fence_create(sched_job->s_entity);
if (!fence)
return -EINVAL;
- job = kzalloc(sizeof(struct amd_sched_job), GFP_KERNEL);
- if (!job)
- return -ENOMEM;
- job->sched = sched;
- job->s_entity = c_entity;
- job->data = data;
- *fence = amd_sched_fence_create(c_entity);
- if ((*fence) == NULL) {
- kfree(job);
- return -EINVAL;
- }
- fence_get(&(*fence)->base);
- job->s_fence = *fence;
- while (kfifo_in_spinlocked(&c_entity->job_queue, &job, sizeof(void *),
- &c_entity->queue_lock) != sizeof(void *)) {
+ fence_get(&fence->base);
+ sched_job->s_fence = fence;
+ while (kfifo_in_spinlocked(&sched_job->s_entity->job_queue,
+ &sched_job, sizeof(void *),
+ &sched_job->s_entity->queue_lock) !=
+ sizeof(void *)) {
/**
* Current context used up all its IB slots
* wait here, or need to check whether GPU is hung
@@ -313,8 +301,8 @@
schedule();
}
/* first job wake up scheduler */
- if ((kfifo_len(&c_entity->job_queue) / sizeof(void *)) == 1)
- wake_up_interruptible(&sched->wait_queue);
+ if ((kfifo_len(&sched_job->s_entity->job_queue) / sizeof(void *)) == 1)
+ wake_up_interruptible(&sched_job->sched->wait_queue);
return 0;
}
@@ -333,10 +321,8 @@
list_del(&sched_job->list);
atomic64_dec(&sched->hw_rq_count);
spin_unlock_irqrestore(&sched->queue_lock, flags);
-
- sched->ops->process_job(sched, sched_job);
fence_put(&sched_job->s_fence->base);
- kfree(sched_job);
+ sched->ops->process_job(sched, sched_job);
wake_up_interruptible(&sched->wait_queue);
}
@@ -359,7 +345,9 @@
r = kfifo_out(&c_entity->job_queue, &job, sizeof(void *));
if (r != sizeof(void *))
continue;
- r = sched->ops->prepare_job(sched, c_entity, job);
+ r = 0;
+ if (sched->ops->prepare_job)
+ r = sched->ops->prepare_job(sched, c_entity, job);
if (!r) {
unsigned long flags;
spin_lock_irqsave(&sched->queue_lock, flags);