From patchwork Tue Jun 25 17:59:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bob Beckett X-Patchwork-Id: 11016275 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 3317214E5 for ; Tue, 25 Jun 2019 18:02:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 269342846C for ; Tue, 25 Jun 2019 18:02:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A9EB28474; Tue, 25 Jun 2019 18:02:50 +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 C9AA22846C for ; Tue, 25 Jun 2019 18:02:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 668F26E209; Tue, 25 Jun 2019 18:02:43 +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 582F56E1BD 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 CE79E28A3F3 From: Robert Beckett To: dri-devel@lists.freedesktop.org Subject: [PATCH v3 1/4] drm/vblank: warn on sending stale event Date: Tue, 25 Jun 2019 18:59:12 +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 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 | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c index 603ab105125d..7dabb2bdb733 100644 --- a/drivers/gpu/drm/drm_vblank.c +++ b/drivers/gpu/drm/drm_vblank.c @@ -918,6 +918,19 @@ 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: + * - 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 + * in-between a drm_crtc_vblank_off()/on() pair) + * If all of these conditions hold then drm_crtc_send_vblank_event is + * going to give you a garbage timestamp and and sequence number (the last + * recorded before the irq was disabled). If you call drm_crtc_vblank_get/put + * around it, or after vblank_off, then either of those will have rolled things + * forward for you. + * So, drivers should call drm_crtc_vblank_off() before this function in their + * crtc atomic_disable handlers. */ void drm_crtc_send_vblank_event(struct drm_crtc *crtc, struct drm_pending_vblank_event *e) @@ -925,8 +938,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 {