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.
|
|
|
|
*
|
|
|
|
*/
|
2017-12-07 00:49:39 +08:00
|
|
|
|
2018-05-29 13:53:07 +08: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 18:55:07 +08:00
|
|
|
#include <linux/kthread.h>
|
|
|
|
#include <linux/wait.h>
|
|
|
|
#include <linux/sched.h>
|
2017-02-02 01:07:51 +08:00
|
|
|
#include <uapi/linux/sched/types.h>
|
2015-05-22 18:55:07 +08:00
|
|
|
#include <drm/drmP.h>
|
2017-12-07 00:49:39 +08:00
|
|
|
#include <drm/gpu_scheduler.h>
|
|
|
|
#include <drm/spsc_queue.h>
|
2017-10-13 04:46:26 +08:00
|
|
|
|
2015-09-07 16:06:53 +08:00
|
|
|
#define CREATE_TRACE_POINTS
|
2018-03-30 01:06:33 +08:00
|
|
|
#include "gpu_scheduler_trace.h"
|
2015-09-07 16:06:53 +08:00
|
|
|
|
2017-12-07 00:49:39 +08:00
|
|
|
#define to_drm_sched_job(sched_job) \
|
|
|
|
container_of((sched_job), struct drm_sched_job, queue_node)
|
2017-10-13 04:46:26 +08:00
|
|
|
|
2017-12-07 00:49:39 +08:00
|
|
|
static void drm_sched_process_job(struct dma_fence *f, struct dma_fence_cb *cb);
|
2015-08-24 20:29:40 +08:00
|
|
|
|
2018-05-29 13:53:07 +08:00
|
|
|
/**
|
|
|
|
* drm_sched_rq_init - initialize a given run queue struct
|
|
|
|
*
|
|
|
|
* @rq: scheduler run queue
|
|
|
|
*
|
|
|
|
* Initializes a scheduler runqueue.
|
|
|
|
*/
|
2018-07-13 17:51:13 +08:00
|
|
|
static void drm_sched_rq_init(struct drm_gpu_scheduler *sched,
|
|
|
|
struct drm_sched_rq *rq)
|
2015-05-22 18:55:07 +08:00
|
|
|
{
|
2015-08-18 20:41:25 +08:00
|
|
|
spin_lock_init(&rq->lock);
|
2015-08-12 17:46:04 +08:00
|
|
|
INIT_LIST_HEAD(&rq->entities);
|
|
|
|
rq->current_entity = NULL;
|
2018-07-13 17:51:13 +08:00
|
|
|
rq->sched = sched;
|
2015-05-22 18:55:07 +08:00
|
|
|
}
|
|
|
|
|
2018-05-29 13:53:07 +08: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 20:25:32 +08:00
|
|
|
void drm_sched_rq_add_entity(struct drm_sched_rq *rq,
|
|
|
|
struct drm_sched_entity *entity)
|
2015-05-22 18:55:07 +08:00
|
|
|
{
|
2015-12-11 18:22:52 +08:00
|
|
|
if (!list_empty(&entity->list))
|
|
|
|
return;
|
2015-08-18 20:41:25 +08:00
|
|
|
spin_lock(&rq->lock);
|
2015-08-12 17:46:04 +08:00
|
|
|
list_add_tail(&entity->list, &rq->entities);
|
2015-08-18 20:41:25 +08:00
|
|
|
spin_unlock(&rq->lock);
|
2015-05-22 18:55:07 +08:00
|
|
|
}
|
|
|
|
|
2018-05-29 13:53:07 +08: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 20:25:32 +08:00
|
|
|
void drm_sched_rq_remove_entity(struct drm_sched_rq *rq,
|
|
|
|
struct drm_sched_entity *entity)
|
2015-05-22 18:55:07 +08:00
|
|
|
{
|
2015-12-11 18:22:52 +08:00
|
|
|
if (list_empty(&entity->list))
|
|
|
|
return;
|
2015-08-18 20:41:25 +08:00
|
|
|
spin_lock(&rq->lock);
|
2015-08-12 17:46:04 +08:00
|
|
|
list_del_init(&entity->list);
|
|
|
|
if (rq->current_entity == entity)
|
|
|
|
rq->current_entity = NULL;
|
2015-08-18 20:41:25 +08:00
|
|
|
spin_unlock(&rq->lock);
|
2015-05-22 18:55:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-05-29 13:53:07 +08:00
|
|
|
* drm_sched_rq_select_entity - Select an entity which could provide a job to run
|
2015-11-13 04:10:35 +08:00
|
|
|
*
|
2018-05-29 13:53:07 +08:00
|
|
|
* @rq: scheduler run queue to check.
|
2015-11-13 04:10:35 +08:00
|
|
|
*
|
|
|
|
* Try to find a ready entity, returns NULL if none found.
|
2015-05-22 18:55:07 +08:00
|
|
|
*/
|
2017-12-07 00:49:39 +08:00
|
|
|
static struct drm_sched_entity *
|
|
|
|
drm_sched_rq_select_entity(struct drm_sched_rq *rq)
|
2015-05-22 18:55:07 +08:00
|
|
|
{
|
2017-12-07 00:49:39 +08:00
|
|
|
struct drm_sched_entity *entity;
|
2015-08-12 17:46:04 +08:00
|
|
|
|
2015-08-18 20:41:25 +08:00
|
|
|
spin_lock(&rq->lock);
|
|
|
|
|
|
|
|
entity = rq->current_entity;
|
2015-08-12 17:46:04 +08:00
|
|
|
if (entity) {
|
|
|
|
list_for_each_entry_continue(entity, &rq->entities, list) {
|
2017-12-07 00:49:39 +08:00
|
|
|
if (drm_sched_entity_is_ready(entity)) {
|
2015-08-12 17:46:04 +08:00
|
|
|
rq->current_entity = entity;
|
2015-08-18 20:41:25 +08:00
|
|
|
spin_unlock(&rq->lock);
|
2015-11-13 04:10:35 +08:00
|
|
|
return entity;
|
2015-08-12 17:46:04 +08:00
|
|
|
}
|
2015-05-22 18:55:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-12 17:46:04 +08:00
|
|
|
list_for_each_entry(entity, &rq->entities, list) {
|
2015-05-22 18:55:07 +08:00
|
|
|
|
2017-12-07 00:49:39 +08:00
|
|
|
if (drm_sched_entity_is_ready(entity)) {
|
2015-08-12 17:46:04 +08:00
|
|
|
rq->current_entity = entity;
|
2015-08-18 20:41:25 +08:00
|
|
|
spin_unlock(&rq->lock);
|
2015-11-13 04:10:35 +08:00
|
|
|
return entity;
|
2015-08-12 17:46:04 +08:00
|
|
|
}
|
2015-05-22 18:55:07 +08:00
|
|
|
|
2015-08-12 17:46:04 +08:00
|
|
|
if (entity == rq->current_entity)
|
|
|
|
break;
|
|
|
|
}
|
2015-05-22 18:55:07 +08:00
|
|
|
|
2015-08-18 20:41:25 +08:00
|
|
|
spin_unlock(&rq->lock);
|
|
|
|
|
2015-08-12 17:46:04 +08:00
|
|
|
return NULL;
|
2015-05-22 18:55:07 +08:00
|
|
|
}
|
|
|
|
|
2018-05-29 13:53:07 +08: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-07 00:49:39 +08:00
|
|
|
bool drm_sched_dependency_optimized(struct dma_fence* fence,
|
|
|
|
struct drm_sched_entity *entity)
|
2017-05-09 13:39:40 +08:00
|
|
|
{
|
2018-07-20 20:21:06 +08:00
|
|
|
struct drm_gpu_scheduler *sched = entity->rq->sched;
|
2017-12-07 00:49:39 +08:00
|
|
|
struct drm_sched_fence *s_fence;
|
2017-05-09 13:39:40 +08:00
|
|
|
|
|
|
|
if (!fence || dma_fence_is_signaled(fence))
|
|
|
|
return false;
|
|
|
|
if (fence->context == entity->fence_context)
|
|
|
|
return true;
|
2017-12-07 00:49:39 +08:00
|
|
|
s_fence = to_drm_sched_fence(fence);
|
2017-05-09 13:39:40 +08:00
|
|
|
if (s_fence && s_fence->sched == sched)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2017-12-07 00:49:39 +08:00
|
|
|
EXPORT_SYMBOL(drm_sched_dependency_optimized);
|
2017-05-09 13:39:40 +08:00
|
|
|
|
2018-10-06 01:56:39 +08: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 22:47:13 +08: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 18:05:20 +08: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-07 00:49:39 +08:00
|
|
|
static void drm_sched_job_begin(struct drm_sched_job *s_job)
|
2016-03-04 18:51:02 +08:00
|
|
|
{
|
2017-12-07 00:49:39 +08:00
|
|
|
struct drm_gpu_scheduler *sched = s_job->sched;
|
2018-11-29 18:05:20 +08:00
|
|
|
unsigned long flags;
|
2016-03-04 18:51:02 +08:00
|
|
|
|
2018-11-29 18:05:20 +08:00
|
|
|
spin_lock_irqsave(&sched->job_list_lock, flags);
|
2016-05-18 21:40:58 +08:00
|
|
|
list_add_tail(&s_job->node, &sched->ring_mirror_list);
|
2018-10-06 01:56:39 +08:00
|
|
|
drm_sched_start_timeout(sched);
|
2018-11-29 18:05:20 +08:00
|
|
|
spin_unlock_irqrestore(&sched->job_list_lock, flags);
|
2016-03-04 18:51:02 +08:00
|
|
|
}
|
|
|
|
|
2017-12-07 00:49:39 +08:00
|
|
|
static void drm_sched_job_timedout(struct work_struct *work)
|
2016-05-18 20:19:32 +08:00
|
|
|
{
|
2018-09-26 01:09:02 +08:00
|
|
|
struct drm_gpu_scheduler *sched;
|
|
|
|
struct drm_sched_job *job;
|
2018-11-29 18:05:20 +08:00
|
|
|
unsigned long flags;
|
2018-09-26 01:09:02 +08: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 20:19:32 +08:00
|
|
|
|
2019-05-22 21:57:23 +08:00
|
|
|
if (job) {
|
2018-11-22 18:57:15 +08:00
|
|
|
job->sched->ops->timedout_job(job);
|
2018-10-08 19:30:12 +08:00
|
|
|
|
2019-05-22 21:57:23 +08: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 23:00:23 +08:00
|
|
|
}
|
2019-04-18 23:00:21 +08:00
|
|
|
|
2018-11-29 18:05:20 +08:00
|
|
|
spin_lock_irqsave(&sched->job_list_lock, flags);
|
2018-10-12 22:32:40 +08:00
|
|
|
drm_sched_start_timeout(sched);
|
2018-11-29 18:05:20 +08:00
|
|
|
spin_unlock_irqrestore(&sched->job_list_lock, flags);
|
2016-05-18 20:19:32 +08:00
|
|
|
}
|
|
|
|
|
2018-12-05 05:56:14 +08: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 13:53:07 +08:00
|
|
|
/**
|
2019-04-20 20:50:50 +08:00
|
|
|
* drm_sched_stop - stop the scheduler
|
2018-05-29 13:53:07 +08:00
|
|
|
*
|
|
|
|
* @sched: scheduler instance
|
2019-05-29 22:29:40 +08:00
|
|
|
* @bad: job which caused the time out
|
2018-05-29 13:53:07 +08:00
|
|
|
*
|
2019-04-18 23:00:21 +08: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 13:53:07 +08:00
|
|
|
*/
|
2019-04-18 23:00:21 +08:00
|
|
|
void drm_sched_stop(struct drm_gpu_scheduler *sched, struct drm_sched_job *bad)
|
2016-06-30 11:30:37 +08:00
|
|
|
{
|
2019-04-18 23:00:21 +08:00
|
|
|
struct drm_sched_job *s_job, *tmp;
|
2018-11-29 18:05:20 +08:00
|
|
|
unsigned long flags;
|
2016-06-30 11:30:37 +08:00
|
|
|
|
2018-12-05 05:56:14 +08:00
|
|
|
kthread_park(sched->thread);
|
|
|
|
|
|
|
|
/*
|
2019-04-18 23:00:21 +08: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 05:56:14 +08:00
|
|
|
*/
|
2019-04-18 23:00:21 +08:00
|
|
|
list_for_each_entry_safe_reverse(s_job, tmp, &sched->ring_mirror_list, node) {
|
2017-04-24 17:39:00 +08:00
|
|
|
if (s_job->s_fence->parent &&
|
|
|
|
dma_fence_remove_callback(s_job->s_fence->parent,
|
2018-12-06 03:21:28 +08: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 13:36:44 +08:00
|
|
|
atomic_dec(&sched->hw_rq_count);
|
2018-12-05 05:56:14 +08:00
|
|
|
} else {
|
2019-04-18 23:00:21 +08: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 23:00:23 +08:00
|
|
|
* recovery by some of the drivers but leave a hint
|
|
|
|
* that the guilty job must be released.
|
2019-04-18 23:00:21 +08:00
|
|
|
*/
|
|
|
|
if (bad != s_job)
|
|
|
|
sched->ops->free_job(s_job);
|
2019-04-18 23:00:23 +08:00
|
|
|
else
|
|
|
|
sched->free_guilty = true;
|
2016-06-30 11:30:37 +08:00
|
|
|
}
|
|
|
|
}
|
2019-04-18 23:00:22 +08: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 13:36:44 +08:00
|
|
|
}
|
2018-12-05 05:56:14 +08: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 13:36:44 +08:00
|
|
|
|
2018-05-29 13:53:07 +08:00
|
|
|
/**
|
|
|
|
* drm_sched_job_recovery - recover jobs after a reset
|
|
|
|
*
|
|
|
|
* @sched: scheduler instance
|
2019-05-29 22:29:40 +08:00
|
|
|
* @full_recovery: proceed with complete sched restart
|
2018-05-29 13:53:07 +08:00
|
|
|
*
|
|
|
|
*/
|
2018-12-05 05:56:14 +08:00
|
|
|
void drm_sched_start(struct drm_gpu_scheduler *sched, bool full_recovery)
|
2016-06-29 15:23:55 +08:00
|
|
|
{
|
2017-12-07 00:49:39 +08:00
|
|
|
struct drm_sched_job *s_job, *tmp;
|
2019-04-18 23:00:21 +08:00
|
|
|
unsigned long flags;
|
2016-06-29 15:23:55 +08:00
|
|
|
int r;
|
|
|
|
|
2018-12-06 03:21:28 +08:00
|
|
|
/*
|
|
|
|
* Locking the list is not required here as the sched thread is parked
|
2019-04-18 23:00:21 +08:00
|
|
|
* so no new jobs are being inserted or removed. Also concurrent
|
2018-12-06 03:21:28 +08:00
|
|
|
* GPU recovers can't run in parallel.
|
|
|
|
*/
|
2016-07-25 13:55:35 +08:00
|
|
|
list_for_each_entry_safe(s_job, tmp, &sched->ring_mirror_list, node) {
|
2018-12-05 05:56:14 +08:00
|
|
|
struct dma_fence *fence = s_job->s_fence->parent;
|
2018-04-16 10:07:02 +08:00
|
|
|
|
2019-04-18 23:00:21 +08:00
|
|
|
atomic_inc(&sched->hw_rq_count);
|
|
|
|
|
|
|
|
if (!full_recovery)
|
|
|
|
continue;
|
|
|
|
|
2016-06-29 15:23:55 +08:00
|
|
|
if (fence) {
|
2018-12-06 03:21:28 +08:00
|
|
|
r = dma_fence_add_callback(fence, &s_job->cb,
|
2017-12-07 00:49:39 +08:00
|
|
|
drm_sched_process_job);
|
2016-06-29 15:23:55 +08:00
|
|
|
if (r == -ENOENT)
|
2018-12-06 03:21:28 +08:00
|
|
|
drm_sched_process_job(fence, &s_job->cb);
|
2016-06-29 15:23:55 +08:00
|
|
|
else if (r)
|
|
|
|
DRM_ERROR("fence add callback failed (%d)\n",
|
|
|
|
r);
|
2018-12-05 05:56:14 +08:00
|
|
|
} else
|
2018-12-06 03:21:28 +08:00
|
|
|
drm_sched_process_job(NULL, &s_job->cb);
|
2016-06-29 15:23:55 +08:00
|
|
|
}
|
2018-12-05 05:56:14 +08:00
|
|
|
|
2019-04-18 23:00:21 +08: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 05:56:14 +08:00
|
|
|
|
|
|
|
kthread_unpark(sched->thread);
|
2016-06-29 15:23:55 +08:00
|
|
|
}
|
2018-12-05 05:56:14 +08: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;
|
|
|
|
|
|
|
|
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 23:00:22 +08:00
|
|
|
dma_fence_put(s_job->s_fence->parent);
|
2018-12-05 05:56:14 +08:00
|
|
|
s_job->s_fence->parent = sched->ops->run_job(s_job);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_sched_resubmit_jobs);
|
2016-06-29 15:23:55 +08:00
|
|
|
|
2018-05-16 02:42:20 +08:00
|
|
|
/**
|
2018-05-29 13:53:07 +08:00
|
|
|
* drm_sched_job_init - init a scheduler job
|
2018-05-16 02:42:20 +08:00
|
|
|
*
|
2018-05-29 13:53:07 +08: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 02:42:20 +08:00
|
|
|
* for locking considerations.
|
2018-05-29 13:53:07 +08:00
|
|
|
*
|
|
|
|
* Returns 0 for success, negative error code otherwise.
|
2018-05-16 02:42:20 +08:00
|
|
|
*/
|
2017-12-07 00:49:39 +08:00
|
|
|
int drm_sched_job_init(struct drm_sched_job *job,
|
|
|
|
struct drm_sched_entity *entity,
|
2016-06-30 16:52:03 +08:00
|
|
|
void *owner)
|
2016-03-07 12:49:55 +08:00
|
|
|
{
|
2018-08-08 19:07:11 +08:00
|
|
|
struct drm_gpu_scheduler *sched;
|
|
|
|
|
|
|
|
drm_sched_entity_select_rq(entity);
|
2018-10-19 00:32:46 +08:00
|
|
|
if (!entity->rq)
|
|
|
|
return -ENOENT;
|
|
|
|
|
2018-08-08 19:07:11 +08:00
|
|
|
sched = entity->rq->sched;
|
2018-07-20 20:21:05 +08:00
|
|
|
|
2016-03-07 12:49:55 +08:00
|
|
|
job->sched = sched;
|
2018-04-16 10:07:02 +08:00
|
|
|
job->entity = entity;
|
2017-10-20 02:29:46 +08:00
|
|
|
job->s_priority = entity->rq - sched->sched_rq;
|
2017-12-07 00:49:39 +08:00
|
|
|
job->s_fence = drm_sched_fence_create(entity, owner);
|
2016-03-07 12:49:55 +08:00
|
|
|
if (!job->s_fence)
|
|
|
|
return -ENOMEM;
|
2017-05-09 15:34:07 +08:00
|
|
|
job->id = atomic64_inc_return(&sched->job_id_count);
|
2016-03-07 12:49:55 +08:00
|
|
|
|
2016-05-19 15:54:15 +08:00
|
|
|
INIT_LIST_HEAD(&job->node);
|
2016-03-04 14:33:44 +08:00
|
|
|
|
2016-03-07 12:49:55 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2017-12-07 00:49:39 +08:00
|
|
|
EXPORT_SYMBOL(drm_sched_job_init);
|
2016-03-07 12:49:55 +08:00
|
|
|
|
2018-10-29 17:32:28 +08: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 23:01:01 +08:00
|
|
|
/**
|
2018-05-29 13:53:07 +08: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 23:01:01 +08:00
|
|
|
*/
|
2017-12-07 00:49:39 +08:00
|
|
|
static bool drm_sched_ready(struct drm_gpu_scheduler *sched)
|
2015-08-20 23:01:01 +08:00
|
|
|
{
|
|
|
|
return atomic_read(&sched->hw_rq_count) <
|
|
|
|
sched->hw_submission_limit;
|
|
|
|
}
|
|
|
|
|
2015-08-24 20:29:40 +08:00
|
|
|
/**
|
2018-05-29 13:53:07 +08:00
|
|
|
* drm_sched_wakeup - Wake up the scheduler when it is ready
|
|
|
|
*
|
|
|
|
* @sched: scheduler instance
|
|
|
|
*
|
2015-08-24 20:29:40 +08:00
|
|
|
*/
|
2018-08-06 20:25:32 +08:00
|
|
|
void drm_sched_wakeup(struct drm_gpu_scheduler *sched)
|
2015-08-24 20:29:40 +08:00
|
|
|
{
|
2017-12-07 00:49:39 +08:00
|
|
|
if (drm_sched_ready(sched))
|
2015-08-26 03:39:31 +08:00
|
|
|
wake_up_interruptible(&sched->wake_up_worker);
|
2015-08-24 20:29:40 +08:00
|
|
|
}
|
|
|
|
|
2015-08-20 23:01:01 +08:00
|
|
|
/**
|
2018-05-29 13:53:07 +08: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-07 00:49:39 +08:00
|
|
|
static struct drm_sched_entity *
|
|
|
|
drm_sched_select_entity(struct drm_gpu_scheduler *sched)
|
2015-08-20 23:01:01 +08:00
|
|
|
{
|
2017-12-07 00:49:39 +08:00
|
|
|
struct drm_sched_entity *entity;
|
2015-11-05 15:23:09 +08:00
|
|
|
int i;
|
2015-08-20 23:01:01 +08:00
|
|
|
|
2017-12-07 00:49:39 +08:00
|
|
|
if (!drm_sched_ready(sched))
|
2015-08-20 23:01:01 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Kernel run queue has higher priority than normal run queue*/
|
2017-12-07 00:49:39 +08: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 15:23:09 +08:00
|
|
|
if (entity)
|
|
|
|
break;
|
|
|
|
}
|
2015-08-20 23:01:01 +08:00
|
|
|
|
2015-11-13 04:10:35 +08:00
|
|
|
return entity;
|
2015-08-20 23:01:01 +08:00
|
|
|
}
|
|
|
|
|
2018-05-29 13:53:07 +08:00
|
|
|
/**
|
|
|
|
* drm_sched_process_job - process a job
|
|
|
|
*
|
|
|
|
* @f: fence
|
|
|
|
* @cb: fence callbacks
|
|
|
|
*
|
|
|
|
* Called after job has finished execution.
|
|
|
|
*/
|
2017-12-07 00:49:39 +08:00
|
|
|
static void drm_sched_process_job(struct dma_fence *f, struct dma_fence_cb *cb)
|
2015-08-06 03:22:10 +08:00
|
|
|
{
|
2018-12-06 03:21:28 +08: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-07 00:49:39 +08:00
|
|
|
struct drm_gpu_scheduler *sched = s_fence->sched;
|
2015-08-06 03:22:10 +08:00
|
|
|
|
2015-08-19 22:12:15 +08:00
|
|
|
atomic_dec(&sched->hw_rq_count);
|
2018-08-01 16:20:00 +08:00
|
|
|
atomic_dec(&sched->num_jobs);
|
2018-12-06 03:21:28 +08:00
|
|
|
|
2019-04-18 23:00:21 +08:00
|
|
|
trace_drm_sched_process_job(s_fence);
|
2018-12-06 03:21:28 +08:00
|
|
|
|
2017-12-07 00:49:39 +08:00
|
|
|
drm_sched_fence_finished(s_fence);
|
2015-08-26 03:39:31 +08:00
|
|
|
wake_up_interruptible(&sched->wake_up_worker);
|
2019-04-18 23:00:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_sched_cleanup_jobs - destroy finished jobs
|
|
|
|
*
|
|
|
|
* @sched: scheduler instance
|
|
|
|
*
|
|
|
|
* Remove all finished jobs from the mirror list and destroy them.
|
|
|
|
*/
|
|
|
|
static void drm_sched_cleanup_jobs(struct drm_gpu_scheduler *sched)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
/* Don't destroy jobs while the timeout worker is running */
|
2019-05-21 07:16:49 +08:00
|
|
|
if (sched->timeout != MAX_SCHEDULE_TIMEOUT &&
|
|
|
|
!cancel_delayed_work(&sched->work_tdr))
|
2019-04-18 23:00:21 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
while (!list_empty(&sched->ring_mirror_list)) {
|
|
|
|
struct drm_sched_job *job;
|
|
|
|
|
|
|
|
job = list_first_entry(&sched->ring_mirror_list,
|
|
|
|
struct drm_sched_job, node);
|
|
|
|
if (!dma_fence_is_signaled(&job->s_fence->finished))
|
|
|
|
break;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&sched->job_list_lock, flags);
|
|
|
|
/* remove job from ring_mirror_list */
|
|
|
|
list_del_init(&job->node);
|
|
|
|
spin_unlock_irqrestore(&sched->job_list_lock, flags);
|
|
|
|
|
|
|
|
sched->ops->free_job(job);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* queue timeout for next job */
|
|
|
|
spin_lock_irqsave(&sched->job_list_lock, flags);
|
|
|
|
drm_sched_start_timeout(sched);
|
|
|
|
spin_unlock_irqrestore(&sched->job_list_lock, flags);
|
2018-12-06 03:21:28 +08:00
|
|
|
|
2015-08-06 03:22:10 +08:00
|
|
|
}
|
|
|
|
|
2018-05-29 13:53:07 +08:00
|
|
|
/**
|
|
|
|
* drm_sched_blocked - check if the scheduler is blocked
|
|
|
|
*
|
|
|
|
* @sched: scheduler instance
|
|
|
|
*
|
|
|
|
* Returns true if blocked, otherwise false.
|
|
|
|
*/
|
2017-12-07 00:49:39 +08:00
|
|
|
static bool drm_sched_blocked(struct drm_gpu_scheduler *sched)
|
2016-06-12 15:41:58 +08:00
|
|
|
{
|
|
|
|
if (kthread_should_park()) {
|
|
|
|
kthread_parkme();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-29 13:53:07 +08:00
|
|
|
/**
|
|
|
|
* drm_sched_main - main scheduler thread
|
|
|
|
*
|
|
|
|
* @param: scheduler instance
|
|
|
|
*
|
|
|
|
* Returns 0.
|
|
|
|
*/
|
2017-12-07 00:49:39 +08:00
|
|
|
static int drm_sched_main(void *param)
|
2015-05-22 18:55:07 +08:00
|
|
|
{
|
|
|
|
struct sched_param sparam = {.sched_priority = 1};
|
2017-12-07 00:49:39 +08:00
|
|
|
struct drm_gpu_scheduler *sched = (struct drm_gpu_scheduler *)param;
|
2017-10-13 04:46:26 +08:00
|
|
|
int r;
|
2015-05-22 18:55:07 +08:00
|
|
|
|
|
|
|
sched_setscheduler(current, SCHED_FIFO, &sparam);
|
|
|
|
|
|
|
|
while (!kthread_should_stop()) {
|
2017-12-07 00:49:39 +08:00
|
|
|
struct drm_sched_entity *entity = NULL;
|
|
|
|
struct drm_sched_fence *s_fence;
|
|
|
|
struct drm_sched_job *sched_job;
|
2016-10-25 20:00:45 +08:00
|
|
|
struct dma_fence *fence;
|
2015-08-06 03:22:10 +08:00
|
|
|
|
2015-08-26 03:39:31 +08:00
|
|
|
wait_event_interruptible(sched->wake_up_worker,
|
2019-04-18 23:00:21 +08:00
|
|
|
(drm_sched_cleanup_jobs(sched),
|
2017-12-07 00:49:39 +08:00
|
|
|
(!drm_sched_blocked(sched) &&
|
|
|
|
(entity = drm_sched_select_entity(sched))) ||
|
2019-04-18 23:00:21 +08:00
|
|
|
kthread_should_stop()));
|
2015-08-19 23:37:52 +08:00
|
|
|
|
2015-11-13 04:10:35 +08:00
|
|
|
if (!entity)
|
|
|
|
continue;
|
|
|
|
|
2017-12-07 00:49:39 +08:00
|
|
|
sched_job = drm_sched_entity_pop_job(entity);
|
2015-09-09 09:05:55 +08:00
|
|
|
if (!sched_job)
|
2015-08-19 23:37:52 +08:00
|
|
|
continue;
|
|
|
|
|
2015-09-09 09:05:55 +08:00
|
|
|
s_fence = sched_job->s_fence;
|
2015-10-10 08:48:42 +08:00
|
|
|
|
2015-08-20 23:08:25 +08:00
|
|
|
atomic_inc(&sched->hw_rq_count);
|
2017-12-07 00:49:39 +08:00
|
|
|
drm_sched_job_begin(sched_job);
|
2016-05-18 19:00:38 +08:00
|
|
|
|
2015-09-09 09:05:55 +08:00
|
|
|
fence = sched->ops->run_job(sched_job);
|
2017-12-07 00:49:39 +08:00
|
|
|
drm_sched_fence_scheduled(s_fence);
|
2017-09-28 17:51:32 +08:00
|
|
|
|
2015-08-06 03:22:10 +08:00
|
|
|
if (fence) {
|
2016-10-25 20:00:45 +08:00
|
|
|
s_fence->parent = dma_fence_get(fence);
|
2018-12-06 03:21:28 +08:00
|
|
|
r = dma_fence_add_callback(fence, &sched_job->cb,
|
2017-12-07 00:49:39 +08:00
|
|
|
drm_sched_process_job);
|
2015-08-06 03:22:10 +08:00
|
|
|
if (r == -ENOENT)
|
2018-12-06 03:21:28 +08:00
|
|
|
drm_sched_process_job(fence, &sched_job->cb);
|
2015-08-06 03:22:10 +08:00
|
|
|
else if (r)
|
2016-05-18 15:43:07 +08:00
|
|
|
DRM_ERROR("fence add callback failed (%d)\n",
|
|
|
|
r);
|
2016-10-25 20:00:45 +08:00
|
|
|
dma_fence_put(fence);
|
2018-12-05 05:56:14 +08:00
|
|
|
} else
|
2018-12-06 03:21:28 +08:00
|
|
|
drm_sched_process_job(NULL, &sched_job->cb);
|
2015-08-20 20:47:46 +08:00
|
|
|
|
2015-08-26 03:39:31 +08:00
|
|
|
wake_up(&sched->job_scheduled);
|
2015-05-22 18:55:07 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-05-29 13:53:07 +08:00
|
|
|
* drm_sched_init - Init a gpu scheduler instance
|
2015-05-22 18:55:07 +08:00
|
|
|
*
|
2018-05-29 13:53:07 +08: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 18:55:07 +08:00
|
|
|
*
|
2015-09-09 02:22:31 +08:00
|
|
|
* Return 0 on success, otherwise error code.
|
2018-05-29 13:53:07 +08:00
|
|
|
*/
|
2017-12-07 00:49:39 +08:00
|
|
|
int drm_sched_init(struct drm_gpu_scheduler *sched,
|
|
|
|
const struct drm_sched_backend_ops *ops,
|
2017-10-17 13:40:54 +08:00
|
|
|
unsigned hw_submission,
|
|
|
|
unsigned hang_limit,
|
|
|
|
long timeout,
|
|
|
|
const char *name)
|
2015-05-22 18:55:07 +08:00
|
|
|
{
|
2018-11-29 18:05:19 +08:00
|
|
|
int i, ret;
|
2015-05-22 18:55:07 +08:00
|
|
|
sched->ops = ops;
|
2015-08-05 19:52:14 +08:00
|
|
|
sched->hw_submission_limit = hw_submission;
|
2015-09-09 02:22:31 +08:00
|
|
|
sched->name = name;
|
2015-10-10 08:48:42 +08:00
|
|
|
sched->timeout = timeout;
|
2017-10-17 13:40:54 +08:00
|
|
|
sched->hang_limit = hang_limit;
|
2017-12-07 00:49:39 +08:00
|
|
|
for (i = DRM_SCHED_PRIORITY_MIN; i < DRM_SCHED_PRIORITY_MAX; i++)
|
2018-07-13 17:51:13 +08:00
|
|
|
drm_sched_rq_init(sched, &sched->sched_rq[i]);
|
2015-05-22 18:55:07 +08:00
|
|
|
|
2015-08-26 03:39:31 +08:00
|
|
|
init_waitqueue_head(&sched->wake_up_worker);
|
|
|
|
init_waitqueue_head(&sched->job_scheduled);
|
2016-03-04 14:33:44 +08:00
|
|
|
INIT_LIST_HEAD(&sched->ring_mirror_list);
|
|
|
|
spin_lock_init(&sched->job_list_lock);
|
2015-08-19 22:12:15 +08:00
|
|
|
atomic_set(&sched->hw_rq_count, 0);
|
2018-09-26 01:09:02 +08:00
|
|
|
INIT_DELAYED_WORK(&sched->work_tdr, drm_sched_job_timedout);
|
2018-08-01 16:20:00 +08:00
|
|
|
atomic_set(&sched->num_jobs, 0);
|
2017-03-10 10:25:50 +08:00
|
|
|
atomic64_set(&sched->job_id_count, 0);
|
2015-09-09 02:22:31 +08:00
|
|
|
|
2015-05-22 18:55:07 +08:00
|
|
|
/* Each scheduler will run on a seperate kernel thread */
|
2017-12-07 00:49:39 +08:00
|
|
|
sched->thread = kthread_run(drm_sched_main, sched, sched->name);
|
2015-08-20 22:59:38 +08:00
|
|
|
if (IS_ERR(sched->thread)) {
|
2018-11-29 18:05:19 +08:00
|
|
|
ret = PTR_ERR(sched->thread);
|
|
|
|
sched->thread = NULL;
|
2015-09-09 02:22:31 +08:00
|
|
|
DRM_ERROR("Failed to create scheduler for %s.\n", name);
|
2018-11-29 18:05:19 +08:00
|
|
|
return ret;
|
2015-05-22 18:55:07 +08:00
|
|
|
}
|
|
|
|
|
2018-10-19 00:32:46 +08:00
|
|
|
sched->ready = true;
|
2015-09-09 02:22:31 +08:00
|
|
|
return 0;
|
2015-05-22 18:55:07 +08:00
|
|
|
}
|
2017-12-07 00:49:39 +08:00
|
|
|
EXPORT_SYMBOL(drm_sched_init);
|
2015-05-22 18:55:07 +08:00
|
|
|
|
|
|
|
/**
|
2018-05-29 13:53:07 +08:00
|
|
|
* drm_sched_fini - Destroy a gpu scheduler
|
|
|
|
*
|
|
|
|
* @sched: scheduler instance
|
2015-05-22 18:55:07 +08:00
|
|
|
*
|
2018-05-29 13:53:07 +08:00
|
|
|
* Tears down and cleans up the scheduler.
|
2015-05-22 18:55:07 +08:00
|
|
|
*/
|
2017-12-07 00:49:39 +08:00
|
|
|
void drm_sched_fini(struct drm_gpu_scheduler *sched)
|
2015-05-22 18:55:07 +08:00
|
|
|
{
|
2015-11-04 00:10:03 +08:00
|
|
|
if (sched->thread)
|
|
|
|
kthread_stop(sched->thread);
|
2018-10-19 00:32:46 +08:00
|
|
|
|
|
|
|
sched->ready = false;
|
2015-05-22 18:55:07 +08:00
|
|
|
}
|
2017-12-07 00:49:39 +08:00
|
|
|
EXPORT_SYMBOL(drm_sched_fini);
|