From patchwork Mon Apr 1 09:50:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chunming Zhou X-Patchwork-Id: 10879529 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 96D9D14DE for ; Mon, 1 Apr 2019 09:51:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F73028814 for ; Mon, 1 Apr 2019 09:51:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 735FE28820; Mon, 1 Apr 2019 09:51:58 +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 18A8828814 for ; Mon, 1 Apr 2019 09:51:58 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 27BA96E683; Mon, 1 Apr 2019 09:51:57 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on062c.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe48::62c]) by gabe.freedesktop.org (Postfix) with ESMTPS id 684B46E681; Mon, 1 Apr 2019 09:51:55 +0000 (UTC) Received: from DM5PR12CA0010.namprd12.prod.outlook.com (2603:10b6:4:1::20) by BN8PR12MB2964.namprd12.prod.outlook.com (2603:10b6:408:61::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1750.17; Mon, 1 Apr 2019 09:51:53 +0000 Received: from CO1NAM03FT062.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::200) by DM5PR12CA0010.outlook.office365.com (2603:10b6:4:1::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1750.15 via Frontend Transport; Mon, 1 Apr 2019 09:51:53 +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 CO1NAM03FT062.mail.protection.outlook.com (10.152.81.50) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1750.16 via Frontend Transport; Mon, 1 Apr 2019 09:51:52 +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, 1 Apr 2019 04:51:51 -0500 From: Chunming Zhou To: , , , , , Subject: [PATCH 5/9] drm/syncobj: use the timeline point in drm_syncobj_find_fence v4 Date: Mon, 1 Apr 2019 17:50:59 +0800 Message-ID: <20190401095103.9592-6-david1.zhou@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190401095103.9592-1-david1.zhou@amd.com> References: <20190401095103.9592-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)(396003)(136003)(376002)(39860400002)(346002)(2980300002)(428003)(199004)(189003)(14444005)(8676002)(4326008)(11346002)(104016004)(76176011)(81156014)(53936002)(47776003)(72206003)(446003)(356004)(53416004)(54906003)(50226002)(68736007)(2906002)(8936002)(110136005)(66574012)(50466002)(316002)(1076003)(186003)(77096007)(26005)(478600001)(81166006)(36756003)(2201001)(105586002)(2870700001)(6636002)(97736004)(5660300002)(23676004)(7696005)(106466001)(5820100001)(336012)(476003)(486006)(126002)(426003)(2616005)(86362001)(305945005); DIR:OUT; SFP:1101; SCL:1; SRVR:BN8PR12MB2964; H:SATLEXCHOV02.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; A:1; MX:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 86212f47-f225-4c9c-3bdd-08d6b687ab49 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(5600139)(711020)(4605104)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060); SRVR:BN8PR12MB2964; X-MS-TrafficTypeDiagnostic: BN8PR12MB2964: X-Microsoft-Antispam-PRVS: X-Forefront-PRVS: 0994F5E0C5 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: 18Q9HpaVuKWBjBiUH/33h+BCoMvxUGxAE273qquDsjToqj4PvqIHLAD3ss6GXEDkHgIjE08CvKaaKr/HlSNwcaQhzUoCA85giT+RXLJDnXNPHW/pbugHJg/XRyxx4zjX3z/uvqrmEx7JSyAhWSkCCBFaIRI79ZtoWZ8WesrlulHUkYNl96OtjMYpNq2gNFnW/nV74qFSj6Hlo3ixl2OG17SqlBxzJHMxv9lINoixVq8Kwmv/B5eOPGk5z5F3cBk/KF4lfoo/1MUjwedsA+sZaVOzHZipTNZN4DUogAQ5baO3GaGieS1q84KOMwGPbmCsbdzkiUlhO7z22rPKuDZTgpJ3QhLZpepBvt3ioo4dBJPdzaFQ3921uz2NVh7zFofK0JdeGE3kMLPd1ZwrM8Nno3+YHYvkRKp7kIuNDvkEoC4= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Apr 2019 09:51:52.7879 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 86212f47-f225-4c9c-3bdd-08d6b687ab49 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: BN8PR12MB2964 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=IwrsOUmZRlb65BSkEbBph6w6B+bUW+XLswYxbmaNR38=; b=vSVY+FH4GobRwNGmirN6iZeeBd9+n35CKx+p1vDo4NeqFhec8ypotpnpbmTvGrao8QjyiRcO7KJjv5/8NCoxo6LWG70uSEBjCdd1xOB/fsg5/SujWJF66mKXmrtiG037w9z3RBqFckH3iw4cSwAjuitScJqx259Vy12QZlCkY6Y= 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 Reviewed-by: 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 3a1be7f79de1..6c273e73d920 100644 --- a/drivers/gpu/drm/drm_syncobj.c +++ b/drivers/gpu/drm/drm_syncobj.c @@ -214,6 +214,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 @@ -234,16 +236,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);