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);