2015-05-22 17:55:07 +07: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 18:52:14 +07:00
|
|
|
#include <linux/fence.h>
|
2015-05-22 17:55:07 +07:00
|
|
|
|
|
|
|
struct amd_gpu_scheduler;
|
2015-08-12 16:46:04 +07:00
|
|
|
struct amd_sched_rq;
|
2015-05-22 17:55:07 +07:00
|
|
|
|
2015-11-05 10:41:50 +07:00
|
|
|
extern struct kmem_cache *sched_fence_slab;
|
|
|
|
extern atomic_t sched_fence_slab_ref;
|
|
|
|
|
2015-05-22 17:55:07 +07:00
|
|
|
/**
|
|
|
|
* A scheduler entity is a wrapper around a job queue or a group
|
2016-03-03 18:00:50 +07:00
|
|
|
* of other entities. Entities take turns emitting jobs from their
|
2015-05-22 17:55:07 +07:00
|
|
|
* job queues to corresponding hardware ring based on scheduling
|
|
|
|
* policy.
|
|
|
|
*/
|
|
|
|
struct amd_sched_entity {
|
|
|
|
struct list_head list;
|
2015-09-07 23:07:14 +07:00
|
|
|
struct amd_sched_rq *rq;
|
|
|
|
struct amd_gpu_scheduler *sched;
|
|
|
|
|
2015-08-05 23:33:21 +07:00
|
|
|
spinlock_t queue_lock;
|
2015-09-07 23:07:14 +07:00
|
|
|
struct kfifo job_queue;
|
|
|
|
|
|
|
|
atomic_t fence_seq;
|
2015-08-02 10:18:04 +07:00
|
|
|
uint64_t fence_context;
|
2015-09-07 23:07:14 +07:00
|
|
|
|
2015-08-25 16:05:36 +07:00
|
|
|
struct fence *dependency;
|
|
|
|
struct fence_cb cb;
|
2015-05-22 17:55:07 +07: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 16:46:04 +07:00
|
|
|
struct amd_sched_rq {
|
2015-08-18 19:41:25 +07:00
|
|
|
spinlock_t lock;
|
2015-08-12 16:46:04 +07:00
|
|
|
struct list_head entities;
|
|
|
|
struct amd_sched_entity *current_entity;
|
2015-05-22 17:55:07 +07:00
|
|
|
};
|
|
|
|
|
2015-08-02 10:18:04 +07:00
|
|
|
struct amd_sched_fence {
|
2016-05-20 17:53:52 +07:00
|
|
|
struct fence scheduled;
|
|
|
|
struct fence finished;
|
2015-08-31 22:02:52 +07:00
|
|
|
struct fence_cb cb;
|
2016-06-30 10:23:31 +07:00
|
|
|
struct fence *parent;
|
2015-09-07 23:16:49 +07:00
|
|
|
struct amd_gpu_scheduler *sched;
|
2015-08-02 10:18:04 +07:00
|
|
|
spinlock_t lock;
|
2015-08-24 11:47:36 +07:00
|
|
|
void *owner;
|
2015-08-02 10:18:04 +07:00
|
|
|
};
|
|
|
|
|
2015-08-05 18:52:14 +07:00
|
|
|
struct amd_sched_job {
|
|
|
|
struct amd_gpu_scheduler *sched;
|
2015-08-06 14:19:12 +07:00
|
|
|
struct amd_sched_entity *s_entity;
|
2015-08-02 10:18:04 +07:00
|
|
|
struct amd_sched_fence *s_fence;
|
2016-05-19 14:54:15 +07:00
|
|
|
struct fence_cb finish_cb;
|
|
|
|
struct work_struct finish_work;
|
|
|
|
struct list_head node;
|
|
|
|
struct delayed_work work_tdr;
|
2015-08-05 18:52:14 +07:00
|
|
|
};
|
|
|
|
|
2016-05-20 17:53:52 +07:00
|
|
|
extern const struct fence_ops amd_sched_fence_ops_scheduled;
|
|
|
|
extern const struct fence_ops amd_sched_fence_ops_finished;
|
2015-08-02 10:18:04 +07:00
|
|
|
static inline struct amd_sched_fence *to_amd_sched_fence(struct fence *f)
|
|
|
|
{
|
2016-05-20 17:53:52 +07:00
|
|
|
if (f->ops == &amd_sched_fence_ops_scheduled)
|
|
|
|
return container_of(f, struct amd_sched_fence, scheduled);
|
2015-08-02 10:18:04 +07:00
|
|
|
|
2016-05-20 17:53:52 +07:00
|
|
|
if (f->ops == &amd_sched_fence_ops_finished)
|
|
|
|
return container_of(f, struct amd_sched_fence, finished);
|
2015-08-02 10:18:04 +07:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-05-22 17:55:07 +07: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 08:05:55 +07:00
|
|
|
struct fence *(*dependency)(struct amd_sched_job *sched_job);
|
|
|
|
struct fence *(*run_job)(struct amd_sched_job *sched_job);
|
2016-05-18 19:19:32 +07:00
|
|
|
void (*timedout_job)(struct amd_sched_job *sched_job);
|
2016-05-19 14:54:15 +07:00
|
|
|
void (*free_job)(struct amd_sched_job *sched_job);
|
2015-05-22 17:55:07 +07:00
|
|
|
};
|
|
|
|
|
2015-11-05 14:23:09 +07:00
|
|
|
enum amd_sched_priority {
|
|
|
|
AMD_SCHED_PRIORITY_KERNEL = 0,
|
|
|
|
AMD_SCHED_PRIORITY_NORMAL,
|
|
|
|
AMD_SCHED_MAX_PRIORITY
|
|
|
|
};
|
|
|
|
|
2015-05-22 17:55:07 +07:00
|
|
|
/**
|
|
|
|
* One scheduler is implemented for each hardware ring
|
|
|
|
*/
|
|
|
|
struct amd_gpu_scheduler {
|
2016-04-10 21:30:00 +07:00
|
|
|
const struct amd_sched_backend_ops *ops;
|
2015-09-09 01:22:31 +07:00
|
|
|
uint32_t hw_submission_limit;
|
2015-10-10 07:48:42 +07:00
|
|
|
long timeout;
|
2015-09-09 01:22:31 +07:00
|
|
|
const char *name;
|
2015-11-05 14:23:09 +07:00
|
|
|
struct amd_sched_rq sched_rq[AMD_SCHED_MAX_PRIORITY];
|
2015-08-26 02:39:31 +07:00
|
|
|
wait_queue_head_t wake_up_worker;
|
|
|
|
wait_queue_head_t job_scheduled;
|
2015-09-09 01:22:31 +07:00
|
|
|
atomic_t hw_rq_count;
|
|
|
|
struct task_struct *thread;
|
2016-03-04 13:33:44 +07:00
|
|
|
struct list_head ring_mirror_list;
|
|
|
|
spinlock_t job_list_lock;
|
2015-05-22 17:55:07 +07:00
|
|
|
};
|
|
|
|
|
2015-09-09 01:22:31 +07:00
|
|
|
int amd_sched_init(struct amd_gpu_scheduler *sched,
|
2016-04-10 21:30:00 +07:00
|
|
|
const struct amd_sched_backend_ops *ops,
|
2015-10-10 07:48:42 +07:00
|
|
|
uint32_t hw_submission, long timeout, const char *name);
|
2015-09-09 01:22:31 +07:00
|
|
|
void amd_sched_fini(struct amd_gpu_scheduler *sched);
|
2015-05-22 17:55:07 +07:00
|
|
|
|
2015-08-05 23:33:21 +07:00
|
|
|
int amd_sched_entity_init(struct amd_gpu_scheduler *sched,
|
|
|
|
struct amd_sched_entity *entity,
|
2015-08-12 16:46:04 +07:00
|
|
|
struct amd_sched_rq *rq,
|
2015-08-05 23:33:21 +07:00
|
|
|
uint32_t jobs);
|
2015-08-21 20:46:43 +07:00
|
|
|
void amd_sched_entity_fini(struct amd_gpu_scheduler *sched,
|
|
|
|
struct amd_sched_entity *entity);
|
2015-11-06 01:49:48 +07:00
|
|
|
void amd_sched_entity_push_job(struct amd_sched_job *sched_job);
|
2015-05-22 17:55:07 +07:00
|
|
|
|
2015-08-02 10:18:04 +07:00
|
|
|
struct amd_sched_fence *amd_sched_fence_create(
|
2015-08-24 11:47:36 +07:00
|
|
|
struct amd_sched_entity *s_entity, void *owner);
|
2015-11-05 18:57:10 +07:00
|
|
|
void amd_sched_fence_scheduled(struct amd_sched_fence *fence);
|
2016-05-20 17:53:52 +07:00
|
|
|
void amd_sched_fence_finished(struct amd_sched_fence *fence);
|
2016-03-07 11:49:55 +07:00
|
|
|
int amd_sched_job_init(struct amd_sched_job *job,
|
2016-05-18 14:43:07 +07:00
|
|
|
struct amd_gpu_scheduler *sched,
|
|
|
|
struct amd_sched_entity *entity,
|
2016-06-30 15:52:03 +07:00
|
|
|
void *owner);
|
2015-05-22 17:55:07 +07:00
|
|
|
#endif
|