From patchwork Fri Apr 21 16:23:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mario Kleiner X-Patchwork-Id: 9693133 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 3600D601D4 for ; Fri, 21 Apr 2017 16:23:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 283EF28334 for ; Fri, 21 Apr 2017 16:23:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1CE7728630; Fri, 21 Apr 2017 16:23:44 +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 C52F328334 for ; Fri, 21 Apr 2017 16:23:43 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 01DB46E5D2; Fri, 21 Apr 2017 16:23:43 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1760B6E5D2; Fri, 21 Apr 2017 16:23:42 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id z129so5781985wmb.1; Fri, 21 Apr 2017 09:23:42 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=nl1Dg/3E3kqpRq1c/eZW3xvumwflrbu+xK85dsot8zw=; b=DMWVVt6520aLz/MPVk/lyerrdMRjY+4r7k7jc1hgwrHMG3sEi53gyogqnB2x5Gfvg1 noQUsBYuyXSWVFegJyH3IqA/4xSyOX12b34mJ/TtutJDtQsjjUNbjVpTL4hK6rD6IzJC EUZyTKnY82Zy4jkeg6P0NVAb/Ulcmn3H9Wi/00Yc3N0JYaxA9c19VBgEalnr38oQga3E rUoLYUfhHB4kVgTR/gzROcbC3Xf1NMeHXy2DlQFDvEvpb2BJsLFSfVezkXj9DM8wQZEj JtseQG9OaCYKT7HOvn70rd+sT5xAowHokgA/zKiuWTYCeWbXq6Ji66TgxgLAJMjD4pS/ ckkQ== 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:mime-version:content-transfer-encoding; bh=nl1Dg/3E3kqpRq1c/eZW3xvumwflrbu+xK85dsot8zw=; b=uJvXGanTfSj5uwiWSPRuWu7HLXaxlbS7+gf10PrLvTKwc6BkaxOHo5h1i8dwuPdeLt 9T5GMkUnmuYD0Uh+7OvEzFuXlcMs5nM6DxE9XrkX4cduZAtaql+wIFglUBEss/2HqPY+ t+H96m3WGp1GHqSdqEXb2O4BkGSr+wgWNFZi/2ZLeoOE97NDQHaT73JoJJJL6TdoWuTg B4Bm020bhDN7bb8OS6efS8tvFtftBSiX9yLBO5GCBAinoPTk9/pCq0scyDj/NWMXRCN/ mNrZ3401VW6yFjE5EyfscT/qd3o6LJfGb+4VhVKcIDiNk5xqtWTab92Btk3m0pPiD/uq Abnw== X-Gm-Message-State: AN3rC/42mywE4ICNSUbqlV00FJznnHkfc2DjWyN+4twtDkaX46+v2r2Q 74XN3fmtychn6uEj X-Received: by 10.80.170.20 with SMTP id o20mr63613edc.117.1492791820473; Fri, 21 Apr 2017 09:23:40 -0700 (PDT) Received: from twisty.localdomain (x590c7df0.dyn.telefonica.de. [89.12.125.240]) by smtp.gmail.com with ESMTPSA id i28sm519138ede.38.2017.04.21.09.23.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 21 Apr 2017 09:23:39 -0700 (PDT) From: Mario Kleiner To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/2] drm/amd/display: Prevent premature pageflip when comitting in vblank. Date: Fri, 21 Apr 2017 18:23:06 +0200 Message-Id: <1492791786-24543-3-git-send-email-mario.kleiner.de@gmail.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1492791786-24543-1-git-send-email-mario.kleiner.de@gmail.com> References: <1492791786-24543-1-git-send-email-mario.kleiner.de@gmail.com> MIME-Version: 1.0 Cc: alexander.deucher@amd.com, michel.daenzer@amd.com, amd-gfx@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Make sure we do not program a hw pageflip inside vblank 'n' iff the atomic flip is comitted while inside the same vblank 'n'. We must defer such a flip by one refresh cycle to vblank 'n+1'. Without this, pageflips programmed via X11 GLX_OML_sync_control extensions glXSwapBuffersMscOML(..., target_msc, ...); call and/or via DRI3/Present PresentPixmap(..., target_msc, ...); request will complete one vblank too early whenever target_msc > current_msc + 1, ie. more than 1 vblank in the future. In such a case, the call of the pageflip ioctl() would be triggered by a queued drmWaitVblank() vblank event, which itself gets dispatched inside the vblank one frame before the target_msc vblank. Testing with this patch does no longer show any problems with OML_sync_control swap scheduling or flip completion timestamps. Tested on R9 380 Tonga. Signed-off-by: Mario Kleiner Cc: Harry Wentland Cc: Alex Deucher Cc: Michel Dänzer Reviewed-by: Michel Dänzer --- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_types.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_types.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_types.c index 086a842..19be2d9 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_types.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_types.c @@ -2460,6 +2460,9 @@ static void amdgpu_dm_do_flip( struct amdgpu_device *adev = crtc->dev->dev_private; bool async_flip = (acrtc->flip_flags & DRM_MODE_PAGE_FLIP_ASYNC) != 0; + /* Prepare wait for target vblank early - before the fence-waits */ + target_vblank = target - drm_crtc_vblank_count(crtc) + + amdgpu_get_vblank_counter_kms(crtc->dev, acrtc->crtc_id); /*TODO This might fail and hence better not used, wait * explicitly on fences instead @@ -2478,13 +2481,9 @@ static void amdgpu_dm_do_flip( amdgpu_bo_unreserve(abo); - /* Wait for target vblank */ /* Wait until we're out of the vertical blank period before the one * targeted by the flip */ - target_vblank = target - drm_crtc_vblank_count(crtc) + - amdgpu_get_vblank_counter_kms(crtc->dev, acrtc->crtc_id); - while ((acrtc->enabled && (amdgpu_get_crtc_scanoutpos(adev->ddev, acrtc->crtc_id, 0, &vpos, &hpos, NULL, NULL, @@ -2763,7 +2762,7 @@ void amdgpu_dm_atomic_commit_tail( amdgpu_dm_do_flip( crtc, fb, - drm_crtc_vblank_count(crtc)); + drm_crtc_vblank_count(crtc) + 1); wait_for_vblank = acrtc->flip_flags & DRM_MODE_PAGE_FLIP_ASYNC ?