From patchwork Mon Jan 2 12:59:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 9493455 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 7F83E62AB3 for ; Mon, 2 Jan 2017 13:00:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 732151FF27 for ; Mon, 2 Jan 2017 13:00:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 678B5223B2; Mon, 2 Jan 2017 13:00:00 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID 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 264FF1FF27 for ; Mon, 2 Jan 2017 13:00:00 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D54A389DE6; Mon, 2 Jan 2017 12:59:50 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x241.google.com (mail-wm0-x241.google.com [IPv6:2a00:1450:400c:c09::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2981889DE6 for ; Mon, 2 Jan 2017 12:59:49 +0000 (UTC) Received: by mail-wm0-x241.google.com with SMTP id c85so43726564wmi.1 for ; Mon, 02 Jan 2017 04:59:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=WteIRVr0r0mvpjwxk3uqmIaAwB0InJw42qJX2gFnu34=; b=Ja8lYmuhwRHNoF1fxJveWz1jB6JkpDBjsjxhBJYl8KTlH9Dt4qx8UmUIavzgqiknmi 7F2iPFYqh4MW7ugpCukIa+No2zrRirdWXMu7JNXDN1FCD+6tJiOrFAtTyO8v5Xx4lrk1 FTKcEdW+7FF4/qgDtjMxJtph4DwwV742JBpXjyjTwVO6fbe191/rQT1tEHRxOrl6yaTO rchrNTM/aZTABwRbTS733ximc1vlnDQDk1QpRGGv2zj5WHxT7m9TkDI7rHw+o4m8puUB z2cqm04QjrBw+Kqi1mIqBPPmMQjdeJ+Bsj9tBMo/BA8XjYC3Zp1qWG3pI/Y4UKreXv8j I/sQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=WteIRVr0r0mvpjwxk3uqmIaAwB0InJw42qJX2gFnu34=; b=YPWqNRDKKldCk8NSMUXzfcLeBNa9XsMWTitG5ewbr21sBSpPAoRisFjNS3trxw+YnC O1f/XHCrO8I4FIv2RdUKPbGHdIE9BcvbV+tS/Ht0eq7wF3hECXOuNDVQTZhyLUo0W3je 91bVxEd0sG/3p9RDqK6f+badAQM7EnXvt9GCf+IlBrCGnDL7Lrt3UcjwxVTP4i32CCMk f3qmAmUTKMU2hxHszOKQjDG+RMUl3w2UyGUTiwocaeu6gA1gqCQhfOlMdtQDXLqDJZQ8 XvVsKmqk2oe8YkOuwwRh5o6t8BfWUlpEnpllPMcxKpHrg8gJV8ANdrHowZ/aqnJl+yyN GmjA== X-Gm-Message-State: AIkVDXI303FBzL7R20Gh8JX7DlveD5m2fAj0vplxUjFF58jO7ufDZIk3B9kB4/6yPJ7jjA== X-Received: by 10.28.18.194 with SMTP id 185mr49068792wms.124.1483361987335; Mon, 02 Jan 2017 04:59:47 -0800 (PST) Received: from cizrna.lan ([109.72.12.216]) by smtp.gmail.com with ESMTPSA id f126sm84058006wme.22.2017.01.02.04.59.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Jan 2017 04:59:46 -0800 (PST) From: Tomeu Vizoso To: linux-kernel@vger.kernel.org Subject: [PATCH v14 2/4] drm: crc: Wait for a frame before returning from open() Date: Mon, 2 Jan 2017 13:59:10 +0100 Message-Id: <20170102125912.22305-3-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170102125912.22305-1-tomeu.vizoso@collabora.com> References: <20170102125912.22305-1-tomeu.vizoso@collabora.com> Cc: Tomeu Vizoso , Emil Velikov , dri-devel@lists.freedesktop.org, Daniel Vetter X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Don't return from the open() call on the crc/data file until the HW has produced a first frame, as there's great variability in when the HW is able to do that and userspace shouldn't have to guess when this specific HW is ready to start giving frame CRCs. Signed-off-by: Tomeu Vizoso --- drivers/gpu/drm/drm_debugfs_crc.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/drm_debugfs_crc.c b/drivers/gpu/drm/drm_debugfs_crc.c index 68b171af237b..8b0eeeed4d78 100644 --- a/drivers/gpu/drm/drm_debugfs_crc.c +++ b/drivers/gpu/drm/drm_debugfs_crc.c @@ -125,6 +125,12 @@ static const struct file_operations drm_crtc_crc_control_fops = { .write = crc_control_write }; +static int crtc_crc_data_count(struct drm_crtc_crc *crc) +{ + assert_spin_locked(&crc->lock); + return CIRC_CNT(crc->head, crc->tail, DRM_CRC_ENTRIES_NR); +} + static int crtc_crc_open(struct inode *inode, struct file *filep) { struct drm_crtc *crtc = inode->i_private; @@ -160,8 +166,19 @@ static int crtc_crc_open(struct inode *inode, struct file *filep) crc->entries = entries; crc->values_cnt = values_cnt; crc->opened = true; + + /* + * Only return once we got a first frame, so userspace doesn't have to + * guess when this particular piece of HW will be ready to start + * generating CRCs. + */ + ret = wait_event_interruptible_lock_irq(crc->wq, + crtc_crc_data_count(crc), + crc->lock); spin_unlock_irq(&crc->lock); + WARN_ON(ret); + return 0; err_disable: @@ -189,12 +206,6 @@ static int crtc_crc_release(struct inode *inode, struct file *filep) return 0; } -static int crtc_crc_data_count(struct drm_crtc_crc *crc) -{ - assert_spin_locked(&crc->lock); - return CIRC_CNT(crc->head, crc->tail, DRM_CRC_ENTRIES_NR); -} - /* * 1 frame field of 10 chars plus a number of CRC fields of 10 chars each, space * separated, with a newline at the end and null-terminated.