From patchwork Mon Jun 4 15:03: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: 10446789 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5F96960375 for ; Mon, 4 Jun 2018 15:04:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C6F528852 for ; Mon, 4 Jun 2018 15:04:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 407B428860; Mon, 4 Jun 2018 15:04:12 +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 8560228852 for ; Mon, 4 Jun 2018 15:04:10 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8C8096E8E6; Mon, 4 Jun 2018 15:04:07 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM01-BY2-obe.outbound.protection.outlook.com (mail-by2nam01on0070.outbound.protection.outlook.com [104.47.34.70]) by gabe.freedesktop.org (Postfix) with ESMTPS id 71DD46E4A8; Mon, 4 Jun 2018 15:04:06 +0000 (UTC) Received: from SN1PR12CA0062.namprd12.prod.outlook.com (2603:10b6:802:20::33) by DM3PR12MB0764.namprd12.prod.outlook.com (2a01:111:e400:5984::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.820.14; Mon, 4 Jun 2018 15:04:04 +0000 Received: from DM3NAM03FT003.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e49::205) by SN1PR12CA0062.outlook.office365.com (2603:10b6:802:20::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.820.15 via Frontend Transport; Mon, 4 Jun 2018 15:04:04 +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 DM3NAM03FT003.mail.protection.outlook.com (10.152.82.87) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.841.10 via Frontend Transport; Mon, 4 Jun 2018 15:04:03 +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.382.0; Mon, 4 Jun 2018 10:04:01 -0500 From: Andrey Grodzovsky To: , Subject: [PATCH v3 1/2] drm/scheduler: Avoid using wait_event_killable for dying process. Date: Mon, 4 Jun 2018 11:03:55 -0400 Message-ID: <1528124636-17283-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)(39860400002)(346002)(376002)(39380400002)(2980300002)(428003)(189003)(199004)(53416004)(44832011)(59450400001)(68736007)(104016004)(110136005)(316002)(16586007)(2906002)(36756003)(50466002)(77096007)(26005)(106466001)(54906003)(105586002)(2616005)(476003)(126002)(486006)(7696005)(8676002)(72206003)(4326008)(305945005)(86362001)(48376002)(50226002)(51416003)(356003)(336012)(186003)(47776003)(53936002)(426003)(97736004)(478600001)(450100002)(81156014)(81166006)(8936002)(6666003)(5660300001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM3PR12MB0764; H:SATLEXCHOV01.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; MX:1; A:1; X-Microsoft-Exchange-Diagnostics: 1; DM3NAM03FT003; 1:vnPAQjDUHv73AaGu1eAj2J5RNL1RX4VBm4zFmj+DfDJ8FF44ttuvmzMCGwAfaSOaOU6OoUc7opEpHgweRdxgvPiIz9tt/WqIFgWf5pecAQ+KYHM9RrofdGpjIbM96yb0 X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060); SRVR:DM3PR12MB0764; X-Microsoft-Exchange-Diagnostics: 1; DM3PR12MB0764; 3:JKuaqPS5abx6WPzichaFYwml+p2fTk5HAVCthmopc7h7UN6vFIT8nmFBuGOMofklDFb98hwIt/sPEyJ4HH68zkRE6kuv6ryxhfuX0Jm5X+w/y/th1Ic33SQ/GHhUxgLc4ihuLWbb7oVQTDYfrsBHGXzNqyHOOF2QQtu5zIKPUtzU2MgplhzlPH81uMw1QHXIEPfvkb2eSG/UfG12LIfQ3Qrn3ymyXZPbuliIanRw099WqXKjdC58xOiZjsLYMxb/261dFYmYYKSG7is/oUqQB1+ZeTREo+gQBilQb1VOGz4QqNuCPogtlGQw58VqERsikqSyGguwhEAOUsk3uOQjDJC41D990nyFVB2xJBQ3Kyc=; 25:BbvopnrXQc96Avca4MP16223fl5rvAzYieUMOrVGDhhx0/0rwPQ4OokIpOo4E56WmliB3Bs6X4q4ZurEYchY3sv/p+8br2vP2mH2zjwQhUq3WMyoLs+0q52sT0QxJI4eB9+WFGUU9OT8SzcXMi0+lyS1OQtvpxLEaHWAhMVX3PlSroUG/SD1/hmu1ZX/6gznl6RZcY90XTfU6OpU1pmJfrTKcuzzC37lYgdeVhFm7dye7deIaY9nAtyADTXn6LzcRC6KNXIXxJzziJYZiW6dLXkpgaxROs15wPo8VX6HIy0QHiyBF6268iAtk+oYR4HRKbgOn435MdCFSVg/tshLSA== X-MS-TrafficTypeDiagnostic: DM3PR12MB0764: X-Microsoft-Exchange-Diagnostics: 1; DM3PR12MB0764; 31:/nNFAHOjX83SFlW5FN2dv5Wcl6FeXCCpDd81dWHIzW4soJFalo6D4qe/kd7mw120yaY5Qv5G9lT2pN7Cfs7A8VPgb2w960Abtd9suQp/7Vd7txeOZGpePhb6TtmRusXO0pwv+P5naHr3IwSKGMFLS9ATZkjgnEPvCL8hIn2oMi3AjBDuEQBufVTJN5K/rF4M1gldO6XaWn4+hcSMT2PjqpTqo9GEaZrr87obiX1+xOE=; 20:iS3uAMmnN9diaIoSZyobdI2RhPhL/uvBrDCFm8iZf9IbgUTjqo1xHxYdmOdkr0wo96IYJ2lVxQpeRoI7zD8t5YfQDRbfEf41gu3K5Fh03ewVAavidzWyv1x9lDqAqFoHxbyTCtEVoVe3Bdz1AncgUqzyYkdEUPGGjv+sVlwqt4DBQxwtKDb8cv88VT+C1QjVeKuDX3I2Zh17NE/gruVWqdtFVL1monBTebqmi/wECfqN7A/tOLhKzV5QVII9ICML8wzIvC1d4UfjsizXcXR41bq8DIvFrhejJCPZoZlPeB9lAJ+5HXfNg3CLl9KiLl4rmuU70jAuKeUaTgcpwD+ffXrgkZIBIjeDWZ8K52LuKf0z+ChKv0IV+JUh1GjSWx5NrJoM/rhc2QS6jFBTMYKfaCyUfVjdQ/z+uFilTXs58yh3PdIrkfj0A0iDqQ9eArApT2Jo4OJ4qjcyZFaqG02xQJzmnlJQrr9uAeNrKghS8OzGetRdqEKgjpUQjlxrD1TH X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(10201501046)(3002001)(93006095)(93003095)(3231254)(944501410)(52105095)(6055026)(149027)(150027)(6041310)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123560045)(20161123564045)(6072148)(201708071742011)(7699016); SRVR:DM3PR12MB0764; BCL:0; PCL:0; RULEID:; SRVR:DM3PR12MB0764; X-Microsoft-Exchange-Diagnostics: 1; DM3PR12MB0764; 4:VX9Zd3o9J7Dpm/LYW+C6+RiMNrFcf7QSB8FUc4D2JThXOrcAEQ/BXgXLDIfhFUN9nGyUG8I8bwPIe7YspG6C/VToMgvpDDsmpfe6baPA8Jr/nA0Ju2ZMNp3/ExPMs2FpvMlsJMOC69u8JdQs5VBf9AdgB3BsQ7AKZdoXgRU6WseF9PQDxAqepfX3Jl+uRX7iODcdVpx8TtM1B4oOT2Ycsazdv6/PTHofJhOw8PQOMQvUu8ak7GRy1NMnOdWWglS0SaFPHovBXFQ+r5yusw31OEwrYuuaQqxULmEORkJDqZyVlEaWxkt8ogiQY2S4+qct X-Forefront-PRVS: 069373DFB6 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM3PR12MB0764; 23:OWMD9Onq1ScVjbb+MNYRwE17gKHWo2wMjZFUEb9IR?= =?us-ascii?Q?DPfZt3cxuEE8XiITv2PN2c0kyMZJMdzvKU5yehA3zRlqtzmfSxu1JeV15Ngd?= =?us-ascii?Q?G755Q+Y9qA1uAEzvGqn6/OWlMoMpA6/6llCkQGyvSwr8bsoqySbrwHtXgELc?= =?us-ascii?Q?QgEBFdbBHOmqVCzFDObdVkA3f/z2TdUfpWvNZppAFoIT38CjSF7juL8LMLQc?= =?us-ascii?Q?9ZUnKq55EiWZDGo+mZ3+wJyDs6OsslNBlhdU4p1g1U77kuM3Ny+LqUc5ydFm?= =?us-ascii?Q?mbL+Q6kMX4362EOec5ogJ5iu7Dx2GUx0drYqjtIl5ZMB0PDt03iT+SyIWEr3?= =?us-ascii?Q?4biRfWDOs3BJBebVfx2ssUu/+Rzy1JvKc0WQkJFlak3HONmMn8oSQL0Z1Kb3?= =?us-ascii?Q?pOF7yHelkhQFIql8cIk59aBZhMDwzKx8wz2woNxKllVfq57XLWLfoesdSgkZ?= =?us-ascii?Q?ZJs6haxIP22tHd1GSf3cEyTBC4oukst3OdyJW6KGO40hLc3vCdRzEHTL+r/m?= =?us-ascii?Q?GZ2VLu9ER6JcP6vm1oolEG87QjMdHFsoxSytIAVaeFKJcRHqfa5tkNECnK1i?= =?us-ascii?Q?VvBUTkolKobjRSZ87bAHB/Or2ZH6W2itYanDJTasxXKIhCuaFldp4eZtRr1/?= =?us-ascii?Q?HJCfA/9Q1wwnmdTKsbeU63MohK39MAcaI0Kpm/OUkvNuBWPKB3K7h7LjN+OK?= =?us-ascii?Q?ekgr8WGYucEGzRkwCRnoN0WBocdXoOPUEtSYkSkZ7k4Chgcf5AthZN4Q4n0P?= =?us-ascii?Q?rEnC9asQWTt9Q1DQXL3OBCbpY92eBJYru4dDx6PawGWPwhOpDl9vXy0p8C6r?= =?us-ascii?Q?3hObvp2XuXIiCMaimfgy+VLs4STr4rqE9MjCf4cIQbuor0sNQfvpNCpf7W/N?= =?us-ascii?Q?MkTMYJrqpWhs/+uyKJHn+JG6dwiATjDU/dmdY0vPVrVViuqwNAyvfFbnElI9?= =?us-ascii?Q?R0Dl1r2Dhp/b+ckGb4/XXWwtZ5v/a2IyUEgwz3cI9IMOD93l6KgtiOZs3hBZ?= =?us-ascii?Q?roI8siv/WlnoXgvezcD1zUbvhj3/DZMJpSUnRLv5XFXU0CzKe11hwoelmW7E?= =?us-ascii?Q?siNj2PLFMUSS19cvk1tHspems63tmPNWNwsOE5azTLzFFekfmkXsi6WlnXGO?= =?us-ascii?Q?tvTJZhoIOGEzRYIXAzc1JtYh0aiErjXOyOEs/n7a/Xwu5ouR2kUK8UKf/DA1?= =?us-ascii?Q?bLEKIVGArUKyx0=3D?= X-Microsoft-Antispam-Message-Info: 4NQNCTIAEMMyeF9mhXNbwtRkO70fG64lqr7NLj9GwRBiGrXe3ZbTrXaLwQ8aP6jmovQAHv3/KwXBRD+VTROoblwdAQvMA9h0dyE/36w8EZTddK4iDSn8bqnGGAWLvIuqdXNz4tO1SEwj2W71iP21kkj2QcnRdTPL7MWSXRMjoZ9LMQFhKUzxJ4gACxRWThqJ X-Microsoft-Exchange-Diagnostics: 1; DM3PR12MB0764; 6:Fcd865JFCXgV0wrRr6scsqKRIH/9jtoROXeDnK4oNAvtm6qcbbQmlqpSS6TuJ67+0euR7lBKo2hG6X9hFcEhNSJx7hxYVz5+lzVoh0ZJlROqE4J823SfVGp6RvxT/PBYDu12jRdFrCpnDzA4JP06hDzEGAKanE5oeskCQXvYAFcVBJDKq20OXnRL4KQZPugvYw1GreNY4e7xEWY7rn/oKiHV6OJNuZUFTMwdl39APYQS9OtWuNDUA9+mthpLh7+LE37+lf8eQII2GUM1dP30lONtFce6xA5L925mQLwWUKxUZzIvM6UNC+AuTL3D2SmecagP1bTEaeWZqqxhEh09guIKbKIbsui6MMFf+4cHWB/dV35cpl++DTRNkVGtMdYlV1UZkh5K7xdvIlv8OEHJQGGVVRJRHmnPEvLJn4K5Dw+tb0rysdO3TXjJbNuukHSetjBiA2icmkUEGNxa8aIHUQ==; 5:w2JlXRbiKy1aHrP9S+/z3n8yZW6cYXLN0QguWN4Up9zkMgLPOHBT5POMjJoC+viAHalyJqZPS01mGUs/jNOqv0iXTWvoHD07x+ziUwSOZPvsbmmKP0rT5AynGY1NvhkizAL76huiJ1hZGK3z0pnfVeAImWHUENGaHPryfYuAyh8=; 24:uGxPmabRtKBayYFhY8sKq0pg9xVMU4Ah7Om8n/O/4DGQmhKBmGpn8G9T2zdbZwHqJ+Ai1ZUud5vmEM2JXV/9hltkOizjoKMwGsYideJivbA= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM3PR12MB0764; 7:Aj9GG2BaCCXd5qaAOVUKUR5RSY+l6+a5cHYRLEjJpwXmXM3NDZxziGa+4QVzVNyGrYl8jgYWrlXef5VR/ceYmPpNm5tSo2RSNc6NoOmrsDI2Zw7Sndi2nAOutUIiEUvuzynii4jbe8Lto6uZipVkYt00O/m7mrcZpAe9IXqenlt+LFJmA0SjCAGARwQjh8fR3EAGIhM8tyvhcrOCzwz4GjMs18deUiUD1/+nWEaxzzmwehRp3k1pBSAxIChpkwGi; 20:s0B+Ke0xH7pIJf5r/r1lo6LdUYHOvvmaf4jDvpehBuwE+pJWbXVQ0hYkLRMDGiai3EuKA+M0wtUSOK6e/1jr7022637M1sC3pt5FQHfThndH6UmjsR5EFU7+zwreWA77Q8b02Fyq8derCpVq7aWmbRKdd2tI1zmuV5YMcPx7Cx8C1ZU2sZKo0xv3f/t4iacxHfNCFKaRA8D4F93ZnhMHMR0AePhlUiCb+eqcAwtHS9CV7ulnkNZbpFpcwsxCiyXH X-MS-Office365-Filtering-Correlation-Id: 2c0ca452-c2d6-445f-bc85-08d5ca2c6966 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jun 2018 15:04:03.6943 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2c0ca452-c2d6-445f-bc85-08d5ca2c6966 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: DM3PR12MB0764 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: Christian.Koenig@amd.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Dying process might be blocked from receiving any more signals so avoid using it. Also retire enity->fini_status and just check the SW queue, if it's not empty do the fallback cleanup. Also handle entity->last_scheduled == NULL use case which happens when HW ring is already hangged whem a new entity tried to enqeue jobs. v2: Return the remaining timeout and use that as parameter for the next call. This way when we need to cleanup multiple queues we don't wait for the entire TO period for each queue but rather in total. Styling comments. Rebase. v3: Update types from unsigned to long. Work with jiffies instead of ms. Return 0 when TO expires. Rebase. Signed-off-by: Andrey Grodzovsky --- drivers/gpu/drm/scheduler/gpu_scheduler.c | 70 +++++++++++++++++++++++-------- include/drm/gpu_scheduler.h | 7 ++-- 2 files changed, 56 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/scheduler/gpu_scheduler.c b/drivers/gpu/drm/scheduler/gpu_scheduler.c index 8c1e80c..1e65221 100644 --- a/drivers/gpu/drm/scheduler/gpu_scheduler.c +++ b/drivers/gpu/drm/scheduler/gpu_scheduler.c @@ -181,7 +181,6 @@ int drm_sched_entity_init(struct drm_gpu_scheduler *sched, entity->rq = rq; entity->sched = sched; entity->guilty = guilty; - entity->fini_status = 0; entity->last_scheduled = NULL; spin_lock_init(&entity->rq_lock); @@ -219,7 +218,8 @@ static bool drm_sched_entity_is_initialized(struct drm_gpu_scheduler *sched, static bool drm_sched_entity_is_idle(struct drm_sched_entity *entity) { rmb(); - if (spsc_queue_peek(&entity->job_queue) == NULL) + + if (!entity->rq || spsc_queue_peek(&entity->job_queue) == NULL) return true; return false; @@ -260,25 +260,42 @@ static void drm_sched_entity_kill_jobs_cb(struct dma_fence *f, * * @sched: scheduler instance * @entity: scheduler entity + * @timeout: time to wait in for Q to become empty in jiffies. * * Splitting drm_sched_entity_fini() into two functions, The first one does the waiting, * removes the entity from the runqueue and returns an error when the process was killed. + * + * Returns the remaining time in jiffies left from the input timeout */ -void drm_sched_entity_do_release(struct drm_gpu_scheduler *sched, - struct drm_sched_entity *entity) +long drm_sched_entity_do_release(struct drm_gpu_scheduler *sched, + struct drm_sched_entity *entity, long timeout) { + long ret = timeout; + if (!drm_sched_entity_is_initialized(sched, entity)) - return; + return ret; /** * The client will not queue more IBs during this fini, consume existing * queued IBs or discard them on SIGKILL */ - if ((current->flags & PF_SIGNALED) && current->exit_code == SIGKILL) - entity->fini_status = -ERESTARTSYS; - else - entity->fini_status = wait_event_killable(sched->job_scheduled, - drm_sched_entity_is_idle(entity)); - drm_sched_entity_set_rq(entity, NULL); + if (current->flags & PF_EXITING) { + if (timeout) { + ret = wait_event_timeout( + sched->job_scheduled, + drm_sched_entity_is_idle(entity), + timeout); + + ret = ret ? timeout - ret : ret; + } + } else + wait_event_killable(sched->job_scheduled, drm_sched_entity_is_idle(entity)); + + + /* For killed process disable any more IBs enqueue right now */ + if ((current->flags & PF_EXITING) && (current->exit_code == SIGKILL)) + drm_sched_entity_set_rq(entity, NULL); + + return ret; } EXPORT_SYMBOL(drm_sched_entity_do_release); @@ -290,11 +307,18 @@ EXPORT_SYMBOL(drm_sched_entity_do_release); * * This should be called after @drm_sched_entity_do_release. It goes over the * entity and signals all jobs with an error code if the process was killed. + * */ void drm_sched_entity_cleanup(struct drm_gpu_scheduler *sched, struct drm_sched_entity *entity) { - if (entity->fini_status) { + + drm_sched_entity_set_rq(entity, NULL); + + /* Consumption of existing IBs wasn't completed. Forcefully + * remove them here. + */ + if (spsc_queue_peek(&entity->job_queue)) { struct drm_sched_job *job; int r; @@ -314,12 +338,22 @@ void drm_sched_entity_cleanup(struct drm_gpu_scheduler *sched, struct drm_sched_fence *s_fence = job->s_fence; drm_sched_fence_scheduled(s_fence); dma_fence_set_error(&s_fence->finished, -ESRCH); - r = dma_fence_add_callback(entity->last_scheduled, &job->finish_cb, - drm_sched_entity_kill_jobs_cb); - if (r == -ENOENT) + + /* + * When pipe is hanged by older entity, new entity might + * not even have chance to submit it's first job to HW + * and so entity->last_scheduled will remain NULL + */ + if (!entity->last_scheduled) { drm_sched_entity_kill_jobs_cb(NULL, &job->finish_cb); - else if (r) - DRM_ERROR("fence add callback failed (%d)\n", r); + } else { + r = dma_fence_add_callback(entity->last_scheduled, &job->finish_cb, + drm_sched_entity_kill_jobs_cb); + if (r == -ENOENT) + drm_sched_entity_kill_jobs_cb(NULL, &job->finish_cb); + else if (r) + DRM_ERROR("fence add callback failed (%d)\n", r); + } } } @@ -339,7 +373,7 @@ EXPORT_SYMBOL(drm_sched_entity_cleanup); void drm_sched_entity_fini(struct drm_gpu_scheduler *sched, struct drm_sched_entity *entity) { - drm_sched_entity_do_release(sched, entity); + drm_sched_entity_do_release(sched, entity, MAX_WAIT_SCHED_ENTITY_Q_EMPTY); drm_sched_entity_cleanup(sched, entity); } EXPORT_SYMBOL(drm_sched_entity_fini); diff --git a/include/drm/gpu_scheduler.h b/include/drm/gpu_scheduler.h index 496442f..7c2dfd6 100644 --- a/include/drm/gpu_scheduler.h +++ b/include/drm/gpu_scheduler.h @@ -27,6 +27,8 @@ #include #include +#define MAX_WAIT_SCHED_ENTITY_Q_EMPTY msecs_to_jiffies(1000) + struct drm_gpu_scheduler; struct drm_sched_rq; @@ -84,7 +86,6 @@ struct drm_sched_entity { struct dma_fence *dependency; struct dma_fence_cb cb; atomic_t *guilty; - int fini_status; struct dma_fence *last_scheduled; }; @@ -283,8 +284,8 @@ int drm_sched_entity_init(struct drm_gpu_scheduler *sched, struct drm_sched_entity *entity, struct drm_sched_rq *rq, atomic_t *guilty); -void drm_sched_entity_do_release(struct drm_gpu_scheduler *sched, - struct drm_sched_entity *entity); +long drm_sched_entity_do_release(struct drm_gpu_scheduler *sched, + struct drm_sched_entity *entity, long timeout); void drm_sched_entity_cleanup(struct drm_gpu_scheduler *sched, struct drm_sched_entity *entity); void drm_sched_entity_fini(struct drm_gpu_scheduler *sched,