From patchwork Thu Dec 6 21:26:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Grodzovsky X-Patchwork-Id: 10716791 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 883DF1759 for ; Thu, 6 Dec 2018 21:26:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 796062D68C for ; Thu, 6 Dec 2018 21:26:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6B7AD2DA84; Thu, 6 Dec 2018 21:26: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 5438A2D68C for ; Thu, 6 Dec 2018 21:26:30 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9A0206E66A; Thu, 6 Dec 2018 21:26:27 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM01-BN3-obe.outbound.protection.outlook.com (mail-eopbgr740077.outbound.protection.outlook.com [40.107.74.77]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2E2BD6E66A; Thu, 6 Dec 2018 21:26:26 +0000 (UTC) Received: from DM5PR12CA0021.namprd12.prod.outlook.com (2603:10b6:4:1::31) by DM2PR12MB0064.namprd12.prod.outlook.com (2a01:111:e400:3c10::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1382.22; Thu, 6 Dec 2018 21:26:23 +0000 Received: from BY2NAM03FT035.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e4a::202) by DM5PR12CA0021.outlook.office365.com (2603:10b6:4:1::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1404.21 via Frontend Transport; Thu, 6 Dec 2018 21:26:23 +0000 Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV02.amd.com (165.204.84.17) by BY2NAM03FT035.mail.protection.outlook.com (10.152.84.223) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1404.17 via Frontend Transport; Thu, 6 Dec 2018 21:26:23 +0000 Received: from agrodzovsky-All-Series.amd.com (10.34.1.3) by SATLEXCHOV02.amd.com (10.181.40.72) with Microsoft SMTP Server id 14.3.389.1; Thu, 6 Dec 2018 15:26:21 -0600 From: Andrey Grodzovsky To: , , , , Subject: [PATCH v2 1/2] drm/sched: Refactor ring mirror list handling. Date: Thu, 6 Dec 2018 16:26:12 -0500 Message-ID: <1544131573-4799-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)(39860400002)(346002)(2980300002)(428003)(199004)(189003)(44832011)(110136005)(72206003)(478600001)(2201001)(97736004)(5660300001)(54906003)(316002)(81156014)(2906002)(86362001)(8676002)(14444005)(16586007)(50466002)(68736007)(81166006)(53936002)(305945005)(105586002)(48376002)(356004)(6666004)(4744004)(36756003)(106466001)(8936002)(50226002)(77096007)(336012)(4326008)(126002)(476003)(2616005)(426003)(53416004)(26005)(486006)(104016004)(47776003)(39060400002)(51416003)(7696005)(186003)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR12MB0064; H:SATLEXCHOV02.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; A:1; MX:1; X-Microsoft-Exchange-Diagnostics: 1; BY2NAM03FT035; 1:dWpbHkXpdIem+jttYQH1fuElvsyns11cKgobwsCnE0BXAxyflO+WWpsuizMR1rSDUB0YzOQRm+dIdJ1Gp7ZX93h4L8hXmdguhVa20C6j64yHSk2bSjGAF4Bup4GNdn4e X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2f238250-ea4c-4ce8-77e1-08d65bc178d0 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(2390098)(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060); SRVR:DM2PR12MB0064; X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0064; 3:ZV0rUqry+bSu9kRkywbkA6i4en1ItXyCR5seqxviBtkJFzkdq2sT4VBtDNna2XfwcutXeb9cMfQS9G8pRZU64Llov+SIQKqRbl9NvAU76psrPl4pDdLOaviJc27lwDkGuNYvuFo9ob4niOkkkAYk8N3layjxmXAVw1J3WQLVjJGxZKq61xkSkc6ViFYHDS//donWgirO1gzGb+MzfKfnHik0Aaes+hEnNCCCi5F2sEfqgNqrU3e5x87/ciogpqZGyOAJucOyuUmSt9mBCXbG4zdhkwvm6fX6ltHMo+z75DCVqXiNKCogWOscgILYWOoFuDYpk62OG79yKJmQ0O8tdhhagD3bgH+C/UrzX32m5DE=; 25:fPGNRdRsmRS/VUnTOhcmqW6Hlq3yS+0dNbePxeF2NsHdykgxEhjn+Qof+Pq1Ou5vaYQ8Dxr+mUe782jbhKduXW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TDvSq X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(93006095)(93003095)(3231455)(999002)(944501520)(52105112)(3002001)(10201501046)(6055026)(148016)(149066)(150057)(6041310)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123558120)(201708071742011)(7699051)(76991095); SRVR:DM2PR12MB0064; BCL:0; PCL:0; RULEID:; SRVR:DM2PR12MB0064; X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0064; 4:MNhd3d3iUrnMhTGJEjtZrP1TgZse081yWapmX5cA5buMz0XF+YByED1BnDLuU1e5AYTxxonXNgs9i/6bZZ7SXc/KpgUhbhTL6mz3+/5It5Jg+GwyYIJ6uDW0x8alpl2Lecn9Ot0yhD799sEFBQINraMioNjh6SUq9UlUfEDr4MKD8FaJbsfkIUjt9hZwddmRohxZVel70uBlULz/qism0SS2XZ/D/m3C6CgoUxkPr3kuluGFr2IQ12oIFPTff2w5lRZkA7v0Dc3j8LrgBUU/qA== X-Forefront-PRVS: 087894CD3C X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM2PR12MB0064; 23:iNZCcKJwQgAuYwl+/VwO8x8qki6fZdWVg9o+eCDEn?= GWaMekTF5cA7y/1dCCRvs/l2hd2S69DoP53uKY8Kf7so5xrLfa89pjKF7y9ojZN4cI/8UEfVQetEbA4V9GlB0HfPuQPqr8aSOhw9RAM/3v0iDktIuMmmez93qJwPI01Qqpc8wnaFEZw+FAfS7eP5RfTqpAJkj2cZZ/IxzLuPn4QtW2iPH/OgR5OrnBPMYhl1p+mvcAqapZcvq/QFeCOUR0SY2SmsAaJY265jvw9A0aQjhxMTZHanmElB1SvLVJvuq0GSrSTsCwAW40Yjhmnuhhnw7C1JA3gHfQZjyv1A7hwfN6gPhG3MfWkEwUTy97Xb1JBU3+t+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ange-Diagnostics: 1; DM2PR12MB0064; 20:Qq6ro+nwJTnTuiRmI1H2kTYcBZK/H4BeMLh/UPY3bl0NKENqlb42yu9tKl1wJSulZ6yX3ynIRdJOc9QyjR+Feb3i3epEvKY1jr4whrT5YS2IU1VF7/S0dxhwnJUrABK0qy47zczfsy/IrAGvYhMRUDKmNnm7qfVqnwDER7ZYKEIkSqeFYm2r4y2xPDqdB35WSVA2Lzoh+Fiooc47BJ92pYNQZQxUSWPH96wxsrER765QNOZFW2HjtVjWDv+mqv3B X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Dec 2018 21:26:23.1372 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2f238250-ea4c-4ce8-77e1-08d65bc178d0 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=[SATLEXCHOV02.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR12MB0064 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); From patchwork Thu Dec 6 21:26:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Grodzovsky X-Patchwork-Id: 10716793 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 5EDEE1759 for ; Thu, 6 Dec 2018 21:26:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E2002D68C for ; Thu, 6 Dec 2018 21:26:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3F0582DA84; Thu, 6 Dec 2018 21:26:36 +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 B06E32D68C for ; Thu, 6 Dec 2018 21:26:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7C8286E66F; Thu, 6 Dec 2018 21:26:34 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM01-SN1-obe.outbound.protection.outlook.com (mail-eopbgr820048.outbound.protection.outlook.com [40.107.82.48]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4F58B6E66F; Thu, 6 Dec 2018 21:26:33 +0000 (UTC) Received: from DM5PR12CA0019.namprd12.prod.outlook.com (2603:10b6:4:1::29) by BY2PR12MB0054.namprd12.prod.outlook.com (2a01:111:e400:2c80::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1404.17; Thu, 6 Dec 2018 21:26:30 +0000 Received: from BY2NAM03FT007.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e4a::200) by DM5PR12CA0019.outlook.office365.com (2603:10b6:4:1::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1404.21 via Frontend Transport; Thu, 6 Dec 2018 21:26:30 +0000 Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV02.amd.com (165.204.84.17) by BY2NAM03FT007.mail.protection.outlook.com (10.152.84.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1404.17 via Frontend Transport; Thu, 6 Dec 2018 21:26:29 +0000 Received: from agrodzovsky-All-Series.amd.com (10.34.1.3) by SATLEXCHOV02.amd.com (10.181.40.72) with Microsoft SMTP Server id 14.3.389.1; Thu, 6 Dec 2018 15:26:27 -0600 From: Andrey Grodzovsky To: , , , , Subject: [PATCH v2 2/2] drm/sched: Rework HW fence processing. Date: Thu, 6 Dec 2018 16:26:13 -0500 Message-ID: <1544131573-4799-2-git-send-email-andrey.grodzovsky@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1544131573-4799-1-git-send-email-andrey.grodzovsky@amd.com> References: <1544131573-4799-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)(346002)(376002)(396003)(39860400002)(136003)(2980300002)(428003)(199004)(189003)(316002)(8676002)(2616005)(16586007)(54906003)(81156014)(47776003)(53416004)(104016004)(39060400002)(336012)(110136005)(81166006)(426003)(2906002)(48376002)(44832011)(26005)(106466001)(486006)(97736004)(105586002)(476003)(126002)(36756003)(77096007)(51416003)(50226002)(14444005)(50466002)(8936002)(186003)(6666004)(86362001)(356004)(2201001)(53936002)(76176011)(5660300001)(7696005)(11346002)(478600001)(72206003)(68736007)(305945005)(446003)(4326008)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR12MB0054; H:SATLEXCHOV02.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; A:1; MX:1; X-Microsoft-Exchange-Diagnostics: 1; BY2NAM03FT007; 1:IfKTpfiRaBe6VGlEp31s0vzw3tdzQoj2I2QG7mwuUAe1s2weK2rcWca2mFpPkLPkIUmy3ww9VPdHjozBx2CjX2U0ReNq7MvD1JeGl7GYg3/oKy3bQIi8s29MVU93kF/R X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 805bd528-22c9-4f3f-c0c4-08d65bc17cd1 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(2390098)(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060); SRVR:BY2PR12MB0054; X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ZffiqHdKFbFrSoba/VmQeB4lI5XFErX3KMZHIa3OcVqE4nGNqvpKW8jlWsieRUpcOnID87hTANl2tR225U1ww8dVUbWiF3VskcgCZysjuLbUKLI4FrycHBQPCF21063GFRuuFkxitU9XbM2L3d8X6he4y/x7VxXvQOCPUYnGFnJi10iGEw2eOPAtZiCWJdjGCq5w6DbRdIVFfISiHI+I45pbkSTlsplbzKPOPNSU4yZAneUcxw3dHdu55CTVQcEcOjm1njyRSzmbrP/a25e0yHzgMKq1UjcUbc9iGeff8v2lgK/sj5deyF2ExVIcgt1seY0JbxbKldEZHI8Qxbt1aP001Ds5L12+iZumewQ/E0nhklMzHZ/OPMpo6EDnKVNG0XX+E5n644sNJ8/NkunCitslpCd0lXJ0XtvONIL0nCiZJrsMYvthOzLu0WOv0UiGQYe7WInND7yQg5jhY/GzTjqjfHt7J/o5wZqVH4o8OQi7sD X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(10201501046)(3002001)(93006095)(93003095)(3231455)(999002)(944501520)(52105112)(6055026)(148016)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123560045)(20161123564045)(201708071742011)(7699051)(76991095); SRVR:BY2PR12MB0054; BCL:0; PCL:0; RULEID:; SRVR:BY2PR12MB0054; X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0054; 4:L9qpJEAHTyyDcXoGooc8ubo3eLbIoCcge7W/F8JLDOGxPV1C5qrzOgTRTn5KkMmhERHtY1GpRDrcWzmVz1FKRknsZ+LCLdOedwyecEI+LvSLYtG7E68nc9kL14ZetYoxyxwAZn1/97GXwcSPQ6RtICzBYQ4K9/c14Kmwj/J9dfsrkPSsNMirsa3jfPX7C88ucSz50z69J4ccVQzGDui3Q/zsgvgihQNtJ50qfbTqVTLz7hn91wyJ0y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rEDA9fQsgoCydua/ebZZgHB9ag0069YM57s72iUOQLF3EO4HEoZi65AxdU3sK5xJcRB+uyW4WqXJK4/cy3+v56ZoqivuxuZHz+lzxFw==; 5:HjzanrAx4HY2bAnnBr+mqR0+H7j3l1l49k7Us4RFl2xIFgOrJOLAXiqxdP0SU6aud67KmgKsduH97KUmd8AyjPOtLcJ5qmkn5U306nG34ydJtzmTXl3p4+mez7R5qIN/bLenkkfr7RhqJV4qFM4TMN+H+yrnvprPZGC9gLrfG2A=; 7:w9xG7BrQypGbt99g0MWoM+U6uKxcpWxyiZsOqu7CntEd+c98YA0unOTo0VNgt9nmQHU6YTipmxj8sZQJMY1vSbRyh56b0ysyRzQIYGeauR82s8X/ldtFMowVR4n/rLa3FHOx/hSHCROduGeRTB+0wg== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BY2PR12MB0054; 20:f2hcHpO7qf0lZB3v/7yxSfETDuHdY5Iodc9soJJIXw4Jk0PJXtm3veXrgjsgkI+u5sJXE6Vi5Qvpm6a3At+xLb+aTdoQHLi8kr4YICRDZW/4QZqBGiGj76zsq1Kzf5EMZ5wlzT9aWg3X61VCsIaCnimeet6XVrgvzfIt5PC4on+UvDCH2j1UC6vAneAI3PcJkmu6K1vZv7l1NFVMIlz2UxqdiD6nwiQgwd5SFy6nhtEZNiaOoPOXLrrKSEwUz1qZ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Dec 2018 21:26:29.8565 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 805bd528-22c9-4f3f-c0c4-08d65bc17cd1 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=[SATLEXCHOV02.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR12MB0054 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. Suggested-by: Christian Koenig Signed-off-by: Andrey Grodzovsky --- drivers/gpu/drm/scheduler/sched_fence.c | 4 +++- drivers/gpu/drm/scheduler/sched_main.c | 41 +++++++++++++++++---------------- include/drm/gpu_scheduler.h | 10 ++++++-- 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/drivers/gpu/drm/scheduler/sched_fence.c b/drivers/gpu/drm/scheduler/sched_fence.c index d8d2dff..e62c239 100644 --- a/drivers/gpu/drm/scheduler/sched_fence.c +++ b/drivers/gpu/drm/scheduler/sched_fence.c @@ -151,7 +151,8 @@ struct drm_sched_fence *to_drm_sched_fence(struct dma_fence *f) EXPORT_SYMBOL(to_drm_sched_fence); struct drm_sched_fence *drm_sched_fence_create(struct drm_sched_entity *entity, - void *owner) + void *owner, + struct drm_sched_job *s_job) { struct drm_sched_fence *fence = NULL; unsigned seq; @@ -163,6 +164,7 @@ struct drm_sched_fence *drm_sched_fence_create(struct drm_sched_entity *entity, fence->owner = owner; fence->sched = entity->rq->sched; spin_lock_init(&fence->lock); + fence->s_job = s_job; seq = atomic_inc_return(&entity->fence_seq); dma_fence_init(&fence->scheduled, &drm_sched_fence_ops_scheduled, diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c index cdf95e2..5359418 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); @@ -363,8 +350,7 @@ void drm_sched_stop(struct drm_gpu_scheduler *sched, struct drm_sched_job *bad, dma_fence_put(s_job->s_fence->parent); s_job->s_fence->parent = NULL; atomic_dec(&sched->hw_rq_count); - } - else { + } else { /* TODO Is it get/put neccessey here ? */ dma_fence_get(&s_job->s_fence->finished); list_add(&s_job->finish_node, &wait_list); @@ -423,7 +409,13 @@ void drm_sched_start(struct drm_gpu_scheduler *sched, bool unpark_only) if (unpark_only) 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; @@ -441,7 +433,6 @@ void drm_sched_start(struct drm_gpu_scheduler *sched, bool unpark_only) } drm_sched_start_timeout(sched); - spin_unlock_irqrestore(&sched->job_list_lock, flags); unpark: kthread_unpark(sched->thread); @@ -505,7 +496,7 @@ int drm_sched_job_init(struct drm_sched_job *job, job->sched = sched; job->entity = entity; job->s_priority = entity->rq - sched->sched_rq; - job->s_fence = drm_sched_fence_create(entity, owner); + job->s_fence = drm_sched_fence_create(entity, owner, job); if (!job->s_fence) return -ENOMEM; job->id = atomic64_inc_return(&sched->job_id_count); @@ -593,15 +584,25 @@ 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_gpu_scheduler *sched = s_fence->sched; + struct drm_sched_job *s_job = s_fence->s_job; + 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); } /** diff --git a/include/drm/gpu_scheduler.h b/include/drm/gpu_scheduler.h index c94b592..23855c6 100644 --- a/include/drm/gpu_scheduler.h +++ b/include/drm/gpu_scheduler.h @@ -115,6 +115,8 @@ struct drm_sched_rq { struct drm_sched_entity *current_entity; }; +struct drm_sched_job; + /** * struct drm_sched_fence - fences corresponding to the scheduling of a job. */ @@ -160,6 +162,9 @@ struct drm_sched_fence { * @owner: job owner for debugging */ void *owner; + + /* Back pointer to owning job */ + struct drm_sched_job *s_job; }; struct drm_sched_fence *to_drm_sched_fence(struct dma_fence *f); @@ -330,8 +335,9 @@ void drm_sched_entity_set_priority(struct drm_sched_entity *entity, enum drm_sched_priority priority); bool drm_sched_entity_is_ready(struct drm_sched_entity *entity); -struct drm_sched_fence *drm_sched_fence_create( - struct drm_sched_entity *s_entity, void *owner); +struct drm_sched_fence *drm_sched_fence_create(struct drm_sched_entity *s_entity, + void *owner, + struct drm_sched_job *s_job); void drm_sched_fence_scheduled(struct drm_sched_fence *fence); void drm_sched_fence_finished(struct drm_sched_fence *fence);