From patchwork Fri Apr 21 16:23:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mario Kleiner X-Patchwork-Id: 9693131 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 512806038D for ; Fri, 21 Apr 2017 16:23:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4316F28334 for ; Fri, 21 Apr 2017 16:23:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 37A5928630; Fri, 21 Apr 2017 16:23:42 +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 9932028334 for ; Fri, 21 Apr 2017 16:23:41 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B12D56E5CE; Fri, 21 Apr 2017 16:23:40 +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 6D4CB6E5CE; Fri, 21 Apr 2017 16:23:39 +0000 (UTC) Received: by mail-wm0-x242.google.com with SMTP id d79so5787012wmi.2; Fri, 21 Apr 2017 09:23:39 -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=XbRgJPoozwyjQ6a5HCVdc5/mcgKiA+odTDqFw25JkW8=; b=DLyFRlc0nGcbF870I/VuURCy/uL9aK0hPkJKma48y0dOEqWDGhQ5GdlrwUPxGuvIJP icdub8lG2eGGwHfnLTzhiujBUJ27lzpHJcLeKqzcRFrdEDg69NK8ELhR79VacZtEHQau ebYrTMc49+uqRQmhx1B7YrsdRGZeK1YBiVqGDE6LMNCjMMDCoCslrBbE0ClkznXiAAIG wJHcG2oi9UwX9oG+JkrdcG6lZ/FIVPnZp0e29jFh+Xj0+xQoApChUd/FnJ7+YMyTV2OO y9enNMW5kIBUfVvDYb7qAzE8UjcZRLmGqM/aqijwjVBFTcvj+CZDbAYjmkCQkp8Drr5f dBQQ== 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=XbRgJPoozwyjQ6a5HCVdc5/mcgKiA+odTDqFw25JkW8=; b=N8fnWYDz16PUHmp+jyr9LKOXWcHtJNA9xq+zFg2ZCRS29zcQRcpGlS6jGDVNJ/B9Ik OGmgMdfqlFYjSs03yVrF1zdu0Wt7IH/P1zHtGVOwH1wwHRXkG+MUOEa+DTfqembyzsSk K+6+uTalyrQ87F+6XoqO9doFGkPfSxn+7c8iPF9WzOpDavA11eBzN0QjulsZTcV/Fjzy MDXcmhp5zM1KPTLX0BiEJHyv0U47aR2cpj5XoycS6HMV+xM1WimU29eaY9EbuDMyg4xH gRn8TV0LdvGFTuMOZmfx/xcbXZyglKLZo3vXCKAyMkPFN5Fo5GLUi7pDAqc8QjUAluZP gpLQ== X-Gm-Message-State: AN3rC/7tWjZ3CJPxRYSkBvr4mmujtzKG73U7kjJeIgi2N1LdKvg3LXJS 0JWrHmHnOp4J8Tny X-Received: by 10.80.151.8 with SMTP id c8mr63064edb.161.1492791817865; Fri, 21 Apr 2017 09:23:37 -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.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 21 Apr 2017 09:23:37 -0700 (PDT) From: Mario Kleiner To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/2] drm/amd/display: Fix race between vblank irq and pageflip irq. Date: Fri, 21 Apr 2017 18:23:05 +0200 Message-Id: <1492791786-24543-2-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: michel.daenzer@amd.com, amd-gfx@lists.freedesktop.org, alexander.deucher@amd.com 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 Since DC now uses CRTC_VERTICAL_INTERRUPT0 as VBLANK irq trigger and vblank interrupts actually happen earliest at start of vblank, instead of a bit before vblank, we no longer need some of the fudging logic to deal with too early vblank irq handling (grep for lb_vblank_lead_lines). This itself fixes a pageflip scheduling bug in DC, caused by uninitialized use of lb_vblank_lead_lines, with a wrong startup value of 0. Thanks to the new vblank irq trigger this value of zero is now actually correct for DC :). A new problem is that vblank irq's race against pflip irq's, and as both can fire at first line of vblank, it is no longer guaranteed that vblank irq handling (therefore -> drm_handle_vblank() -> drm_update_vblank_count()) executes before pflip irq handling for a given vblank interval when a pageflip completes. Therefore the vblank count and timestamps emitted to user-space as part of the pageflip completion event will be often stale and cause new timestamping and swap scheduling errors in user-space. This was observed with large frequency on R9 380 Tonga Pro. Fix this by enforcing a vblank count+timestamp update right before emitting the pageflip completion event from the pflip irq handler. The logic in core drm_update_vblank_count() makes sure that no redundant or conflicting updates happen, iow. the call turns into a no-op if it wasn't needed for that vblank, burning a few microseconds of cpu time though. Successfully tested on AMD R9 380 "Tonga Pro" (VI/DCE 10) with DC enabled on the current DC staging branch. Independent measurement of pageflip completion timing with special hardware measurement equipment now confirms correct pageflip timestamps and counts in the pageflip completion events. Note that there is another unresolved pageflip bug present in current dc staging, which causes pageflips to complete one vblank too early when the pageflip ioctl gets called while in vblank. Something seems to be amiss in the way amdgpu_dm_do_flip() handles 'target_vblank', or how amdgpu_dm_atomic_commit_tail() computes 'target' for calling amdgpu_dm_do_flip(). Signed-off-by: Mario Kleiner Cc: Harry Wentland Cc: Andrey Grodzovsky Cc: Alex Deucher Cc: Michel Dänzer Reviewed-by: Michel Dänzer --- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 3 +++ 1 file changed, 3 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 794362e..0d77b0a 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c @@ -208,6 +208,9 @@ static void dm_pflip_high_irq(void *interrupt_params) if (amdgpu_crtc->event && amdgpu_crtc->event->event.base.type == DRM_EVENT_FLIP_COMPLETE) { + /* Update to correct count/ts if racing with vblank irq */ + drm_accurate_vblank_count(&amdgpu_crtc->base); + drm_crtc_send_vblank_event(&amdgpu_crtc->base, amdgpu_crtc->event); /* page flip completed. clean up */ amdgpu_crtc->event = NULL;