Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp3226193ybd; Fri, 28 Jun 2019 05:08:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqzgGhDeH3oOO+Iu8XwB2eqJWWmY045Gk6Zp66PzM43/JHGyo7zi/4tGL3XloHcurd526pN0 X-Received: by 2002:a17:902:d70a:: with SMTP id w10mr10593351ply.251.1561723691037; Fri, 28 Jun 2019 05:08:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561723691; cv=none; d=google.com; s=arc-20160816; b=gwTtde0MNuHLizmOSX/3tp/W53fuSUpNMXzN/+aDQIQIeBfCRp2q9viFsQ+pXhk5nV BE/yMVc+isMFb5NhLTERKql32G4gbrsUX9yqOiYQyndF373O5DqT28xlRwp8fbZN1BXk dpTsUYEYeWV1AXtMyFIfVngIfqokLR2Nj+1RHbVMGqpk0Z0tugL2HxgqqXY2i9ktPZ4W fLwv6xrHVfpBOqEycgL3Ev+CjWK72AbRiONRULi7X2YOJ6MlUOeFUCD9TqL82uAHiN/F 1S8/uXlwf2vDp4yFnTT88CZXp4Z94t8uSHQTim7qwikR6mk28p8Ix9nmXcgIcw6SvTpG Jgxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=TkJ3UX1hh2J+maRhjRQNpM2tQgk14CCa+IN9jSsMxao=; b=d7Y2EL5MBxG+dtC1fWA4gRSB0YfzOcpjf5akpVaYFVCXi0umLakcGlQVCHHZ7kMqED Kp+g9TxmNuhZe/MeawNMHXdbZ8tzvDEcLRSEP0KRe9dN2KjPMdJA2IUowST8L2OKCxAF XxEfCRE5FU8wTwZplujrl161iU1MeOsdU2YRVHql1gPLgG1uIR4eXCts/0DNCV/UGqSY I3uhqtnXqRKLHSy3kRaYke9OGjdtnCbYEU8scddzlrrWjBMEwU5gXIWdWAdgE6JpdLnX HOu0oiPEDoLjYcCk16F/zxS+K8lJfhlDx/BTF33veqMdbtMIyUPEAuMk6evdi2SKle5Q ChMA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m128si2440600pfm.97.2019.06.28.05.07.52; Fri, 28 Jun 2019 05:08:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727047AbfF1MGK (ORCPT + 99 others); Fri, 28 Jun 2019 08:06:10 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:53996 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726650AbfF1MGD (ORCPT ); Fri, 28 Jun 2019 08:06:03 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: bbeckett) with ESMTPSA id DAE3428A3A1 From: Robert Beckett To: dri-devel@lists.freedesktop.org Cc: Maarten Lankhorst , Maxime Ripard , Sean Paul , David Airlie , Daniel Vetter , linux-kernel@vger.kernel.org, Philipp Zabel , Robert Beckett Subject: [PATCH v4 1/2] drm/vblank: warn on sending stale event Date: Fri, 28 Jun 2019 13:05:31 +0100 Message-Id: <66e100219a2740e493a7b96ebb95d0a2e697f121.1561722822.git.bob.beckett@collabora.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Warn when about to send stale vblank info and add advice to documentation on how to avoid. Signed-off-by: Robert Beckett --- 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 { -- 2.18.0