From patchwork Wed Jun 14 09:08:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maarten Lankhorst X-Patchwork-Id: 9785845 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 5C7E7602C9 for ; Wed, 14 Jun 2017 09:08:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F4B7285E5 for ; Wed, 14 Jun 2017 09:08:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 442EA285EB; Wed, 14 Jun 2017 09:08:58 +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 EAF79285E5 for ; Wed, 14 Jun 2017 09:08:57 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9E83C6E4BE; Wed, 14 Jun 2017 09:08:50 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mblankhorst.nl (mblankhorst.nl [141.105.120.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id 888946E486; Wed, 14 Jun 2017 09:08:48 +0000 (UTC) From: Maarten Lankhorst To: intel-gfx@lists.freedesktop.org Subject: [PATCH v2 1/2] drm/atomic: move waiting for hw_done to a helper Date: Wed, 14 Jun 2017 11:08:41 +0200 Message-Id: <20170614090842.9669-1-maarten.lankhorst@linux.intel.com> X-Mailer: git-send-email 2.11.0 Cc: dri-devel@lists.freedesktop.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 Moving the wait to a helper allows callers outside of the core to wait for pending updates to complete. This can be used to prevent races against nonblocking modesets. Only the hw_done call in swap_state is moved to a helper, doing it for the other callers requires too many changes and I think this is the only useful one to export. Signed-off-by: Maarten Lankhorst --- drivers/gpu/drm/drm_atomic_helper.c | 51 +++++++++++++++++++++++++++---------- include/drm/drm_atomic_helper.h | 1 + 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c index 86d3093c6c9b..1b068ce1aea9 100644 --- a/drivers/gpu/drm/drm_atomic_helper.c +++ b/drivers/gpu/drm/drm_atomic_helper.c @@ -2067,6 +2067,41 @@ void drm_atomic_helper_cleanup_planes(struct drm_device *dev, EXPORT_SYMBOL(drm_atomic_helper_cleanup_planes); /** + * drm_atomic_helper_wait_for_hw_done - wait for all previous hw updates to complete. + * @crtc: crtc to wait on. + * + * This function waits for all previous hardware updates queued on @crtc + * to complete. + * + * Returns: + * 0 on success, negative error code on failure. + */ +int drm_atomic_helper_wait_for_hw_done(struct drm_crtc *crtc) +{ + struct drm_crtc_commit *commit; + long ret; + + spin_lock(&crtc->commit_lock); + commit = list_first_entry_or_null(&crtc->commit_list, + struct drm_crtc_commit, commit_entry); + if (commit) + drm_crtc_commit_get(commit); + spin_unlock(&crtc->commit_lock); + + if (!commit) + return 0; + + ret = wait_for_completion_timeout(&commit->hw_done, 10 * HZ); + drm_crtc_commit_put(commit); + + if (ret == 0) + return -EBUSY; + + return ret > 0 ? 0 : ret; +} +EXPORT_SYMBOL(drm_atomic_helper_wait_for_hw_done); + +/** * drm_atomic_helper_swap_state - store atomic state into current sw state * @state: atomic state * @stall: stall for proceeding commits @@ -2107,28 +2142,16 @@ void drm_atomic_helper_swap_state(struct drm_atomic_state *state, struct drm_crtc_state *old_crtc_state, *new_crtc_state; struct drm_plane *plane; struct drm_plane_state *old_plane_state, *new_plane_state; - struct drm_crtc_commit *commit; void *obj, *obj_state; const struct drm_private_state_funcs *funcs; if (stall) { for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) { - spin_lock(&crtc->commit_lock); - commit = list_first_entry_or_null(&crtc->commit_list, - struct drm_crtc_commit, commit_entry); - if (commit) - drm_crtc_commit_get(commit); - spin_unlock(&crtc->commit_lock); + ret = drm_atomic_helper_wait_for_hw_done(crtc); - if (!commit) - continue; - - ret = wait_for_completion_timeout(&commit->hw_done, - 10*HZ); - if (ret == 0) + if (ret < 0) DRM_ERROR("[CRTC:%d:%s] hw_done timed out\n", crtc->base.id, crtc->name); - drm_crtc_commit_put(commit); } } diff --git a/include/drm/drm_atomic_helper.h b/include/drm/drm_atomic_helper.h index f0a8678ae98e..175a1a3fed36 100644 --- a/include/drm/drm_atomic_helper.h +++ b/include/drm/drm_atomic_helper.h @@ -77,6 +77,7 @@ void drm_atomic_helper_disable_planes_on_crtc(struct drm_crtc_state *old_crtc_state, bool atomic); +int drm_atomic_helper_wait_for_hw_done(struct drm_crtc *crtc); void drm_atomic_helper_swap_state(struct drm_atomic_state *state, bool stall);