2015-05-22 18:55:07 +08:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Advanced Micro Devices, Inc.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _GPU_SCHEDULER_H_
|
|
|
|
#define _GPU_SCHEDULER_H_
|
|
|
|
|
|
|
|
#include <linux/kfifo.h>
|
2016-10-25 20:00:45 +08:00
|
|
|
#include <linux/dma-fence.h>
|
2015-05-22 18:55:07 +08:00
|
|
|
|
|
|
|
struct amd_gpu_scheduler;
|
2015-08-12 17:46:04 +08:00
|
|
|
struct amd_sched_rq;
|
2015-05-22 18:55:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A scheduler entity is a wrapper around a job queue or a group
|
2016-03-03 19:00:50 +08:00
|
|
|
* of other entities. Entities take turns emitting jobs from their
|
2015-05-22 18:55:07 +08:00
|
|
|
* job queues to corresponding hardware ring based on scheduling
|
|
|
|
* policy.
|
|
|
|
*/
|
|
|
|
struct amd_sched_entity {
|
|
|
|
struct list_head list;
|
2015-09-08 00:07:14 +08:00
|
|
|
struct amd_sched_rq *rq;
|
|
|
|
struct amd_gpu_scheduler *sched;
|
|
|
|
|
2015-08-06 00:33:21 +08:00
|
|
|
spinlock_t queue_lock;
|
2015-09-08 00:07:14 +08:00
|
|
|
struct kfifo job_queue;
|
|
|
|
|
|
|
|
atomic_t fence_seq;
|
2015-08-02 11:18:04 +08:00
|
|
|
uint64_t fence_context;
|
2015-09-08 00:07:14 +08:00
|
|
|
|
2016-10-25 20:00:45 +08:00
|
|
|
struct dma_fence *dependency;
|
|
|
|
struct dma_fence_cb cb;
|
2015-05-22 18:55:07 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run queue is a set of entities scheduling command submissions for
|
|
|
|
* one specific ring. It implements the scheduling policy that selects
|
|
|
|
* the next entity to emit commands from.
|
|
|
|
*/
|
2015-08-12 17:46:04 +08:00
|
|
|
struct amd_sched_rq {
|
2015-08-18 20:41:25 +08:00
|
|
|
spinlock_t lock;
|
2015-08-12 17:46:04 +08:00
|
|
|
struct list_head entities;
|
|
|
|
struct amd_sched_entity *current_entity;
|
2015-05-22 18:55:07 +08:00
|
|
|
};
|
|
|
|
|
2015-08-02 11:18:04 +08:00
|
|
|
struct amd_sched_fence {
|
2016-10-25 20:00:45 +08:00
|
|
|
struct dma_fence scheduled;
|
|
|
|
struct dma_fence finished;
|
|
|
|
struct dma_fence_cb cb;
|
|
|
|
struct dma_fence *parent;
|
2015-09-08 00:16:49 +08:00
|
|
|
struct amd_gpu_scheduler *sched;
|
2015-08-02 11:18:04 +08:00
|
|
|
spinlock_t lock;
|
2015-08-24 12:47:36 +08:00
|
|
|
void *owner;
|
2015-08-02 11:18:04 +08:00
|
|
|
};
|
|
|
|
|
2015-08-05 19:52:14 +08:00
|
|
|
struct amd_sched_job {
|
|
|
|
struct amd_gpu_scheduler *sched;
|
2015-08-06 15:19:12 +08:00
|
|
|
struct amd_sched_entity *s_entity;
|
2015-08-02 11:18:04 +08:00
|
|
|
struct amd_sched_fence *s_fence;
|
2016-10-25 20:00:45 +08:00
|
|
|
struct dma_fence_cb finish_cb;
|
2016-05-19 15:54:15 +08:00
|
|
|
struct work_struct finish_work;
|
|
|
|
struct list_head node;
|
|
|
|
struct delayed_work work_tdr;
|
2015-08-05 19:52:14 +08:00
|
|
|
};
|
|
|
|
|
2016-10-25 20:00:45 +08:00
|
|
|
extern const struct dma_fence_ops amd_sched_fence_ops_scheduled;
|
|
|
|
extern const struct dma_fence_ops amd_sched_fence_ops_finished;
|
|
|
|
static inline struct amd_sched_fence *to_amd_sched_fence(struct dma_fence *f)
|
2015-08-02 11:18:04 +08:00
|
|
|
{
|
2016-05-20 18:53:52 +08:00
|
|
|
if (f->ops == &amd_sched_fence_ops_scheduled)
|
|
|
|
return container_of(f, struct amd_sched_fence, scheduled);
|
2015-08-02 11:18:04 +08:00
|
|
|
|
2016-05-20 18:53:52 +08:00
|
|
|
if (f->ops == &amd_sched_fence_ops_finished)
|
|
|
|
return container_of(f, struct amd_sched_fence, finished);
|
2015-08-02 11:18:04 +08:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-05-22 18:55:07 +08:00
|
|
|
/**
|
|
|
|
* Define the backend operations called by the scheduler,
|
|
|
|
* these functions should be implemented in driver side
|
|
|
|
*/
|
|
|
|
struct amd_sched_backend_ops {
|
2016-10-25 20:00:45 +08:00
|
|
|
struct dma_fence *(*dependency)(struct amd_sched_job *sched_job);
|
|
|
|
struct dma_fence *(*run_job)(struct amd_sched_job *sched_job);
|
2016-05-18 20:19:32 +08:00
|
|
|
void (*timedout_job)(struct amd_sched_job *sched_job);
|
2016-05-19 15:54:15 +08:00
|
|
|
void (*free_job)(struct amd_sched_job *sched_job);
|
2015-05-22 18:55:07 +08:00
|
|
|
};
|
|
|
|
|
2015-11-05 15:23:09 +08:00
|
|
|
enum amd_sched_priority {
|
|
|
|
AMD_SCHED_PRIORITY_KERNEL = 0,
|
|
|
|
AMD_SCHED_PRIORITY_NORMAL,
|
|
|
|
AMD_SCHED_MAX_PRIORITY
|
|
|
|
};
|
|
|
|
|
2015-05-22 18:55:07 +08:00
|
|
|
/**
|
|
|
|
* One scheduler is implemented for each hardware ring
|
|
|
|
*/
|
|
|
|
struct amd_gpu_scheduler {
|
2016-04-10 22:30:00 +08:00
|
|
|
const struct amd_sched_backend_ops *ops;
|
2015-09-09 02:22:31 +08:00
|
|
|
uint32_t hw_submission_limit;
|
2015-10-10 08:48:42 +08:00
|
|
|
long timeout;
|
2015-09-09 02:22:31 +08:00
|
|
|
const char *name;
|
2015-11-05 15:23:09 +08:00
|
|
|
struct amd_sched_rq sched_rq[AMD_SCHED_MAX_PRIORITY];
|
2015-08-26 03:39:31 +08:00
|
|
|
wait_queue_head_t wake_up_worker;
|
|
|
|
wait_queue_head_t job_scheduled;
|
2015-09-09 02:22:31 +08:00
|
|
|
atomic_t hw_rq_count;
|
|
|
|
struct task_struct *thread;
|
2016-03-04 14:33:44 +08:00
|
|
|
struct list_head ring_mirror_list;
|
|
|
|
spinlock_t job_list_lock;
|
2015-05-22 18:55:07 +08:00
|
|
|
};
|
|
|
|
|
2015-09-09 02:22:31 +08:00
|
|
|
int amd_sched_init(struct amd_gpu_scheduler *sched,
|
2016-04-10 22:30:00 +08:00
|
|
|
const struct amd_sched_backend_ops *ops,
|
2015-10-10 08:48:42 +08:00
|
|
|
uint32_t hw_submission, long timeout, const char *name);
|
2015-09-09 02:22:31 +08:00
|
|
|
void amd_sched_fini(struct amd_gpu_scheduler *sched);
|
2015-05-22 18:55:07 +08:00
|
|
|
|
2015-08-06 00:33:21 +08:00
|
|
|
int amd_sched_entity_init(struct amd_gpu_scheduler *sched,
|
|
|
|
struct amd_sched_entity *entity,
|
2015-08-12 17:46:04 +08:00
|
|
|
struct amd_sched_rq *rq,
|
2015-08-06 00:33:21 +08:00
|
|
|
uint32_t jobs);
|
2015-08-21 21:46:43 +08:00
|
|
|
void amd_sched_entity_fini(struct amd_gpu_scheduler *sched,
|
|
|
|
struct amd_sched_entity *entity);
|
2015-11-06 02:49:48 +08:00
|
|
|
void amd_sched_entity_push_job(struct amd_sched_job *sched_job);
|
2015-05-22 18:55:07 +08:00
|
|
|
|
2016-10-28 23:04:07 +08:00
|
|
|
int amd_sched_fence_slab_init(void);
|
|
|
|
void amd_sched_fence_slab_fini(void);
|
|
|
|
|
2015-08-02 11:18:04 +08:00
|
|
|
struct amd_sched_fence *amd_sched_fence_create(
|
2015-08-24 12:47:36 +08:00
|
|
|
struct amd_sched_entity *s_entity, void *owner);
|
2015-11-05 19:57:10 +08:00
|
|
|
void amd_sched_fence_scheduled(struct amd_sched_fence *fence);
|
2016-05-20 18:53:52 +08:00
|
|
|
void amd_sched_fence_finished(struct amd_sched_fence *fence);
|
2016-03-07 12:49:55 +08:00
|
|
|
int amd_sched_job_init(struct amd_sched_job *job,
|
2016-05-18 15:43:07 +08:00
|
|
|
struct amd_gpu_scheduler *sched,
|
|
|
|
struct amd_sched_entity *entity,
|
2016-06-30 16:52:03 +08:00
|
|
|
void *owner);
|
2016-06-30 11:30:37 +08:00
|
|
|
void amd_sched_hw_job_reset(struct amd_gpu_scheduler *sched);
|
2016-06-29 15:23:55 +08:00
|
|
|
void amd_sched_job_recovery(struct amd_gpu_scheduler *sched);
|
2015-05-22 18:55:07 +08:00
|
|
|
#endif
|