From patchwork Mon Apr 24 09:46:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mario Kleiner X-Patchwork-Id: 9695949 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 6A730601AE for ; Mon, 24 Apr 2017 09:47:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 59EE820243 for ; Mon, 24 Apr 2017 09:47:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E3312094F; Mon, 24 Apr 2017 09:47:52 +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 076AD20243 for ; Mon, 24 Apr 2017 09:47:51 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A0D806E1E0; Mon, 24 Apr 2017 09:47:50 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x242.google.com (mail-wm0-x242.google.com [IPv6:2a00:1450:400c:c09::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id C20EA6E1E0; Mon, 24 Apr 2017 09:47:49 +0000 (UTC) Received: by mail-wm0-x242.google.com with SMTP id d79so15969275wmi.2; Mon, 24 Apr 2017 02:47:49 -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=R4vo8NFkqsFx6+DBgss+eVM2oDBcQn6QZvb57MIpxdg=; b=Mx0InCEC7CG+/2TJ/Ed8EnrSh3qwIOipN3ArxDnb8IpO0fxiWApdEfG/PEbXsTdS+T pzfnjrDsXVq1k6GvKyfRwGPF6OpkTSta3gIa3zSZqbgO+Aa48S+YPD47jroCwgJGgcen Bm3MmZuQHBa54TQj0BPb/mwb7F1cD0naHS30ITdiCX66ORpN0OAyfcFySzPktbhLpX94 FDpNpBClZkeH0qIscFd1gmxOabHaI4YBqZHyXS+88tk1hfpIrXbcTVtVqnatxC5jDQmV GX04jIhmCYz+LeLLvWHmomZs2RJNI/8xRtOaECOS6pD5uCpDg9sFc+CBsQAF+QUaMna5 FBbg== 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=R4vo8NFkqsFx6+DBgss+eVM2oDBcQn6QZvb57MIpxdg=; b=ECn8HjY0E4fXSrXLWnPgiVv8q3xiamqjzm0CuN5XtyNrnZGVYplNZrfoe59468f1qC MPQVAj/0i+oqJ0UBIzZo58HOC9F/2i8ijgoRK2aDqpzuZDTOGjJTMoVXVxzDQKZiGiXY 5mvfSNVMpmlgaqUQgD5vV51h30QijpwD6Qi5cevUp2zc/XlU5xdvjFv3Fu9YzhmuhkGy KyW2bffezf1h/Cf1k1WfYgTvK2AYUcmXUGRCVfptiplG+YUu1tzJqIMq5AManRHNLOP2 /0PIvZHdmp4zICDIf+b1HAny6NBcTXNXcc1qQS+1dSZi0FCFHWdnSeS+On5e8gkAnvbn t/Lw== X-Gm-Message-State: AN3rC/6c1Kyuxijzclw8pwbB9eGa6HfOdwbWF+ENK/5JrBLE+++9xpgq TRUkCk4XN/z1AA== X-Received: by 10.28.146.207 with SMTP id u198mr8817560wmd.103.1493027268496; Mon, 24 Apr 2017 02:47:48 -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 u88sm1013704wrc.20.2017.04.24.02.47.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 24 Apr 2017 02:47:47 -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. (v2) Date: Mon, 24 Apr 2017 11:46:45 +0200 Message-Id: <1493027205-13069-2-git-send-email-mario.kleiner.de@gmail.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1493027205-13069-1-git-send-email-mario.kleiner.de@gmail.com> References: <1493027205-13069-1-git-send-email-mario.kleiner.de@gmail.com> MIME-Version: 1.0 Cc: Alex Deucher , =?UTF-8?q?Michel=20D=C3=A4nzer?= , 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. v2: Add acked/r-b by Harry and Michel. Signed-off-by: Mario Kleiner Acked-by: Harry Wentland Reviewed-by: Michel Dänzer Cc: Harry Wentland Cc: Alex Deucher Cc: 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 ?