From patchwork Mon Mar 25 08:32:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chunming Zhou X-Patchwork-Id: 10868209 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 6160E15AC for ; Mon, 25 Mar 2019 08:33:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D2BB29271 for ; Mon, 25 Mar 2019 08:33:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4185F29275; Mon, 25 Mar 2019 08:33:14 +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=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 D792B29271 for ; Mon, 25 Mar 2019 08:33:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D40BD6E693; Mon, 25 Mar 2019 08:33:12 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM05-BY2-obe.outbound.protection.outlook.com (mail-eopbgr710074.outbound.protection.outlook.com [40.107.71.74]) by gabe.freedesktop.org (Postfix) with ESMTPS id CE90B6E693; Mon, 25 Mar 2019 08:33:11 +0000 (UTC) Received: from DM3PR12CA0126.namprd12.prod.outlook.com (2603:10b6:0:51::22) by CY1PR12MB0587.namprd12.prod.outlook.com (2a01:111:e400:c439::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1730.15; Mon, 25 Mar 2019 08:33:09 +0000 Received: from CO1NAM03FT004.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::205) by DM3PR12CA0126.outlook.office365.com (2603:10b6:0:51::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1730.18 via Frontend Transport; Mon, 25 Mar 2019 08:33:09 +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 CO1NAM03FT004.mail.protection.outlook.com (10.152.80.154) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1750.11 via Frontend Transport; Mon, 25 Mar 2019 08:33:08 +0000 Received: from zhoucm1.amd.com (10.34.1.3) by SATLEXCHOV02.amd.com (10.181.40.72) with Microsoft SMTP Server id 14.3.389.1; Mon, 25 Mar 2019 03:33:07 -0500 From: Chunming Zhou To: , , , , , Subject: [PATCH 5/9] drm/syncobj: use the timeline point in drm_syncobj_find_fence v4 Date: Mon, 25 Mar 2019 16:32:20 +0800 Message-ID: <20190325083224.2983-5-david1.zhou@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190325083224.2983-1-david1.zhou@amd.com> References: <20190325083224.2983-1-david1.zhou@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)(346002)(136003)(2980300002)(428003)(189003)(199004)(2201001)(486006)(126002)(6666004)(356004)(14444005)(54906003)(86362001)(105586002)(110136005)(53936002)(2906002)(2870700001)(106466001)(5820100001)(36756003)(53416004)(478600001)(66574012)(104016004)(1076003)(4326008)(186003)(47776003)(97736004)(50226002)(68736007)(26005)(77096007)(72206003)(5660300002)(6636002)(8936002)(305945005)(81166006)(8676002)(81156014)(50466002)(336012)(76176011)(426003)(446003)(316002)(2616005)(7696005)(23676004)(11346002)(476003); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR12MB0587; H:SATLEXCHOV02.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; MX:1; A:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f6e50641-bd47-4733-6ce2-08d6b0fc8295 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(2017052603328)(7153060); SRVR:CY1PR12MB0587; X-MS-TrafficTypeDiagnostic: CY1PR12MB0587: X-Microsoft-Antispam-PRVS: X-Forefront-PRVS: 0987ACA2E2 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: /OzoyAWxkN5f8XNgKUixEKwpSJcVD0rZV5Y/PLLB9PljTTaqBu3rEr2gXKX86rYMDpgsyJQoxZHOpnb2lray/rjOpKk5kauTiI7tmJfFxrJUZ21GjYaLCnY5qTLZKi+Z2GoWwNBMVks52VIO6tHdvih0AJdGwyVM4ZbRhycNjvFbfTe7HVF4NEtGBXFCJ+gB2XETYG/xRJDPQvb8skvfXcq+i9BlACH/VG386WsmBKEdOXpUmU7bPGo9AmgdWujev725QUYwJlMIv3cf0aiBWjQSVbswxNYnf3sE7JmtHLAf587P6eAnVErD88dIMwZjJFS1thr/KTsCgC0Js9FKvmLzAtQ2xO4bAF0f+LhB22ubXB5+2iRunoUHLk0eskX1jC5SEj8k440RwGIpAOpKqkpBR448ZsxfSVEKz2P/mus= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2019 08:33:08.5162 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f6e50641-bd47-4733-6ce2-08d6b0fc8295 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: CY1PR12MB0587 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=AokHZFzxFPvJJHyc1sAzCa+9VKtUoZ0Gd6OUe7iOz6U=; b=q+kle8Jz/GRqXzWRzHRNtfdLoAdsHmYq5bo35djYlYSi8jeEYU7ClW6KPjv6T+WCOlbLnkhltd/p2kRnj4LD43+s5/nvbKoAIcbIYKwS1wG/xef74k/It2nY2O5koSFi9BvQkdwumkwwm7ggwjXXIFM+wWWddUOagIJPDvdUnys= X-Mailman-Original-Authentication-Results: spf=none (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; jlekstrand.net; dkim=none (message not signed) header.d=none;jlekstrand.net; dmarc=permerror action=none header.from=amd.com; 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: =?utf-8?q?Christian_K=C3=B6nig?= , =?utf-8?q?Christian_K=C3=B6nig?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Christian König Implement finding the right timeline point in drm_syncobj_find_fence. v2: return -EINVAL when the point is not submitted yet. v3: fix reference counting bug, add flags handling as well v4: add timeout for find fence Signed-off-by: Christian König Cc: Lionel Landwerlin --- drivers/gpu/drm/drm_syncobj.c | 50 ++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c index 0e62a793c8dd..087fd4e7eaf3 100644 --- a/drivers/gpu/drm/drm_syncobj.c +++ b/drivers/gpu/drm/drm_syncobj.c @@ -213,6 +213,8 @@ static void drm_syncobj_assign_null_handle(struct drm_syncobj *syncobj) dma_fence_put(fence); } +/* 5s default for wait submission */ +#define DRM_SYNCOBJ_WAIT_FOR_SUBMIT_TIMEOUT 5000000000ULL /** * drm_syncobj_find_fence - lookup and reference the fence in a sync object * @file_private: drm file private pointer @@ -233,16 +235,58 @@ int drm_syncobj_find_fence(struct drm_file *file_private, struct dma_fence **fence) { struct drm_syncobj *syncobj = drm_syncobj_find(file_private, handle); - int ret = 0; + struct syncobj_wait_entry wait; + u64 timeout = nsecs_to_jiffies64(DRM_SYNCOBJ_WAIT_FOR_SUBMIT_TIMEOUT); + int ret; if (!syncobj) return -ENOENT; *fence = drm_syncobj_fence_get(syncobj); - if (!*fence) { + drm_syncobj_put(syncobj); + + if (*fence) { + ret = dma_fence_chain_find_seqno(fence, point); + if (!ret) + return 0; + dma_fence_put(*fence); + } else { ret = -EINVAL; } - drm_syncobj_put(syncobj); + + if (!(flags & DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT)) + return ret; + + memset(&wait, 0, sizeof(wait)); + wait.task = current; + wait.point = point; + drm_syncobj_fence_add_wait(syncobj, &wait); + + do { + set_current_state(TASK_INTERRUPTIBLE); + if (wait.fence) { + ret = 0; + break; + } + if (timeout == 0) { + ret = -ETIME; + break; + } + + if (signal_pending(current)) { + ret = -ERESTARTSYS; + break; + } + + timeout = schedule_timeout(timeout); + } while (1); + + __set_current_state(TASK_RUNNING); + *fence = wait.fence; + + if (wait.node.next) + drm_syncobj_remove_wait(syncobj, &wait); + return ret; } EXPORT_SYMBOL(drm_syncobj_find_fence);