From patchwork Mon Feb 8 01:13:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Kleiner X-Patchwork-Id: 8246151 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 489FC9F38B for ; Mon, 8 Feb 2016 01:14:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B937F201D3 for ; Mon, 8 Feb 2016 01:14:55 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 9A7E120160 for ; Mon, 8 Feb 2016 01:14:54 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D12DC6E32B; Sun, 7 Feb 2016 17:14:53 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by gabe.freedesktop.org (Postfix) with ESMTPS id 40FCC6E32B for ; Sun, 7 Feb 2016 17:14:52 -0800 (PST) Received: by mail-wm0-f67.google.com with SMTP id g62so13234771wme.2 for ; Sun, 07 Feb 2016 17:14:52 -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:in-reply-to:references; bh=dz3/3N4Sv3/LFy0C5nlKqSyvsNues3jD+FEqHW3YA80=; b=EDLakBWnlyEg82vrbgESz+3jRjktM8lqsACp+uAgTRTb2Nde3gbyJPPPiOGR51bAmV 3RvUepUTRTEngLvf4PadckBqxSThgpTfVCHH5NzGjApSy7/F0IAGjJwfV26QWBzn+xuD j6H6msO47vkywe0xxitTvYQyqdt0/vxK4fhbH8xX8CNnNUUnAnTvIfVYuY6inSo5nP31 ieJA6siSyesFffr/XrbhIdIvvTTyWQtKqg8vE+GREp0KX8Y1lIy0XRKdQF6cXYo+X4nu nR5bn9DeBB4ND8Wd05H/qKkvvlbEouPcjyGf8LjKzcVDBn021YYSnpLw1g+pQDnQ08y3 rFkw== 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:in-reply-to :references; bh=dz3/3N4Sv3/LFy0C5nlKqSyvsNues3jD+FEqHW3YA80=; b=bTMBNU+8m25i3rbnSIO4UZZwJdi0AAWETs9XXYfV55frUIzR3LFA1xU8Y518zPKzZ1 mAZgjdcaI1FAhBzOc68Jik/Ds58mxBqlMNLWqEof/fhH8UGaXx/RbWF+a2rqCok5daRJ O9Kx0d4VgkfSfUSaK2sY1PnuRYYtHXzhr/+TmO5h2/CWwknGs2gqyM7mulNyy5p5tChl ttlIWQK9leJWctrNdTvOWtnBZ6x+YkJHO4w8ibDMFQqkLqAhKWgFFyf79IUnfEP6c7qD 1sV+FBixzBcwOthcKNUkwxUASh0UlEvtUgPoo8sLT9FmxNgjy6IK4PdIOk4umeOHw5dO CkjQ== X-Gm-Message-State: AG10YOQbogWu+qds5tMWdLkeZr/D4Q0Nb6nrXx1XvkEESjUHVEOsQFrim2ggVjvLdQxYVg== X-Received: by 10.194.161.166 with SMTP id xt6mr26751659wjb.98.1454894091077; Sun, 07 Feb 2016 17:14:51 -0800 (PST) Received: from twisty.fritz.box (x4d02db5e.dyn.telefonica.de. [77.2.219.94]) by smtp.gmail.com with ESMTPSA id b5sm9486380wmh.15.2016.02.07.17.14.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 07 Feb 2016 17:14:49 -0800 (PST) From: Mario Kleiner To: dri-devel@lists.freedesktop.org Subject: [PATCH 5/6] drm: Prevent vblank counter jumps with timestamp based update method. Date: Mon, 8 Feb 2016 02:13:28 +0100 Message-Id: <1454894009-15466-6-git-send-email-mario.kleiner.de@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1454894009-15466-1-git-send-email-mario.kleiner.de@gmail.com> References: <1454894009-15466-1-git-send-email-mario.kleiner.de@gmail.com> Cc: daniel.vetter@ffwll.ch, michel@daenzer.net, linux@bernd-steinhauser.de, stable@vger.kernel.org, alexander.deucher@amd.com, christian.koenig@amd.com, vbabka@suse.cz 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-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The changes to drm_update_vblank_count() in Linux 4.4 added a method to emulate a hardware vblank counter by use of high precision vblank timestamps if a kms driver supports those, but doesn't suppport hw vblank counters. That method assumes that the old timestamp from a previous invocation is valid, but that is not always the case. E.g., if drm_reset_vblank_timestamp() gets called during drm_vblank_on() or drm_update_vblank_count() gets called outside vblank irq and the high precision timestamping can't deliver a precise timestamp, ie. drm_get_last_vbltimestamp() delivers a return value of false, then those functions will initialize the old timestamp to zero to mark it as invalid. A following call to drm_update_vblank_count() would then calculate elapsed time with vblank irqs off as current vblank timestamp minus the zero old timestamp and compute a software vblank counter increment that corresponds to system uptime, causing a large forward jump of the software vblank counter. That jump in turn can cause too long waits in drmWaitVblank and very long delays in delivery of vblank events, resulting in hangs of userspace clients. This problem can be observed on nouveau-kms during machine suspend->resume cycles, where drm_vblank_off is called during suspend, drm_vblank_on is called during resume and the first queries to drm_get_last_vbltimestamp() don't deliver high precision timestamps, resulting in a large harmful counter jump. Fix this by checking if the old timestamp used for this calculations is zero == invalid. If so, perform a counter increment of +1 to prevent large counter jumps and reinitialize the timestamps to sane values. Signed-off-by: Mario Kleiner Cc: # 4.4+ Cc: michel@daenzer.net Cc: vbabka@suse.cz Cc: ville.syrjala@linux.intel.com Cc: daniel.vetter@ffwll.ch Cc: dri-devel@lists.freedesktop.org Cc: alexander.deucher@amd.com Cc: christian.koenig@amd.com --- drivers/gpu/drm/drm_irq.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c index fb17c45..88bdf19 100644 --- a/drivers/gpu/drm/drm_irq.c +++ b/drivers/gpu/drm/drm_irq.c @@ -216,6 +216,13 @@ static void drm_update_vblank_count(struct drm_device *dev, unsigned int pipe, DRM_DEBUG_VBL("crtc %u: Redundant vblirq ignored." " diff_ns = %lld, framedur_ns = %d)\n", pipe, (long long) diff_ns, framedur_ns); + + /* No valid t_old to calculate diff? Bump +1 to force reinit. */ + if (t_old->tv_sec == 0 && t_old->tv_usec == 0) { + DRM_DEBUG_VBL("crtc %u: No baseline ts. Bump +1.\n", + pipe); + diff = 1; + } } else { /* some kind of default for drivers w/o accurate vbl timestamping */ diff = (flags & DRM_CALLED_FROM_VBLIRQ) != 0;