From patchwork Thu Aug 11 18:39:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Padovan X-Patchwork-Id: 9275793 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 EFC9C600CB for ; Thu, 11 Aug 2016 18:40:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E2CF328715 for ; Thu, 11 Aug 2016 18:40:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D61B02876F; Thu, 11 Aug 2016 18:40:00 +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.2 required=2.0 tests=BAYES_00, 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 897C228715 for ; Thu, 11 Aug 2016 18:40:00 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B5D9C6E2BE; Thu, 11 Aug 2016 18:39:59 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-yw0-f194.google.com (mail-yw0-f194.google.com [209.85.161.194]) by gabe.freedesktop.org (Postfix) with ESMTPS id DB6196E2BE for ; Thu, 11 Aug 2016 18:39:58 +0000 (UTC) Received: by mail-yw0-f194.google.com with SMTP id u134so169775ywg.3 for ; Thu, 11 Aug 2016 11:39:58 -0700 (PDT) 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=B43bCpbpvpe+fb6ygUzXPX4p00mVfv5DW4CYDeHPi3k=; b=KwpYmipNsCBg2u7deO629v+SRsT6VvudOslX8wV7G2cCXcvl8KNgisGXYS8NaEy/tz JUSLVt5CqdEXwfEbDIdL9ZOBanQvkPA+pK4USnhpPSQ0kcvW012XCl89s3czFAHge/oj H17H+8wx+/SkCjSzgsCuhf9kfsU7i8CbKfCwYbfDSh49KLa7Us83wZYZJMuiz3Yqc813 4LuCroMbuGHcT5ROCFRXDOxfKLmQL9atVmD+lqMe5Jy6PIwvGvY/+RJFoYZ2td0Ubhly xAbcCQ7xjieke/KdqdxYyZmbPRQ0KdnroUM1BDIH2L798Mi7J20B3/+McWLv9THwd1T3 Npcw== X-Gm-Message-State: AEkoouuhQ4Xddn/PxEvVGoa97AhnYROpxDcqFL7u2y83I4XK82j4u+L0dAFlYOrMr3Qkjg== X-Received: by 10.129.91.86 with SMTP id p83mr8126158ywb.148.1470940798135; Thu, 11 Aug 2016 11:39:58 -0700 (PDT) Received: from jade.localdomain ([201.82.189.183]) by smtp.gmail.com with ESMTPSA id x126sm1557663ywg.12.2016.08.11.11.39.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Aug 2016 11:39:57 -0700 (PDT) From: Gustavo Padovan To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/2] drm/fence: allow fence waiting to be interrupted by userspace Date: Thu, 11 Aug 2016 15:39:45 -0300 Message-Id: <1470940785-25870-2-git-send-email-gustavo@padovan.org> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1470940785-25870-1-git-send-email-gustavo@padovan.org> References: <1470940785-25870-1-git-send-email-gustavo@padovan.org> Cc: marcheu@google.com, Daniel Stone , seanpaul@google.com, Daniel Vetter , linux-kernel@vger.kernel.org, laurent.pinchart@ideasonboard.com, Gustavo Padovan , John Harrison , m.chehab@samsung.com 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 From: Gustavo Padovan If userspace is running an synchronously atomic commit and interrupts the atomic operation during fence_wait() it will hang until the timer expires, so here we change the wait to be interruptible so it stop immediately when userspace wants to quit. Also adds the necessary error checking for fence_wait(). v2: Comment by Daniel Vetter - Add error checking for fence_wait() v3: Rebase on top of new atomic noblocking support Signed-off-by: Gustavo Padovan --- drivers/gpu/drm/drm_atomic_helper.c | 29 ++++++++++++++++++++++++----- include/drm/drm_crtc.h | 2 ++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c index fa263b7..5e8ed15 100644 --- a/drivers/gpu/drm/drm_atomic_helper.c +++ b/drivers/gpu/drm/drm_atomic_helper.c @@ -1018,20 +1018,31 @@ int drm_atomic_helper_wait_for_fences(struct drm_device *dev, { struct drm_plane *plane; struct drm_plane_state *plane_state; + struct fence *fence; int i, ret; for_each_plane_in_state(state, plane, plane_state, i) { - if (!plane->state->fence) + if (!plane->state->fence && !plane_state->fence) continue; - WARN_ON(!plane->state->fb); + if (state->swapped) { + fence = plane->state->fence; + WARN_ON(!plane->state->fb); + } else { + fence = plane_state->fence; + WARN_ON(!plane_state->fb); + } - ret = fence_wait(plane->state->fence, intr); + ret = fence_wait(fence, intr); if (ret) return ret; - fence_put(plane->state->fence); - plane->state->fence = NULL; + fence_put(fence); + + if (state->swapped) + plane->state->fence = NULL; + else + plane_state->fence = NULL; } return 0; @@ -1240,6 +1251,12 @@ int drm_atomic_helper_commit(struct drm_device *dev, if (ret) return ret; + if (!nonblock) { + ret = drm_atomic_helper_wait_for_fences(dev, state, true); + if (ret) + return ret; + } + /* * This is the point of no return - everything below never fails except * when the hw goes bonghits. Which means we can commit the new state on @@ -2009,6 +2026,8 @@ void drm_atomic_helper_swap_state(struct drm_atomic_state *state, swap(state->planes[i].state, plane->state); plane->state->state = NULL; } + + state->swapped = true; } EXPORT_SYMBOL(drm_atomic_helper_swap_state); diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h index b618b50..99455d8 100644 --- a/include/drm/drm_crtc.h +++ b/include/drm/drm_crtc.h @@ -2032,6 +2032,7 @@ struct __drm_connnectors_state { * @allow_modeset: allow full modeset * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics * @legacy_set_config: Disable conflicting encoders instead of failing with -EINVAL. + * @swapped: hint to inform if the state was swapped with the device state * @planes: pointer to array of structures with per-plane data * @crtcs: pointer to array of CRTC pointers * @num_connector: size of the @connectors and @connector_states arrays @@ -2043,6 +2044,7 @@ struct drm_atomic_state { bool allow_modeset : 1; bool legacy_cursor_update : 1; bool legacy_set_config : 1; + bool swapped : 1; struct __drm_planes_state *planes; struct __drm_crtcs_state *crtcs; int num_connector;