From patchwork Mon Dec 10 21:43:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Grodzovsky X-Patchwork-Id: 10722577 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A1AF191E for ; Mon, 10 Dec 2018 21:44:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 85C712A350 for ; Mon, 10 Dec 2018 21:44:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 793082A359; Mon, 10 Dec 2018 21:44:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 976BB2A350 for ; Mon, 10 Dec 2018 21:44:17 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2E78D89D87; Mon, 10 Dec 2018 21:44:16 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-eopbgr790082.outbound.protection.outlook.com [40.107.79.82]) by gabe.freedesktop.org (Postfix) with ESMTPS id E79D489D87; Mon, 10 Dec 2018 21:44:14 +0000 (UTC) Received: from MWHPR12CA0047.namprd12.prod.outlook.com (2603:10b6:301:2::33) by CY1PR12MB0838.namprd12.prod.outlook.com (2a01:111:e400:59d2::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1404.19; Mon, 10 Dec 2018 21:44:12 +0000 Received: from CO1NAM03FT022.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::209) by MWHPR12CA0047.outlook.office365.com (2603:10b6:301:2::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1404.19 via Frontend Transport; Mon, 10 Dec 2018 21:44:11 +0000 Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV01.amd.com (165.204.84.17) by CO1NAM03FT022.mail.protection.outlook.com (10.152.80.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1404.17 via Frontend Transport; Mon, 10 Dec 2018 21:44:11 +0000 Received: from agrodzovsky-All-Series.amd.com (10.34.1.3) by SATLEXCHOV01.amd.com (10.181.40.71) with Microsoft SMTP Server id 14.3.389.1; Mon, 10 Dec 2018 15:44:09 -0600 From: Andrey Grodzovsky To: , , , , Subject: [PATCH v3 1/2] drm/sched: Refactor ring mirror list handling. Date: Mon, 10 Dec 2018 16:43:57 -0500 Message-ID: <1544478238-13310-1-git-send-email-andrey.grodzovsky@amd.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:165.204.84.17; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(136003)(346002)(376002)(39860400002)(396003)(2980300002)(428003)(189003)(199004)(2201001)(106466001)(50226002)(53936002)(305945005)(47776003)(86362001)(53416004)(105586002)(2616005)(97736004)(478600001)(476003)(426003)(50466002)(81156014)(8676002)(48376002)(81166006)(72206003)(8936002)(486006)(7696005)(2906002)(110136005)(44832011)(104016004)(36756003)(77096007)(356004)(54906003)(336012)(51416003)(126002)(6666004)(6346003)(5660300001)(26005)(16586007)(4744004)(68736007)(39060400002)(14444005)(186003)(316002)(4326008)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR12MB0838; H:SATLEXCHOV01.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; MX:1; A:1; X-Microsoft-Exchange-Diagnostics: 1; CO1NAM03FT022; 1:Pl5HwnK+iGiibDN21ryAqHr1+Bgn5H3bPyWF7+eoAUymiILHJRBGba4UwGDAbnP0As+kkK06y64GCvdqgNBEMcWhCehT9+vwLpMUJjF4vMWBswqqR9oC2cTIH3YtH84t X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a65fc66a-cd26-4689-0ed1-08d65ee89f24 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(2390098)(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060); SRVR:CY1PR12MB0838; X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0838; 3:p3EZRn5hN/TGZHl/oZJxpF4EwaKj+qQnJ7d8gFikcVvGbRBw8pqrCHKTgG4sqHx7plFKOpTBt94mI8lhJRtm/VexHcnheUfCxWeXQNXMRjFXX/Oer/CE/Jh2AbGOkLiigXcxPj+lmXDhKLyJqhLXMOtWsqZPA2YNoA/cDxu4lMXkUNOxu5lc27s2yFoqA3f9aBqaE3ymqIDBmNYiuoWJuUURSa089yVy32xLBUfIKKWhpa6pItkfxHkJhiD8bg6RJOJCrwk0Ofa9UiYLvEnhv4hd4k+OGjN9/057xk7/Iz7hROgavjp6oLLFFowx3TdejtenSlqy3c8/xPPN2h11ePDufOkUzlXs+PbMLPJoIHw=; 25:frlBG2kImhW9Xk2erJ9muht5QcORIR6LVZp/Dlu+gA5JKRSQ+COyLaHjDpylSrwTrh464saN1tjymi6TGkYBqk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HBdRV0BSp57PKdnRSQ1NZoRN8lLlz27EWG9Zk X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(3230017)(999002)(6040522)(2401047)(5005006)(8121501046)(93006095)(93003095)(3231472)(944501520)(52105112)(10201501046)(3002001)(6055026)(148016)(149066)(150057)(6041310)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(201708071742011)(7699051)(76991095); SRVR:CY1PR12MB0838; BCL:0; PCL:0; RULEID:; SRVR:CY1PR12MB0838; X-Microsoft-Exchange-Diagnostics: 1; CY1PR12MB0838; 4:EB7cpdAtBBtYTwiPsHQOA1OkUiIja0C9GZEQaXgi3s0Z1S0mo2RnxVjYGlsrkou5w4u7ZB4Su4Ps8if0wSLK9r1A00eTn+e4K+RYqpEbKD3lpACUc42+i7hGRojiqtq3Go+bBRgmJpEQC9QCjA+Vrm65Fym8zr85Ml+Zz//1/kjN4LSJJBN8J47tIb/mLHKptmHd3eyrnu/P+NoW8Cm1kKAwztFUG62P825sDl6pKNqScDHMS4/cVldXDewS54YmpkoJ3Udh2sS1jB/3S2DXyQ== X-Forefront-PRVS: 08828D20BC X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR12MB0838; 23:6O+cPD7Q/9dIkESAYXLUFiogWelTK3qpaJ67EUOVK?= wtzj4yX2yHHRb0DmuRV/XTXFIK6LQEkytL8ECDSaGq3pT7D7XwDyvVOqGkhgpbDOPbgR52BOWl+g85ABRH6iFiWlOx6zCWhXuk+KYXQWw7pnVJNRtA4aPxBVK2gzMiFZUGjWVlMHv3qMTWcG5pa2bRUmRdMBd0GHEARwl2V75O3B8oJUgvxZafSgkVo4VNm2HO9rzFKRe1sVtFLYa0JNS9EVrbZ5Xf3E9+VtnusJOyqfhfzJl+Sc52JmG7jo0PO84Z95Egk+JFtcHv4zjJhtiGd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change-Diagnostics: 1; CY1PR12MB0838; 20:lRtpTtOuczoWbMQp4HYgLAZhwSw2jCEFiKpSg09mwc8fdrbVD7wbxyycJFM7wEKP7Whs8+TgTKZK4InMwmr2zqrTuwCU7tFB0YqGlILeTac9/D52DnWcLlQbfMG5jryBFKDymO1pdGeuG5LAqBJjawLQk8poqgmuWL8KEwmY6MjaXlBwDymbXpBzKhLiXMurfFiN7oSAHCy0aQm7gSi2Ek+Kv2nkXX6BFb5jlcyi0UvWF6aH8o7Eh+z3Euuyl0Xr X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2018 21:44:11.0649 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a65fc66a-cd26-4689-0ed1-08d65ee89f24 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXCHOV01.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR12MB0838 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Monk.Liu@amd.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Decauple sched threads stop and start and ring mirror list handling from the policy of what to do about the guilty jobs. When stoppping the sched thread and detaching sched fences from non signaled HW fenes wait for all signaled HW fences to complete before rerunning the jobs. v2: Fix resubmission of guilty job into HW after refactoring. Suggested-by: Christian Koenig Signed-off-by: Andrey Grodzovsky --- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 17 +++-- drivers/gpu/drm/etnaviv/etnaviv_sched.c | 8 +-- drivers/gpu/drm/scheduler/sched_main.c | 110 ++++++++++++++++++----------- drivers/gpu/drm/v3d/v3d_sched.c | 11 +-- include/drm/gpu_scheduler.h | 10 ++- 5 files changed, 95 insertions(+), 61 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c index ef36cc5..42111d5 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c @@ -3292,17 +3292,16 @@ static int amdgpu_device_pre_asic_reset(struct amdgpu_device *adev, /* block all schedulers and reset given job's ring */ for (i = 0; i < AMDGPU_MAX_RINGS; ++i) { struct amdgpu_ring *ring = adev->rings[i]; + bool park_only = job && job->base.sched != &ring->sched; if (!ring || !ring->sched.thread) continue; - kthread_park(ring->sched.thread); + drm_sched_stop(&ring->sched, job ? &job->base : NULL, park_only); - if (job && job->base.sched != &ring->sched) + if (park_only) continue; - drm_sched_hw_job_reset(&ring->sched, job ? &job->base : NULL); - /* after all hw jobs are reset, hw fence is meaningless, so force_completion */ amdgpu_fence_driver_force_completion(ring); } @@ -3445,6 +3444,7 @@ static void amdgpu_device_post_asic_reset(struct amdgpu_device *adev, struct amdgpu_job *job) { int i; + bool unpark_only; for (i = 0; i < AMDGPU_MAX_RINGS; ++i) { struct amdgpu_ring *ring = adev->rings[i]; @@ -3456,10 +3456,13 @@ static void amdgpu_device_post_asic_reset(struct amdgpu_device *adev, * or all rings (in the case @job is NULL) * after above amdgpu_reset accomplished */ - if ((!job || job->base.sched == &ring->sched) && !adev->asic_reset_res) - drm_sched_job_recovery(&ring->sched); + unpark_only = (job && job->base.sched != &ring->sched) || + adev->asic_reset_res; + + if (!unpark_only) + drm_sched_resubmit_jobs(&ring->sched); - kthread_unpark(ring->sched.thread); + drm_sched_start(&ring->sched, unpark_only); } if (!amdgpu_device_has_dc_support(adev)) { diff --git a/drivers/gpu/drm/etnaviv/etnaviv_sched.c b/drivers/gpu/drm/etnaviv/etnaviv_sched.c index 49a6763..fab3b51 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_sched.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_sched.c @@ -109,16 +109,16 @@ static void etnaviv_sched_timedout_job(struct drm_sched_job *sched_job) } /* block scheduler */ - kthread_park(gpu->sched.thread); - drm_sched_hw_job_reset(&gpu->sched, sched_job); + drm_sched_stop(&gpu->sched, sched_job, false); /* get the GPU back into the init state */ etnaviv_core_dump(gpu); etnaviv_gpu_recover_hang(gpu); + drm_sched_resubmit_jobs(&gpu->sched); + /* restart scheduler after GPU is usable again */ - drm_sched_job_recovery(&gpu->sched); - kthread_unpark(gpu->sched.thread); + drm_sched_start(&gpu->sched); } static void etnaviv_sched_free_job(struct drm_sched_job *sched_job) diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c index dbb6906..cdf95e2 100644 --- a/drivers/gpu/drm/scheduler/sched_main.c +++ b/drivers/gpu/drm/scheduler/sched_main.c @@ -60,8 +60,6 @@ static void drm_sched_process_job(struct dma_fence *f, struct dma_fence_cb *cb); -static void drm_sched_expel_job_unlocked(struct drm_sched_job *s_job); - /** * drm_sched_rq_init - initialize a given run queue struct * @@ -342,13 +340,21 @@ static void drm_sched_job_timedout(struct work_struct *work) * @bad: bad scheduler job * */ -void drm_sched_hw_job_reset(struct drm_gpu_scheduler *sched, struct drm_sched_job *bad) +void drm_sched_stop(struct drm_gpu_scheduler *sched, struct drm_sched_job *bad, + bool park_only) { struct drm_sched_job *s_job; struct drm_sched_entity *entity, *tmp; unsigned long flags; + struct list_head wait_list; int i; + kthread_park(sched->thread); + if (park_only) + return; + + INIT_LIST_HEAD(&wait_list); + spin_lock_irqsave(&sched->job_list_lock, flags); list_for_each_entry_reverse(s_job, &sched->ring_mirror_list, node) { if (s_job->s_fence->parent && @@ -358,9 +364,24 @@ void drm_sched_hw_job_reset(struct drm_gpu_scheduler *sched, struct drm_sched_jo s_job->s_fence->parent = NULL; atomic_dec(&sched->hw_rq_count); } + else { + /* TODO Is it get/put neccessey here ? */ + dma_fence_get(&s_job->s_fence->finished); + list_add(&s_job->finish_node, &wait_list); + } } spin_unlock_irqrestore(&sched->job_list_lock, flags); + /* + * Verify all the signaled jobs in mirror list are removed from the ring + * We rely on the fact that any finish_work in progress will wait for this + * handler to complete before releasing all of the jobs we iterate. + */ + list_for_each_entry(s_job, &wait_list, finish_node) { + dma_fence_wait(&s_job->s_fence->finished, false); + dma_fence_put(&s_job->s_fence->finished); + } + if (bad && bad->s_priority != DRM_SCHED_PRIORITY_KERNEL) { atomic_inc(&bad->karma); /* don't increase @bad's karma if it's from KERNEL RQ, @@ -385,7 +406,7 @@ void drm_sched_hw_job_reset(struct drm_gpu_scheduler *sched, struct drm_sched_jo } } } -EXPORT_SYMBOL(drm_sched_hw_job_reset); +EXPORT_SYMBOL(drm_sched_stop); /** * drm_sched_job_recovery - recover jobs after a reset @@ -393,33 +414,21 @@ EXPORT_SYMBOL(drm_sched_hw_job_reset); * @sched: scheduler instance * */ -void drm_sched_job_recovery(struct drm_gpu_scheduler *sched) +void drm_sched_start(struct drm_gpu_scheduler *sched, bool unpark_only) { struct drm_sched_job *s_job, *tmp; - bool found_guilty = false; unsigned long flags; int r; - spin_lock_irqsave(&sched->job_list_lock, flags); + if (unpark_only) + goto unpark; + + spin_lock_irqsave(&sched->job_list_lock, flags); list_for_each_entry_safe(s_job, tmp, &sched->ring_mirror_list, node) { struct drm_sched_fence *s_fence = s_job->s_fence; - struct dma_fence *fence; - uint64_t guilty_context; - - 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); - - spin_unlock_irqrestore(&sched->job_list_lock, flags); - fence = sched->ops->run_job(s_job); - atomic_inc(&sched->hw_rq_count); + struct dma_fence *fence = s_job->s_fence->parent; if (fence) { - s_fence->parent = dma_fence_get(fence); r = dma_fence_add_callback(fence, &s_fence->cb, drm_sched_process_job); if (r == -ENOENT) @@ -427,18 +436,47 @@ void drm_sched_job_recovery(struct drm_gpu_scheduler *sched) else if (r) DRM_ERROR("fence add callback failed (%d)\n", r); - dma_fence_put(fence); - } else { - if (s_fence->finished.error < 0) - drm_sched_expel_job_unlocked(s_job); + } else drm_sched_process_job(NULL, &s_fence->cb); - } - spin_lock_irqsave(&sched->job_list_lock, flags); } + drm_sched_start_timeout(sched); spin_unlock_irqrestore(&sched->job_list_lock, flags); + +unpark: + kthread_unpark(sched->thread); } -EXPORT_SYMBOL(drm_sched_job_recovery); +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; + + /*TODO DO we need spinlock here ? */ + 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); + + s_job->s_fence->parent = sched->ops->run_job(s_job); + atomic_inc(&sched->hw_rq_count); + } +} +EXPORT_SYMBOL(drm_sched_resubmit_jobs); /** * drm_sched_job_init - init a scheduler job @@ -634,26 +672,14 @@ static int drm_sched_main(void *param) DRM_ERROR("fence add callback failed (%d)\n", r); dma_fence_put(fence); - } else { - if (s_fence->finished.error < 0) - drm_sched_expel_job_unlocked(sched_job); + } else drm_sched_process_job(NULL, &s_fence->cb); - } wake_up(&sched->job_scheduled); } return 0; } -static void drm_sched_expel_job_unlocked(struct drm_sched_job *s_job) -{ - struct drm_gpu_scheduler *sched = s_job->sched; - - spin_lock(&sched->job_list_lock); - list_del_init(&s_job->node); - spin_unlock(&sched->job_list_lock); -} - /** * drm_sched_init - Init a gpu scheduler instance * diff --git a/drivers/gpu/drm/v3d/v3d_sched.c b/drivers/gpu/drm/v3d/v3d_sched.c index 445b2ef..f99346a 100644 --- a/drivers/gpu/drm/v3d/v3d_sched.c +++ b/drivers/gpu/drm/v3d/v3d_sched.c @@ -178,18 +178,19 @@ v3d_job_timedout(struct drm_sched_job *sched_job) for (q = 0; q < V3D_MAX_QUEUES; q++) { struct drm_gpu_scheduler *sched = &v3d->queue[q].sched; - kthread_park(sched->thread); - drm_sched_hw_job_reset(sched, (sched_job->sched == sched ? - sched_job : NULL)); + drm_sched_stop(sched, (sched_job->sched == sched ? + sched_job : NULL), false); } /* get the GPU back into the init state */ v3d_reset(v3d); + for (q = 0; q < V3D_MAX_QUEUES; q++) + drm_sched_resubmit_jobs(sched_job->sched); + /* Unblock schedulers and restart their jobs. */ for (q = 0; q < V3D_MAX_QUEUES; q++) { - drm_sched_job_recovery(&v3d->queue[q].sched); - kthread_unpark(v3d->queue[q].sched.thread); + drm_sched_start(&v3d->queue[q].sched, false); } mutex_unlock(&v3d->reset_lock); diff --git a/include/drm/gpu_scheduler.h b/include/drm/gpu_scheduler.h index 47e1979..c94b592 100644 --- a/include/drm/gpu_scheduler.h +++ b/include/drm/gpu_scheduler.h @@ -175,6 +175,7 @@ struct drm_sched_fence *to_drm_sched_fence(struct dma_fence *f); * finished to remove the job from the * @drm_gpu_scheduler.ring_mirror_list. * @node: used to append this struct to the @drm_gpu_scheduler.ring_mirror_list. + * @finish_node: used in a list to wait on before resetting the scheduler * @id: a unique id assigned to each job scheduled on the scheduler. * @karma: increment on every hang caused by this job. If this exceeds the hang * limit of the scheduler then the job is marked guilty and will not @@ -193,6 +194,7 @@ struct drm_sched_job { struct dma_fence_cb finish_cb; struct work_struct finish_work; struct list_head node; + struct list_head finish_node; uint64_t id; atomic_t karma; enum drm_sched_priority s_priority; @@ -298,9 +300,11 @@ int drm_sched_job_init(struct drm_sched_job *job, void *owner); void drm_sched_job_cleanup(struct drm_sched_job *job); void drm_sched_wakeup(struct drm_gpu_scheduler *sched); -void drm_sched_hw_job_reset(struct drm_gpu_scheduler *sched, - struct drm_sched_job *job); -void drm_sched_job_recovery(struct drm_gpu_scheduler *sched); +void drm_sched_stop(struct drm_gpu_scheduler *sched, + struct drm_sched_job *job, + bool park_only); +void drm_sched_start(struct drm_gpu_scheduler *sched, bool unpark_only); +void drm_sched_resubmit_jobs(struct drm_gpu_scheduler *sched); bool drm_sched_dependency_optimized(struct dma_fence* fence, struct drm_sched_entity *entity); void drm_sched_fault(struct drm_gpu_scheduler *sched);