From patchwork Fri Jun 28 14:15:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bob Beckett X-Patchwork-Id: 11022507 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 BD8D81575 for ; Fri, 28 Jun 2019 14:18:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AEBAB285C3 for ; Fri, 28 Jun 2019 14:18:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A2AB1285D1; Fri, 28 Jun 2019 14:18: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=-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 209BA284C5 for ; Fri, 28 Jun 2019 14:18:00 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5448D6E92D; Fri, 28 Jun 2019 14:17:55 +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 [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by gabe.freedesktop.org (Postfix) with ESMTPS id A74966E92C for ; Fri, 28 Jun 2019 14:17:53 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: bbeckett) with ESMTPSA id 1BEF828A35D From: Robert Beckett To: dri-devel@lists.freedesktop.org Subject: [PATCH v5 1/2] drm/vblank: warn on sending stale event Date: Fri, 28 Jun 2019 15:15:35 +0100 Message-Id: <3d03364bc0ed9bce6219a14fd325820035f42e72.1561729581.git.bob.beckett@collabora.com> 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 , =?utf-8?q?Michel_D=C3=A4nzer?= , David Airlie , Dhinakaran Pandiyan , Rodrigo Vivi , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Warn when about to send stale vblank info and add advice to documentation on how to avoid. Signed-off-by: Robert Beckett Reviewed-by: Daniel Vetter --- drivers/gpu/drm/drm_vblank.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c index 603ab105125d..9395b8c690b8 100644 --- a/drivers/gpu/drm/drm_vblank.c +++ b/drivers/gpu/drm/drm_vblank.c @@ -918,6 +918,20 @@ EXPORT_SYMBOL(drm_crtc_arm_vblank_event); * * See drm_crtc_arm_vblank_event() for a helper which can be used in certain * situation, especially to send out events for atomic commit operations. + * + * Care should be taken to avoid stale timestamps. If all of the following are + * true: + * - your driver has vblank support (i.e. dev->num_crtcs > 0) + * - the vblank irq is off (i.e. no one called drm_crtc_vblank_get()) + * - from the vblank code's pov the pipe is still running (i.e. not after the + * call to drm_crtc_vblank_off() but before the next call to + * drm_crtc_vblank_on()) + * then drm_crtc_send_vblank_event is going to give you a garbage timestamp and + * sequence number (the last recorded before the irq was disabled). + * + * Drivers must either hold a vblank reference acquired through + * drm_crtc_vblank_get() or the vblank must have been shut off by calling + * drm_crtc_vblank_off(). */ void drm_crtc_send_vblank_event(struct drm_crtc *crtc, struct drm_pending_vblank_event *e) @@ -925,8 +939,12 @@ void drm_crtc_send_vblank_event(struct drm_crtc *crtc, struct drm_device *dev = crtc->dev; u64 seq; unsigned int pipe = drm_crtc_index(crtc); + struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; ktime_t now; + WARN_ONCE(dev->num_crtcs > 0 && !vblank->enabled && !vblank->inmodeset, + "sending stale vblank info\n"); + if (dev->num_crtcs > 0) { seq = drm_vblank_count_and_time(dev, pipe, &now); } else { From patchwork Fri Jun 28 14:15:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bob Beckett X-Patchwork-Id: 11022509 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 AA98A1575 for ; Fri, 28 Jun 2019 14:18:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9AD1A284C5 for ; Fri, 28 Jun 2019 14:18:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F1DD285C3; Fri, 28 Jun 2019 14:18:02 +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 4980A284C5 for ; Fri, 28 Jun 2019 14:18:02 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 565C36E92E; Fri, 28 Jun 2019 14:17:55 +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 F0AFE6E92B for ; Fri, 28 Jun 2019 14:17:53 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: bbeckett) with ESMTPSA id 67BF4284CF8 From: Robert Beckett To: dri-devel@lists.freedesktop.org Subject: [PATCH v5 2/2] Revert "drm/vblank: Do not update vblank count if interrupts are already disabled." Date: Fri, 28 Jun 2019 15:15:36 +0100 Message-Id: <3f4e42ee5250ce8697f4ad2fa6b57ef8bd5b9663.1561729581.git.bob.beckett@collabora.com> 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 , =?utf-8?q?Michel_D=C3=A4nzer?= , David Airlie , Dhinakaran Pandiyan , Rodrigo Vivi , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP If interrupts are already disabled, then the timestamp for the vblank does not get updated, causing a stale timestamp to be reported to userland while disabling crtcs. This reverts commit 68036b08b91bc491ccc308f902616a570a49227c. Signed-off-by: Robert Beckett --- drivers/gpu/drm/drm_vblank.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c index 9395b8c690b8..d71c49983be3 100644 --- a/drivers/gpu/drm/drm_vblank.c +++ b/drivers/gpu/drm/drm_vblank.c @@ -371,25 +371,23 @@ void drm_vblank_disable_and_save(struct drm_device *dev, unsigned int pipe) spin_lock_irqsave(&dev->vblank_time_lock, irqflags); /* - * Update vblank count and disable vblank interrupts only if the - * interrupts were enabled. This avoids calling the ->disable_vblank() - * operation in atomic context with the hardware potentially runtime - * suspended. + * Only disable vblank interrupts if they're enabled. This avoids + * calling the ->disable_vblank() operation in atomic context with the + * hardware potentially runtime suspended. */ - if (!vblank->enabled) - goto out; + if (vblank->enabled) { + __disable_vblank(dev, pipe); + vblank->enabled = false; + } /* - * Update the count and timestamp to maintain the + * Always update the count and timestamp to maintain the * appearance that the counter has been ticking all along until * this time. This makes the count account for the entire time * between drm_crtc_vblank_on() and drm_crtc_vblank_off(). */ drm_update_vblank_count(dev, pipe, false); - __disable_vblank(dev, pipe); - vblank->enabled = false; -out: spin_unlock_irqrestore(&dev->vblank_time_lock, irqflags); }