From patchwork Mon Apr 24 09:46:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mario Kleiner X-Patchwork-Id: 9695947 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 3630A601AE for ; Mon, 24 Apr 2017 09:47:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 235E720243 for ; Mon, 24 Apr 2017 09:47:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 161422094F; Mon, 24 Apr 2017 09:47: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=-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 AC8DC20243 for ; Mon, 24 Apr 2017 09:47:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E90276E1D3; Mon, 24 Apr 2017 09:47:46 +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 956BD6E1D3; Mon, 24 Apr 2017 09:47:45 +0000 (UTC) Received: by mail-wm0-x242.google.com with SMTP id z129so15945019wmb.1; Mon, 24 Apr 2017 02:47:45 -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=r74ysUvZTlhOX074lWeoCNplXxnuqz98nvEYznrfGBc=; b=IQN10ROwbw2CmalrXXu5Zg/FL+qvoehWE1TtIDWXqke7Lvo9cwfDMEyI8Ka+wxIVKp gNahghL89+7vBQY3qLfpqrj8pYsl0a7u67hgNF8IVv7BhigZN/lCZ4o9NOHT3lhX8JOj NAV3OJBlxykM3aALiyYG4IFQNyqmz6RvH0r5eWkvhzTx8YaCjZ2n7zQAqGEsSA184qat IQ/OtSZ/4qSrQPRlxiaoJSQD2UOsfwNiRJvBa3hqu3cJy2RYFKbPjWnoENrZFyvMM9w8 kuYNDcAKHDyf4Fx6LrXggvqogNZ+5cLAo/5OmRkq5NlJcytxOoEDPWDeN53owuS3/bX1 9y8Q== 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=r74ysUvZTlhOX074lWeoCNplXxnuqz98nvEYznrfGBc=; b=TQTDYFWPiFFSysfM+i+VKuk8dtcJ2RTt2PHh722TSSJMTJf8jl4IQ1J6+3XOFqdcTL z5X5X6dmgJIh4XMR5BqMkxGshqsaKiqcigPTUw85VlHJV1Iet8mbwLSVLU5AcwIyIWGv ua2pNmmtWqX97cQWXKFcT8DnrBLuBdgoNuEacPnJ7QbmQrHFuhMpCnktzFo/MUfj2MI3 l2WSu9/mRTGkbrinwX2T2J5Jiz9i67A7BQ57+p5AByuAfa2Bkbjsblxev6FKmhADs5Ld tpYZgOv+dEFt6vO3lGk7yrB5mc77dH51Pby3nUkf7mM+Ye0cDFGDXl3XathLmLC9oTOC EfxA== X-Gm-Message-State: AN3rC/7IHtRc19fzwfoonPhOTZcnmbrikCqDaqAceKQJw1CqxBLpQQ3a 6U1dHVZEOw44Vw== X-Received: by 10.28.45.212 with SMTP id t203mr8377244wmt.99.1493027264177; Mon, 24 Apr 2017 02:47:44 -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.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 24 Apr 2017 02:47:43 -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. (v2) Date: Mon, 24 Apr 2017 11:46:44 +0200 Message-Id: <1493027205-13069-1-git-send-email-mario.kleiner.de@gmail.com> X-Mailer: git-send-email 2.7.0 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 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. v2: Review comments by Michel, drop outdated paragraph about problem already fixed in 2nd patch of the series. Add acked/r-b by Harry and Michel. Signed-off-by: Mario Kleiner Acked-by: Harry Wentland Reviewed-by: Michel Dänzer Cc: Andrey Grodzovsky Cc: Alex Deucher Cc: 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;