2015-05-22 10:55:07 +00: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>
|
2015-08-05 11:52:14 +00:00
|
|
|
#include <linux/fence.h>
|
2015-05-22 10:55:07 +00:00
|
|
|
|
2015-11-05 11:57:10 +00:00
|
|
|
#define AMD_SCHED_FENCE_SCHEDULED_BIT FENCE_FLAG_USER_BITS
|
|
|
|
|
2015-05-22 10:55:07 +00:00
|
|
|
struct amd_gpu_scheduler;
|
2015-08-12 09:46:04 +00:00
|
|
|
struct amd_sched_rq;
|
2015-05-22 10:55:07 +00:00
|
|
|
|
2015-11-05 03:41:50 +00:00
|
|
|
extern struct kmem_cache *sched_fence_slab;
|
|
|
|
extern atomic_t sched_fence_slab_ref;
|
|
|
|
|
2015-05-22 10:55:07 +00:00
|
|
|
/**
|
|
|
|
* A scheduler entity is a wrapper around a job queue or a group
|
2016-03-03 11:00:50 +00:00
|
|
|
* of other entities. Entities take turns emitting jobs from their
|
2015-05-22 10:55:07 +00:00
|
|
|
* job queues to corresponding hardware ring based on scheduling
|
|
|
|
* policy.
|
|
|
|
*/
|
|
|
|
struct amd_sched_entity {
|
|
|
|
struct list_head list;
|
2015-09-07 16:07:14 +00:00
|
|
|
struct amd_sched_rq *rq;
|
|
|
|
struct amd_gpu_scheduler *sched;
|
|
|
|
|
2015-08-05 16:33:21 +00:00
|
|
|
spinlock_t queue_lock;
|
2015-09-07 16:07:14 +00:00
|
|
|
struct kfifo job_queue;
|
|
|
|
|
|
|
|
atomic_t fence_seq;
|
2015-08-02 03:18:04 +00:00
|
|
|
uint64_t fence_context;
|
2015-09-07 16:07:14 +00:00
|
|
|
|
2015-08-25 09:05:36 +00:00
|
|
|
struct fence *dependency;
|
|
|
|
struct fence_cb cb;
|
2015-05-22 10:55:07 +00: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 09:46:04 +00:00
|
|
|
struct amd_sched_rq {
|
2015-08-18 12:41:25 +00:00
|
|
|
spinlock_t lock;
|
2015-08-12 09:46:04 +00:00
|
|
|
struct list_head entities;
|
|
|
|
struct amd_sched_entity *current_entity;
|
2015-05-22 10:55:07 +00:00
|
|
|
};
|
|
|
|
|
2015-08-02 03:18:04 +00:00
|
|
|
struct amd_sched_fence {
|
|
|
|
struct fence base;
|
2015-08-31 15:02:52 +00:00
|
|
|
struct fence_cb cb;
|
2015-11-05 11:57:10 +00:00
|
|
|
struct list_head scheduled_cb;
|
2015-09-07 16:16:49 +00:00
|
|
|
struct amd_gpu_scheduler *sched;
|
2015-08-02 03:18:04 +00:00
|
|
|
spinlock_t lock;
|
2015-08-24 04:47:36 +00:00
|
|
|
void *owner;
|
2016-05-03 13:54:54 +00:00
|
|
|
struct amd_sched_job *s_job;
|
2015-08-02 03:18:04 +00:00
|
|
|
};
|
|
|
|
|
2015-08-05 11:52:14 +00:00
|
|
|
struct amd_sched_job {
|
2016-03-10 04:14:44 +00:00
|
|
|
struct kref refcount;
|
2015-08-05 11:52:14 +00:00
|
|
|
struct amd_gpu_scheduler *sched;
|
2015-08-06 07:19:12 +00:00
|
|
|
struct amd_sched_entity *s_entity;
|
2015-08-02 03:18:04 +00:00
|
|
|
struct amd_sched_fence *s_fence;
|
2016-03-03 11:00:50 +00:00
|
|
|
bool use_sched; /* true if the job goes to scheduler */
|
|
|
|
struct fence_cb cb_free_job;
|
|
|
|
struct work_struct work_free_job;
|
2016-03-04 06:33:44 +00:00
|
|
|
struct list_head node;
|
2016-03-04 10:51:02 +00:00
|
|
|
struct delayed_work work_tdr;
|
|
|
|
void (*timeout_callback) (struct work_struct *work);
|
2016-03-10 04:14:44 +00:00
|
|
|
void (*free_callback)(struct kref *refcount);
|
2015-08-05 11:52:14 +00:00
|
|
|
};
|
|
|
|
|
2015-08-02 03:18:04 +00:00
|
|
|
extern const struct fence_ops amd_sched_fence_ops;
|
|
|
|
static inline struct amd_sched_fence *to_amd_sched_fence(struct fence *f)
|
|
|
|
{
|
|
|
|
struct amd_sched_fence *__f = container_of(f, struct amd_sched_fence, base);
|
|
|
|
|
|
|
|
if (__f->base.ops == &amd_sched_fence_ops)
|
|
|
|
return __f;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-05-22 10:55:07 +00:00
|
|
|
/**
|
|
|
|
* Define the backend operations called by the scheduler,
|
|
|
|
* these functions should be implemented in driver side
|
|
|
|
*/
|
|
|
|
struct amd_sched_backend_ops {
|
2015-09-09 01:05:55 +00:00
|
|
|
struct fence *(*dependency)(struct amd_sched_job *sched_job);
|
|
|
|
struct fence *(*run_job)(struct amd_sched_job *sched_job);
|
2016-03-04 10:51:02 +00:00
|
|
|
void (*begin_job)(struct amd_sched_job *sched_job);
|
|
|
|
void (*finish_job)(struct amd_sched_job *sched_job);
|
2015-05-22 10:55:07 +00:00
|
|
|
};
|
|
|
|
|
2015-11-05 07:23:09 +00:00
|
|
|
enum amd_sched_priority {
|
|
|
|
AMD_SCHED_PRIORITY_KERNEL = 0,
|
|
|
|
AMD_SCHED_PRIORITY_NORMAL,
|
|
|
|
AMD_SCHED_MAX_PRIORITY
|
|
|
|
};
|
|
|
|
|
2015-05-22 10:55:07 +00:00
|
|
|
/**
|
|
|
|
* One scheduler is implemented for each hardware ring
|
|
|
|
*/
|
|
|
|
struct amd_gpu_scheduler {
|
2016-04-10 14:30:00 +00:00
|
|
|
const struct amd_sched_backend_ops *ops;
|
2015-09-08 18:22:31 +00:00
|
|
|
uint32_t hw_submission_limit;
|
2015-10-10 00:48:42 +00:00
|
|
|
long timeout;
|
2015-09-08 18:22:31 +00:00
|
|
|
const char *name;
|
2015-11-05 07:23:09 +00:00
|
|
|
struct amd_sched_rq sched_rq[AMD_SCHED_MAX_PRIORITY];
|
2015-08-25 19:39:31 +00:00
|
|
|
wait_queue_head_t wake_up_worker;
|
|
|
|
wait_queue_head_t job_scheduled;
|
2015-09-08 18:22:31 +00:00
|
|
|
atomic_t hw_rq_count;
|
|
|
|
struct task_struct *thread;
|
2016-03-04 06:33:44 +00:00
|
|
|
struct list_head ring_mirror_list;
|
|
|
|
spinlock_t job_list_lock;
|
2015-05-22 10:55:07 +00:00
|
|
|
};
|
|
|
|
|
2015-09-08 18:22:31 +00:00
|
|
|
int amd_sched_init(struct amd_gpu_scheduler *sched,
|
2016-04-10 14:30:00 +00:00
|
|
|
const struct amd_sched_backend_ops *ops,
|
2015-10-10 00:48:42 +00:00
|
|
|
uint32_t hw_submission, long timeout, const char *name);
|
2015-09-08 18:22:31 +00:00
|
|
|
void amd_sched_fini(struct amd_gpu_scheduler *sched);
|
2015-05-22 10:55:07 +00:00
|
|
|
|
2015-08-05 16:33:21 +00:00
|
|
|
int amd_sched_entity_init(struct amd_gpu_scheduler *sched,
|
|
|
|
struct amd_sched_entity *entity,
|
2015-08-12 09:46:04 +00:00
|
|
|
struct amd_sched_rq *rq,
|
2015-08-05 16:33:21 +00:00
|
|
|
uint32_t jobs);
|
2015-08-21 13:46:43 +00:00
|
|
|
void amd_sched_entity_fini(struct amd_gpu_scheduler *sched,
|
|
|
|
struct amd_sched_entity *entity);
|
2015-11-05 18:49:48 +00:00
|
|
|
void amd_sched_entity_push_job(struct amd_sched_job *sched_job);
|
2015-05-22 10:55:07 +00:00
|
|
|
|
2015-08-02 03:18:04 +00:00
|
|
|
struct amd_sched_fence *amd_sched_fence_create(
|
2015-08-24 04:47:36 +00:00
|
|
|
struct amd_sched_entity *s_entity, void *owner);
|
2015-11-05 11:57:10 +00:00
|
|
|
void amd_sched_fence_scheduled(struct amd_sched_fence *fence);
|
2015-08-02 03:18:04 +00:00
|
|
|
void amd_sched_fence_signal(struct amd_sched_fence *fence);
|
2016-03-07 04:49:55 +00:00
|
|
|
int amd_sched_job_init(struct amd_sched_job *job,
|
|
|
|
struct amd_gpu_scheduler *sched,
|
|
|
|
struct amd_sched_entity *entity,
|
2016-03-04 10:51:02 +00:00
|
|
|
void (*timeout_cb)(struct work_struct *work),
|
2016-03-10 04:14:44 +00:00
|
|
|
void (*free_cb)(struct kref* refcount),
|
2016-03-07 04:49:55 +00:00
|
|
|
void *owner, struct fence **fence);
|
2016-03-04 06:33:44 +00:00
|
|
|
void amd_sched_job_pre_schedule(struct amd_gpu_scheduler *sched ,
|
|
|
|
struct amd_sched_job *s_job);
|
2016-03-04 10:51:02 +00:00
|
|
|
void amd_sched_job_finish(struct amd_sched_job *s_job);
|
|
|
|
void amd_sched_job_begin(struct amd_sched_job *s_job);
|
2016-03-10 04:14:44 +00:00
|
|
|
static inline void amd_sched_job_get(struct amd_sched_job *job) {
|
|
|
|
if (job)
|
|
|
|
kref_get(&job->refcount);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void amd_sched_job_put(struct amd_sched_job *job) {
|
|
|
|
if (job)
|
|
|
|
kref_put(&job->refcount, job->free_callback);
|
|
|
|
}
|
|
|
|
|
2015-05-22 10:55:07 +00:00
|
|
|
#endif
|