From patchwork Wed Jan 30 16:06:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shayenne Moura X-Patchwork-Id: 10788905 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8F0D313BF for ; Wed, 30 Jan 2019 16:06:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C9372934D for ; Wed, 30 Jan 2019 16:06:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E0502BA5C; Wed, 30 Jan 2019 16:06:45 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 7A8762934D for ; Wed, 30 Jan 2019 16:06:43 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A96836E603; Wed, 30 Jan 2019 16:06:42 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qt1-x842.google.com (mail-qt1-x842.google.com [IPv6:2607:f8b0:4864:20::842]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9C5F76E603 for ; Wed, 30 Jan 2019 16:06:41 +0000 (UTC) Received: by mail-qt1-x842.google.com with SMTP id e5so26712823qtr.12 for ; Wed, 30 Jan 2019 08:06:41 -0800 (PST) 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:references :mime-version:content-disposition:in-reply-to:user-agent; bh=hH3U0WFHZZpNJH6bCOhEbZsbYJbx6ZUSf+ECUNlMvDg=; b=e8yC8TzeuOZQQClkFZbwKKWGCqrk+cdbrXu/PzjhqwswN/rnMgchGpnbH+Rnu7XRyf guG2f20SgXgFVHhu/GYVBBYqnMesUJJGPc0kD6ZpVfSrEOR2//Kf8DrKAmbFXjD+1Wtl G2suNfao4Cducn8lZewv507QDPML1hpNXeBDb2EG3mg99QQFpTSRc064BP8X7DBrJJo4 4FexjC8wJWJk7Z4NBe3F5MQ/ySRnNMWqn1aXsiS0bTSNf3dJZLBLDoGsLv+YsSIUQMmL iYTlsshyaxMv+lP+PuQBPTjeSR9zMvKoXsllgFJzghqKPoOpixODyjj1TL3fbvfq9CXC jmKQ== X-Gm-Message-State: AJcUukfQE+AAbwcQJcmIBxfWXuTEl1VMJ/ydq7Wwj9LYXsSUMzB47efP a8OIFcySA0xb8mB3JJ+0Ly4= X-Google-Smtp-Source: ALg8bN62AN5MtRpb4sM9A0YfNwTP3LMSKoNQz7lz4SN59FCQAtpAVqbXaqJUwYbbm5SF7fgbbZPkzA== X-Received: by 2002:ac8:543:: with SMTP id c3mr30900897qth.34.1548864400728; Wed, 30 Jan 2019 08:06:40 -0800 (PST) Received: from smtp.gmail.com ([143.107.45.1]) by smtp.gmail.com with ESMTPSA id u4sm1547948qkk.51.2019.01.30.08.06.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 Jan 2019 08:06:40 -0800 (PST) Date: Wed, 30 Jan 2019 14:06:36 -0200 From: Shayenne Moura To: Rodrigo Siqueira , Haneen Mohammed , Daniel Vetter , David Airlie Subject: [PATCH 1/2] drm/vkms: Bugfix extra vblank frame Message-ID: <171e6e1c239cbca0c3df7183ed8acdfeeace9cf4.1548856186.git.shayenneluzmoura@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20171215 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP kms_flip tests are breaking on vkms when simulate vblank because vblank event sequence count returns one extra frame after arm vblank event to make a page flip. When vblank interrupt happens, userspace processes the vblank event and issues the next page flip command. Kernel calls queue_work to call commit_planes and arm the new page flip. The next vblank picks up the newly armed vblank event and vblank interrupt happens again. The arm and vblank event are asynchronous, then, on the next vblank, we receive x+2 from `get_vblank_timestamp`, instead x+1, although timestamp and vblank seqno matches. Function `get_vblank_timestamp` is reached by 2 ways: - from `drm_mode_page_flip_ioctl`: driver is doing one atomic operation to synchronize planes in the same output. There is no vblank simulation, the `drm_crtc_arm_vblank_event` function adds 1 on vblank count, and the variable in_vblank_irq is false - from `vkms_vblank_simulate`: since the driver is doing a vblank simulation, the variable in_vblank_irq is true. Fix this problem subtracting one vblank period from vblank_time when `get_vblank_timestamp` is called from trace `drm_mode_page_flip_ioctl`, i.e., is not a real vblank interrupt, and getting the timestamp and vblank seqno when it is a real vblank interrupt. The reason for all this is that get_vblank_timestamp always supplies the timestamp for the next vblank event. The hrtimer is the vblank simulator, and it needs the correct previous value to present the next vblank. Since this is how hw timestamp registers work and what the vblank core expects. Signed-off-by: Shayenne Moura Signed-off-by: Daniel Vetter Reviewed-by: Rodrigo Siqueira --- drivers/gpu/drm/vkms/vkms_crtc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c index d44bfc392491..23146ff2a25b 100644 --- a/drivers/gpu/drm/vkms/vkms_crtc.c +++ b/drivers/gpu/drm/vkms/vkms_crtc.c @@ -87,6 +87,9 @@ bool vkms_get_vblank_timestamp(struct drm_device *dev, unsigned int pipe, *vblank_time = output->vblank_hrtimer.node.expires; + if (!in_vblank_irq) + *vblank_time -= output->period_ns; + return true; }