From patchwork Wed Sep 14 12:54:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Figa X-Patchwork-Id: 9331367 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 20DD660231 for ; Wed, 14 Sep 2016 12:56:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 127581FFC9 for ; Wed, 14 Sep 2016 12:56:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0731729D32; Wed, 14 Sep 2016 12:56:08 +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_SIGNED, 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 9EF381FFC9 for ; Wed, 14 Sep 2016 12:56:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 459A66E406; Wed, 14 Sep 2016 12:55:44 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pa0-x235.google.com (mail-pa0-x235.google.com [IPv6:2607:f8b0:400e:c03::235]) by gabe.freedesktop.org (Postfix) with ESMTPS id 22DB36E239 for ; Wed, 14 Sep 2016 12:55:17 +0000 (UTC) Received: by mail-pa0-x235.google.com with SMTP id id6so5300224pad.3 for ; Wed, 14 Sep 2016 05:55:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zL4b14kJOj/J/c1FD4cvxI5AXZbnJcOibOx7kjlaEHM=; b=VGmmUgxYZ+f9Ys3CuORRnCx9/IY3A007eKFtlWBxKB1xuq2sgU15ZSz6ANVfD6WjwO lkQ/Ro6PhflmpY0JWT08sO92CxGJDOGNtMQDpT5gU2ohUuq89KtnJNsnCDLZ56x0iw35 HAG5WkyctgbZ5vP5ckwnNY7wB6yAt7eU0uJts= 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=zL4b14kJOj/J/c1FD4cvxI5AXZbnJcOibOx7kjlaEHM=; b=O+yUXzb2OuYo5KjldOq6Ol65kaWDTnhLa7zxPYxyDWfx8FYylMXefAYsinMyo+mZq/ 50VFxlwWKXmROkqsTewnZNVUDKEK0xXbrbQWtukLhzbcGOEOCSOdWHOMCgyK20KFyU2r +bB22DCKR7Ryz8RhZjoDPOw19RQS6mcNpxZ+Rgm/Hx8GsoUZ8JLhpf8asCBZl1nBMaNl fQw7q8UTpJMrqMIUgFccyzKuWZ8Ts9l3YC2sXua913jJTgGLNtrIUnQldxpaZD3U6deE jfwaxrd0sew3pH8nNZrojQbu+9qWoxiYgvN+R6rEoeJhbJPr1YK68Rj04xsfof7mi4VS XE1g== X-Gm-Message-State: AE9vXwNOJxdyxCIh6l1nY+FHV5gn4y1V7FaILy6lQVW5hKPmULXaUDPZ9ZBm1Rptg982hjAD X-Received: by 10.66.86.105 with SMTP id o9mr4268848paz.108.1473857715770; Wed, 14 Sep 2016 05:55:15 -0700 (PDT) Received: from basement.tok.corp.google.com ([100.103.3.207]) by smtp.gmail.com with ESMTPSA id t7sm5601309paz.21.2016.09.14.05.55.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Sep 2016 05:55:15 -0700 (PDT) From: Tomasz Figa To: dri-devel@lists.freedesktop.org Subject: [PATCH 3/8] drm/rockchip: Avoid race with vblank count increment Date: Wed, 14 Sep 2016 21:54:56 +0900 Message-Id: <1473857701-9250-4-git-send-email-tfiga@chromium.org> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <1473857701-9250-1-git-send-email-tfiga@chromium.org> References: <1473857701-9250-1-git-send-email-tfiga@chromium.org> Cc: linux-kernel@vger.kernel.org, Tomasz Figa , linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.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: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Since VOP does not have a hardware vblank count register, the ongoing commit might be racing with a requested vblank interrupt, which would increment the software vblank counter before the changes being committed actually happen. To avoid this, we can extend .atomic_flush(), so after it sets cfg_done bit, it polls the vblank interrupt bit until it's inactive to make sure that any old vblank interrupt gets to the handler and then uses synchronize_irq(vop->irq) to make sure the handler finishes running. The polling case should happen very rarely, but even if, the total wait time should be relatively low and in practice almost equal to the vop hardirq handler running time. Signed-off-by: Tomasz Figa --- drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c index 68988c6..f989440 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -1063,6 +1064,32 @@ static void vop_crtc_enable(struct drm_crtc *crtc) rockchip_drm_psr_activate(&vop->crtc); } +static bool vop_fs_irq_is_pending(struct vop *vop) +{ + return VOP_INTR_GET_TYPE(vop, status, FS_INTR); +} + +static void vop_wait_for_irq_handler(struct vop *vop) +{ + bool pending; + int ret; + + /* + * Spin until frame start interrupt status bit goes low, which means + * that interrupt handler was invoked and cleared it. The timeout of + * 10 msecs is really too long, but it is just a safety measure if + * something goes really wrong. The wait will only happen in the very + * unlikely case of a vblank happening exactly at the same time and + * shouldn't exceed microseconds range. + */ + ret = readx_poll_timeout_atomic(vop_fs_irq_is_pending, vop, pending, + !pending, 0, 10 * 1000); + if (ret) + DRM_DEV_ERROR(vop->dev, "VOP vblank IRQ stuck for 10 ms\n"); + + synchronize_irq(vop->irq); +} + static void vop_crtc_atomic_flush(struct drm_crtc *crtc, struct drm_crtc_state *old_crtc_state) { @@ -1076,6 +1103,13 @@ static void vop_crtc_atomic_flush(struct drm_crtc *crtc, vop_cfg_done(vop); spin_unlock(&vop->reg_lock); + + /* + * There is a (rather unlikely) possiblity that a vblank interrupt + * fired before we set the cfg_done bit. To avoid spuriously + * signalling flip completion we need to wait for it to finish. + */ + vop_wait_for_irq_handler(vop); } static void vop_crtc_atomic_begin(struct drm_crtc *crtc,