From patchwork Mon Dec 17 19:51:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Grodzovsky X-Patchwork-Id: 10734211 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 5A0BD6C5 for ; Mon, 17 Dec 2018 19:52:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A9D22A20E for ; Mon, 17 Dec 2018 19:52:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3DF332A212; Mon, 17 Dec 2018 19:52:21 +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 541322A20E for ; Mon, 17 Dec 2018 19:52:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B1CB06E6BA; Mon, 17 Dec 2018 19:52:16 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM05-DM3-obe.outbound.protection.outlook.com (mail-eopbgr730056.outbound.protection.outlook.com [40.107.73.56]) by gabe.freedesktop.org (Postfix) with ESMTPS id 578C86E6B7; Mon, 17 Dec 2018 19:52:15 +0000 (UTC) Received: from BN6PR1201CA0002.namprd12.prod.outlook.com (2603:10b6:405:4c::12) by MW2PR12MB2443.namprd12.prod.outlook.com (2603:10b6:907:8::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1425.22; Mon, 17 Dec 2018 19:52:11 +0000 Received: from DM3NAM03FT005.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e49::200) by BN6PR1201CA0002.outlook.office365.com (2603:10b6:405:4c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1425.19 via Frontend Transport; Mon, 17 Dec 2018 19:52:10 +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 DM3NAM03FT005.mail.protection.outlook.com (10.152.82.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1446.11 via Frontend Transport; Mon, 17 Dec 2018 19:52:10 +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, 17 Dec 2018 13:52:08 -0600 From: Andrey Grodzovsky To: , , , , Subject: [PATCH v4 1/2] drm/sched: Refactor ring mirror list handling. Date: Mon, 17 Dec 2018 14:51:54 -0500 Message-ID: <1545076315-26861-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)(396003)(39860400002)(376002)(346002)(2980300002)(428003)(199004)(189003)(4744004)(50226002)(5660300001)(6666004)(8676002)(36756003)(14444005)(81166006)(81156014)(48376002)(105586002)(356004)(50466002)(86362001)(53416004)(2201001)(47776003)(8936002)(106466001)(44832011)(486006)(126002)(77096007)(336012)(68736007)(26005)(305945005)(72206003)(2906002)(97736004)(2616005)(476003)(53936002)(186003)(110136005)(104016004)(478600001)(426003)(54906003)(39060400002)(316002)(7696005)(51416003)(4326008)(16586007)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:MW2PR12MB2443; H:SATLEXCHOV01.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; A:1; MX:1; X-Microsoft-Exchange-Diagnostics: 1; DM3NAM03FT005; 1:jpJYrtPRZWYe1Rq8JatMi/ypXwwwHv5/vuWPn9Kw1loQUvgI2db0EC2QoDXWlA8s5uQjdD3qtzs0EnGHmRdO5HJfVOTEahJY7eit6wSp/PzdXGtRy5AZa6PKSrJKz0RC X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 50d36e29-b797-4e98-6853-08d664592213 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060); SRVR:MW2PR12MB2443; X-Microsoft-Exchange-Diagnostics: 1; MW2PR12MB2443; 3:BxA1OfDskKETofcBbaSwowBD5dEz/hGTxLknLxpMsJaRjSQdisjyAlrgMUW9jmJCE62WYMOPwoxzkNlu/l3cqhsFYiRMVnPMGoZxk8lRzZTWjMLeqNg39xH+GqMxRRNUnkvqWlAurn4bTvhOgudvOaRcofnWMOKwIOLqS7TKNpbkz1b4IYXoQ3zb8e2qGUddMNcZ5ALXO2wr9vgIXWNK2jV1JMOO1ZegtFXyS5rnINkSgpUguhwtOw6FRPIg7rMlgJSCx3FuCIEw+fQ5zmD80LK3c0c4s5PE7+O8zzqSgt3utgb3BWJ0LNC/18LFmkQ3CkTYPKYJhvv0qVJJUp39hMuV6pl6y/ZFCDFUNonF1vk=; 25:7ETK5xBkJXHqp3dK9C6HCNMbjI2jjWkWR/6bzK2S9DdDorc/6yTp92Hbxmi1DXIadB2M11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y808I00H4 X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(3230021)(999002)(6040522)(2401047)(5005006)(8121501046)(93006095)(93003095)(3002001)(3231475)(944501520)(52105112)(10201501046)(6055026)(148016)(149066)(150057)(6041310)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123558120)(20161123562045)(201708071742011)(7699051)(76991095); SRVR:MW2PR12MB2443; BCL:0; PCL:0; RULEID:; SRVR:MW2PR12MB2443; X-Microsoft-Exchange-Diagnostics: 1; MW2PR12MB2443; 4:zsN8y0WKtqqlArjmmPCSGAz8UDaMSseyffKm7ZDw4iYFmhl+c1U4Ox35AwU9yIySIbCgKUgktpSAkmpHjWNxEz8v1De7Byv8Rl7807fb4lPnc1eJ5NoeCGm6t6BRoJ/vvaeZnzmwdE3mEe2peVp6E9gG+m0y2ovhiJ9OOAw/bDQi2wlY1LaSgoiBk7HvzbqowW/v+BkQF3Wwv41uonIThG6ljkSaNDDx6urXTbWGB3GA57VOis4oAumJFsvbf6etxQSoR7zeOy2Awd8Pdz7fTA== X-Forefront-PRVS: 08897B549D X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MW2PR12MB2443; 23:+S9VF559KVMYiWunTuB6cVfM8kGEFn+nd25/P22DZ?= vN+iiVukvD6u9Bku8fYVWcgsrni1FRn71t4to/HJFFbvOjVzxJEFI9OKTB+ALGI6L0U8RSXbN0O5U9oENxn+1x7rcZPoVEH783l5C/kXnJZAxUFL86CmvHi2wyWHEjUrtsCqszRh5wiK54R7mfwIt5Jvgxa7qf0VtPGKDhCOFKNhpnhIU4rn0M+BMqYq0Tk9xULW3q/MRKS2pQywGNLqeYLTSfub40wl4pOzxKBNnpIABHEWNhKlPJ3pZ5lCR1lsAP4715nuS9rxPseNBiTex4XI1OHdw7Bf4iaK/yf5PpKaFJzoKMqqlsW5cXvEHTM2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6PhodyeGpHD5M5qBH/omaW7DnqOpPMlicFVnSi5RcLUofBg33GshmrUQHWjIKzjlpy0TWKNaDC3d6wxOmYrtUXWQlA01cZK5bz1d7JEn1MzCVS2QrKI/AqNgGpyRREgEMjlzCGET94Ez X-Microsoft-Exchange-Diagnostics: 1; MW2PR12MB2443; 6:Sf0SYbkb1mSB4n28cZvlrQctsB6PSjZhiSznhjCCDsEoctKT7VeVzIxXrP7xYMwW1wAwcNkqWFzP7k2ofEfuquKIhZOFhhijh0iYWvsUs6DDG2ONLkOT8xzEP14v8x9IIoTRmy7Uw8cLCINQ+47AKeWok5c8g6W9zq+UTI5Jcnu2OpyBqzJPjvbmOel+OvC4CGgRBHS1svfF9C+lxop7GeTjAcNGiEuIPomhw7ZPYjD54FNA4LCSRWCznjUH34sy//y96ZE4iac3tibUUDVfUgiPVcS7rgg4M2Giw8pk2vCeuTYVSjlqRTmJSNPATgvGb/kt8fhD3QnO01DyTW3hbvZ5fl6TA+fQoFA5le86KINTap1J1PZlpEvosHM189aSthhvoiGTK6xrsHfAhd3BCtDdOAu4s0JcvLTcFRPagZFvkUB8rcxWAWWdVvlnSbyoYCoiGmMv1h4GmBb12aQ9Tw==; 5:k6x8D8DnYqg/5K6UIohGHhOrGKLSs5mGflSsXsb4Af/1clsZelg+NKgDLrpFuxUGLJy9U8PBDCHTFusEeyKdVXtVyaqJ/+aUnnTKWlzJPAIAVgXV73YyKihumgBuQ+pxBNSW3aQVsmVRgrk/Fi9ociwS2afXuEZ+wh0M6+mwRm8=; 7:jSmrr2A2H/ARePD0V5GrF7r8t3iu58Ulg7mroJ9X/LrmXuPBMUvpQHm+owcPmhrpydgCWAwfPiUbswohi0GmB+giQO8abLljiOoDrPiTbBw8NGaN/wdOWU5LYeCnD53uzto6SwO1BtkixUwUJy7VdA== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; MW2PR12MB2443; 20:h0PYNwdbVLaIfGRkP3TsIkhn7E3vG4p9VuifkZff8E4fAwpV7JlXo2T59FZOC6eoAcD0D9+xML2WZkA6IqUBzAVtoynzd4f0r71iZO0e6A9aUWKy5Xj76a6zR3trf/R2NJAGx/gcKL30GIaup6k5VbufYfPA9ZRd3hfQMVqMhgRXeLb4ZUPaDQ+IIghApxk8WXNY+1wMjSKb8jiX2agf07S4GWQn1y2F0j7G/V62R8cnp/wFbBONCyNmWB6imc4D X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Dec 2018 19:52:10.2630 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 50d36e29-b797-4e98-6853-08d664592213 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: MW2PR12MB2443 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. v4: Full restart for all the jobs, not only from guilty ring. Extract karma increase into standalone function. 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 | 164 +++++++++++++++++------------ drivers/gpu/drm/v3d/v3d_sched.c | 9 +- include/drm/gpu_scheduler.h | 9 +- 5 files changed, 118 insertions(+), 89 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c index 8a078f4..8ac4f43 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c @@ -3298,12 +3298,7 @@ static int amdgpu_device_pre_asic_reset(struct amdgpu_device *adev, if (!ring || !ring->sched.thread) continue; - kthread_park(ring->sched.thread); - - if (job && job->base.sched != &ring->sched) - continue; - - drm_sched_hw_job_reset(&ring->sched, job ? &job->base : NULL); + drm_sched_stop(&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); @@ -3454,14 +3449,10 @@ static void amdgpu_device_post_asic_reset(struct amdgpu_device *adev, if (!ring || !ring->sched.thread) continue; - /* only need recovery sched of the given job's ring - * 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); + if (!adev->asic_reset_res) + drm_sched_resubmit_jobs(&ring->sched); - kthread_unpark(ring->sched.thread); + drm_sched_start(&ring->sched, !adev->asic_reset_res); } 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..d7075cd 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); /* 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, true); } 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..1cf9541 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 * @@ -335,6 +333,41 @@ static void drm_sched_job_timedout(struct work_struct *work) spin_unlock_irqrestore(&sched->job_list_lock, flags); } +static 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; + } + } +} + /** * drm_sched_hw_job_reset - stop the scheduler if it contains the bad job * @@ -342,12 +375,15 @@ 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) { struct drm_sched_job *s_job; - struct drm_sched_entity *entity, *tmp; unsigned long flags; - int i; + struct list_head wait_list; + + kthread_park(sched->thread); + + 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) { @@ -357,35 +393,28 @@ void drm_sched_hw_job_reset(struct drm_gpu_scheduler *sched, struct drm_sched_jo dma_fence_put(s_job->s_fence->parent); 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); - 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, - * becuase sometimes GPU hang would cause kernel jobs (like VM updating jobs) - * corrupt but keep in mind that kernel jobs always considered good. - */ - 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; - } + /* + * 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) + drm_sched_increase_karma(bad); } -EXPORT_SYMBOL(drm_sched_hw_job_reset); +EXPORT_SYMBOL(drm_sched_stop); /** * drm_sched_job_recovery - recover jobs after a reset @@ -393,33 +422,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 full_recovery) { struct drm_sched_job *s_job, *tmp; - bool found_guilty = false; unsigned long flags; int r; + if (!full_recovery) + 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 +444,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 +680,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..aaa10b0 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 ? + drm_sched_stop(sched, (sched_job->sched == sched ? sched_job : NULL)); } /* 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, true); } mutex_unlock(&v3d->reset_lock); diff --git a/include/drm/gpu_scheduler.h b/include/drm/gpu_scheduler.h index 47e1979..441384c 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,10 @@ 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); +void drm_sched_start(struct drm_gpu_scheduler *sched, bool full_recovery); +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); From patchwork Mon Dec 17 19:51:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Grodzovsky X-Patchwork-Id: 10734213 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 AADA36C5 for ; Mon, 17 Dec 2018 19:52:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9BCDA2A20E for ; Mon, 17 Dec 2018 19:52:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8D3B32A212; Mon, 17 Dec 2018 19:52:24 +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 0B3F02A20E for ; Mon, 17 Dec 2018 19:52:24 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 559396E6C3; Mon, 17 Dec 2018 19:52:22 +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-eopbgr790050.outbound.protection.outlook.com [40.107.79.50]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9C83D6E6BF; Mon, 17 Dec 2018 19:52:20 +0000 (UTC) Received: from BN4PR12CA0005.namprd12.prod.outlook.com (2603:10b6:403:2::15) by MW2PR12MB2441.namprd12.prod.outlook.com (2603:10b6:907:8::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1425.22; Mon, 17 Dec 2018 19:52:17 +0000 Received: from DM3NAM03FT013.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e49::208) by BN4PR12CA0005.outlook.office365.com (2603:10b6:403:2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1425.19 via Frontend Transport; Mon, 17 Dec 2018 19:52:17 +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 DM3NAM03FT013.mail.protection.outlook.com (10.152.82.79) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1446.11 via Frontend Transport; Mon, 17 Dec 2018 19:52:16 +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, 17 Dec 2018 13:52:15 -0600 From: Andrey Grodzovsky To: , , , , Subject: [PATCH v4 2/2] drm/sched: Rework HW fence processing. Date: Mon, 17 Dec 2018 14:51:55 -0500 Message-ID: <1545076315-26861-2-git-send-email-andrey.grodzovsky@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1545076315-26861-1-git-send-email-andrey.grodzovsky@amd.com> References: <1545076315-26861-1-git-send-email-andrey.grodzovsky@amd.com> 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)(39860400002)(376002)(136003)(396003)(346002)(2980300002)(428003)(199004)(189003)(76176011)(51416003)(53416004)(106466001)(53936002)(104016004)(356004)(6666004)(39060400002)(478600001)(50226002)(4326008)(81166006)(5024004)(81156014)(14444005)(8676002)(8936002)(476003)(44832011)(486006)(72206003)(305945005)(16586007)(54906003)(110136005)(186003)(316002)(68736007)(426003)(126002)(336012)(446003)(47776003)(7696005)(5660300001)(2906002)(50466002)(36756003)(86362001)(105586002)(97736004)(11346002)(48376002)(26005)(77096007)(2616005)(2201001)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:MW2PR12MB2441; H:SATLEXCHOV01.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; A:1; MX:1; X-Microsoft-Exchange-Diagnostics: 1; DM3NAM03FT013; 1:woMeWUII4KQdv3lsMwFmHlDp4c2kgl92qlZsy8tglZwHDR+JD4JSVO2sP9nY6XTwwJnZJGkmvcqkLJ02nWN3KYfHVwGrnVFvWzPBMeFCNW793wawwAOvGckVRco4ZrOB X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c8411aeb-9975-426b-4b0b-08d66459260d X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060); SRVR:MW2PR12MB2441; X-Microsoft-Exchange-Diagnostics: 1; MW2PR12MB2441; 3:7wcjAhk+Q+4UrBecRFbla6AMxJJNiV6daVMdF0uvIX7kwoHxk4WNc0vrnORnv5bRCFfhDtmdVYCFd18eoB4kRcvDHHC90Fjo21Mw3MkGGlzAiPgX7lkT6QLGqrfDQFm28+YlJj6i5fCL40Gv+6s7Uo31ZftUp3bx3LgVPVc7kRndG3xGNDaB27cfOax7Ut47xskfvglR5kSysNIAeCyKOpCYrDoS5UpxujJVy1Oqi0kNrY8c7czr3QAvdUE4/slkE0it1+mvKqmqY13jiD+kdd3YW1HO2vFHushApvklll5IIC4Jq+fbTun+dLcpFsPj9x/iEpOMG43Wj+N4q2hFRwa2ovhBqsratIMcW9dHPUc=; 25:VUlK3jQ144WPd/AL09eZx1oU7V5bL0HDmF6orQdVkbGBY6/5cZMA5N8vR7sVCxq1iIjZm2Mc0GLkiHZOaiaK+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FYrxT X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(3230021)(999002)(6040522)(2401047)(8121501046)(5005006)(10201501046)(93006095)(93003095)(3002001)(3231475)(944501520)(52105112)(6055026)(148016)(149066)(150057)(6041310)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123560045)(20161123558120)(201708071742011)(7699051)(76991095); SRVR:MW2PR12MB2441; BCL:0; PCL:0; RULEID:; SRVR:MW2PR12MB2441; X-Microsoft-Exchange-Diagnostics: 1; MW2PR12MB2441; 4:mW/ARi0FT1R/y65rdWd51+Krt/CcfDLhl7NtYH+ylJyijjnfWpGkUVTT+AezeiR6UIedJ3mQsBk++3SpdsmnNLhUQCX78cg6+Ualy07zJ/gm8XcEpZthDr8Dfq84h9ZtlmPELOGVQNWRtNyDe+oRIolc/zSH1kSEMgQ3vcWWuublSj1qTc+VHMn//fuKMwcGumcLzAjesHCGyEJ4yynPxHeAAYUJu31mfUrvT5kXuUMJwVMRlN56cZKUJmW2zl/T0bUgNitKPq9SMIKISfyKTQ== X-Forefront-PRVS: 08897B549D X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MW2PR12MB2441; 23:M3wrbfMbBjTczhuKaG62L7AuyL0m/w9PggXIJHO7r?= d9OnFVLGyNWEzRTY03hGqf1StkorROytJba+jzeSt5AmJ47v+CVkQ5s9aVRniPYTSQPgcClDJKQ7Rux9kCu+O+ypOgmX2roqLKtF2bojWU6eNWGrVk6kOxbEF/2Hxc1Sp1f8/2RgeVmWsz2dZZ3DOkyuI44uryBraLvUF2UCj+YPq6/N7dBx0UltCArbCgcN/il4zI50KoPi3Wq598E+rkvslfsuRBSZux2j+J0eliI9TDPaOMUHid7ETiE8rfprb2vLTPT99cfUylSc5Vgn+xPkQwu6fUu3igm+AzDRCc+GC5QfZik/KhfzR5Bq+KIY/OPeXRXUgs6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IBp7/qeDj2DlupMmJ+0laWSaikJdcVuTsGSE2cPHZE5jkmvtrxAg/FJR1wnJweFN2mA1S7m5xs9GspgNd+cFpzU86eDBGcUf+/ZIDj5Kn4hvFml2/cSgZanwqBmxra7ZqGsO/EJ1SvRrjwDddpAkhkW79Z9VLIxkstylkt5BOQ X-Microsoft-Exchange-Diagnostics: 1; MW2PR12MB2441; 6:+bklUzOi+otgEOckFbAgVbX6XzRoGR2ncD/Z07N5+4XsinvYLlmhT1175Uu1UEPeIa4DDtPXQGEMTsBjxuK2y9Zg7V7kDVTaf0/rG3hMEmul8jLfw/VCgTrYF+2hdXD86frgJup1DBL3ARY1WP4mlqS2TtxkFt7iooJ8L0b8BQ2VBUohA6ddlP0NXKBMbwhk62oQlkjJxOiE76caB6nYRbexOYvEf8NaFnn1dnidGj1/oVvRyGlUQh6yHUnS5gvJ0YNms3QU7TwErC9xtaWMs/UPX9bx/F9cVsWoL7vkmcjEijCNh5wZmmqPbBs7Nun2v9RqpjJB/STOPyJFXLu+W4QIlPry993aJ8GOLiibDKkrngB7YeffA/jkVMWZalDH8vNg2kgBp31h/2jWRm04D2Po05uwOPhiNSaPUng5efU4e5SzSN/GwnRRKVt8NdFwPOz+MNjCsiuD+uWKZjN1xg==; 5:OSt+LIexF2dqJZ6KfbKu3enjFVv63ZLDlPLiZg/pj8WT8u5bX4i0AuOfdAf5AQ5lYQWccwhNWlKrS99pmj6z/+4P5OTv9b0aNNtCvNYDpM1wAye68iWebR/lVXJhKvtvSPyolCjpFChwaS1AyVEQXDadg2yJLaJmMt5EkenGzf4=; 7:+XV2LmMPR2TGUs1pWeYj2qSLmgYArshWzagqmn8PMXyzmyhdL9bbIgJuSMGn4akX6/ttSHXoWvALrbjsGF5+LVwBzuHc+WMFbmvW5adtfe3VIkPdgDF4lKhGVFdAx8OGEUDt/gmDxSdIvc2X4ouCjw== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; MW2PR12MB2441; 20:c7/lp4EjXmulFRiTIoOp57QhiFvvu+nLjCknrnE+CshVEOiy7jU3vsWp9/N9AFiRGnmPX75YeUg7tWiP6XJBKwCYCgppnzQ60W0ZbQKMNkD3HRFVzM9xBykivshheFp03F8IwiMaug6Q5gkdCpzhPgtkLqhoVQrt3Dq19sfNI0uvkwE3L05qXjOg29tDim3wl2cLgIUWObNTs0U3dgmEvyeTdXgl6JUKfKV8pWfeA08QGRijmPatZ6kGJCIN/iZg X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Dec 2018 19:52:16.9651 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c8411aeb-9975-426b-4b0b-08d66459260d 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: MW2PR12MB2441 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 Expedite job deletion from ring mirror list to the HW fence signal callback instead from finish_work, together with waiting for all such fences to signal in drm_sched_stop we garantee that already signaled job will not be processed twice. Remove the sched finish fence callback and just submit finish_work directly from the HW fence callback. v2: Fix comments. v3: Attach hw fence cb to sched_job Suggested-by: Christian Koenig Signed-off-by: Andrey Grodzovsky --- drivers/gpu/drm/scheduler/sched_main.c | 55 +++++++++++++++++----------------- include/drm/gpu_scheduler.h | 6 ++-- 2 files changed, 29 insertions(+), 32 deletions(-) diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c index 1cf9541..40df9b9 100644 --- a/drivers/gpu/drm/scheduler/sched_main.c +++ b/drivers/gpu/drm/scheduler/sched_main.c @@ -284,8 +284,6 @@ static void drm_sched_job_finish(struct work_struct *work) cancel_delayed_work_sync(&sched->work_tdr); spin_lock_irqsave(&sched->job_list_lock, flags); - /* remove job from ring_mirror_list */ - list_del_init(&s_job->node); /* queue TDR for next job */ drm_sched_start_timeout(sched); spin_unlock_irqrestore(&sched->job_list_lock, flags); @@ -293,22 +291,11 @@ static void drm_sched_job_finish(struct work_struct *work) sched->ops->free_job(s_job); } -static void drm_sched_job_finish_cb(struct dma_fence *f, - struct dma_fence_cb *cb) -{ - struct drm_sched_job *job = container_of(cb, struct drm_sched_job, - finish_cb); - schedule_work(&job->finish_work); -} - static void drm_sched_job_begin(struct drm_sched_job *s_job) { struct drm_gpu_scheduler *sched = s_job->sched; unsigned long flags; - dma_fence_add_callback(&s_job->s_fence->finished, &s_job->finish_cb, - drm_sched_job_finish_cb); - spin_lock_irqsave(&sched->job_list_lock, flags); list_add_tail(&s_job->node, &sched->ring_mirror_list); drm_sched_start_timeout(sched); @@ -389,7 +376,7 @@ void drm_sched_stop(struct drm_gpu_scheduler *sched, struct drm_sched_job *bad) list_for_each_entry_reverse(s_job, &sched->ring_mirror_list, node) { if (s_job->s_fence->parent && dma_fence_remove_callback(s_job->s_fence->parent, - &s_job->s_fence->cb)) { + &s_job->cb)) { dma_fence_put(s_job->s_fence->parent); s_job->s_fence->parent = NULL; atomic_dec(&sched->hw_rq_count); @@ -425,31 +412,34 @@ EXPORT_SYMBOL(drm_sched_stop); void drm_sched_start(struct drm_gpu_scheduler *sched, bool full_recovery) { struct drm_sched_job *s_job, *tmp; - unsigned long flags; int r; if (!full_recovery) goto unpark; - spin_lock_irqsave(&sched->job_list_lock, flags); + /* + * Locking the list is not required here as the sched thread is parked + * so no new jobs are being pushed in to HW and in drm_sched_stop we + * flushed all the jobs who were still in mirror list but who already + * signaled and removed them self from the list. Also concurrent + * GPU recovers can't run in parallel. + */ 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 = s_job->s_fence->parent; if (fence) { - r = dma_fence_add_callback(fence, &s_fence->cb, + r = dma_fence_add_callback(fence, &s_job->cb, drm_sched_process_job); if (r == -ENOENT) - drm_sched_process_job(fence, &s_fence->cb); + drm_sched_process_job(fence, &s_job->cb); else if (r) DRM_ERROR("fence add callback failed (%d)\n", r); } else - drm_sched_process_job(NULL, &s_fence->cb); + drm_sched_process_job(NULL, &s_job->cb); } drm_sched_start_timeout(sched); - spin_unlock_irqrestore(&sched->job_list_lock, flags); unpark: kthread_unpark(sched->thread); @@ -598,18 +588,27 @@ drm_sched_select_entity(struct drm_gpu_scheduler *sched) */ static void drm_sched_process_job(struct dma_fence *f, struct dma_fence_cb *cb) { - struct drm_sched_fence *s_fence = - container_of(cb, struct drm_sched_fence, cb); + struct drm_sched_job *s_job = container_of(cb, struct drm_sched_job, cb); + struct drm_sched_fence *s_fence = s_job->s_fence; struct drm_gpu_scheduler *sched = s_fence->sched; + unsigned long flags; + + cancel_delayed_work(&sched->work_tdr); - dma_fence_get(&s_fence->finished); atomic_dec(&sched->hw_rq_count); atomic_dec(&sched->num_jobs); + + spin_lock_irqsave(&sched->job_list_lock, flags); + /* remove job from ring_mirror_list */ + list_del_init(&s_job->node); + spin_unlock_irqrestore(&sched->job_list_lock, flags); + drm_sched_fence_finished(s_fence); trace_drm_sched_process_job(s_fence); - dma_fence_put(&s_fence->finished); wake_up_interruptible(&sched->wake_up_worker); + + schedule_work(&s_job->finish_work); } /** @@ -672,16 +671,16 @@ static int drm_sched_main(void *param) if (fence) { s_fence->parent = dma_fence_get(fence); - r = dma_fence_add_callback(fence, &s_fence->cb, + r = dma_fence_add_callback(fence, &sched_job->cb, drm_sched_process_job); if (r == -ENOENT) - drm_sched_process_job(fence, &s_fence->cb); + drm_sched_process_job(fence, &sched_job->cb); else if (r) DRM_ERROR("fence add callback failed (%d)\n", r); dma_fence_put(fence); } else - drm_sched_process_job(NULL, &s_fence->cb); + drm_sched_process_job(NULL, &sched_job->cb); wake_up(&sched->job_scheduled); } diff --git a/include/drm/gpu_scheduler.h b/include/drm/gpu_scheduler.h index 441384c..c5bbf4e 100644 --- a/include/drm/gpu_scheduler.h +++ b/include/drm/gpu_scheduler.h @@ -138,10 +138,6 @@ struct drm_sched_fence { struct dma_fence finished; /** - * @cb: the callback for the parent fence below. - */ - struct dma_fence_cb cb; - /** * @parent: the fence returned by &drm_sched_backend_ops.run_job * when scheduling the job on hardware. We signal the * &drm_sched_fence.finished fence once parent is signalled. @@ -182,6 +178,7 @@ struct drm_sched_fence *to_drm_sched_fence(struct dma_fence *f); * be scheduled further. * @s_priority: the priority of the job. * @entity: the entity to which this job belongs. + * @cb: the callback for the parent fence in s_fence. * * A job is created by the driver using drm_sched_job_init(), and * should call drm_sched_entity_push_job() once it wants the scheduler @@ -199,6 +196,7 @@ struct drm_sched_job { atomic_t karma; enum drm_sched_priority s_priority; struct drm_sched_entity *entity; + struct dma_fence_cb cb; }; static inline bool drm_sched_invalidate_job(struct drm_sched_job *s_job,