Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp4035531ybd; Tue, 25 Jun 2019 12:52:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqw4OrCv+zNl5a1mI8Vlf6XXGB/FpY+O32dG27R1Mp1WlRETaERqjAdd5aLTqXKo/AjmLdrV X-Received: by 2002:a17:90a:36a9:: with SMTP id t38mr634215pjb.19.1561492362087; Tue, 25 Jun 2019 12:52:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561492362; cv=none; d=google.com; s=arc-20160816; b=PdgQVpP90AWYPHvRduLPHknS+sr+E0Y9wxopxrIRlG6gBIEfOmgOIRtTklpAjdYNVE 1vIoXm9sZDhmYrRGeoqjU9Ro4wUPA+f7/duJKvoezLpiKu5Va/xPRaEInwMW/7rHs3aF hxQw3k7bFJuU6P9OP5TIhvDJx/73yZe6O8yQ96PmfV62M8Pcf0cOCzDiPqZ8Q6uwX8Yd 2DD66yBhMIBN2c3f3pir+90kiOfq0P9fbMJEc7fImZqCeM0/h/y7nICI9fdlYPGetW8O kplEMh4Sup/IJLavYNruF0IUlhOi2lbJuShzbcHdgS2hMFcJYH6k2ofgq/Y9Bdf589O/ 6twQ== 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=LWlV11+YlKvYSgajRlgwpULAvKrMluUbv6jhWWKdazNiRrrHoP7fqwSmhpfzDWf969 jK0T6PS6C1sSdUT+hA9rhlzlMbaOYulFZF1t5de2+GTr9JYuZlSHjvbHf3O20HJSyGs1 AkouxKsaGIX22VblRJfZgRg4+7RMYnEIBVwgC9CHsvhiIqH6LOIdKvCD3+AGiV+0v07J vcBDfWfk7JPFg9PtyFW9YBf7y1hSPTe7ie8dJNj51oELzJu0jHCt/8j/fg+CPR1/PK6y PdZlAKum5E+zp3YC6S0gItK9t/o3aoP86XnwFi1Iqn1ygX8D/Zl+hVCt4d66yw6JWmT9 dAsw== 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 j6si1059296plk.120.2019.06.25.12.52.26; Tue, 25 Jun 2019 12:52:42 -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 S1732778AbfFYSCj (ORCPT + 99 others); Tue, 25 Jun 2019 14:02:39 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:58764 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727289AbfFYSCi (ORCPT ); Tue, 25 Jun 2019 14:02:38 -0400 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 Cc: Maarten Lankhorst , Maxime Ripard , Sean Paul , David Airlie , Daniel Vetter , Philipp Zabel , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Robert Beckett 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: 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