From patchwork Mon Feb 11 03:22:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Kleiner X-Patchwork-Id: 10805071 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 2B57D6C2 for ; Mon, 11 Feb 2019 03:22:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 19ACF29AF5 for ; Mon, 11 Feb 2019 03:22:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0D8A129AF7; Mon, 11 Feb 2019 03:22:48 +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,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 704BE29AF5 for ; Mon, 11 Feb 2019 03:22:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6D5FE6E13B; Mon, 11 Feb 2019 03:22:42 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by gabe.freedesktop.org (Postfix) with ESMTPS id BBA026E0EE; Mon, 11 Feb 2019 03:22:39 +0000 (UTC) Received: by mail-wm1-x342.google.com with SMTP id r17so14528640wmh.5; Sun, 10 Feb 2019 19:22:39 -0800 (PST) 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=5Zf+bNqcnSOdY5DubBuACKrreVcvr0qL2xZNZJm/Yvw=; b=jTA7w/YfceMZdNuiXbPoEBOy6J8jqojB1amWqgiK5UzTB9WVNzxzOKWTmNpNoVD7UX J6QAQyF+7I19F90Bv8tLkAy7sSIOJsA0svG7518M/C4aIWxOQ6deN8jvNhtCWi58+/zq fmdEqdLJbp34IvOkaJ/X4SZhwKVlqzID7AekJfP4wxZjmYP6jqq6wKysO8h1NdWaJMdr oPQaFwvwewjfETgGLtEoTVNWhFkgY+mY5Sh4yJHTo1boNjcXdCxFUH9c8DUrjvGHegXv bCP63X24nWm2EFoLkdohs3v0L0WxoI5CDSUezAHwmC+sTEbOUyvqtVd6BN3N7iVE4RjH wusQ== X-Gm-Message-State: AHQUAuY+AT4ST7I1I08WFgQDdzZaTUJ2Hy5gl1PPwc2EHpFW6vue43tT thalTrtAIGGnBbdMVFazBAdCzLj/ X-Google-Smtp-Source: AHgI3IbahV8XDXCODwvKFiApW3iMTXHUoMGKxExNIugUfUeCyNXD6WhwaQJc36ic5G3o8Q0HP+mIbw== X-Received: by 2002:a5d:52c3:: with SMTP id r3mr6362723wrv.163.1549855358164; Sun, 10 Feb 2019 19:22:38 -0800 (PST) Received: from twisty.cin.medizin.uni-tuebingen.de ([2a01:c23:8429:3400:e9fd:d3f1:412c:598a]) by smtp.gmail.com with ESMTPSA id m21sm19379971wmi.43.2019.02.10.19.22.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Feb 2019 19:22:37 -0800 (PST) From: Mario Kleiner To: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH 1/3] drm/amdgpu: Fix get_crtc_scanoutpos behavior in vrr when vpos >= vtotal. Date: Mon, 11 Feb 2019 04:22:23 +0100 Message-Id: <20190211032225.9488-2-mario.kleiner.de@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190211032225.9488-1-mario.kleiner.de@gmail.com> References: <20190211032225.9488-1-mario.kleiner.de@gmail.com> 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: michel@daenzer.net, stable@vger.kernel.org, Alex Deucher , Nicholas Kazlauskas MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP This reverts commit 520f08df45fbe300ed650da786a74093d658b7e1 ("drm/amdgpu: Correct get_crtc_scanoutpos behavior when vpos >= vtotal") While the explanation in that commit is correct wrt. the hardware counter sometimes returning a position >= vtotal in vrr mode if the query happens while we are inside the "extended front porch", the math without this commit still returns the desired *vpos value for achieving a proper vblank timestamping behavior in vrr mode, according to the kernel documentation about how vblank timestamps should behave in vrr mode. According to the vrr mode docs, the vblank timestamp (calculated by drm_calc_vbltimestamp_from_scanoutpos()) is always supposed to be the one corresponding to the end of vblank as if vblank duration is == minimum vblank duration under vrr == vblank duration of the regular fixed refresh rate mode timing. Iow. it must be the same timestamp as would show up in non-vrr mode, even if the current vblank may be much longer (by an unknown amount of time), due to an extended front porch duration. Doing the math on this shows that we get the correct *vpos values to feed into the drm_calc_vbltimestamp_from_scanoutpos() helper for this to happen by using exactly the same correction: *vpos = *vpos - vtotal - vbl_end Therefore we don't need any special case for *vpos >= vtotal and the special case would cause wrong timestamps. The only quirk compared to non-vrr mode is that this can return a *vpos >= 0 despite being in vblank, ie. while returning the DRM_SCANOUTPOS_IN_VBLANK flag. Auditing all callers of the function shows this doesn't matter, as they all use the dedicated DRM_SCANOUTPOS_IN_VBLANK flag to check for "in vblank", but not the sign of *vpos. This patch should make sure that amdgpu_display_get_crtc_scanoutpos() always returns a *vpos value which leads to a stable vblank timestamp, regardless where the scanout position is during the function call. This stability is important to not confuse the vblank_disable_immediate logic in DRM cores vblank counting, and to provide some stable timestamp for future improvements of the pageflip timestamping under vrr. Fixes: 520f08df45fb ("drm/amdgpu: Correct get_crtc_scanoutpos behavior when vpos >= vtotal") Signed-off-by: Mario Kleiner Cc: Cc: Nicholas Kazlauskas Cc: Harry Wentland Cc: Alex Deucher --- drivers/gpu/drm/amd/amdgpu/amdgpu_display.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c index 4e944737b708..13da4e3549f6 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c @@ -779,12 +779,22 @@ bool amdgpu_display_crtc_scaling_mode_fixup(struct drm_crtc *crtc, * Returns vpos as a positive number while in active scanout area. * Returns vpos as a negative number inside vblank, counting the number * of scanlines to go until end of vblank, e.g., -1 means "one scanline - * until start of active scanout / end of vblank." + * until start of active scanout / end of vblank." Note that in variable + * refresh rate mode (vrr), vpos may be positive inside the extended front + * porch, despite being inside vblank, and a negative number does not + * always define the number of scanline to true end of vblank. Instead + * the vpos values behave as if the crtc would operate in fixed refresh + * rate mode. This allows the drm_calc_vbltimestamp_from_scanoutpos() + * helper to calculate appropriate and stable vblank timestamps as specified + * for vrr mode - corresponding to the shortest vblank duration under vrr. + * In vrr mode therefore check the returned Flags for presence of + * DRM_SCANOUTPOS_IN_VBLANK to detect if the scanout is currently inside + * or outside true vblank. * * \return Flags, or'ed together as follows: * * DRM_SCANOUTPOS_VALID = Query successful. - * DRM_SCANOUTPOS_INVBL = Inside vblank. + * DRM_SCANOUTPOS_IN_VBLANK = Inside vblank. * DRM_SCANOUTPOS_ACCURATE = Returned position is accurate. A lack of * this flag means that returned position may be offset by a constant but * unknown small number of scanlines wrt. real scanout position. @@ -876,12 +886,7 @@ int amdgpu_display_get_crtc_scanoutpos(struct drm_device *dev, /* Inside "upper part" of vblank area? Apply corrective offset if so: */ if (in_vbl && (*vpos >= vbl_start)) { vtotal = mode->crtc_vtotal; - - /* With variable refresh rate displays the vpos can exceed - * the vtotal value. Clamp to 0 to return -vbl_end instead - * of guessing the remaining number of lines until scanout. - */ - *vpos = (*vpos < vtotal) ? (*vpos - vtotal) : 0; + *vpos = *vpos - vtotal; } /* Correct for shifted end of vbl at vbl_end. */ From patchwork Mon Feb 11 03:22:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Kleiner X-Patchwork-Id: 10805075 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 5FA171399 for ; Mon, 11 Feb 2019 03:22:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4EA4229AF5 for ; Mon, 11 Feb 2019 03:22:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 431CC29AF7; Mon, 11 Feb 2019 03:22:51 +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,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 B967629AF5 for ; Mon, 11 Feb 2019 03:22:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3EEF86E13D; Mon, 11 Feb 2019 03:22:43 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by gabe.freedesktop.org (Postfix) with ESMTPS id D9CF16E0EE; Mon, 11 Feb 2019 03:22:40 +0000 (UTC) Received: by mail-wm1-x341.google.com with SMTP id d15so14627503wmb.3; Sun, 10 Feb 2019 19:22:40 -0800 (PST) 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=aUgaiamsxd0F5YBMAsN3rEhaeOiEltCMxggsxzGz9GY=; b=q/2Znu4A2pf/++g5imcjsvhK67O5+EhNaSVRm4iE/tg9LjbhOUb/UGrI2pSAWgVQRu PxYS0uYf4D7OxhUMS//5YjlFgnRK63XyvVlSknhChchbBiJKc4xouM7wZM3jxrmlS878 GUG0IZ/6d9beOoWlDKvz43hSjtNTC+b9O3jIwKoTzAIiv31tNgfBrtg7DVdZh314MGEc j0JkUu6NHUwKJo4I3Xs7wl1i7r72X9ze8FMSc34nQzR3FbkbvSESS2XFX+kEGANSosUf VGfFbmHnCViBwaW4IYgP3CCI9Jrwbya8zk6EQdVxaG1m3htnFkIPCxO3kfI/BEnbkFdy hoQQ== X-Gm-Message-State: AHQUAuZkR+8j/GJvxv56W8Oz8PyW+m38xCsZppqUOctgVrxO97+3nxuI 6GKsvb1aCF/vjCoQaGEykNvU85RF X-Google-Smtp-Source: AHgI3IZHBObIURpWZ6/FhWBugR8ZBsx8odN6Lo9GZOVbrwizh2PnyzsXX4V6E3e/LFhg0ZYsQM3q1Q== X-Received: by 2002:a5d:6b8b:: with SMTP id n11mr24759174wrx.216.1549855359243; Sun, 10 Feb 2019 19:22:39 -0800 (PST) Received: from twisty.cin.medizin.uni-tuebingen.de ([2a01:c23:8429:3400:e9fd:d3f1:412c:598a]) by smtp.gmail.com with ESMTPSA id m21sm19379971wmi.43.2019.02.10.19.22.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Feb 2019 19:22:38 -0800 (PST) From: Mario Kleiner To: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH 2/3] drm: Add basic helper to allow precise pageflip timestamps in vrr. Date: Mon, 11 Feb 2019 04:22:24 +0100 Message-Id: <20190211032225.9488-3-mario.kleiner.de@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190211032225.9488-1-mario.kleiner.de@gmail.com> References: <20190211032225.9488-1-mario.kleiner.de@gmail.com> 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: Alex Deucher , michel@daenzer.net, Nicholas Kazlauskas MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP The pageflip completion timestamps transmitted to userspace via pageflip completion events are supposed to describe the time at which the first pixel of the new post-pageflip scanout buffer leaves the video output of the gpu. This time is identical to end of vblank, when active scanout starts. For a crtc in standard fixed refresh rate, the end of vblank is identical to the vblank timestamps calculated by drm_update_vblank_count() at each vblank interrupt, or each vblank dis-/enable. Therefore pageflip events just carry that vblank timestamp as their pageflip timestamp. For a crtc switched to variable refresh rate mode (vrr), the pageflip completion timestamps are identical to the vblank timestamps iff the pageflip was executed early in vblank, before the minimum vblank duration elapsed. In this case the time of display onset is identical to when the crtc is running in fixed refresh rate. However, if a pageflip completes later in the vblank, inside the "extended front porch" in vrr mode, then the vblank will terminate at a fixed (back porch) duration after flip, so the display onset time is delayed correspondingly. In this case the vblank timestamp computed at vblank irq time would be too early, and we need a way to calculate an estimated pageflip timestamp that will be later than the vblank timestamp. How a driver determines such a "late flip" timestamp is hw and driver specific, but this patch adds a new helper function that allows the driver to propose such an alternate "late flip" timestamp for use in pageflip events: drm_crtc_set_vrr_pageflip_timestamp(crtc, flip_timestamp); When sending out pageflip events, we now compare that proposed flip_timestamp against the vblank timestamp of the current vblank of flip completion and choose to send out the greater/ later timestamp as flip completion timestamp. The most simple way for a kms driver to supply a suitable flip_timestamp in vrr mode would be to simply take a timestamp at start of the pageflip completion handler, e.g., pageflip irq handler: flip_timestamp = ktime_get(); and then set that as proposed "late" alternative timestamp via ... drm_crtc_set_vrr_pageflip_timestamp(crtc, flip_timestamp); More clever approaches could try to add some corrective offset for fixed back porch duration, or ideally use hardware features like hw timestamps to calculate the exact end time of vblank. Signed-off-by: Mario Kleiner Cc: Nicholas Kazlauskas Cc: Harry Wentland Cc: Alex Deucher --- drivers/gpu/drm/drm_vblank.c | 49 +++++++++++++++++++++++++++++++++++- include/drm/drm_vblank.h | 8 ++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c index 98e091175921..4b3a4c38fabe 100644 --- a/drivers/gpu/drm/drm_vblank.c +++ b/drivers/gpu/drm/drm_vblank.c @@ -814,10 +814,21 @@ static void send_vblank_event(struct drm_device *dev, u64 seq, ktime_t now) { struct timespec64 tv; + ktime_t alt_flip_time; switch (e->event.base.type) { - case DRM_EVENT_VBLANK: case DRM_EVENT_FLIP_COMPLETE: + /* + * For flip completion events, override "now" time + * with alt_flip_time provided by the driver via + * drm_crtc_set_vrr_pageflip_timestamp() in VRR mode + * if that time is later than given "now" vblank time. + */ + alt_flip_time = dev->vblank[e->pipe].alt_flip_time; + if (alt_flip_time > now) + now = alt_flip_time; + /* Fallthrough */ + case DRM_EVENT_VBLANK: tv = ktime_to_timespec64(now); e->event.vbl.sequence = seq; /* @@ -916,11 +927,47 @@ void drm_crtc_send_vblank_event(struct drm_crtc *crtc, now = ktime_get(); } + e->pipe = pipe; send_vblank_event(dev, e, seq, now); } EXPORT_SYMBOL(drm_crtc_send_vblank_event); +/** + * drm_crtc_set_vrr_pageflip_timestamp - helper to set alternate pageflip time + * @crtc: the source CRTC of the pageflip completion event + * @flip_time: The alternate pageflip completion timestamp in VRR mode + * + * In variable refresh rate mode (VRR), a pageflip completion timestamp carried + * by the pageflip event can never be earlier than the vblank timestamp of the + * vblank of flip completion, as that vblank timestamp defines the end of the + * shortest possible vblank duration. In case of a delayed flip completion + * inside the extended VRR front porch however, the end of vblank can be much + * later, so the driver must assign an estimated timestamp of that later end of + * vblank. For a CRTC in VRR mode, the driver should use this helper function to + * set an alternate flip completion timestamp in case of late flip completions + * in extended vblank. In the most simple case, this @flip_time timestamp could + * simply be a ktime_get() timestamp taken at the start of the pageflip + * completion routine, with some constant duration of the back porch interval + * added, although more precise estimates may be possible on some hardware if + * the hardware provides some means of timestamping the true end of vblank. + * + * When sending out pageflip events, e.g., via drm_crtc_send_vblank_event(), it + * will use either the standard vblank timestamp, calculated for a minimum + * duration vblank, or the provided @flip_time if that time is later than the + * vblank timestamp, to get the best possible estimate of start of display of + * the new post-pageflip scanout buffer. + */ +void drm_crtc_set_vrr_pageflip_timestamp(struct drm_crtc *crtc, + ktime_t flip_time) +{ + struct drm_device *dev = crtc->dev; + struct drm_vblank_crtc *vblank = &dev->vblank[drm_crtc_index(crtc)]; + + vblank->alt_flip_time = flip_time; +} +EXPORT_SYMBOL(drm_crtc_set_vrr_pageflip_timestamp); + static int __enable_vblank(struct drm_device *dev, unsigned int pipe) { if (drm_core_check_feature(dev, DRIVER_MODESET)) { diff --git a/include/drm/drm_vblank.h b/include/drm/drm_vblank.h index 6ad9630d4f48..aacf44694ab6 100644 --- a/include/drm/drm_vblank.h +++ b/include/drm/drm_vblank.h @@ -117,6 +117,12 @@ struct drm_vblank_crtc { * @time: Vblank timestamp corresponding to @count. */ ktime_t time; + /** + * @alt_flip_time: Vblank timestamp for end of extended vblank due to + * a late pageflip completion in variable refresh rate mode. Pageflip + * events will carry the later one of @time and @alt_flip_time. + */ + ktime_t alt_flip_time; /** * @refcount: Number of users/waiters of the vblank interrupt. Only when @@ -179,6 +185,8 @@ int drm_vblank_init(struct drm_device *dev, unsigned int num_crtcs); u64 drm_crtc_vblank_count(struct drm_crtc *crtc); u64 drm_crtc_vblank_count_and_time(struct drm_crtc *crtc, ktime_t *vblanktime); +void drm_crtc_set_vrr_pageflip_timestamp(struct drm_crtc *crtc, + ktime_t flip_time); void drm_crtc_send_vblank_event(struct drm_crtc *crtc, struct drm_pending_vblank_event *e); void drm_crtc_arm_vblank_event(struct drm_crtc *crtc, From patchwork Mon Feb 11 03:22:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Kleiner X-Patchwork-Id: 10805073 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 C3AB61399 for ; Mon, 11 Feb 2019 03:22:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B375729AF5 for ; Mon, 11 Feb 2019 03:22:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A7C1629AF7; Mon, 11 Feb 2019 03:22:49 +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,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 5184629AF5 for ; Mon, 11 Feb 2019 03:22:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9FA6F6E140; Mon, 11 Feb 2019 03:22:43 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by gabe.freedesktop.org (Postfix) with ESMTPS id DAA5D6E13B; Mon, 11 Feb 2019 03:22:41 +0000 (UTC) Received: by mail-wm1-x344.google.com with SMTP id p6so14027579wmc.1; Sun, 10 Feb 2019 19:22:41 -0800 (PST) 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=0EBqAd+WxitKG+JFyjCmHosRHtKgny8ARrlJtTQQP7Q=; b=oAptQsgr4pY8weWFOJZFyeqNABDBmY/s9G9DV1Gp+K4qHa7X/IiL6J049ey/UMghIM R51kYgbnL1raeCnUkjnEpbvsWcOPa60L1w4zNQV5y1wZpZg81s/jH3zKJBZ6RX6SZAyb 8w7yWJpMWDpNnsb3ukq9JuOcgSIggg+5JHfFk5HfEBjWDtSnNYjm8ekUroftvzUQ5k0j JqNwgJlrr9P34elv7v0pD9ZgnJLyR9ZiCBUKkpC9sM922/ObsXviOeWSVhyTkfhjvvFh 95sokCpPLv5NrDkaoFMiAqomcllx5z1YlMIw2b4Dm1E34MvuRVCbAYiZzU2zg+KRjr9M WjMg== X-Gm-Message-State: AHQUAubMI1y1v+yOVq+PWoz45C/B8hEml9v17R1VGDfBGyCpNUUP1OGl n6pZjW53TR1l7jxz0l4yWuikQC9l X-Google-Smtp-Source: AHgI3IZIL9uEpXO/NotYVt1Qwu0nnYqze7E/L/bk9n3zzD1QDSi7gOzQxdy8kk5rttjlQskr+2wgNQ== X-Received: by 2002:a05:6000:6:: with SMTP id h6mr24813872wrx.68.1549855360384; Sun, 10 Feb 2019 19:22:40 -0800 (PST) Received: from twisty.cin.medizin.uni-tuebingen.de ([2a01:c23:8429:3400:e9fd:d3f1:412c:598a]) by smtp.gmail.com with ESMTPSA id m21sm19379971wmi.43.2019.02.10.19.22.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Feb 2019 19:22:39 -0800 (PST) From: Mario Kleiner To: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH 3/3] drm/amd/display: Provide more accurate pageflip timestamps in vrr mode. Date: Mon, 11 Feb 2019 04:22:25 +0100 Message-Id: <20190211032225.9488-4-mario.kleiner.de@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190211032225.9488-1-mario.kleiner.de@gmail.com> References: <20190211032225.9488-1-mario.kleiner.de@gmail.com> 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: Alex Deucher , michel@daenzer.net, Nicholas Kazlauskas MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP This implements more accurate pageflip completion timestamps for crtc's running in variable refresh rate mode. In vrr mode, the pageflip completion interrupt handler takes a ktime_get() timestamp of pageflip completion as a at least roughly correct lower estimate of when the vblank of flip completion will end and thereby display of the new scanout buffer will start. It submits this proposed timestamp via the new helper function drm_crtc_set_vrr_pageflip_timestamp(). The DRM core will decide when sending out pageflip events, if the regular vblank timestamp gets sent out, or this alternate later timestamp, following the rule that a post-flip buffer can't start displaying earlier than the vblank timestamp, which corresponds to the end of the shortest possible vblank interval under vrr mode. This is a crude first implementation, but it should reduce pageflip timestamp errors from potentially dozens of milliseconds to probably less than 2 msecs in the common case, given the fixed and short back-porch duration and the usually low interrupt dispatch delay from pageflip interrupt. Signed-off-by: Mario Kleiner Cc: Nicholas Kazlauskas Cc: Harry Wentland Cc: Alex Deucher --- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c index d4da331aa349..49c5a044297f 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c @@ -280,7 +280,9 @@ static void dm_pflip_high_irq(void *interrupt_params) struct amdgpu_crtc *amdgpu_crtc; struct common_irq_params *irq_params = interrupt_params; struct amdgpu_device *adev = irq_params->adev; + struct dm_crtc_state *acrtc_state; unsigned long flags; + ktime_t t_onset = ktime_get(); amdgpu_crtc = get_crtc_by_otg_inst(adev, irq_params->irq_src - IRQ_TYPE_PFLIP); @@ -306,6 +308,24 @@ static void dm_pflip_high_irq(void *interrupt_params) /* Update to correct count(s) if racing with vblank irq */ amdgpu_crtc->last_flip_vblank = drm_crtc_accurate_vblank_count(&amdgpu_crtc->base); + /* VRR pageflip timestamp handling: In VRR mode, compute alternate flip + * timestamp for flip completion in extended front porch, ie. estimating + * the time of the end of a longer than minimum vblank interval. DRM + * will decide to use this alternate timestamp, or the standard vblank + * timestamp for minimum duration vblank. The later timestamp is the one + * chosen for the pageflip event. + */ + acrtc_state = to_dm_crtc_state(amdgpu_crtc->base.state); + if (acrtc_state->freesync_config.state == VRR_STATE_ACTIVE_VARIABLE) { + /* FIXME: t_onset is just a pflip irq timestamp taken above. + * Add the fixed back-porch duration? Or even better use some + * hardware trickery to get a more precise estimate of true + * end of vblank? + */ + /* Propose "late" vblank end timestamp for consideration. */ + drm_crtc_set_vrr_pageflip_timestamp(&amdgpu_crtc->base, t_onset); + } + /* wake up userspace */ if (amdgpu_crtc->event) { drm_crtc_send_vblank_event(&amdgpu_crtc->base, amdgpu_crtc->event);