From patchwork Wed Nov 23 06:58:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Kleiner X-Patchwork-Id: 9442659 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 5259C600BA for ; Wed, 23 Nov 2016 06:59:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 43FF020700 for ; Wed, 23 Nov 2016 06:59:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 377712094D; Wed, 23 Nov 2016 06:59: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 22E6720700 for ; Wed, 23 Nov 2016 06:59:42 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D881F6E6AF; Wed, 23 Nov 2016 06:59:33 +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 AC1A76E6AF; Wed, 23 Nov 2016 06:59:31 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id g23so777863wme.1; Tue, 22 Nov 2016 22:59:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=0ggPmeESpvllqkhZgNh4qd0tJ8RBQXWJqlt51RhI9sQ=; b=EerpgAm3/ignQRgm23yCfo4c1XzCGcXNz18SMVKzCssJkT3wKv2kss/Xn0wwdcmE+A zRpTzphJFS4JKAamYL4IA6ynz64t8sUnshIz5gC9kAKhlIkhGt1yMwV046Z06n0u9lNo 2jIEJ8yoI2V2RBwEUk5Nvl8dOoYr9POWWMxLXDN1Nj69Ks4gFaG94cL36OUiRDcmbgh/ Izx95UBUkUxzyh5AgHc7iBAhSym6yNBGv3YrVl6/XjjEx6ktDt7SbFJfgXBGL/8FNy3j a3ZgyCJ6VY32tH8qgCqCxSGoLvLBoKLa9aE55wdQhKdzVJtxJGtUgaHUJoIpN0tmJjBn EYgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=0ggPmeESpvllqkhZgNh4qd0tJ8RBQXWJqlt51RhI9sQ=; b=GYCpyQOb/sk0oZ3OoHaxkgOIhVND+dglyn9X2frAmjp4Do/v5GpSGfoxX4JKia6E0c Ad+Wkm41DLzzoXZRARWm/mypJQ24vuniSmQ6P7U9/SX38NMiFK2kPIxDdF2I0OSV7cOK qbqZWrw2jjg+Bqc56MDyPK5nB02hMxL+CpuQgRiqR4zwDqflqEFcD2tmwrPcj8Vt4HWa umax2Z/KlnkS5eI4gjO3X5Ij741qBnaUolD5yPFLe+54BI7BUPKeGdKQ+extW9n6Oh2x qUL5lvNjyWbubweGVw+ZpG3WwdwNz33Amgbt4CPauxI9HMMaGSW1YYKreS1NnhGvofWn arbw== X-Gm-Message-State: AKaTC00ntcfGFgBMLL69H1wiMSQDOjvIKU1HvHzQ+KGUGLvE+GV0A1dIN6K2q5/yQ2MOyg== X-Received: by 10.28.226.139 with SMTP id z133mr6147192wmg.139.1479884370030; Tue, 22 Nov 2016 22:59:30 -0800 (PST) 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 q7sm34682332wjh.9.2016.11.22.22.59.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Nov 2016 22:59:29 -0800 (PST) From: Mario Kleiner To: dri-devel@lists.freedesktop.org Subject: [PATCH] drm/nouveau/kms/nv50: Fix atomic pageflip events. Date: Wed, 23 Nov 2016 07:58:54 +0100 Message-Id: <1479884334-9995-1-git-send-email-mario.kleiner.de@gmail.com> X-Mailer: git-send-email 2.7.0 Cc: nouveau@lists.freedesktop.org, Ben Skeggs 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: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP The new atomic modesetting/pageflip code for nv50+ for Linux 4.10+ no longer uses pageflip irq's to signal flip completion. Instead it polls for flip completion from within a kthread/work queue. This creates a race between the vblank irq handler updating the vblank count and timestamp for the vblank of flip completion, and the kthread's polling code detecting flip completion and sending out the flip completion event. Depending on who executes a few microseconds earlier, the flip completion event will either contain correct count/timestamp or a stale count/timestamp from the previous vblank. This error was observed for about 50% of all executed flips, e.g., observable under DRI2 by the Xorg.log filling with flip handler warning messages. Call drm_accurate_vblank_count() before sending out flip completion events to enforce a vblank count/ts update for the vblank of flip completion and avoid stale counts/timestamps. This fix leads to one redundant call to drm_update_vblank_count for each completed flip, but no other side effects. On a ~6 year old Core i7 M620@ 2.67GHz the redundant call costs about 10 usecs per flip Successfully tested on GeForce 9500/9600/330M so far. Signed-off-by: Mario Kleiner Cc: Ben Skeggs --- drivers/gpu/drm/nouveau/nv50_display.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gpu/drm/nouveau/nv50_display.c b/drivers/gpu/drm/nouveau/nv50_display.c index a9855a4..ad9aedb 100644 --- a/drivers/gpu/drm/nouveau/nv50_display.c +++ b/drivers/gpu/drm/nouveau/nv50_display.c @@ -4087,6 +4087,8 @@ nv50_disp_atomic_commit_tail(struct drm_atomic_state *state) for_each_crtc_in_state(state, crtc, crtc_state, i) { if (crtc->state->event) { unsigned long flags; + /* Get correct count/ts if racing with vblank irq */ + drm_accurate_vblank_count(crtc); spin_lock_irqsave(&crtc->dev->event_lock, flags); drm_crtc_send_vblank_event(crtc, crtc->state->event); spin_unlock_irqrestore(&crtc->dev->event_lock, flags);