From patchwork Tue Jun 25 17:59:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bob Beckett X-Patchwork-Id: 11016267 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 B68686C5 for ; Tue, 25 Jun 2019 18:02:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A94F02846C for ; Tue, 25 Jun 2019 18:02:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D46428475; Tue, 25 Jun 2019 18:02:44 +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,UNPARSEABLE_RELAY 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 400DB2846C for ; Tue, 25 Jun 2019 18:02:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CBB896E1BD; Tue, 25 Jun 2019 18:02:42 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by gabe.freedesktop.org (Postfix) with ESMTPS id E662E6E1BD for ; Tue, 25 Jun 2019 18:02:38 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: bbeckett) with ESMTPSA id 8D2A6286276 From: Robert Beckett To: dri-devel@lists.freedesktop.org Subject: [PATCH v3 3/4] drm/vblank: estimate vblank while disabling vblank if interrupt disabled Date: Tue, 25 Jun 2019 18:59:14 +0100 Message-Id: X-Mailer: git-send-email 2.18.0 In-Reply-To: References: 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: Robert Beckett , Maxime Ripard , Shawn Guo , linux-kernel@vger.kernel.org, David Airlie , NXP Linux Team , Sean Paul , Pengutronix Kernel Team , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP If interrupts are disabled (e.g. via vblank_disable_fn) and we come to disable vblank, update the vblank count to best guess as to what it would be had the interrupts remained enabled, and update the timesamp to now. This avoids a stale vblank event being sent while disabling crtcs during atomic modeset. Fixes: 68036b08b91bc ("drm/vblank: Do not update vblank count if interrupts are already disabled.") Signed-off-by: Robert Beckett --- drivers/gpu/drm/drm_vblank.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c index 7dabb2bdb733..db68b8cbf797 100644 --- a/drivers/gpu/drm/drm_vblank.c +++ b/drivers/gpu/drm/drm_vblank.c @@ -375,9 +375,23 @@ void drm_vblank_disable_and_save(struct drm_device *dev, unsigned int pipe) * interrupts were enabled. This avoids calling the ->disable_vblank() * operation in atomic context with the hardware potentially runtime * suspended. + * If interrupts are disabled (e.g. via blank_disable_fn) then make + * best guess as to what it would be now and make sure we have an up + * to date timestamp. */ - if (!vblank->enabled) + if (!vblank->enabled) { + ktime_t now = ktime_get(); + u32 diff = 0; + if (vblank->framedur_ns) { + u64 diff_ns = ktime_to_ns(ktime_sub(now, vblank->time)); + diff = DIV_ROUND_CLOSEST_ULL(diff_ns, + vblank->framedur_ns); + } + + store_vblank(dev, pipe, diff, now, vblank->count); + goto out; + } /* * Update the count and timestamp to maintain the