From patchwork Mon Jun 4 18:39:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Grodzovsky X-Patchwork-Id: 10447155 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 27A2760375 for ; Mon, 4 Jun 2018 18:41:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 17CDE29317 for ; Mon, 4 Jun 2018 18:41:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 15146291C1; Mon, 4 Jun 2018 18:41:48 +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 C26A42936C for ; Mon, 4 Jun 2018 18:40:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A60D76EBBD; Mon, 4 Jun 2018 18:40:47 +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-by2nam01on0058.outbound.protection.outlook.com [104.47.34.58]) by gabe.freedesktop.org (Postfix) with ESMTPS id EBFFC6E55C; Mon, 4 Jun 2018 18:40:42 +0000 (UTC) Received: from DM5PR12CA0005.namprd12.prod.outlook.com (2603:10b6:4:1::15) by DM3PR12MB0762.namprd12.prod.outlook.com (2a01:111:e400:5984::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.820.15; Mon, 4 Jun 2018 18:40:40 +0000 Received: from DM3NAM03FT061.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e49::208) by DM5PR12CA0005.outlook.office365.com (2603:10b6:4:1::15) 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 18:40:40 +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 DM3NAM03FT061.mail.protection.outlook.com (10.152.83.123) 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 18:40:40 +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 13:40:38 -0500 From: Andrey Grodzovsky To: , Subject: [PATCH v4 2/2] drm/amdgpu: move amdgpu_ctx_mgr_entity_fini to f_ops flush hook. Date: Mon, 4 Jun 2018 14:39:59 -0400 Message-ID: <1528137599-2188-2-git-send-email-andrey.grodzovsky@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1528137599-2188-1-git-send-email-andrey.grodzovsky@amd.com> References: <1528137599-2188-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)(39380400002)(39860400002)(396003)(376002)(346002)(2980300002)(428003)(199004)(189003)(50466002)(7696005)(105586002)(476003)(5660300001)(53936002)(336012)(36756003)(2906002)(575784001)(446003)(86362001)(16586007)(44832011)(316002)(486006)(106466001)(126002)(11346002)(53416004)(110136005)(50226002)(6666003)(48376002)(72206003)(478600001)(47776003)(97736004)(426003)(54906003)(2616005)(77096007)(81156014)(81166006)(76176011)(26005)(51416003)(8676002)(305945005)(68736007)(59450400001)(450100002)(186003)(104016004)(356003)(8936002)(4326008); DIR:OUT; SFP:1101; SCL:1; SRVR:DM3PR12MB0762; H:SATLEXCHOV01.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; A:1; MX:1; X-Microsoft-Exchange-Diagnostics: 1; DM3NAM03FT061; 1:rJqXlXXXP4IpwlCGTbM32eEsernTum2pM+EdqGdYIUHtpBj9GAv9s3N09B6KWJpq0cgflXE43cYEyRSsjglKs4ta/vgw1EqtJZx7+3x8O4ipzysKPAhjOkxjoZ8lJYSM X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060); SRVR:DM3PR12MB0762; X-Microsoft-Exchange-Diagnostics: 1; DM3PR12MB0762; 3:iY5PvtxloIqpsebF5B4Z3+1puj5WLwU51YFlwQ9gIHZsq4taVA6svTvoXIF14SrlxPr2oKf0p2XqybuGWacxgzcV+Er0KNbiKaiVA8ze4nPNo2lSFIZ/1VGCwF3QJcBYdlUSCa7+0Yic8fpFzJBbRLNv+lq4auct42MissKU4fUTLYYZARltLooyOh0Fu301e4V7IfTVU5aJQunIC+23WvOrqslsbL/d3ZG7BG0J43NwXb8nLOyLrpe24uzP4syCtBSNz0tWI2gu7u70+gVgbmY/z6LF5q/kuJIu0v0gvKEIvPaC1sBvzXQh3L8PiMMcnhPi/LTwJn972QNnQSknyq59VNiLSjyTQ2996StRjLQ=; 25:hXj13HBgqIWjmDzVx5Q6UHAzJaQmQa0tDpj9I/eWj0S9B8bB0DZ9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v53VcWgouGXisUZdIpwep 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)(5005006)(8121501046)(3231254)(944501410)(52105095)(10201501046)(93006095)(93003095)(3002001)(6055026)(149027)(150027)(6041310)(20161123562045)(20161123560045)(20161123564045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011)(7699016); SRVR:DM3PR12MB0762; BCL:0; PCL:0; RULEID:; SRVR:DM3PR12MB0762; X-Microsoft-Exchange-Diagnostics: 1; DM3PR12MB0762; 4:76BoqGI9+X8e9cdZ6jkL7edRxIoHe67qnxP2lGLl+Or4lmuqb6RX3QI8A6/FL0WQb5CW5FHgF/uI0v0j8giAgUskvWOx/eewsAlLUJTXQyQSw/SX3Kr10ckTjY2x+1TgAdIZUtmW3hLoVLN+hXhYjCc41IC0yRjrpWlwnc6dqlEOt3YI+m1FcubVemQLbYIpc/UYxHSQdCOErVwzjA+DAiO7xMM/WJsiare6SsWGU5uwyMBD3SF/XfBdHd61lJuGfGcrSF1gTce0pE5o4sL6Jr2xJTmHRQjB8R/xgAqs9/vwUMvlz10WTfigb2cJgtCV X-Forefront-PRVS: 069373DFB6 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM3PR12MB0762; 23:ehAOqNFWaysEuK0BqyJdd9tTuV8vgKDJox7f/P51B?= =?us-ascii?Q?3+HZc8erkH7HE2jS7bP89dD0yXMgOxc7rjTWgV0YOUgcNeEMXnJwbZY6Hi6m?= =?us-ascii?Q?pzX3V1PdRmXkW0Wa24ununV2xXsRa6ufWdvwU08mN/4QzYlpMId3puU6L1Fb?= =?us-ascii?Q?1OExc5s5qUWRTWM7A4tfwFaB+d7G2IF2tiU8j8XSsrIXLD/ngiYEgOChtFz1?= =?us-ascii?Q?DH2YQq039A1sdHcYaH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IO2ntu4ltxKuLiJlqCAuD4qIjLp5AT0=; 24:TriMoAQ0FPM5s7nRR2h0ROwj5GdPXgeS2UQTfoLzZNkJTDd28yv5nf9L4eWHywBhuUwjsyhwuv+3DGBIG97S5cIZfsYUTYYPYB854AwYz9s= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM3PR12MB0762; 7:1+mChu/pv7jMeODnI2NOAKEQGRriKhni0UuZ6hlYhrYTlS5yDkWUUldYOBKLCY0C2svON3oLSg0m+wt6+Uuj0KR3Fhs1j1Qo7jMMzah9dEzV6YYIFetnJoRmAaKB5fOm6e9HwOab7il5oqLb1CXJCmN9Y/kbzcemIW0yHCux0fKGBf7UTwi4Q+89KQlSi3UqQD9VlEkW2iG/SGT8Jx6b1UlbKvIozUivliaVy1xQUhRX9HJChfUTalUp3LqdMAdd; 20:UfuUo43kuTjYrRkn01j3uz5u8RKK2LUcmQY9/rJOH+eSLlVsFkykdV5Ul0wZuLTVTjn2lt8i/v56X4sanbOov4sN/tGfXltGiT+QgqnxC4wBhLEJ8lDGpiPyf2Tjl76LD5KIQ6bPNuvzDqeUJSC2LlFQjkiZQGCk3la/9GJ6zrW/QMFwa9xsDVTLSJBeDSbHyCWUxonV5SURVzyTLDSYmMdStt2JpjIu+4YJkrcucNg/62lJxOwcnT/NY4pIruOE X-MS-Office365-Filtering-Correlation-Id: b2abf757-b1d2-4f48-c19e-08d5ca4aabe6 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jun 2018 18:40:40.1960 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b2abf757-b1d2-4f48-c19e-08d5ca4aabe6 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: DM3PR12MB0762 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);