From patchwork Thu Dec 27 19:28:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Grodzovsky X-Patchwork-Id: 10744031 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 06E7A91E for ; Thu, 27 Dec 2018 19:28:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE148287E6 for ; Thu, 27 Dec 2018 19:28:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CB9DB289AB; Thu, 27 Dec 2018 19:28:27 +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 BBEB9287E6 for ; Thu, 27 Dec 2018 19:28:26 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2353C6E80B; Thu, 27 Dec 2018 19:28:22 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM04-CO1-obe.outbound.protection.outlook.com (mail-eopbgr690087.outbound.protection.outlook.com [40.107.69.87]) by gabe.freedesktop.org (Postfix) with ESMTPS id C681D6E809; Thu, 27 Dec 2018 19:28:20 +0000 (UTC) Received: from BN6PR1201CA0015.namprd12.prod.outlook.com (2603:10b6:405:4c::25) by CY4PR12MB1669.namprd12.prod.outlook.com (2603:10b6:910:11::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1446.24; Thu, 27 Dec 2018 19:28:18 +0000 Received: from CO1NAM03FT009.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::203) by BN6PR1201CA0015.outlook.office365.com (2603:10b6:405:4c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1471.20 via Frontend Transport; Thu, 27 Dec 2018 19:28:18 +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 CO1NAM03FT009.mail.protection.outlook.com (10.152.80.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1471.13 via Frontend Transport; Thu, 27 Dec 2018 19:28:17 +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; Thu, 27 Dec 2018 13:28:15 -0600 From: Andrey Grodzovsky To: , , , , Subject: [PATCH v6 1/2] drm/sched: Refactor ring mirror list handling. Date: Thu, 27 Dec 2018 14:28:06 -0500 Message-ID: <1545938887-22901-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)(396003)(136003)(376002)(346002)(39860400002)(2980300002)(428003)(199004)(189003)(5660300001)(48376002)(104016004)(47776003)(305945005)(2906002)(68736007)(50466002)(44832011)(51416003)(126002)(476003)(77096007)(336012)(36756003)(53936002)(2201001)(4744004)(186003)(26005)(426003)(6346003)(16586007)(356004)(106466001)(81166006)(2616005)(8936002)(7696005)(486006)(50226002)(86362001)(105586002)(8676002)(53416004)(478600001)(54906003)(316002)(97736004)(110136005)(72206003)(6666004)(81156014)(39060400002)(14444005)(4326008)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR12MB1669; H:SATLEXCHOV01.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; A:1; MX:1; X-Microsoft-Exchange-Diagnostics: 1; CO1NAM03FT009; 1:+TItYMw5F+zyfh/wax90pTn4j2C2d7FtQhaQ6gj9RBHDlKBU/5Zr3s2Sgd/f+KC/VyelM8AQauzuO/d68/aMZ0EKAwIBrAioBpKkWEou62xM6qfvaoHeApbv0asJl2tp X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b8641227-162a-4127-81ec-08d66c317447 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600098)(711020)(2017052603328)(7153060); SRVR:CY4PR12MB1669; X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1669; 3:IZvas2HDJgvUqO3V2BMuo+ze6ljWdhnK6OkrfIKbuImTWBUupQZCcsnVjl0Y66e+HxHTrmtEBnhJ4HkBycMCNEF8p7FNKKdRee5qWGJ7qNoswOuQFGIV4lAOJhpa/NzthdOCfrVBOB2O7bEAS0TBuh9pjYEDEQUfebHFoMfD7ytrOOCBlpjeAu/jZklTHb9sZJzAkTuEZWxzRO2OabP4rRN/MBMJXJNBdcRyX+kdATCqe2a81r3YwTVsKP1O4uIu+ImJWQor/yK3xYDezDxy9yNF5+yIn3/tEPlyJS1mEgYucq09tsgrskDTR6f0IOUBFCTM1o7wp9D7OqyO6v77zzpoAPTfp/Cz4i0B03pgeu8=; 25:/Hvtn+BXDHU+YeEs7M2aIGEE57CSyps+opBfrShNGRmsg4uDxkZ9tjkD4fNb/vzxiz1R2NYTwU3V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B2nvaSYfV X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(3230021)(908002)(999002)(5005026)(6040522)(8220047)(2401047)(8121501046)(10201501046)(3231475)(944501520)(52105112)(93006095)(93003095)(3002001)(6055026)(6041310)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123560045)(201708071742011)(7699051)(76991095); SRVR:CY4PR12MB1669; BCL:0; PCL:0; RULEID:; SRVR:CY4PR12MB1669; X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1669; 4:M/CBLF4hmAV1JmEiBDhfFw9gLP1sC5jo5QFi8Q8ueJe5OmbT7c1yvakQYmNNOENd1+sekvPq/t/DLnGw0YyQs5Rdj7t2dkDbJ2Zu7f2JEE6SwtdrmS8+T+0dthufZCa9La+e66gaA/YCcxDS5rIkM7v3TfXYqMDF7qdKkwmZYNscPpLxAvs/GunxlvfEGFC1ZlfJxb3aCMCObBsT4jWFwhOKkdi0WtxYQ+1V9JZ15seQ4Eyte1xtpFg2oC+z+aPqI5lUsMOzOwCwTNYI1pZBEQ== X-Forefront-PRVS: 0899B47777 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY4PR12MB1669; 23:a00VCNSWmFCZxko9jAjR/2zZRNtqE9aTGLNukQ1Oe?= PoYYPUf/KeCSQpnkOm3dJPmqwVHLBpbROTX7SjDsKlZ1P7KUTlHWUxQDgx+45lzNdLW16eM/cSUOPpl6IoAH5BjxjDvG01wRHzhTkE5I8x06ZfY+1Gi26/Sajs1lnUNDsjgnEyNR+e3oQQ7y8xBDnHBmzXLgYuxJc1FewWY2YC0dxgGD20JTSGIrLkeb/Ed++BmBPiZACgSOx7zeoj/J0wdicOp6Jp59Q8cSpwN6I0fZf0lJNEU7d2QwZwHNQ38TjTN4uvGr46sDsfY2hoZmjT91ZWU8J1qbSu6EMAUA075Woh6Q1sEfvPozLn8QYnB9br8mC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beb5SBpb5LvICvqB80kCMjPFRD4QrWDYMU/FGs1DOtOGOmctP9EJs3MAXzd72VyRi+voxHXfr886Jow2Y+r4+gHVXU/oeL6YzP7MCgklJsqsupGYtNrm9eRG0R0xc91b66WF852QmP2+aNy9aEc0vr6qAHS3xyESh8VRh8rpebZ5hTA X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1669; 6:kf42epStTszPGdfsghllg5nOQF1z0/Atujes1sxfduKBSq1lK9UsDr5FvxhpBrUJ65cc3zjU4DzGeXXbyjIN9jr3pctB+TdwO93hSNzoF4SO2o0FbrRPL7I/TdqOAoELc/EvtfdFxy+Zs9ctYOzFsClTctv1su2Tn4gqWfzYzD+1xbSX12yJCyB44Oz3wPa17r05XCD4623064K7Gd1WlgOjqsuRWaSRWBZZPhofQZ7R5m/BHhHjF8KStc98tV+B7wiyDgE/PW7BYEk6HuT5glPtuC6VuNRCAykFpclgXfLg8SsySziMripcyLxnXv0blXbcXMuyvaVouDP0tAVeYcC2ozkxYL5edXX7qgFufMGIMHdgG55fr465a9vvBjiHE/iG33Lb1HATEhB3fWpHnxr9kxaRwpZ8xg41Ig5snwj+T7Sq9Z99alJLuYn5e0TD+kNcreWFFmLjBnO1RF8RBQ==; 5:KwKdGSIbaFHRa1Ch7U/7sXpJQXjHDNm1OpCTreADdCh2h3ko5i/ShWH3XMd4FYT6FHKPeqyvRVoec4Jus01e8Txjn/5pT9+xZGZmtWEYZ5+0GWkjo+2dKjZ+rOH3ywZU90XVAPEje7tfPBkEMouF4RRsAVc9zzBYjpUjQKE8op0=; 7:Jk6O/89a5mpf/YUe9CiQ5MHWVWWAB2Xc5cjDh1VolVPRcUKTIIXX3sSWsAfifF4Xm52zTetqvCVzJMProY42SXNrYBNK3FDgev6WOWieDiQ1mreVwEbl4YprMvIbZVoiQuAXzFEFJrFBRf5JzsGlOw== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1669; 20:BcC1I85XV0VtPgfYri56UgyeEJr3fIhrT//V33713KfmhWC1Ajbil8NrFYZT7hvk90f6t+0BJWQaCH+AuTBv8BZaWqJv4KVhufIe/1JPTnxOnmjP0YBd7NaT3Z58D3a6fvq7nI/9VTer9+BEwjL/zxVTmp8hS6qU100N94OUunyCRr/fN77u6UlRrhRpZxAnFWZmXi2KRD22fpthTlgTEjNLACJrpMzp8uUt+JUAfrZellbUTBkTH/+d+s7q3hHI X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Dec 2018 19:28:17.5482 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b8641227-162a-4127-81ec-08d66c317447 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: CY4PR12MB1669 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. v5: Rework waiting for signaled jobs without relying on the job struct itself as those might already be freed for non 'guilty' job's schedulers. Expose karma increase to drivers. v6: Use list_for_each_entry_safe_continue and drm_sched_process_job in case fence already signaled. Call drm_sched_increase_karma only once for amdgpu and add documentation. Suggested-by: Christian Koenig Signed-off-by: Andrey Grodzovsky --- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 20 ++- drivers/gpu/drm/etnaviv/etnaviv_sched.c | 11 +- drivers/gpu/drm/scheduler/sched_main.c | 195 +++++++++++++++++++---------- drivers/gpu/drm/v3d/v3d_sched.c | 12 +- include/drm/gpu_scheduler.h | 8 +- 5 files changed, 157 insertions(+), 89 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c index 98df8e4..6a0601c 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c @@ -3298,17 +3298,15 @@ 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); } + if(job) + drm_sched_increase_karma(&job->base); + if (!amdgpu_sriov_vf(adev)) { @@ -3454,14 +3452,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..6f1268f 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_sched.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_sched.c @@ -109,16 +109,19 @@ 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); + + if(sched_job) + drm_sched_increase_karma(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..54e809b 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,51 @@ static void drm_sched_job_timedout(struct work_struct *work) spin_unlock_irqrestore(&sched->job_list_lock, flags); } + /** + * 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); + /** * drm_sched_hw_job_reset - stop the scheduler if it contains the bad job * @@ -342,13 +385,22 @@ 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; + struct drm_sched_job *s_job, *tmp; unsigned long flags; - int i; + struct dma_fence *wait_fence = NULL; + int r; + + kthread_park(sched->thread); + /* + * Verify all the signaled jobs in mirror list are removed from the ring + * by waiting for their respective scheduler fences to signal. + * Continually repeat traversing the ring mirror list until no more signaled + * fences are found + */ +retry_wait: 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 && @@ -357,35 +409,43 @@ 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 { + wait_fence = dma_fence_get(&s_job->s_fence->finished); + break; } } - 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]; + /* No signaled jobs in the ring, its safe to proceed to ASIC reset */ + if (!wait_fence) { + spin_unlock_irqrestore(&sched->job_list_lock, flags); + return; + } - 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; + /* Restore removed cb since removing again already removed cb is undefined */ + list_for_each_entry_safe_continue(s_job, tmp, &sched->ring_mirror_list, node) { + + if (s_job->s_fence->parent) { + r = dma_fence_add_callback(s_job->s_fence->parent, + &s_job->s_fence->cb, + drm_sched_process_job); + if (r == -ENOENT) + drm_sched_process_job(s_job->s_fence->parent, + &s_job->s_fence->cb); + else if (r) + DRM_ERROR("fence add callback failed (%d)\n", + r); } } + spin_unlock_irqrestore(&sched->job_list_lock, flags); + + dma_fence_wait(wait_fence, false); + dma_fence_put(wait_fence); + wait_fence = NULL; + + goto retry_wait; } -EXPORT_SYMBOL(drm_sched_hw_job_reset); + +EXPORT_SYMBOL(drm_sched_stop); /** * drm_sched_job_recovery - recover jobs after a reset @@ -393,33 +453,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 +475,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_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_job_recovery); +EXPORT_SYMBOL(drm_sched_resubmit_jobs); /** * drm_sched_job_init - init a scheduler job @@ -634,26 +711,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..f76d9ed 100644 --- a/drivers/gpu/drm/v3d/v3d_sched.c +++ b/drivers/gpu/drm/v3d/v3d_sched.c @@ -178,18 +178,22 @@ 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)); + + if(sched_job) + drm_sched_increase_karma(sched_job); } /* 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..4f21faf 100644 --- a/include/drm/gpu_scheduler.h +++ b/include/drm/gpu_scheduler.h @@ -298,9 +298,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); +void drm_sched_start(struct drm_gpu_scheduler *sched, bool full_recovery); +void drm_sched_resubmit_jobs(struct drm_gpu_scheduler *sched); +void drm_sched_increase_karma(struct drm_sched_job *bad); 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 Thu Dec 27 19:28:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Grodzovsky X-Patchwork-Id: 10744033 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 5414C6C5 for ; Thu, 27 Dec 2018 19:28:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 42EDC287E6 for ; Thu, 27 Dec 2018 19:28:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3588D289AB; Thu, 27 Dec 2018 19:28:31 +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 A2EC2287E6 for ; Thu, 27 Dec 2018 19:28:30 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0DB806E813; Thu, 27 Dec 2018 19:28:29 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM04-SN1-obe.outbound.protection.outlook.com (mail-eopbgr700049.outbound.protection.outlook.com [40.107.70.49]) by gabe.freedesktop.org (Postfix) with ESMTPS id C46146E80D; Thu, 27 Dec 2018 19:28:27 +0000 (UTC) Received: from DM5PR12CA0070.namprd12.prod.outlook.com (2603:10b6:3:103::32) by BN8PR12MB3474.namprd12.prod.outlook.com (2603:10b6:408:46::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1471.20; Thu, 27 Dec 2018 19:28:26 +0000 Received: from CO1NAM03FT054.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::209) by DM5PR12CA0070.outlook.office365.com (2603:10b6:3:103::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1471.20 via Frontend Transport; Thu, 27 Dec 2018 19:28:25 +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 CO1NAM03FT054.mail.protection.outlook.com (10.152.81.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1471.13 via Frontend Transport; Thu, 27 Dec 2018 19:28:25 +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; Thu, 27 Dec 2018 13:28:23 -0600 From: Andrey Grodzovsky To: , , , , Subject: [PATCH v6 2/2] drm/sched: Rework HW fence processing. Date: Thu, 27 Dec 2018 14:28:07 -0500 Message-ID: <1545938887-22901-2-git-send-email-andrey.grodzovsky@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1545938887-22901-1-git-send-email-andrey.grodzovsky@amd.com> References: <1545938887-22901-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)(396003)(136003)(376002)(39860400002)(346002)(2980300002)(428003)(199004)(189003)(6666004)(53416004)(2906002)(426003)(36756003)(8676002)(5660300001)(8936002)(356004)(86362001)(336012)(186003)(104016004)(51416003)(77096007)(7696005)(76176011)(68736007)(81166006)(81156014)(26005)(47776003)(106466001)(105586002)(305945005)(446003)(44832011)(11346002)(97736004)(50226002)(39060400002)(478600001)(316002)(48376002)(50466002)(5024004)(14444005)(54906003)(110136005)(476003)(2201001)(16586007)(486006)(126002)(4326008)(72206003)(53936002)(2616005)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:BN8PR12MB3474; H:SATLEXCHOV01.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; A:1; MX:1; X-Microsoft-Exchange-Diagnostics: 1; CO1NAM03FT054; 1:DXNVmzQk576UYnmzkR77fPrEyObSvSaEJB8AiGeKlz4YSXZ1biOUHpuT9wDZ6QGuYpbksz4iIE/obXerNJGpSatQ+rfh4+bDkGW/nxsw03cL5HDqXhQ9aJzuqaBVMNCt X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e8201694-b069-47e5-8c0b-08d66c3178bb X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060); SRVR:BN8PR12MB3474; X-Microsoft-Exchange-Diagnostics: 1; BN8PR12MB3474; 3:DkPe8lBtmwhbKT4U4GpdPevYpf/nGAMs7tnotZZYI9mR+LcYwS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TJ5F2jqbQdyuj5vZ1hQecYpDGdXIXDmmAO892cinsgE+OZqHHVqSlC4wo4MIw4T8xt407kiDB9TavRtg3x0AvP9Ij1UQbm6qbxtQi7E1O0h18zgYgbO3JiDciBCvXZhGIy052876788vdA0N1E9WUds/RQQ8Tf9yiR9TlrVX17y5hX2Y9Z2P6WBNLeDCUEepagsxhFlkbugPkoqk2Y2+OWW2DoVztFsdsfo99VoHq421zXOpi9RfqTFGDh3JXSyPxKrigQlBgGVQe+LvQPUELPINdEhJQqZ4noujkuunIy3dBQLJ5y13OEDviNoFrpfBmVzubt3wlZAdBHYVJ5am7904hoMle/OWfhyccGzDuBqICOV5ZCRSA/DRlhVquHqDPjgq+TDzfUM1krSiYS5Df17SO0Jfv9VCybBUAGYhFUaRpwTw/ X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(3230021)(908002)(999002)(5005026)(6040522)(2401047)(8121501046)(3231475)(944501520)(52105112)(93006095)(93003095)(10201501046)(3002001)(6055026)(6041310)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123560045)(20161123562045)(201708071742011)(7699051)(76991095); SRVR:BN8PR12MB3474; BCL:0; PCL:0; RULEID:; SRVR:BN8PR12MB3474; X-Microsoft-Exchange-Diagnostics: 1; BN8PR12MB3474; 4:CAAudGC+3qc36ZkiIhmn1+KRD1y6HVM2foTlvBYEcMQfnDxCWhgrc0gw44b0lZsEhLiV+PSdGLQrRAJiYli4JeW1Qbq5T+w9MXCxizK0lvshYKKnvQcbNmHDKQhykAZan1EB/EtxoypJlT8JVlEbW1Djd/c52KefVkkpfko2JoxV5rkkIrBhf4t6y8+uVyMXkJIjObX3DTDI6ErMKsxRDlqfNPgkfKGY/2PASnrd/LqVxBTvoySN6D0zGqa9Q8hb57BkLUqmIVnvR81t/qrl6w== X-Forefront-PRVS: 0899B47777 X-Microsoft-Exchange-Diagnostics: =?us-ascii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Le4izl/y4Nda8ca5bM1Q==; 5:OXGdAKYfWZuvDmVZ9wZZNCapIXE9WE3xNkiPvIQrL+bSP9yFeDR62T/PGVuYHqEEq7SFANp/scXziJctPZCokbU87eZyeIqufzM1Gd9ihok6aEU4/GlUecuKTOAkYIbsOYaWPCzftuq17TZo3+lwP3tDNz+7Lnaj1QXEIL/tmr8=; 7:Kaz8aBKZldnFBOluy0Ng7whJoPo1MBF5uKUW0mOPVxkfPd4M8WTZ6dTElssFgPKHuK6tmXy71r5k1ORKRml7bMXbz6p710IBCwzMKTDnIWX6aGy4iaOZRzp3JI1xbuKIz7L2pg1BJYb+XSkoRuGPVA== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN8PR12MB3474; 20:pRSLVSBOxUJEH3UkgNr+3WNKL2DWthUw43Jz52w9iC2Raca5bPLRbQm6gVa2LDenfc0wcJFzUA4hhyBU4w2zD6CYFRDDMFepzbXz6M5ld963x1qKDHi87wU+hKPZarKmvkBLj1/foQ1DBmgzBL1HfbuQhl4GtHcnGarHjw1BzuUpqwUwxNHrkzGGPhqavWs+G0x/poYFX5Lc1q00Ff94tjFWmXb0GeXZLEm2DNZDKKYYgdTc3+Cd3fgY3/bPVII2 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Dec 2018 19:28:25.2226 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e8201694-b069-47e5-8c0b-08d66c3178bb 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: BN8PR12MB3474 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 v5: Rebase Suggested-by: Christian Koenig Signed-off-by: Andrey Grodzovsky --- drivers/gpu/drm/scheduler/sched_main.c | 59 +++++++++++++++++----------------- include/drm/gpu_scheduler.h | 6 ++-- 2 files changed, 31 insertions(+), 34 deletions(-) diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c index 54e809b..58bd33a 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); @@ -405,7 +392,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); @@ -426,11 +413,11 @@ void drm_sched_stop(struct drm_gpu_scheduler *sched, struct drm_sched_job *bad) if (s_job->s_fence->parent) { r = dma_fence_add_callback(s_job->s_fence->parent, - &s_job->s_fence->cb, + &s_job->cb, drm_sched_process_job); if (r == -ENOENT) drm_sched_process_job(s_job->s_fence->parent, - &s_job->s_fence->cb); + &s_job->cb); else if (r) DRM_ERROR("fence add callback failed (%d)\n", r); @@ -456,31 +443,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); @@ -629,18 +619,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); } /** @@ -703,16 +702,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 4f21faf..62c2352 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. @@ -181,6 +177,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 @@ -197,6 +194,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,