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.
|
|
|
|
*
|
|
|
|
*/
|
2017-12-06 23:49:39 +07:00
|
|
|
|
2018-05-29 12:53:07 +07:00
|
|
|
/**
|
|
|
|
* DOC: Overview
|
|
|
|
*
|
|
|
|
* The GPU scheduler provides entities which allow userspace to push jobs
|
|
|
|
* into software queues which are then scheduled on a hardware run queue.
|
|
|
|
* The software queues have a priority among them. The scheduler selects the entities
|
|
|
|
* from the run queue using a FIFO. The scheduler provides dependency handling
|
|
|
|
* features among jobs. The driver is supposed to provide callback functions for
|
|
|
|
* backend operations to the scheduler like submitting a job to hardware run queue,
|
|
|
|
* returning the dependencies of a job etc.
|
|
|
|
*
|
|
|
|
* The organisation of the scheduler is the following:
|
|
|
|
*
|
|
|
|
* 1. Each hw run queue has one scheduler
|
|
|
|
* 2. Each scheduler has multiple run queues with different priorities
|
|
|
|
* (e.g., HIGH_HW,HIGH_SW, KERNEL, NORMAL)
|
|
|
|
* 3. Each scheduler run queue has a queue of entities to schedule
|
|
|
|
* 4. Entities themselves maintain a queue of jobs that will be scheduled on
|
|
|
|
* the hardware.
|
|
|
|
*
|
|
|
|
* The jobs in a entity are always scheduled in the order that they were pushed.
|
|
|
|
*/
|
|
|
|
|
2015-05-22 17:55:07 +07:00
|
|
|
#include <linux/kthread.h>
|
|
|
|
#include <linux/wait.h>
|
|
|
|
#include <linux/sched.h>
|
2019-11-05 04:30:05 +07:00
|
|
|
#include <linux/completion.h>
|
2017-02-02 00:07:51 +07:00
|
|
|
#include <uapi/linux/sched/types.h>
|
2019-06-30 13:19:14 +07:00
|
|
|
|
|
|
|
#include <drm/drm_print.h>
|
2017-12-06 23:49:39 +07:00
|
|
|
#include <drm/gpu_scheduler.h>
|
|
|
|
#include <drm/spsc_queue.h>
|
2017-10-13 03:46:26 +07:00
|
|
|
|
2015-09-07 15:06:53 +07:00
|
|
|
#define CREATE_TRACE_POINTS
|
2018-03-30 00:06:33 +07:00
|
|
|
#include "gpu_scheduler_trace.h"
|
2015-09-07 15:06:53 +07:00
|
|
|
|
2017-12-06 23:49:39 +07:00
|
|
|
#define to_drm_sched_job(sched_job) \
|
|
|
|
container_of((sched_job), struct drm_sched_job, queue_node)
|
2017-10-13 03:46:26 +07:00
|
|
|
|
2017-12-06 23:49:39 +07:00
|
|
|
static void drm_sched_process_job(struct dma_fence *f, struct dma_fence_cb *cb);
|
2015-08-24 19:29:40 +07:00
|
|
|
|
2018-05-29 12:53:07 +07:00
|
|
|
/**
|
|
|
|
* drm_sched_rq_init - initialize a given run queue struct
|
|
|
|
*
|
|
|
|
* @rq: scheduler run queue
|
|
|
|
*
|
|
|
|
* Initializes a scheduler runqueue.
|
|
|
|
*/
|
2018-07-13 16:51:13 +07:00
|
|
|
static void drm_sched_rq_init(struct drm_gpu_scheduler *sched,
|
|
|
|
struct drm_sched_rq *rq)
|
2015-05-22 17:55:07 +07:00
|
|
|
{
|
2015-08-18 19:41:25 +07:00
|
|
|
spin_lock_init(&rq->lock);
|
2015-08-12 16:46:04 +07:00
|
|
|
INIT_LIST_HEAD(&rq->entities);
|
|
|
|
rq->current_entity = NULL;
|
2018-07-13 16:51:13 +07:00
|
|
|
rq->sched = sched;
|
2015-05-22 17:55:07 +07:00
|
|
|
}
|
|
|
|
|
2018-05-29 12:53:07 +07:00
|
|
|
/**
|
|
|
|
* drm_sched_rq_add_entity - add an entity
|
|
|
|
*
|
|
|
|
* @rq: scheduler run queue
|
|
|
|
* @entity: scheduler entity
|
|
|
|
*
|
|
|
|
* Adds a scheduler entity to the run queue.
|
|
|
|
*/
|
2018-08-06 19:25:32 +07:00
|
|
|
void drm_sched_rq_add_entity(struct drm_sched_rq *rq,
|
|
|
|
struct drm_sched_entity *entity)
|
2015-05-22 17:55:07 +07:00
|
|
|
{
|
2015-12-11 17:22:52 +07:00
|
|
|
if (!list_empty(&entity->list))
|
|
|
|
return;
|
2015-08-18 19:41:25 +07:00
|
|
|
spin_lock(&rq->lock);
|
2015-08-12 16:46:04 +07:00
|
|
|
list_add_tail(&entity->list, &rq->entities);
|
2015-08-18 19:41:25 +07:00
|
|
|
spin_unlock(&rq->lock);
|
2015-05-22 17:55:07 +07:00
|
|
|
}
|
|
|
|
|
2018-05-29 12:53:07 +07:00
|
|
|
/**
|
|
|
|
* drm_sched_rq_remove_entity - remove an entity
|
|
|
|
*
|
|
|
|
* @rq: scheduler run queue
|
|
|
|
* @entity: scheduler entity
|
|
|
|
*
|
|
|
|
* Removes a scheduler entity from the run queue.
|
|
|
|
*/
|
2018-08-06 19:25:32 +07:00
|
|
|
void drm_sched_rq_remove_entity(struct drm_sched_rq *rq,
|
|
|
|
struct drm_sched_entity *entity)
|
2015-05-22 17:55:07 +07:00
|
|
|
{
|
2015-12-11 17:22:52 +07:00
|
|
|
if (list_empty(&entity->list))
|
|
|
|
return;
|
2015-08-18 19:41:25 +07:00
|
|
|
spin_lock(&rq->lock);
|
2015-08-12 16:46:04 +07:00
|
|
|
list_del_init(&entity->list);
|
|
|
|
if (rq->current_entity == entity)
|
|
|
|
rq->current_entity = NULL;
|
2015-08-18 19:41:25 +07:00
|
|
|
spin_unlock(&rq->lock);
|
2015-05-22 17:55:07 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-05-29 12:53:07 +07:00
|
|
|
* drm_sched_rq_select_entity - Select an entity which could provide a job to run
|
2015-11-13 03:10:35 +07:00
|
|
|
*
|
2018-05-29 12:53:07 +07:00
|
|
|
* @rq: scheduler run queue to check.
|
2015-11-13 03:10:35 +07:00
|
|
|
*
|
|
|
|
* Try to find a ready entity, returns NULL if none found.
|
2015-05-22 17:55:07 +07:00
|
|
|
*/
|
2017-12-06 23:49:39 +07:00
|
|
|
static struct drm_sched_entity *
|
|
|
|
drm_sched_rq_select_entity(struct drm_sched_rq *rq)
|
2015-05-22 17:55:07 +07:00
|
|
|
{
|
2017-12-06 23:49:39 +07:00
|
|
|
struct drm_sched_entity *entity;
|
2015-08-12 16:46:04 +07:00
|
|
|
|
2015-08-18 19:41:25 +07:00
|
|
|
spin_lock(&rq->lock);
|
|
|
|
|
|
|
|
entity = rq->current_entity;
|
2015-08-12 16:46:04 +07:00
|
|
|
if (entity) {
|
|
|
|
list_for_each_entry_continue(entity, &rq->entities, list) {
|
2017-12-06 23:49:39 +07:00
|
|
|
if (drm_sched_entity_is_ready(entity)) {
|
2015-08-12 16:46:04 +07:00
|
|
|
rq->current_entity = entity;
|
2019-11-05 04:30:05 +07:00
|
|
|
reinit_completion(&entity->entity_idle);
|
2015-08-18 19:41:25 +07:00
|
|
|
spin_unlock(&rq->lock);
|
2015-11-13 03:10:35 +07:00
|
|
|
return entity;
|
2015-08-12 16:46:04 +07:00
|
|
|
}
|
2015-05-22 17:55:07 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-12 16:46:04 +07:00
|
|
|
list_for_each_entry(entity, &rq->entities, list) {
|
2015-05-22 17:55:07 +07:00
|
|
|
|
2017-12-06 23:49:39 +07:00
|
|
|
if (drm_sched_entity_is_ready(entity)) {
|
2015-08-12 16:46:04 +07:00
|
|
|
rq->current_entity = entity;
|
2019-11-05 04:30:05 +07:00
|
|
|
reinit_completion(&entity->entity_idle);
|
2015-08-18 19:41:25 +07:00
|
|
|
spin_unlock(&rq->lock);
|
2015-11-13 03:10:35 +07:00
|
|
|
return entity;
|
2015-08-12 16:46:04 +07:00
|
|
|
}
|
2015-05-22 17:55:07 +07:00
|
|
|
|
2015-08-12 16:46:04 +07:00
|
|
|
if (entity == rq->current_entity)
|
|
|
|
break;
|
|
|
|
}
|
2015-05-22 17:55:07 +07:00
|
|
|
|
2015-08-18 19:41:25 +07:00
|
|
|
spin_unlock(&rq->lock);
|
|
|
|
|
2015-08-12 16:46:04 +07:00
|
|
|
return NULL;
|
2015-05-22 17:55:07 +07:00
|
|
|
}
|
|
|
|
|
2018-05-29 12:53:07 +07:00
|
|
|
/**
|
|
|
|
* drm_sched_dependency_optimized
|
|
|
|
*
|
|
|
|
* @fence: the dependency fence
|
|
|
|
* @entity: the entity which depends on the above fence
|
|
|
|
*
|
|
|
|
* Returns true if the dependency can be optimized and false otherwise
|
|
|
|
*/
|
2017-12-06 23:49:39 +07:00
|
|
|
bool drm_sched_dependency_optimized(struct dma_fence* fence,
|
|
|
|
struct drm_sched_entity *entity)
|
2017-05-09 12:39:40 +07:00
|
|
|
{
|
2018-07-20 19:21:06 +07:00
|
|
|
struct drm_gpu_scheduler *sched = entity->rq->sched;
|
2017-12-06 23:49:39 +07:00
|
|
|
struct drm_sched_fence *s_fence;
|
2017-05-09 12:39:40 +07:00
|
|
|
|
|
|
|
if (!fence || dma_fence_is_signaled(fence))
|
|
|
|
return false;
|
|
|
|
if (fence->context == entity->fence_context)
|
|
|
|
return true;
|
2017-12-06 23:49:39 +07:00
|
|
|
s_fence = to_drm_sched_fence(fence);
|
2017-05-09 12:39:40 +07:00
|
|
|
if (s_fence && s_fence->sched == sched)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2017-12-06 23:49:39 +07:00
|
|
|
EXPORT_SYMBOL(drm_sched_dependency_optimized);
|
2017-05-09 12:39:40 +07:00
|
|
|
|
2018-10-06 00:56:39 +07:00
|
|
|
/**
|
|
|
|
* drm_sched_start_timeout - start timeout for reset worker
|
|
|
|
*
|
|
|
|
* @sched: scheduler instance to start the worker for
|
|
|
|
*
|
|
|
|
* Start the timeout for the given scheduler.
|
|
|
|
*/
|
|
|
|
static void drm_sched_start_timeout(struct drm_gpu_scheduler *sched)
|
|
|
|
{
|
|
|
|
if (sched->timeout != MAX_SCHEDULE_TIMEOUT &&
|
|
|
|
!list_empty(&sched->ring_mirror_list))
|
|
|
|
schedule_delayed_work(&sched->work_tdr, sched->timeout);
|
|
|
|
}
|
|
|
|
|
2018-10-12 21:47:13 +07:00
|
|
|
/**
|
|
|
|
* drm_sched_fault - immediately start timeout handler
|
|
|
|
*
|
|
|
|
* @sched: scheduler where the timeout handling should be started.
|
|
|
|
*
|
|
|
|
* Start timeout handling immediately when the driver detects a hardware fault.
|
|
|
|
*/
|
|
|
|
void drm_sched_fault(struct drm_gpu_scheduler *sched)
|
|
|
|
{
|
|
|
|
mod_delayed_work(system_wq, &sched->work_tdr, 0);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_sched_fault);
|
|
|
|
|
2018-11-29 17:05:20 +07:00
|
|
|
/**
|
|
|
|
* drm_sched_suspend_timeout - Suspend scheduler job timeout
|
|
|
|
*
|
|
|
|
* @sched: scheduler instance for which to suspend the timeout
|
|
|
|
*
|
|
|
|
* Suspend the delayed work timeout for the scheduler. This is done by
|
|
|
|
* modifying the delayed work timeout to an arbitrary large value,
|
|
|
|
* MAX_SCHEDULE_TIMEOUT in this case. Note that this function can be
|
|
|
|
* called from an IRQ context.
|
|
|
|
*
|
|
|
|
* Returns the timeout remaining
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
unsigned long drm_sched_suspend_timeout(struct drm_gpu_scheduler *sched)
|
|
|
|
{
|
|
|
|
unsigned long sched_timeout, now = jiffies;
|
|
|
|
|
|
|
|
sched_timeout = sched->work_tdr.timer.expires;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Modify the timeout to an arbitrarily large value. This also prevents
|
|
|
|
* the timeout to be restarted when new submissions arrive
|
|
|
|
*/
|
|
|
|
if (mod_delayed_work(system_wq, &sched->work_tdr, MAX_SCHEDULE_TIMEOUT)
|
|
|
|
&& time_after(sched_timeout, now))
|
|
|
|
return sched_timeout - now;
|
|
|
|
else
|
|
|
|
return sched->timeout;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_sched_suspend_timeout);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_sched_resume_timeout - Resume scheduler job timeout
|
|
|
|
*
|
|
|
|
* @sched: scheduler instance for which to resume the timeout
|
|
|
|
* @remaining: remaining timeout
|
|
|
|
*
|
|
|
|
* Resume the delayed work timeout for the scheduler. Note that
|
|
|
|
* this function can be called from an IRQ context.
|
|
|
|
*/
|
|
|
|
void drm_sched_resume_timeout(struct drm_gpu_scheduler *sched,
|
|
|
|
unsigned long remaining)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&sched->job_list_lock, flags);
|
|
|
|
|
|
|
|
if (list_empty(&sched->ring_mirror_list))
|
|
|
|
cancel_delayed_work(&sched->work_tdr);
|
|
|
|
else
|
|
|
|
mod_delayed_work(system_wq, &sched->work_tdr, remaining);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&sched->job_list_lock, flags);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_sched_resume_timeout);
|
|
|
|
|
2017-12-06 23:49:39 +07:00
|
|
|
static void drm_sched_job_begin(struct drm_sched_job *s_job)
|
2016-03-04 17:51:02 +07:00
|
|
|
{
|
2017-12-06 23:49:39 +07:00
|
|
|
struct drm_gpu_scheduler *sched = s_job->sched;
|
2018-11-29 17:05:20 +07:00
|
|
|
unsigned long flags;
|
2016-03-04 17:51:02 +07:00
|
|
|
|
2018-11-29 17:05:20 +07:00
|
|
|
spin_lock_irqsave(&sched->job_list_lock, flags);
|
2016-05-18 20:40:58 +07:00
|
|
|
list_add_tail(&s_job->node, &sched->ring_mirror_list);
|
2018-10-06 00:56:39 +07:00
|
|
|
drm_sched_start_timeout(sched);
|
2018-11-29 17:05:20 +07:00
|
|
|
spin_unlock_irqrestore(&sched->job_list_lock, flags);
|
2016-03-04 17:51:02 +07:00
|
|
|
}
|
|
|
|
|
2017-12-06 23:49:39 +07:00
|
|
|
static void drm_sched_job_timedout(struct work_struct *work)
|
2016-05-18 19:19:32 +07:00
|
|
|
{
|
2018-09-26 00:09:02 +07:00
|
|
|
struct drm_gpu_scheduler *sched;
|
|
|
|
struct drm_sched_job *job;
|
2018-11-29 17:05:20 +07:00
|
|
|
unsigned long flags;
|
2018-09-26 00:09:02 +07:00
|
|
|
|
|
|
|
sched = container_of(work, struct drm_gpu_scheduler, work_tdr.work);
|
|
|
|
job = list_first_entry_or_null(&sched->ring_mirror_list,
|
|
|
|
struct drm_sched_job, node);
|
2016-05-18 19:19:32 +07:00
|
|
|
|
2019-05-22 20:57:23 +07:00
|
|
|
if (job) {
|
2018-11-22 17:57:15 +07:00
|
|
|
job->sched->ops->timedout_job(job);
|
2018-10-08 18:30:12 +07:00
|
|
|
|
2019-05-22 20:57:23 +07:00
|
|
|
/*
|
|
|
|
* Guilty job did complete and hence needs to be manually removed
|
|
|
|
* See drm_sched_stop doc.
|
|
|
|
*/
|
|
|
|
if (sched->free_guilty) {
|
|
|
|
job->sched->ops->free_job(job);
|
|
|
|
sched->free_guilty = false;
|
|
|
|
}
|
2019-04-18 22:00:23 +07:00
|
|
|
}
|
2019-04-18 22:00:21 +07:00
|
|
|
|
2018-11-29 17:05:20 +07:00
|
|
|
spin_lock_irqsave(&sched->job_list_lock, flags);
|
2018-10-12 21:32:40 +07:00
|
|
|
drm_sched_start_timeout(sched);
|
2018-11-29 17:05:20 +07:00
|
|
|
spin_unlock_irqrestore(&sched->job_list_lock, flags);
|
2016-05-18 19:19:32 +07:00
|
|
|
}
|
|
|
|
|
2018-12-05 04:56:14 +07:00
|
|
|
/**
|
|
|
|
* drm_sched_increase_karma - Update sched_entity guilty flag
|
|
|
|
*
|
|
|
|
* @bad: The job guilty of time out
|
|
|
|
*
|
|
|
|
* Increment on every hang caused by the 'bad' job. If this exceeds the hang
|
|
|
|
* limit of the scheduler then the respective sched entity is marked guilty and
|
|
|
|
* jobs from it will not be scheduled further
|
|
|
|
*/
|
|
|
|
void drm_sched_increase_karma(struct drm_sched_job *bad)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct drm_sched_entity *tmp;
|
|
|
|
struct drm_sched_entity *entity;
|
|
|
|
struct drm_gpu_scheduler *sched = bad->sched;
|
|
|
|
|
|
|
|
/* don't increase @bad's karma if it's from KERNEL RQ,
|
|
|
|
* because sometimes GPU hang would cause kernel jobs (like VM updating jobs)
|
|
|
|
* corrupt but keep in mind that kernel jobs always considered good.
|
|
|
|
*/
|
|
|
|
if (bad->s_priority != DRM_SCHED_PRIORITY_KERNEL) {
|
|
|
|
atomic_inc(&bad->karma);
|
|
|
|
for (i = DRM_SCHED_PRIORITY_MIN; i < DRM_SCHED_PRIORITY_KERNEL;
|
|
|
|
i++) {
|
|
|
|
struct drm_sched_rq *rq = &sched->sched_rq[i];
|
|
|
|
|
|
|
|
spin_lock(&rq->lock);
|
|
|
|
list_for_each_entry_safe(entity, tmp, &rq->entities, list) {
|
|
|
|
if (bad->s_fence->scheduled.context ==
|
|
|
|
entity->fence_context) {
|
|
|
|
if (atomic_read(&bad->karma) >
|
|
|
|
bad->sched->hang_limit)
|
|
|
|
if (entity->guilty)
|
|
|
|
atomic_set(entity->guilty, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
spin_unlock(&rq->lock);
|
|
|
|
if (&entity->list != &rq->entities)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_sched_increase_karma);
|
|
|
|
|
2018-05-29 12:53:07 +07:00
|
|
|
/**
|
2019-04-20 19:50:50 +07:00
|
|
|
* drm_sched_stop - stop the scheduler
|
2018-05-29 12:53:07 +07:00
|
|
|
*
|
|
|
|
* @sched: scheduler instance
|
2019-05-29 21:29:40 +07:00
|
|
|
* @bad: job which caused the time out
|
2018-05-29 12:53:07 +07:00
|
|
|
*
|
2019-04-18 22:00:21 +07:00
|
|
|
* Stop the scheduler and also removes and frees all completed jobs.
|
|
|
|
* Note: bad job will not be freed as it might be used later and so it's
|
|
|
|
* callers responsibility to release it manually if it's not part of the
|
|
|
|
* mirror list any more.
|
|
|
|
*
|
2018-05-29 12:53:07 +07:00
|
|
|
*/
|
2019-04-18 22:00:21 +07:00
|
|
|
void drm_sched_stop(struct drm_gpu_scheduler *sched, struct drm_sched_job *bad)
|
2016-06-30 10:30:37 +07:00
|
|
|
{
|
2019-04-18 22:00:21 +07:00
|
|
|
struct drm_sched_job *s_job, *tmp;
|
2018-11-29 17:05:20 +07:00
|
|
|
unsigned long flags;
|
2016-06-30 10:30:37 +07:00
|
|
|
|
2018-12-05 04:56:14 +07:00
|
|
|
kthread_park(sched->thread);
|
|
|
|
|
|
|
|
/*
|
2019-04-18 22:00:21 +07:00
|
|
|
* Iterate the job list from later to earlier one and either deactive
|
|
|
|
* their HW callbacks or remove them from mirror list if they already
|
|
|
|
* signaled.
|
|
|
|
* This iteration is thread safe as sched thread is stopped.
|
2018-12-05 04:56:14 +07:00
|
|
|
*/
|
2019-04-18 22:00:21 +07:00
|
|
|
list_for_each_entry_safe_reverse(s_job, tmp, &sched->ring_mirror_list, node) {
|
2017-04-24 16:39:00 +07:00
|
|
|
if (s_job->s_fence->parent &&
|
|
|
|
dma_fence_remove_callback(s_job->s_fence->parent,
|
2018-12-06 02:21:28 +07:00
|
|
|
&s_job->cb)) {
|
drm/amdgpu/SRIOV:implement guilty job TDR for(V2)
1,TDR will kickout guilty job if it hang exceed the threshold
of the given one from kernel paramter "job_hang_limit", that
way a bad command stream will not infinitly cause GPU hang.
by default this threshold is 1 so a job will be kicked out
after it hang.
2,if a job timeout TDR routine will not reset all sched/ring,
instead if will only reset on the givn one which is indicated
by @job of amdgpu_sriov_gpu_reset, that way we don't need to
reset and recover each sched/ring if we already know which job
cause GPU hang.
3,unblock sriov_gpu_reset for AI family.
V2:
1:put kickout guilty job after sched parked.
2:since parking scheduler prior to kickout already occupies a
while, we can do last check on the in question job before
doing hw_reset.
TODO:
1:when a job is considered as guilty, we should mark some flag
in its fence status flag, and let UMD side aware that this
fence signaling is not due to job complete but job hang.
2:if gpu reset cause all video memory lost, we need introduce
a new policy to implement TDR, like drop all jobs not yet
signaled, and all IOCTL on this device will return ERROR
DEVICE_LOST.
this will be implemented later.
Signed-off-by: Monk Liu <Monk.Liu@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2017-05-11 12:36:44 +07:00
|
|
|
atomic_dec(&sched->hw_rq_count);
|
2018-12-05 04:56:14 +07:00
|
|
|
} else {
|
2019-04-18 22:00:21 +07:00
|
|
|
/*
|
|
|
|
* remove job from ring_mirror_list.
|
|
|
|
* Locking here is for concurrent resume timeout
|
|
|
|
*/
|
|
|
|
spin_lock_irqsave(&sched->job_list_lock, flags);
|
|
|
|
list_del_init(&s_job->node);
|
|
|
|
spin_unlock_irqrestore(&sched->job_list_lock, flags);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for job's HW fence callback to finish using s_job
|
|
|
|
* before releasing it.
|
|
|
|
*
|
|
|
|
* Job is still alive so fence refcount at least 1
|
|
|
|
*/
|
|
|
|
dma_fence_wait(&s_job->s_fence->finished, false);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We must keep bad job alive for later use during
|
2019-04-18 22:00:23 +07:00
|
|
|
* recovery by some of the drivers but leave a hint
|
|
|
|
* that the guilty job must be released.
|
2019-04-18 22:00:21 +07:00
|
|
|
*/
|
|
|
|
if (bad != s_job)
|
|
|
|
sched->ops->free_job(s_job);
|
2019-04-18 22:00:23 +07:00
|
|
|
else
|
|
|
|
sched->free_guilty = true;
|
2016-06-30 10:30:37 +07:00
|
|
|
}
|
|
|
|
}
|
2019-04-18 22:00:22 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop pending timer in flight as we rearm it in drm_sched_start. This
|
|
|
|
* avoids the pending timeout work in progress to fire right away after
|
|
|
|
* this TDR finished and before the newly restarted jobs had a
|
|
|
|
* chance to complete.
|
|
|
|
*/
|
|
|
|
cancel_delayed_work(&sched->work_tdr);
|
drm/amdgpu/SRIOV:implement guilty job TDR for(V2)
1,TDR will kickout guilty job if it hang exceed the threshold
of the given one from kernel paramter "job_hang_limit", that
way a bad command stream will not infinitly cause GPU hang.
by default this threshold is 1 so a job will be kicked out
after it hang.
2,if a job timeout TDR routine will not reset all sched/ring,
instead if will only reset on the givn one which is indicated
by @job of amdgpu_sriov_gpu_reset, that way we don't need to
reset and recover each sched/ring if we already know which job
cause GPU hang.
3,unblock sriov_gpu_reset for AI family.
V2:
1:put kickout guilty job after sched parked.
2:since parking scheduler prior to kickout already occupies a
while, we can do last check on the in question job before
doing hw_reset.
TODO:
1:when a job is considered as guilty, we should mark some flag
in its fence status flag, and let UMD side aware that this
fence signaling is not due to job complete but job hang.
2:if gpu reset cause all video memory lost, we need introduce
a new policy to implement TDR, like drop all jobs not yet
signaled, and all IOCTL on this device will return ERROR
DEVICE_LOST.
this will be implemented later.
Signed-off-by: Monk Liu <Monk.Liu@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2017-05-11 12:36:44 +07:00
|
|
|
}
|
2018-12-05 04:56:14 +07:00
|
|
|
|
|
|
|
EXPORT_SYMBOL(drm_sched_stop);
|
drm/amdgpu/SRIOV:implement guilty job TDR for(V2)
1,TDR will kickout guilty job if it hang exceed the threshold
of the given one from kernel paramter "job_hang_limit", that
way a bad command stream will not infinitly cause GPU hang.
by default this threshold is 1 so a job will be kicked out
after it hang.
2,if a job timeout TDR routine will not reset all sched/ring,
instead if will only reset on the givn one which is indicated
by @job of amdgpu_sriov_gpu_reset, that way we don't need to
reset and recover each sched/ring if we already know which job
cause GPU hang.
3,unblock sriov_gpu_reset for AI family.
V2:
1:put kickout guilty job after sched parked.
2:since parking scheduler prior to kickout already occupies a
while, we can do last check on the in question job before
doing hw_reset.
TODO:
1:when a job is considered as guilty, we should mark some flag
in its fence status flag, and let UMD side aware that this
fence signaling is not due to job complete but job hang.
2:if gpu reset cause all video memory lost, we need introduce
a new policy to implement TDR, like drop all jobs not yet
signaled, and all IOCTL on this device will return ERROR
DEVICE_LOST.
this will be implemented later.
Signed-off-by: Monk Liu <Monk.Liu@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2017-05-11 12:36:44 +07:00
|
|
|
|
2018-05-29 12:53:07 +07:00
|
|
|
/**
|
|
|
|
* drm_sched_job_recovery - recover jobs after a reset
|
|
|
|
*
|
|
|
|
* @sched: scheduler instance
|
2019-05-29 21:29:40 +07:00
|
|
|
* @full_recovery: proceed with complete sched restart
|
2018-05-29 12:53:07 +07:00
|
|
|
*
|
|
|
|
*/
|
2018-12-05 04:56:14 +07:00
|
|
|
void drm_sched_start(struct drm_gpu_scheduler *sched, bool full_recovery)
|
2016-06-29 14:23:55 +07:00
|
|
|
{
|
2017-12-06 23:49:39 +07:00
|
|
|
struct drm_sched_job *s_job, *tmp;
|
2019-04-18 22:00:21 +07:00
|
|
|
unsigned long flags;
|
2016-06-29 14:23:55 +07:00
|
|
|
int r;
|
|
|
|
|
2018-12-06 02:21:28 +07:00
|
|
|
/*
|
|
|
|
* Locking the list is not required here as the sched thread is parked
|
2019-04-18 22:00:21 +07:00
|
|
|
* so no new jobs are being inserted or removed. Also concurrent
|
2018-12-06 02:21:28 +07:00
|
|
|
* GPU recovers can't run in parallel.
|
|
|
|
*/
|
2016-07-25 12:55:35 +07:00
|
|
|
list_for_each_entry_safe(s_job, tmp, &sched->ring_mirror_list, node) {
|
2018-12-05 04:56:14 +07:00
|
|
|
struct dma_fence *fence = s_job->s_fence->parent;
|
2018-04-16 09:07:02 +07:00
|
|
|
|
2019-04-18 22:00:21 +07:00
|
|
|
atomic_inc(&sched->hw_rq_count);
|
|
|
|
|
|
|
|
if (!full_recovery)
|
|
|
|
continue;
|
|
|
|
|
2016-06-29 14:23:55 +07:00
|
|
|
if (fence) {
|
2018-12-06 02:21:28 +07:00
|
|
|
r = dma_fence_add_callback(fence, &s_job->cb,
|
2017-12-06 23:49:39 +07:00
|
|
|
drm_sched_process_job);
|
2016-06-29 14:23:55 +07:00
|
|
|
if (r == -ENOENT)
|
2018-12-06 02:21:28 +07:00
|
|
|
drm_sched_process_job(fence, &s_job->cb);
|
2016-06-29 14:23:55 +07:00
|
|
|
else if (r)
|
|
|
|
DRM_ERROR("fence add callback failed (%d)\n",
|
|
|
|
r);
|
2018-12-05 04:56:14 +07:00
|
|
|
} else
|
2018-12-06 02:21:28 +07:00
|
|
|
drm_sched_process_job(NULL, &s_job->cb);
|
2016-06-29 14:23:55 +07:00
|
|
|
}
|
2018-12-05 04:56:14 +07:00
|
|
|
|
2019-04-18 22:00:21 +07:00
|
|
|
if (full_recovery) {
|
|
|
|
spin_lock_irqsave(&sched->job_list_lock, flags);
|
|
|
|
drm_sched_start_timeout(sched);
|
|
|
|
spin_unlock_irqrestore(&sched->job_list_lock, flags);
|
|
|
|
}
|
2018-12-05 04:56:14 +07:00
|
|
|
|
|
|
|
kthread_unpark(sched->thread);
|
2016-06-29 14:23:55 +07:00
|
|
|
}
|
2018-12-05 04:56:14 +07:00
|
|
|
EXPORT_SYMBOL(drm_sched_start);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_sched_resubmit_jobs - helper to relunch job from mirror ring list
|
|
|
|
*
|
|
|
|
* @sched: scheduler instance
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void drm_sched_resubmit_jobs(struct drm_gpu_scheduler *sched)
|
|
|
|
{
|
|
|
|
struct drm_sched_job *s_job, *tmp;
|
|
|
|
uint64_t guilty_context;
|
|
|
|
bool found_guilty = false;
|
2019-10-25 02:39:06 +07:00
|
|
|
struct dma_fence *fence;
|
2018-12-05 04:56:14 +07:00
|
|
|
|
|
|
|
list_for_each_entry_safe(s_job, tmp, &sched->ring_mirror_list, node) {
|
|
|
|
struct drm_sched_fence *s_fence = s_job->s_fence;
|
|
|
|
|
|
|
|
if (!found_guilty && atomic_read(&s_job->karma) > sched->hang_limit) {
|
|
|
|
found_guilty = true;
|
|
|
|
guilty_context = s_job->s_fence->scheduled.context;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found_guilty && s_job->s_fence->scheduled.context == guilty_context)
|
|
|
|
dma_fence_set_error(&s_fence->finished, -ECANCELED);
|
|
|
|
|
2019-04-18 22:00:22 +07:00
|
|
|
dma_fence_put(s_job->s_fence->parent);
|
2019-10-25 02:39:06 +07:00
|
|
|
fence = sched->ops->run_job(s_job);
|
|
|
|
|
|
|
|
if (IS_ERR_OR_NULL(fence)) {
|
2019-10-29 22:03:05 +07:00
|
|
|
if (IS_ERR(fence))
|
|
|
|
dma_fence_set_error(&s_fence->finished, PTR_ERR(fence));
|
|
|
|
|
2019-10-25 02:39:06 +07:00
|
|
|
s_job->s_fence->parent = NULL;
|
|
|
|
} else {
|
|
|
|
s_job->s_fence->parent = fence;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-05 04:56:14 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_sched_resubmit_jobs);
|
2016-06-29 14:23:55 +07:00
|
|
|
|
2018-05-16 01:42:20 +07:00
|
|
|
/**
|
2018-05-29 12:53:07 +07:00
|
|
|
* drm_sched_job_init - init a scheduler job
|
2018-05-16 01:42:20 +07:00
|
|
|
*
|
2018-05-29 12:53:07 +07:00
|
|
|
* @job: scheduler job to init
|
|
|
|
* @entity: scheduler entity to use
|
|
|
|
* @owner: job owner for debugging
|
|
|
|
*
|
|
|
|
* Refer to drm_sched_entity_push_job() documentation
|
2018-05-16 01:42:20 +07:00
|
|
|
* for locking considerations.
|
2018-05-29 12:53:07 +07:00
|
|
|
*
|
|
|
|
* Returns 0 for success, negative error code otherwise.
|
2018-05-16 01:42:20 +07:00
|
|
|
*/
|
2017-12-06 23:49:39 +07:00
|
|
|
int drm_sched_job_init(struct drm_sched_job *job,
|
|
|
|
struct drm_sched_entity *entity,
|
2016-06-30 15:52:03 +07:00
|
|
|
void *owner)
|
2016-03-07 11:49:55 +07:00
|
|
|
{
|
2018-08-08 18:07:11 +07:00
|
|
|
struct drm_gpu_scheduler *sched;
|
|
|
|
|
|
|
|
drm_sched_entity_select_rq(entity);
|
2018-10-18 23:32:46 +07:00
|
|
|
if (!entity->rq)
|
|
|
|
return -ENOENT;
|
|
|
|
|
2018-08-08 18:07:11 +07:00
|
|
|
sched = entity->rq->sched;
|
2018-07-20 19:21:05 +07:00
|
|
|
|
2016-03-07 11:49:55 +07:00
|
|
|
job->sched = sched;
|
2018-04-16 09:07:02 +07:00
|
|
|
job->entity = entity;
|
2017-10-20 01:29:46 +07:00
|
|
|
job->s_priority = entity->rq - sched->sched_rq;
|
2017-12-06 23:49:39 +07:00
|
|
|
job->s_fence = drm_sched_fence_create(entity, owner);
|
2016-03-07 11:49:55 +07:00
|
|
|
if (!job->s_fence)
|
|
|
|
return -ENOMEM;
|
2017-05-09 14:34:07 +07:00
|
|
|
job->id = atomic64_inc_return(&sched->job_id_count);
|
2016-03-07 11:49:55 +07:00
|
|
|
|
2016-05-19 14:54:15 +07:00
|
|
|
INIT_LIST_HEAD(&job->node);
|
2016-03-04 13:33:44 +07:00
|
|
|
|
2016-03-07 11:49:55 +07:00
|
|
|
return 0;
|
|
|
|
}
|
2017-12-06 23:49:39 +07:00
|
|
|
EXPORT_SYMBOL(drm_sched_job_init);
|
2016-03-07 11:49:55 +07:00
|
|
|
|
2018-10-29 16:32:28 +07:00
|
|
|
/**
|
|
|
|
* drm_sched_job_cleanup - clean up scheduler job resources
|
|
|
|
*
|
|
|
|
* @job: scheduler job to clean up
|
|
|
|
*/
|
|
|
|
void drm_sched_job_cleanup(struct drm_sched_job *job)
|
|
|
|
{
|
|
|
|
dma_fence_put(&job->s_fence->finished);
|
|
|
|
job->s_fence = NULL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_sched_job_cleanup);
|
|
|
|
|
2015-08-20 22:01:01 +07:00
|
|
|
/**
|
2018-05-29 12:53:07 +07:00
|
|
|
* drm_sched_ready - is the scheduler ready
|
|
|
|
*
|
|
|
|
* @sched: scheduler instance
|
|
|
|
*
|
|
|
|
* Return true if we can push more jobs to the hw, otherwise false.
|
2015-08-20 22:01:01 +07:00
|
|
|
*/
|
2017-12-06 23:49:39 +07:00
|
|
|
static bool drm_sched_ready(struct drm_gpu_scheduler *sched)
|
2015-08-20 22:01:01 +07:00
|
|
|
{
|
|
|
|
return atomic_read(&sched->hw_rq_count) <
|
|
|
|
sched->hw_submission_limit;
|
|
|
|
}
|
|
|
|
|
2015-08-24 19:29:40 +07:00
|
|
|
/**
|
2018-05-29 12:53:07 +07:00
|
|
|
* drm_sched_wakeup - Wake up the scheduler when it is ready
|
|
|
|
*
|
|
|
|
* @sched: scheduler instance
|
|
|
|
*
|
2015-08-24 19:29:40 +07:00
|
|
|
*/
|
2018-08-06 19:25:32 +07:00
|
|
|
void drm_sched_wakeup(struct drm_gpu_scheduler *sched)
|
2015-08-24 19:29:40 +07:00
|
|
|
{
|
2017-12-06 23:49:39 +07:00
|
|
|
if (drm_sched_ready(sched))
|
2015-08-26 02:39:31 +07:00
|
|
|
wake_up_interruptible(&sched->wake_up_worker);
|
2015-08-24 19:29:40 +07:00
|
|
|
}
|
|
|
|
|
2015-08-20 22:01:01 +07:00
|
|
|
/**
|
2018-05-29 12:53:07 +07:00
|
|
|
* drm_sched_select_entity - Select next entity to process
|
|
|
|
*
|
|
|
|
* @sched: scheduler instance
|
|
|
|
*
|
|
|
|
* Returns the entity to process or NULL if none are found.
|
|
|
|
*/
|
2017-12-06 23:49:39 +07:00
|
|
|
static struct drm_sched_entity *
|
|
|
|
drm_sched_select_entity(struct drm_gpu_scheduler *sched)
|
2015-08-20 22:01:01 +07:00
|
|
|
{
|
2017-12-06 23:49:39 +07:00
|
|
|
struct drm_sched_entity *entity;
|
2015-11-05 14:23:09 +07:00
|
|
|
int i;
|
2015-08-20 22:01:01 +07:00
|
|
|
|
2017-12-06 23:49:39 +07:00
|
|
|
if (!drm_sched_ready(sched))
|
2015-08-20 22:01:01 +07:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Kernel run queue has higher priority than normal run queue*/
|
2017-12-06 23:49:39 +07:00
|
|
|
for (i = DRM_SCHED_PRIORITY_MAX - 1; i >= DRM_SCHED_PRIORITY_MIN; i--) {
|
|
|
|
entity = drm_sched_rq_select_entity(&sched->sched_rq[i]);
|
2015-11-05 14:23:09 +07:00
|
|
|
if (entity)
|
|
|
|
break;
|
|
|
|
}
|
2015-08-20 22:01:01 +07:00
|
|
|
|
2015-11-13 03:10:35 +07:00
|
|
|
return entity;
|
2015-08-20 22:01:01 +07:00
|
|
|
}
|
|
|
|
|
2018-05-29 12:53:07 +07:00
|
|
|
/**
|
|
|
|
* drm_sched_process_job - process a job
|
|
|
|
*
|
|
|
|
* @f: fence
|
|
|
|
* @cb: fence callbacks
|
|
|
|
*
|
|
|
|
* Called after job has finished execution.
|
|
|
|
*/
|
2017-12-06 23:49:39 +07:00
|
|
|
static void drm_sched_process_job(struct dma_fence *f, struct dma_fence_cb *cb)
|
2015-08-06 02:22:10 +07:00
|
|
|
{
|
2018-12-06 02:21:28 +07:00
|
|
|
struct drm_sched_job *s_job = container_of(cb, struct drm_sched_job, cb);
|
|
|
|
struct drm_sched_fence *s_fence = s_job->s_fence;
|
2017-12-06 23:49:39 +07:00
|
|
|
struct drm_gpu_scheduler *sched = s_fence->sched;
|
2015-08-06 02:22:10 +07:00
|
|
|
|
2015-08-19 21:12:15 +07:00
|
|
|
atomic_dec(&sched->hw_rq_count);
|
2018-08-01 15:20:00 +07:00
|
|
|
atomic_dec(&sched->num_jobs);
|
2018-12-06 02:21:28 +07:00
|
|
|
|
2019-04-18 22:00:21 +07:00
|
|
|
trace_drm_sched_process_job(s_fence);
|
2018-12-06 02:21:28 +07:00
|
|
|
|
2017-12-06 23:49:39 +07:00
|
|
|
drm_sched_fence_finished(s_fence);
|
2015-08-26 02:39:31 +07:00
|
|
|
wake_up_interruptible(&sched->wake_up_worker);
|
2019-04-18 22:00:21 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-10-25 17:51:56 +07:00
|
|
|
* drm_sched_get_cleanup_job - fetch the next finished job to be destroyed
|
2019-04-18 22:00:21 +07:00
|
|
|
*
|
|
|
|
* @sched: scheduler instance
|
|
|
|
*
|
2019-10-25 17:51:56 +07:00
|
|
|
* Returns the next finished job from the mirror list (if there is one)
|
|
|
|
* ready for it to be destroyed.
|
2019-04-18 22:00:21 +07:00
|
|
|
*/
|
2019-10-25 17:51:56 +07:00
|
|
|
static struct drm_sched_job *
|
|
|
|
drm_sched_get_cleanup_job(struct drm_gpu_scheduler *sched)
|
2019-04-18 22:00:21 +07:00
|
|
|
{
|
2019-10-25 17:51:56 +07:00
|
|
|
struct drm_sched_job *job;
|
2019-04-18 22:00:21 +07:00
|
|
|
unsigned long flags;
|
|
|
|
|
2019-11-08 05:55:15 +07:00
|
|
|
/*
|
|
|
|
* Don't destroy jobs while the timeout worker is running OR thread
|
|
|
|
* is being parked and hence assumed to not touch ring_mirror_list
|
|
|
|
*/
|
|
|
|
if ((sched->timeout != MAX_SCHEDULE_TIMEOUT &&
|
|
|
|
!cancel_delayed_work(&sched->work_tdr)) ||
|
|
|
|
__kthread_should_park(sched->thread))
|
2019-10-25 17:51:56 +07:00
|
|
|
return NULL;
|
2019-04-18 22:00:21 +07:00
|
|
|
|
2019-10-25 17:51:56 +07:00
|
|
|
spin_lock_irqsave(&sched->job_list_lock, flags);
|
2019-04-18 22:00:21 +07:00
|
|
|
|
2019-10-25 17:51:56 +07:00
|
|
|
job = list_first_entry_or_null(&sched->ring_mirror_list,
|
2019-04-18 22:00:21 +07:00
|
|
|
struct drm_sched_job, node);
|
|
|
|
|
2019-10-25 17:51:56 +07:00
|
|
|
if (job && dma_fence_is_signaled(&job->s_fence->finished)) {
|
2019-04-18 22:00:21 +07:00
|
|
|
/* remove job from ring_mirror_list */
|
|
|
|
list_del_init(&job->node);
|
2019-10-25 17:51:56 +07:00
|
|
|
} else {
|
|
|
|
job = NULL;
|
|
|
|
/* queue timeout for next job */
|
|
|
|
drm_sched_start_timeout(sched);
|
2019-04-18 22:00:21 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&sched->job_list_lock, flags);
|
2018-12-06 02:21:28 +07:00
|
|
|
|
2019-10-25 17:51:56 +07:00
|
|
|
return job;
|
2015-08-06 02:22:10 +07:00
|
|
|
}
|
|
|
|
|
2018-05-29 12:53:07 +07:00
|
|
|
/**
|
|
|
|
* drm_sched_blocked - check if the scheduler is blocked
|
|
|
|
*
|
|
|
|
* @sched: scheduler instance
|
|
|
|
*
|
|
|
|
* Returns true if blocked, otherwise false.
|
|
|
|
*/
|
2017-12-06 23:49:39 +07:00
|
|
|
static bool drm_sched_blocked(struct drm_gpu_scheduler *sched)
|
2016-06-12 14:41:58 +07:00
|
|
|
{
|
|
|
|
if (kthread_should_park()) {
|
|
|
|
kthread_parkme();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-29 12:53:07 +07:00
|
|
|
/**
|
|
|
|
* drm_sched_main - main scheduler thread
|
|
|
|
*
|
|
|
|
* @param: scheduler instance
|
|
|
|
*
|
|
|
|
* Returns 0.
|
|
|
|
*/
|
2017-12-06 23:49:39 +07:00
|
|
|
static int drm_sched_main(void *param)
|
2015-05-22 17:55:07 +07:00
|
|
|
{
|
|
|
|
struct sched_param sparam = {.sched_priority = 1};
|
2017-12-06 23:49:39 +07:00
|
|
|
struct drm_gpu_scheduler *sched = (struct drm_gpu_scheduler *)param;
|
2017-10-13 03:46:26 +07:00
|
|
|
int r;
|
2015-05-22 17:55:07 +07:00
|
|
|
|
|
|
|
sched_setscheduler(current, SCHED_FIFO, &sparam);
|
|
|
|
|
|
|
|
while (!kthread_should_stop()) {
|
2017-12-06 23:49:39 +07:00
|
|
|
struct drm_sched_entity *entity = NULL;
|
|
|
|
struct drm_sched_fence *s_fence;
|
|
|
|
struct drm_sched_job *sched_job;
|
2016-10-25 19:00:45 +07:00
|
|
|
struct dma_fence *fence;
|
2019-10-25 17:51:56 +07:00
|
|
|
struct drm_sched_job *cleanup_job = NULL;
|
2015-08-06 02:22:10 +07:00
|
|
|
|
2015-08-26 02:39:31 +07:00
|
|
|
wait_event_interruptible(sched->wake_up_worker,
|
2019-10-25 17:51:56 +07:00
|
|
|
(cleanup_job = drm_sched_get_cleanup_job(sched)) ||
|
2017-12-06 23:49:39 +07:00
|
|
|
(!drm_sched_blocked(sched) &&
|
|
|
|
(entity = drm_sched_select_entity(sched))) ||
|
2019-10-25 17:51:56 +07:00
|
|
|
kthread_should_stop());
|
|
|
|
|
|
|
|
if (cleanup_job) {
|
|
|
|
sched->ops->free_job(cleanup_job);
|
|
|
|
/* queue timeout for next job */
|
|
|
|
drm_sched_start_timeout(sched);
|
|
|
|
}
|
2015-08-19 22:37:52 +07:00
|
|
|
|
2015-11-13 03:10:35 +07:00
|
|
|
if (!entity)
|
|
|
|
continue;
|
|
|
|
|
2017-12-06 23:49:39 +07:00
|
|
|
sched_job = drm_sched_entity_pop_job(entity);
|
2019-11-05 04:30:05 +07:00
|
|
|
|
|
|
|
complete(&entity->entity_idle);
|
|
|
|
|
2015-09-09 08:05:55 +07:00
|
|
|
if (!sched_job)
|
2015-08-19 22:37:52 +07:00
|
|
|
continue;
|
|
|
|
|
2015-09-09 08:05:55 +07:00
|
|
|
s_fence = sched_job->s_fence;
|
2015-10-10 07:48:42 +07:00
|
|
|
|
2015-08-20 22:08:25 +07:00
|
|
|
atomic_inc(&sched->hw_rq_count);
|
2017-12-06 23:49:39 +07:00
|
|
|
drm_sched_job_begin(sched_job);
|
2016-05-18 18:00:38 +07:00
|
|
|
|
2015-09-09 08:05:55 +07:00
|
|
|
fence = sched->ops->run_job(sched_job);
|
2017-12-06 23:49:39 +07:00
|
|
|
drm_sched_fence_scheduled(s_fence);
|
2017-09-28 16:51:32 +07:00
|
|
|
|
2019-10-25 02:39:06 +07:00
|
|
|
if (!IS_ERR_OR_NULL(fence)) {
|
2016-10-25 19:00:45 +07:00
|
|
|
s_fence->parent = dma_fence_get(fence);
|
2018-12-06 02:21:28 +07:00
|
|
|
r = dma_fence_add_callback(fence, &sched_job->cb,
|
2017-12-06 23:49:39 +07:00
|
|
|
drm_sched_process_job);
|
2015-08-06 02:22:10 +07:00
|
|
|
if (r == -ENOENT)
|
2018-12-06 02:21:28 +07:00
|
|
|
drm_sched_process_job(fence, &sched_job->cb);
|
2015-08-06 02:22:10 +07:00
|
|
|
else if (r)
|
2016-05-18 14:43:07 +07:00
|
|
|
DRM_ERROR("fence add callback failed (%d)\n",
|
|
|
|
r);
|
2016-10-25 19:00:45 +07:00
|
|
|
dma_fence_put(fence);
|
2019-10-25 02:39:06 +07:00
|
|
|
} else {
|
2019-10-29 22:03:05 +07:00
|
|
|
if (IS_ERR(fence))
|
|
|
|
dma_fence_set_error(&s_fence->finished, PTR_ERR(fence));
|
2019-10-25 02:39:06 +07:00
|
|
|
|
2018-12-06 02:21:28 +07:00
|
|
|
drm_sched_process_job(NULL, &sched_job->cb);
|
2019-10-25 02:39:06 +07:00
|
|
|
}
|
2015-08-20 19:47:46 +07:00
|
|
|
|
2015-08-26 02:39:31 +07:00
|
|
|
wake_up(&sched->job_scheduled);
|
2015-05-22 17:55:07 +07:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-05-29 12:53:07 +07:00
|
|
|
* drm_sched_init - Init a gpu scheduler instance
|
2015-05-22 17:55:07 +07:00
|
|
|
*
|
2018-05-29 12:53:07 +07:00
|
|
|
* @sched: scheduler instance
|
|
|
|
* @ops: backend operations for this scheduler
|
|
|
|
* @hw_submission: number of hw submissions that can be in flight
|
|
|
|
* @hang_limit: number of times to allow a job to hang before dropping it
|
|
|
|
* @timeout: timeout value in jiffies for the scheduler
|
|
|
|
* @name: name used for debugging
|
2015-05-22 17:55:07 +07:00
|
|
|
*
|
2015-09-09 01:22:31 +07:00
|
|
|
* Return 0 on success, otherwise error code.
|
2018-05-29 12:53:07 +07:00
|
|
|
*/
|
2017-12-06 23:49:39 +07:00
|
|
|
int drm_sched_init(struct drm_gpu_scheduler *sched,
|
|
|
|
const struct drm_sched_backend_ops *ops,
|
2017-10-17 12:40:54 +07:00
|
|
|
unsigned hw_submission,
|
|
|
|
unsigned hang_limit,
|
|
|
|
long timeout,
|
|
|
|
const char *name)
|
2015-05-22 17:55:07 +07:00
|
|
|
{
|
2018-11-29 17:05:19 +07:00
|
|
|
int i, ret;
|
2015-05-22 17:55:07 +07:00
|
|
|
sched->ops = ops;
|
2015-08-05 18:52:14 +07:00
|
|
|
sched->hw_submission_limit = hw_submission;
|
2015-09-09 01:22:31 +07:00
|
|
|
sched->name = name;
|
2015-10-10 07:48:42 +07:00
|
|
|
sched->timeout = timeout;
|
2017-10-17 12:40:54 +07:00
|
|
|
sched->hang_limit = hang_limit;
|
2017-12-06 23:49:39 +07:00
|
|
|
for (i = DRM_SCHED_PRIORITY_MIN; i < DRM_SCHED_PRIORITY_MAX; i++)
|
2018-07-13 16:51:13 +07:00
|
|
|
drm_sched_rq_init(sched, &sched->sched_rq[i]);
|
2015-05-22 17:55:07 +07:00
|
|
|
|
2015-08-26 02:39:31 +07:00
|
|
|
init_waitqueue_head(&sched->wake_up_worker);
|
|
|
|
init_waitqueue_head(&sched->job_scheduled);
|
2016-03-04 13:33:44 +07:00
|
|
|
INIT_LIST_HEAD(&sched->ring_mirror_list);
|
|
|
|
spin_lock_init(&sched->job_list_lock);
|
2015-08-19 21:12:15 +07:00
|
|
|
atomic_set(&sched->hw_rq_count, 0);
|
2018-09-26 00:09:02 +07:00
|
|
|
INIT_DELAYED_WORK(&sched->work_tdr, drm_sched_job_timedout);
|
2018-08-01 15:20:00 +07:00
|
|
|
atomic_set(&sched->num_jobs, 0);
|
2017-03-10 09:25:50 +07:00
|
|
|
atomic64_set(&sched->job_id_count, 0);
|
2015-09-09 01:22:31 +07:00
|
|
|
|
2015-05-22 17:55:07 +07:00
|
|
|
/* Each scheduler will run on a seperate kernel thread */
|
2017-12-06 23:49:39 +07:00
|
|
|
sched->thread = kthread_run(drm_sched_main, sched, sched->name);
|
2015-08-20 21:59:38 +07:00
|
|
|
if (IS_ERR(sched->thread)) {
|
2018-11-29 17:05:19 +07:00
|
|
|
ret = PTR_ERR(sched->thread);
|
|
|
|
sched->thread = NULL;
|
2015-09-09 01:22:31 +07:00
|
|
|
DRM_ERROR("Failed to create scheduler for %s.\n", name);
|
2018-11-29 17:05:19 +07:00
|
|
|
return ret;
|
2015-05-22 17:55:07 +07:00
|
|
|
}
|
|
|
|
|
2018-10-18 23:32:46 +07:00
|
|
|
sched->ready = true;
|
2015-09-09 01:22:31 +07:00
|
|
|
return 0;
|
2015-05-22 17:55:07 +07:00
|
|
|
}
|
2017-12-06 23:49:39 +07:00
|
|
|
EXPORT_SYMBOL(drm_sched_init);
|
2015-05-22 17:55:07 +07:00
|
|
|
|
|
|
|
/**
|
2018-05-29 12:53:07 +07:00
|
|
|
* drm_sched_fini - Destroy a gpu scheduler
|
|
|
|
*
|
|
|
|
* @sched: scheduler instance
|
2015-05-22 17:55:07 +07:00
|
|
|
*
|
2018-05-29 12:53:07 +07:00
|
|
|
* Tears down and cleans up the scheduler.
|
2015-05-22 17:55:07 +07:00
|
|
|
*/
|
2017-12-06 23:49:39 +07:00
|
|
|
void drm_sched_fini(struct drm_gpu_scheduler *sched)
|
2015-05-22 17:55:07 +07:00
|
|
|
{
|
2015-11-03 23:10:03 +07:00
|
|
|
if (sched->thread)
|
|
|
|
kthread_stop(sched->thread);
|
2018-10-18 23:32:46 +07:00
|
|
|
|
|
|
|
sched->ready = false;
|
2015-05-22 17:55:07 +07:00
|
|
|
}
|
2017-12-06 23:49:39 +07:00
|
|
|
EXPORT_SYMBOL(drm_sched_fini);
|