From patchwork Mon Dec 18 10:24:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dhinakaran Pandiyan X-Patchwork-Id: 10118743 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AE75E603FA for ; Mon, 18 Dec 2017 10:25:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9C63528931 for ; Mon, 18 Dec 2017 10:25:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 90F0926E51; Mon, 18 Dec 2017 10:25:26 +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=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID 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 31D2D26E51 for ; Mon, 18 Dec 2017 10:25:26 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DC6F389FC9; Mon, 18 Dec 2017 10:25:25 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-pl0-x244.google.com (mail-pl0-x244.google.com [IPv6:2607:f8b0:400e:c01::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id B3BAC89FC9 for ; Mon, 18 Dec 2017 10:25:24 +0000 (UTC) Received: by mail-pl0-x244.google.com with SMTP id bi12so4546486plb.6 for ; Mon, 18 Dec 2017 02:25:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WWFIyQqVyuOhSMfFZ5XL70+JdcwGEow++VLVMVGQ0UA=; b=WLqB4a6qHfRKQG+WhFyOvPR3hpR0TxmytvhiB4MMN51ystNsV0cg6TmlsTQT2/rbIn ziEjHzEz7aqgZApxyJAPQxypZbtRi59KU5qM/B0p/FAwNdmmhdKHejhU8iBB1YZuF96O KfCpC2qFJxv0CxiQtr0CHk21wYlwqTA3gawwupyN2Vq+GXq620O5f5eL1yOFy7d/OG3u xRpZ7hJK11CFwQVcYVNEoSFU8KTxjgETC8wdEI9s0MzhkVwgI7k0OzK2D/mmNUuQPb8F yM0OR15GCFCYtJf/NjkoHyOYFfx9BtE+8M+nhrsAq+RLzhTDLMFEavhMCu2qGHduBrdj 8Zgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WWFIyQqVyuOhSMfFZ5XL70+JdcwGEow++VLVMVGQ0UA=; b=ebS1gTLf+/ysggj0cJ2U1ewecTMhnKgtlkqxwCbsipjW0u+RYeXQ6g/BTgAayaUQer o5UIO64P4PVBDQgA6yY90PmPrzQwCu0NwZ/SXgcy4Fv7VlhJfI37cvQ4GF2UWIaXiDZ9 YRcv8YISDSyLrV46wCeq6f3fyYvtX4E7i6rrE9gfAuQReqBjI3fYnOoH1c5DL9/QGfPh eIDLMYUCgU6uwfqnQ7IJfMGmNxaXRJjMxMMD8jEHr5cRNzfktkkYZDCEGdxHS7PtcDEX VtzITWCm/bvD1jIVR+EQz8Bb8yD/RKeLZE3pK1VEFC8+MR4+bR0Uf3lLIqu6s1vB5n/L B4QA== X-Gm-Message-State: AKGB3mKb4Go88IOjvOW8sKLwbBpogp7AiWHhbtf7VLaDG6vqORQVQ6bp JHxPOI6ABkJIuR5RGYcEYVgbvQ== X-Google-Smtp-Source: ACJfBosgBP9OH3TXrOfese8wqBPYoXpR0KwDruB0BddOOhoW89FMSslGKzBXd/6pcOu5q7nAMUUHgg== X-Received: by 10.84.168.162 with SMTP id f31mr21720830plb.249.1513592723830; Mon, 18 Dec 2017 02:25:23 -0800 (PST) Received: from localhost.localdomain ([2601:1c0:5402:5a00:d047:2358:10ac:f41c]) by smtp.gmail.com with ESMTPSA id u125sm21206499pgc.94.2017.12.18.02.25.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Dec 2017 02:25:22 -0800 (PST) From: Dhinakaran Pandiyan X-Google-Original-From: Dhinakaran Pandiyan To: intel-gfx@lists.freedesktop.org Date: Mon, 18 Dec 2017 02:24:42 -0800 Message-Id: <20171218102445.2709-2-dhinakaran.pandiyan@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171218102445.2709-1-dhinakaran.pandiyan@intel.com> References: <20171218102445.2709-1-dhinakaran.pandiyan@intel.com> Cc: Dhinakaran Pandiyan Subject: [Intel-gfx] [CI v2 2/5] drm/vblank: Restoring vblank counts after device runtime PM events. X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP The HW frame counter can get reset when devices enters low power states and this messes up any following vblank count updates. So, compute the missed vblank interrupts for that low power state duration using time stamps. This is similar to _crtc_vblank_on() except that it doesn't enable vblank interrupts because this function is expected to be called from the driver _enable_vblank() vfunc. Signed-off-by: Dhinakaran Pandiyan --- drivers/gpu/drm/drm_vblank.c | 33 +++++++++++++++++++++++++++++++++ include/drm/drm_vblank.h | 1 + 2 files changed, 34 insertions(+) diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c index 7eee82c06ed8..494e2cff6e55 100644 --- a/drivers/gpu/drm/drm_vblank.c +++ b/drivers/gpu/drm/drm_vblank.c @@ -1230,6 +1230,39 @@ void drm_crtc_vblank_on(struct drm_crtc *crtc) } EXPORT_SYMBOL(drm_crtc_vblank_on); +void drm_crtc_vblank_restore(struct drm_device *dev, unsigned int pipe) +{ + ktime_t t_vblank; + struct drm_vblank_crtc *vblank; + int framedur_ns; + u64 diff_ns; + u32 cur_vblank, diff = 1; + int count = DRM_TIMESTAMP_MAXRETRIES; + + if (WARN_ON(pipe >= dev->num_crtcs)) + return; + + vblank = &dev->vblank[pipe]; + WARN_ONCE((drm_debug & DRM_UT_VBL) && !vblank->framedur_ns, + "Cannot compute missed vblanks without frame duration\n"); + framedur_ns = vblank->framedur_ns; + + do { + cur_vblank = __get_vblank_counter(dev, pipe); + drm_get_last_vbltimestamp(dev, pipe, &t_vblank, false); + } while (cur_vblank != __get_vblank_counter(dev, pipe) && --count > 0); + + diff_ns = ktime_to_ns(ktime_sub(t_vblank, vblank->time)); + if (framedur_ns) + diff = DIV_ROUND_CLOSEST_ULL(diff_ns, framedur_ns); + + + DRM_DEBUG_VBL("missed %d vblanks in %lld ns, frame duration=%d ns, hw_diff=%d\n", + diff, diff_ns, framedur_ns, cur_vblank - vblank->last); + store_vblank(dev, pipe, diff, t_vblank, cur_vblank); +} +EXPORT_SYMBOL(drm_crtc_vblank_restore); + static void drm_legacy_vblank_pre_modeset(struct drm_device *dev, unsigned int pipe) { diff --git a/include/drm/drm_vblank.h b/include/drm/drm_vblank.h index 848b463a0af5..aafcbef91bd7 100644 --- a/include/drm/drm_vblank.h +++ b/include/drm/drm_vblank.h @@ -180,6 +180,7 @@ void drm_crtc_vblank_off(struct drm_crtc *crtc); void drm_crtc_vblank_reset(struct drm_crtc *crtc); void drm_crtc_vblank_on(struct drm_crtc *crtc); u32 drm_crtc_accurate_vblank_count(struct drm_crtc *crtc); +void drm_crtc_vblank_restore(struct drm_device *dev, unsigned int pipe); bool drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev, unsigned int pipe, int *max_error,