Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp6132481ybi; Tue, 4 Jun 2019 19:47:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqzwbfWRklnZMyOD/M/fVvBsu/eY1y+vtqlD3KAxeOxNxgxe8ndzWWfgXSpxsqgIIkbqMdNc X-Received: by 2002:a63:a08:: with SMTP id 8mr1076831pgk.46.1559702874856; Tue, 04 Jun 2019 19:47:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559702874; cv=none; d=google.com; s=arc-20160816; b=rb4RLMebddg2ia1sPa84Xo9KBnvelTKm0pdUduINrMT3WByfReL7pCOBjcdX6G8Qh0 bSwAXzJE+AGelLW+BUFIoklNWlZG6PMFZ51BiNZ7FKh+qyf2yckBpG4ZEBeDGJdo2a7t LcyCZb9OQOPSsJrv1hLpTU0g0NLuGLLXeAINaXBHulEUuTOK9+i2ZZnLEzS0zVzJafXJ xGckybodKhfJYpl6KBIzRqEMRwbTK+iAfqvWYb0ADYusWWb5ld5kFdZrU5zsb7WRl4T7 QaO9fz55D/4Vq8rV4T1Tw6skfbfdySMv/6jBVN+kAMhbhE2exk0cxXIXpykwKN6w7uWr WQvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=BQfBVOtXcs0qzMIh6nmcxcUOcBUU3ej7Z8jgcon5kpQ=; b=I8J+g6W0JdaQH8AXCR9kPdNUs+s6Cu8640ca30cI6j8CkpUwIeSKDCXK70GBjoJT5L ZW/5EJBc77WxXSw9wHGHkIgLCT5tWX6PcRi4V8BrkpRPJZJaoBRUqzojnpsaSz6FH+V5 4U3vAmvRVa7UhxWz7oCJ7duQnn4wS/2gIsAbxVWu9GL0AYehUHD2s12XXwrtAHj404hi KXVeAxCodgHynY7FWUOzfALU5AB9X3xKgPbfThxcKpX0wFj4ek57RiJA3LIho97NSyYw QwxnlTEg/M+/H7XZabPXoCgOIglWp+IC4T41b/bpWzdq6M0snHxgSd/Bgu6hpwHJYLnB htaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DGd6ZJMu; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k193si25554598pgc.473.2019.06.04.19.47.38; Tue, 04 Jun 2019 19:47:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DGd6ZJMu; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726872AbfFECpu (ORCPT + 99 others); Tue, 4 Jun 2019 22:45:50 -0400 Received: from mail-qt1-f194.google.com ([209.85.160.194]:40611 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726463AbfFECpu (ORCPT ); Tue, 4 Jun 2019 22:45:50 -0400 Received: by mail-qt1-f194.google.com with SMTP id a15so1871664qtn.7 for ; Tue, 04 Jun 2019 19:45:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=BQfBVOtXcs0qzMIh6nmcxcUOcBUU3ej7Z8jgcon5kpQ=; b=DGd6ZJMuCw4wWZb+/hxWOpe9FC4seEzDtRiNche1kXONtQmbx5I/TVyogo3MR8MUWg HX6XrIaLRKq5qnBeAO1kziZycNh11yLibk5y5Z6zxNAz8FpGMDO4W8zjHpTOY48uxwh0 2yKqYIbwCADSDGxIwSiX7e67IIgsaFx29/f9EbgczyWWZ1017hDufsviKY6l9RCB28BB yg10iQ1Zs85d6jclpSeI8s7DyqFvT0MEh22tb5XTElf2lZM+Z4VU2FdRWd5Q/dP15QjI 6AN1fOJ8cyAqtPqmjBSFFa2+GQ1DFLGRfKssCxSb3x/3Sz8OmAip2ggLGaejoPGMjZ3G HksA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=BQfBVOtXcs0qzMIh6nmcxcUOcBUU3ej7Z8jgcon5kpQ=; b=dR6M5dLV4hZ2BWdszf/CcSAHXEqPQTnmRfEQ0SKsnqEoGR3/yDnfFWMM+ZuwFSYE5Z H7ZxT0SEYSTv91zNsrGjiIcIFz28uS8Jb8StfnEAL5YdxVnVkExgLpfcrcYbLTVEJdQw gvxNkjzr6zUbN3Z6TY+1b9X65HlzdIPqQuzo6wr775vz4+7WNMJ2VPPGeRmOaMfMP0UJ iLynGgEidsX/+xb129gwk5elUqrvedXN4zdJli9A57Hdvda0uYiSVzFUOlrjPuKJArYd hP21kA21QPawS9IqvR3vPhc7Hptgme5gUoOBJu++ijEQoWgNx8GNj0hfbhU+z++dnoDH gvWg== X-Gm-Message-State: APjAAAXeNb4PQgttlgkbdQuQFnlVFubwisfYAayrOp3ZemaPV+LNr34B tXviXS+yUNhpMgJCRhD1JoqCia9JML4= X-Received: by 2002:aed:3804:: with SMTP id j4mr31335025qte.361.1559702748899; Tue, 04 Jun 2019 19:45:48 -0700 (PDT) Received: from smtp.gmail.com ([187.121.151.146]) by smtp.gmail.com with ESMTPSA id k40sm9325569qta.50.2019.06.04.19.45.44 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 04 Jun 2019 19:45:48 -0700 (PDT) Date: Tue, 4 Jun 2019 23:45:43 -0300 From: Rodrigo Siqueira To: Simon Ser , Ville Syrjala , Shayenne Moura , Haneen Mohammed , Daniel Vetter , David Airlie Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, 18oliveira.charles@gmail.com Subject: [PATCH V2] drm/vkms: Avoid extra discount in the timestamp value Message-ID: <20190605024543.pcsnkf74mmgfhtuh@smtp.gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="fjpgzm34khffs6b6" Content-Disposition: inline User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --fjpgzm34khffs6b6 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable After the commit def35e7c5926 ("drm/vkms: Bugfix extra vblank frame") some of the crc tests started to fail in the vkms with the following error: [drm:drm_crtc_add_crc_entry [drm]] *ERROR* Overflow of CRC buffer, userspace reads too slow. [drm] failed to queue vkms_crc_work_handle ... The aforementioned commit fixed the extra vblank added by `drm_crtc_arm_vblank_event()` which is invoked inside `vkms_crtc_atomic_flush()` if the vblank event count was zero, otherwise `drm_crtc_send_vblank_event()` is invoked. The fix was implemented in `vkms_get_vblank_timestamp()` by subtracting one period from the current timestamp, as the code snippet below illustrates: if (!in_vblank_irq) *vblank_time -=3D output->period_ns; The above fix works well when `drm_crtc_arm_vblank_event()` is invoked. However, it does not properly work when `drm_crtc_send_vblank_event()` executes since it subtracts the correct timestamp, which it shouldn't. In this case, the `drm_crtc_accurate_vblank_count()` function will returns the wrong frame number, which generates the aforementioned error. Such decrease in `get_vblank_timestamp()` produce a negative number in the following calculation within `drm_update_vblank_count()`: u64 diff_ns =3D ktime_to_ns(ktime_sub(t_vblank, vblank->time)); After this operation, the DIV_ROUND_CLOSEST_ULL macro is invoked using diff_ns with a negative number, which generates an undefined result; therefore, the returned frame is a huge and incorrect number. Finally, the code below is part of the `vkms_crc_work_handle()`, note that the while loop depends on the returned value from `drm_crtc_accurate_vblank_count()` which may cause the loop to take a long time to finish in case of huge value. frame_end =3D drm_crtc_accurate_vblank_count(crtc); while (frame_start <=3D frame_end) drm_crtc_add_crc_entry(crtc, true, frame_start++, &crc32); This commit fixes this issue by checking if the vblank timestamp corresponding to the current software vblank counter is equal to the current vblank; if they are equal, it means that `drm_crtc_send_vblank_event()` was invoked and vkms does not need to discount the extra vblank, otherwise, `drm_crtc_arm_vblank_event()` was executed and vkms have to discount the extra vblank. This fix made the CRC tests work again whereas keep all tests from kms_flip working as well. V2: Update commit message Signed-off-by: Rodrigo Siqueira Signed-off-by: Shayenne Moura --- drivers/gpu/drm/vkms/vkms_crtc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_c= rtc.c index 7508815fac11..3ce60e66673e 100644 --- a/drivers/gpu/drm/vkms/vkms_crtc.c +++ b/drivers/gpu/drm/vkms/vkms_crtc.c @@ -74,9 +74,13 @@ bool vkms_get_vblank_timestamp(struct drm_device *dev, u= nsigned int pipe, { struct vkms_device *vkmsdev =3D drm_device_to_vkms_device(dev); struct vkms_output *output =3D &vkmsdev->output; + struct drm_vblank_crtc *vblank =3D &dev->vblank[pipe]; =20 *vblank_time =3D output->vblank_hrtimer.node.expires; =20 + if (*vblank_time =3D=3D vblank->time) + return true; + if (!in_vblank_irq) *vblank_time -=3D output->period_ns; =20 --=20 2.21.0 --fjpgzm34khffs6b6 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEE4tZ+ii1mjMCMQbfkWJzP/comvP8FAlz3LNcACgkQWJzP/com vP/X4hAApcr5/bEnDAvsOsV2xeueMBVUxkCOy5jyP804U41fgrRvvSmSXL9r4Aha 6gaKPXNYjxTX/q6NiVLJ0eKd/ghuyjdWEygnVKzslqkdlZPMGLsXW+eh9CVEPpdS 3ntASLzK+X8SEK0ghEqwIBjibvigKl7m9/Me/5dcF9omezMDYUgdCuip2Bl12S7u snxH/0kfZZ4FbpvkzNg19rK7Jy3gQaJhJ2NVokdY3tNsqwRlRC2o25oISFXZCC+T /GDKvUs2MlV24b8l+IOECZrAyXa3627IoKGhirNXbNdPipU5/lel5c5uy0u38zVO 2yH7veHOs45SNrFKayY0M8CsEorBtg4BuYZdLToYZz6+MwuRODj758nVb3zTqPPS EpUg1kya5bV9WujDz9oVodf7AwWa+/7G98VSwDCa5ffc6NLODLSwiRzCa380GdS+ UZGAt6nEMXXwBkYPgLsQuZ/2tZ3ASRdgRbZN7zDCWmGi/ataX1/psdFpDAfTtsVU 2lJY665DmPvtT1QPNyfZKV+A76RYfdxXYk6ANd65cWFPyQ+15oYYejo8cfBt3gO0 FayQJzWXgMXkeOkUJJLaeNsQIth1wamo4AYKNrM3cf9bCKG8lQaObkvufjpWbnAF XUCj3wDLKxkc0zOpA0nsXI9N5ZagdqHadTFnFlW9IKkBJHEuKzk= =5usR -----END PGP SIGNATURE----- --fjpgzm34khffs6b6--