From patchwork Mon Jun 4 15:03:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Grodzovsky X-Patchwork-Id: 10446791 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 E2F2760284 for ; Mon, 4 Jun 2018 15:04:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CDBBA28783 for ; Mon, 4 Jun 2018 15:04:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C0E9F2885C; Mon, 4 Jun 2018 15:04: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 5F89B28783 for ; Mon, 4 Jun 2018 15:04:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B3BF56EB5B; Mon, 4 Jun 2018 15:04:34 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on0089.outbound.protection.outlook.com [104.47.36.89]) by gabe.freedesktop.org (Postfix) with ESMTPS id E89846EB5B; Mon, 4 Jun 2018 15:04:32 +0000 (UTC) Received: from MWHPR1201CA0004.namprd12.prod.outlook.com (2603:10b6:301:4a::14) by SN1PR12MB0768.namprd12.prod.outlook.com (2a01:111:e400:c45b::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.820.13; Mon, 4 Jun 2018 15:04:30 +0000 Received: from DM3NAM03FT007.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e49::209) by MWHPR1201CA0004.outlook.office365.com (2603:10b6:301:4a::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.820.11 via Frontend Transport; Mon, 4 Jun 2018 15:04:29 +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 DM3NAM03FT007.mail.protection.outlook.com (10.152.82.68) 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:29 +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:28 -0500 From: Andrey Grodzovsky To: , Subject: [PATCH v3 2/2] drm/amdgpu: move amdgpu_ctx_mgr_entity_fini to f_ops flush hook. Date: Mon, 4 Jun 2018 11:03:56 -0400 Message-ID: <1528124636-17283-2-git-send-email-andrey.grodzovsky@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1528124636-17283-1-git-send-email-andrey.grodzovsky@amd.com> References: <1528124636-17283-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)(396003)(376002)(39380400002)(346002)(2980300002)(428003)(199004)(189003)(11346002)(53936002)(104016004)(426003)(478600001)(68736007)(305945005)(48376002)(36756003)(356003)(81166006)(8676002)(72206003)(81156014)(53416004)(50466002)(47776003)(50226002)(8936002)(6666003)(105586002)(106466001)(26005)(126002)(5660300001)(4326008)(2906002)(2616005)(486006)(476003)(450100002)(186003)(44832011)(97736004)(59450400001)(76176011)(16586007)(7696005)(575784001)(51416003)(316002)(86362001)(54906003)(110136005)(446003)(336012)(77096007); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0768; H:SATLEXCHOV01.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; A:1; MX:1; X-Microsoft-Exchange-Diagnostics: 1; DM3NAM03FT007; 1:pCoQJ5npNkbOBaZQI4prv4fDMh69vYB/poYRNLTRrLJPko0uB8kNBzw4oiwqrQDvRP/Rf0w21JLaOjXImkBN7eBCj3iePVBWYbnBRQW7wQBAcg4prU3Bt8brxpL/5U1K X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060); SRVR:SN1PR12MB0768; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0768; 3:5UJ7yQBELDyzx6JTPSjSeHTMv4dXZl53WP9GXdSCc2IeXTPWfAm6Y53cJZYFay54RDzgb8hxrWDYWEB9AU4CcYThFxZjQFUgAeLhPTdVI+2luV+ly9qbaYeBsF0W8Tcfkaru91D7zwpuinhrUhKF2tX738sIOheejZBFme2gg0bE5lr8wla5A53amPM/xX2pILsondvg5ZpNOOn5uRbh3hKfx1sTV1WiCxs4MiWhbt5WXBs5INpRWwMziZ6Ijc9e6kP0y1OaBY4MXWyYbJH7ObHtOHv01tJSpjZO3EkA47dqGmMsayQhWRSC8N4i5hkmeqSty2lbcKOnuXR3jooHaJ7gAvPc/JdGnBJ4yCgUXlo=; 25:KfsXAeqpuwdQMJiOcTocrBgZcNP4pUeQkQWW0t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OVqc/djr13FV9pHIpjQtZptkQoNewF730BRpDuXsgfQ1xU2qi9eSQ 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)(93006095)(93003095)(3002001)(3231254)(944501410)(52105095)(6055026)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123558120)(20161123564045)(6072148)(201708071742011)(7699016); SRVR:SN1PR12MB0768; BCL:0; PCL:0; RULEID:; SRVR:SN1PR12MB0768; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0768; 4:kSwnBOyJL1hnuLgJwpCRC4PXpCUb3jxDb4gGDQpu3ET3IDfVUGDuznktWkOjLvFgTOpld+MQ2778hgqy0OkcIQTtCYLi2+mQxToVk9EO6GMolW335NbRxXr8HNCSJ2QIINjfGaH8c1zgj8SyL2pI+PCo4ZGJUu2nIKpBmaYd90UOVeSohhOkOVAnOEkcWAvpsQzGPRWngQHUZx8tfKmTMDkVC0rg1O9uedIHJ7ctDbiGMl9YmFMycXljZKYA+ud9yy3d3qz4VXUlDW4MzlQGc28nwhExnGa7iVaqQZ3vSMyPeO9I4GdDt01XyX9BFRuT X-Forefront-PRVS: 069373DFB6 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN1PR12MB0768; 23:3iBA0amYP57//PyTrPTLQJ0AFWJdRjVAJDSh22kWw?= =?us-ascii?Q?vGj9viuZTec/hvaOnv+Dhomb2ahc4afeHqn3rsxvNrCOoWZ97uL36GmuMDtC?= =?us-ascii?Q?IHy1wetSJ0g2LhSiBskNUgQ2D9bUQuaSl3CP5o8Xfcu6cjJemmrGt1XZZs5o?= =?us-ascii?Q?r1PJ3gsMtFenRhyBOEC7uJj7XVVqdqRgO80dSsHHEPtDiawqEjNWd93Tf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SFG4ViCbsrPiDTy0NwhwhMf1mDTYRnpZMjLKmCc8fFlO/kxcU/68=; 24:qV6o9QuI98SWw8O09DgQusPsB+9wujcTOz/ILWJ29FgSYQn8oQBT0mGzJ7fYKCsAzAtOTBUMEm7LUW9JXNpmQOXOA7FQ2NmXKC0BngktZiI= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0768; 7:Bg2IIk1fYFdfCPL8W4Ehow2vf1sPwg7ue334HKI4DHiUtiR/gx9Z/3oOqiyDFC0621mdpmNWgxbgRxwr1lHvOKhjaVujLXt9nVeFbrXTBHon0By//RnkeQfFfCGBjdfsYAk0SMx/I3VdZQUyUilhN/+XEDvpYJK/jnwsAdo62w40Vmd9eOd3yldHNcgfo23abs+3WL4sxuw7r+1+AS/8BzjPFK9J5mfwoiWERsKAd6XPdy4rKxO/TIDJOFsI0get; 20:R1zXAajaKF213W3flXPznBe5J5uhEMIH9gjj5eunFGigaAgaBd82fE8coD6j+f/ScB8qyLaJKf7GWoaEpSA6IrdaX11mRO9V1n+sqEPR5Fk/3YgI7Gd3o+oSaAtXB12mszbMWnOEZeSqQTzl0XKV503hxzZUcs/4x3VgzjhSdq0vwRvREaBMF7hNn4VqFeiD4u/vBtEdZDaPbr9lGspgdMpi9ixsttHoWESvGpvcYHK1JB3hUZCTk2mTAMdFj2kq X-MS-Office365-Filtering-Correlation-Id: 7e06e780-acf1-4981-a517-08d5ca2c78c1 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jun 2018 15:04:29.4559 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7e06e780-acf1-4981-a517-08d5ca2c78c1 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: SN1PR12MB0768 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 With this we can now terminate jobs enqueue into SW queue the moment the task is being killed instead of waiting for last user of drm file to release it. Also stop checking for kref_read(&ctx->refcount) == 1 when calling drm_sched_entity_do_release since other task might still hold a reference to this entity but we don't care since KILL means terminate job submission regardless of what other tasks are doing. v2: Use returned remaining timeout as parameter for the next call. Rebase. v3: Switch to working with jiffies. Streamline remainder TO usage. Rebase. Signed-off-by: Andrey Grodzovsky --- drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 14 ++++++++------ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 12 ++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 1 - 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c index c5bb362..64b3a1e 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c @@ -449,26 +449,28 @@ void amdgpu_ctx_mgr_entity_fini(struct amdgpu_ctx_mgr *mgr) struct amdgpu_ctx *ctx; struct idr *idp; uint32_t id, i; + long max_wait = MAX_WAIT_SCHED_ENTITY_Q_EMPTY; idp = &mgr->ctx_handles; + mutex_lock(&mgr->lock); idr_for_each_entry(idp, ctx, id) { - if (!ctx->adev) + if (!ctx->adev) { + mutex_unlock(&mgr->lock); return; + } for (i = 0; i < ctx->adev->num_rings; i++) { if (ctx->adev->rings[i] == &ctx->adev->gfx.kiq.ring) continue; - if (kref_read(&ctx->refcount) == 1) - drm_sched_entity_do_release(&ctx->adev->rings[i]->sched, - &ctx->rings[i].entity); - else - DRM_ERROR("ctx %p is still alive\n", ctx); + max_wait = drm_sched_entity_do_release(&ctx->adev->rings[i]->sched, + &ctx->rings[i].entity, max_wait); } } + mutex_unlock(&mgr->lock); } void amdgpu_ctx_mgr_entity_cleanup(struct amdgpu_ctx_mgr *mgr) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c index b0bf2f2..a549483 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c @@ -855,9 +855,21 @@ static const struct dev_pm_ops amdgpu_pm_ops = { .runtime_idle = amdgpu_pmops_runtime_idle, }; +static int amdgpu_flush(struct file *f, fl_owner_t id) +{ + struct drm_file *file_priv = f->private_data; + struct amdgpu_fpriv *fpriv = file_priv->driver_priv; + + amdgpu_ctx_mgr_entity_fini(&fpriv->ctx_mgr); + + return 0; +} + + static const struct file_operations amdgpu_driver_kms_fops = { .owner = THIS_MODULE, .open = drm_open, + .flush = amdgpu_flush, .release = drm_release, .unlocked_ioctl = amdgpu_drm_ioctl, .mmap = amdgpu_mmap, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c index ca21549..1239384 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c @@ -930,7 +930,6 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev, return; pm_runtime_get_sync(dev->dev); - amdgpu_ctx_mgr_entity_fini(&fpriv->ctx_mgr); if (adev->asic_type != CHIP_RAVEN) { amdgpu_uvd_free_handles(adev, file_priv);