From patchwork Mon Apr 24 16:54:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mario Kleiner X-Patchwork-Id: 9696787 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 00083603F2 for ; Mon, 24 Apr 2017 16:54:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E3AF528305 for ; Mon, 24 Apr 2017 16:54:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D7152283FE; Mon, 24 Apr 2017 16:54:50 +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 563A428305 for ; Mon, 24 Apr 2017 16:54:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BD8846E271; Mon, 24 Apr 2017 16:54:48 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr0-x241.google.com (mail-wr0-x241.google.com [IPv6:2a00:1450:400c:c0c::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1D2676E270; Mon, 24 Apr 2017 16:54:47 +0000 (UTC) Received: by mail-wr0-x241.google.com with SMTP id 6so7518554wrb.1; Mon, 24 Apr 2017 09:54:47 -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:mime-version :content-transfer-encoding; bh=wCB4sPn/xNI5ZmuwWtMJQpAT3UDPHqYpCo3pYxXX63M=; b=LNTFH2eulN8PEmg4D5bQw03E55S82TOCSTyT0NEPvNQCqMxHuYonHfzbE7FTL8LCus irVkI1Ja9scubAFsSoVImuHMSY5ZPHMYYXEvo+VWheEWQZ5gDBFWnBsoIyASXyog8eyL kdZGDOL3DH+80UaVM2ves71B0o16v9CpTC/hF44oF+9CyhueDwdGMfLd6O+CsqhHaddh uwgSg1ATlFfI+phJwCV1KZtdVgGzOsH6DSSSXMjV/cA3WHa6FthtMFC7knksiLVF6QlU JDNjzrG8xI81W2m2l0Krsi7BVrPdJaljA5ZbYmpFV3wxM/Ip2o0uvQOM2MHph+KYzy/x dWFA== 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:mime-version :content-transfer-encoding; bh=wCB4sPn/xNI5ZmuwWtMJQpAT3UDPHqYpCo3pYxXX63M=; b=qf5339D1F4b5DRsjojqKgcN/XmIElJW76k8l6HUravyXCuyXOocNnkjNHgosO7xafF s3vsl8s1WQpvSg2g629UJ968uKAp3nRTp8mU6+gjcc64UYEeT8zSHPw2k//3ODekWKx2 KEgl0UpcV+ZJclMrxACo4BkBsZ2mLPgj4WlHKlKs/S82Ze+eEbAKFAvNe9Q4FMhgeNtR 4RYfGfgfsBPfPJdfrOZlS9ZsUjYueHSLd04vyGtcs8fjg3Ats/4zjMmwyE2GNl/j6B7N 120G+SGAlJ+vXjj8opZZRYX6ff6DOgctRf+PtzHSWSKEk2z1B9yjQuheZg3X6Odp6UnP 9g3g== X-Gm-Message-State: AN3rC/515sVoevrJYWVZM0OP0zntgzsR+o1Xv0v1SwXVDtFVjSi6Mhh8 QUZPaOKPo1rpUw== X-Received: by 10.223.136.131 with SMTP id f3mr6773688wrf.118.1493052885753; Mon, 24 Apr 2017 09:54:45 -0700 (PDT) Received: from twisty.cin.medizin.uni-tuebingen.de (cin-11.medizin.uni-tuebingen.de. [134.2.118.242]) by smtp.gmail.com with ESMTPSA id l82sm910931wmf.17.2017.04.24.09.54.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 24 Apr 2017 09:54:44 -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. (v3) Date: Mon, 24 Apr 2017 18:54:20 +0200 Message-Id: <1493052860-15178-1-git-send-email-mario.kleiner.de@gmail.com> X-Mailer: git-send-email 2.7.0 MIME-Version: 1.0 Cc: =?UTF-8?q?Michel=20D=C3=A4nzer?= , amd-gfx@lists.freedesktop.org, Alex Deucher 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', unless this is a DRM_MODE_PAGE_FLIP_ASYNC async pageflip, which must always execute as soon as possible. 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. v2: Add acked/r-b by Harry and Michel. v3: Feedback from Andrey: Must not wait an extra frame for DRM_MODE_PAGE_FLIP_ASYNC flips. Signed-off-by: Mario Kleiner Acked-by: Harry Wentland Reviewed-by: Michel Dänzer Cc: Harry Wentland Cc: Alex Deucher Cc: Michel Dänzer Reviewed-by: Andrey Grodzovsky --- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_types.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 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..82b2ce6 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, @@ -2760,14 +2759,15 @@ void amdgpu_dm_atomic_commit_tail( pflip_needed = !state->allow_modeset; if (pflip_needed) { + wait_for_vblank = + acrtc->flip_flags & DRM_MODE_PAGE_FLIP_ASYNC ? + false : true; + amdgpu_dm_do_flip( - crtc, - fb, - drm_crtc_vblank_count(crtc)); + crtc, + fb, + drm_crtc_vblank_count(crtc) + wait_for_vblank); - wait_for_vblank = - acrtc->flip_flags & DRM_MODE_PAGE_FLIP_ASYNC ? - false : true; /*clean up the flags for next usage*/ acrtc->flip_flags = 0; }