From patchwork Fri Mar 18 23:15:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 8624431 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 66CB79F44D for ; Fri, 18 Mar 2016 23:15:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 155202039D for ; Fri, 18 Mar 2016 23:15:53 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id DDA8220396 for ; Fri, 18 Mar 2016 23:15:51 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 11F516E415; Fri, 18 Mar 2016 23:15:34 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qg0-x22c.google.com (mail-qg0-x22c.google.com [IPv6:2607:f8b0:400d:c04::22c]) by gabe.freedesktop.org (Postfix) with ESMTPS id 794D06E42A; Fri, 18 Mar 2016 23:15:26 +0000 (UTC) Received: by mail-qg0-x22c.google.com with SMTP id u110so113142375qge.3; Fri, 18 Mar 2016 16:15:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yUURMVvGDj/lWGJmHQKhiw+fy/iVIPeUb79wMbmWzBI=; b=ePNeftzNeX2O/xChMHSNAPluQGClU5gPCd+i8DjKTSgbeFfcKpM0FJk3qpnvYFkDoz LrZBRi6isLiAPqxtpk9Mb+ZlrogbGlFU1cRWDu+qBHSMEcs9nTFfocBRC0BqrNtzapVl gSwZzUV14c9CxMKnzC9EJFPcfD0R/4UD8si8BMIgalJWxzzsqFreHGFe7F3ItersejEr Tm3H9oNzFjuJGFii3lfT8UpwIRHi5M+XCjljG+oCTt98w2h3mtsWea5k+FHEA2HFNbfY iRD6K8LtHPeCxvk2Dpi7QGllKXpfG9MANlWOayJOFpKZD9wwn7QB30jxw9jsuw24hu0t uo8A== 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=yUURMVvGDj/lWGJmHQKhiw+fy/iVIPeUb79wMbmWzBI=; b=KfDGrRaFmF0gVksB6mrbrvq11utg++5xAzwL5hAKZESOHyt/k80facBkqwzU2NSg/0 treVxcXnpu0rjy2TvCXlg6odciOvL05YcaDJ+i0Pm3oJV0dxY569ZjGRcbA01nMsmQA8 6dYYHLHGKpbJdDbP0XIRMnutYAUXvXxXfvRr0TRqsQGDWrzKDwvm0oRhUVk9BFE+AWIO 9K6b5Tnt4peiHbN5n7DZ61Y4JcAmQDdvfZGa1S6oS9k8J8UAWYChTDwXNUvsrrhUpcLz qU9dqAEkJhXHY3SXGd1QAW8dAKGQAwRztG5oWBIbB5cZ/FtwM4RUg1YRQHGKSGUUgwDd dWVQ== X-Gm-Message-State: AD7BkJJcNLtO7rGk5kH/JE5A4eESVmiE2W76e3LIAgnTmX/qjnwW7OO9plYu8ZbkAUVpUg== X-Received: by 10.140.226.71 with SMTP id w68mr13018643qhb.4.1458342924477; Fri, 18 Mar 2016 16:15:24 -0700 (PDT) Received: from localhost ([2601:184:4000:90da:6af7:28ff:fe77:e429]) by smtp.gmail.com with ESMTPSA id x64sm6959311qhx.47.2016.03.18.16.15.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Mar 2016 16:15:23 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Subject: [PATCH 10/11] drm/msm: remove fence_cbs Date: Fri, 18 Mar 2016 19:15:03 -0400 Message-Id: <1458342904-23326-11-git-send-email-robdclark@gmail.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1458342904-23326-1-git-send-email-robdclark@gmail.com> References: <1458342904-23326-1-git-send-email-robdclark@gmail.com> Cc: maarten.lankhorst@canonical.com, linux-arm-msm@vger.kernel.org, freedreno@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-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This was only used for atomic commit these days. So instead just give atomic it's own work-queue where we can do a block on each bo in turn. Simplifies things a whole bunch and makes the 'struct fence' conversion easier. Signed-off-by: Rob Clark --- drivers/gpu/drm/msm/msm_atomic.c | 77 +++++++++++++++++----------------------- drivers/gpu/drm/msm/msm_drv.c | 4 +++ drivers/gpu/drm/msm/msm_drv.h | 5 +-- drivers/gpu/drm/msm/msm_fence.c | 43 ---------------------- drivers/gpu/drm/msm/msm_fence.h | 16 --------- drivers/gpu/drm/msm/msm_gem.c | 9 ++++- 6 files changed, 47 insertions(+), 107 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_atomic.c b/drivers/gpu/drm/msm/msm_atomic.c index 61f59db..7fc719d 100644 --- a/drivers/gpu/drm/msm/msm_atomic.c +++ b/drivers/gpu/drm/msm/msm_atomic.c @@ -18,18 +18,16 @@ #include "msm_drv.h" #include "msm_kms.h" #include "msm_gem.h" -#include "msm_gpu.h" /* temporary */ #include "msm_fence.h" struct msm_commit { struct drm_device *dev; struct drm_atomic_state *state; - uint32_t fence; - struct msm_fence_cb fence_cb; + struct work_struct work; uint32_t crtc_mask; }; -static void fence_cb(struct msm_fence_cb *cb); +static void commit_worker(struct work_struct *work); /* block until specified crtcs are no longer pending update, and * atomically mark them as pending update @@ -71,11 +69,7 @@ static struct msm_commit *commit_init(struct drm_atomic_state *state) c->dev = state->dev; c->state = state; - /* TODO we might need a way to indicate to run the cb on a - * different wq so wait_for_vblanks() doesn't block retiring - * bo's.. - */ - INIT_FENCE_CB(&c->fence_cb, fence_cb); + INIT_WORK(&c->work, commit_worker); return c; } @@ -113,16 +107,39 @@ static void msm_atomic_wait_for_commit_done(struct drm_device *dev, } } +static void wait_fences(struct msm_commit *c, bool async) +{ + int nplanes = c->dev->mode_config.num_total_plane; + ktime_t timeout = ktime_add_ms(ktime_get(), 1000); + int i; + + for (i = 0; i < nplanes; i++) { + struct drm_plane *plane = c->state->planes[i]; + struct drm_plane_state *new_state = c->state->plane_states[i]; + + if (!plane) + continue; + + if ((plane->state->fb != new_state->fb) && new_state->fb) { + struct drm_gem_object *obj = + msm_framebuffer_bo(new_state->fb, 0); + msm_gem_cpu_sync(obj, MSM_PREP_READ, &timeout); + } + } +} + /* The (potentially) asynchronous part of the commit. At this point * nothing can fail short of armageddon. */ -static void complete_commit(struct msm_commit *c) +static void complete_commit(struct msm_commit *c, bool async) { struct drm_atomic_state *state = c->state; struct drm_device *dev = state->dev; struct msm_drm_private *priv = dev->dev_private; struct msm_kms *kms = priv->kms; + wait_fences(c, async); + kms->funcs->prepare_commit(kms, state); drm_atomic_helper_commit_modeset_disables(dev, state); @@ -155,17 +172,9 @@ static void complete_commit(struct msm_commit *c) commit_destroy(c); } -static void fence_cb(struct msm_fence_cb *cb) +static void commit_worker(struct work_struct *work) { - struct msm_commit *c = - container_of(cb, struct msm_commit, fence_cb); - complete_commit(c); -} - -static void add_fb(struct msm_commit *c, struct drm_framebuffer *fb) -{ - struct drm_gem_object *obj = msm_framebuffer_bo(fb, 0); - c->fence = max(c->fence, msm_gem_fence(to_msm_bo(obj), MSM_PREP_READ)); + complete_commit(container_of(work, struct msm_commit, work), true); } int msm_atomic_check(struct drm_device *dev, @@ -205,9 +214,7 @@ int msm_atomic_commit(struct drm_device *dev, struct drm_atomic_state *state, bool async) { struct msm_drm_private *priv = dev->dev_private; - int nplanes = dev->mode_config.num_total_plane; int ncrtcs = dev->mode_config.num_crtc; - ktime_t timeout; struct msm_commit *c; int i, ret; @@ -232,20 +239,6 @@ int msm_atomic_commit(struct drm_device *dev, } /* - * Figure out what fence to wait for: - */ - for (i = 0; i < nplanes; i++) { - struct drm_plane *plane = state->planes[i]; - struct drm_plane_state *new_state = state->plane_states[i]; - - if (!plane) - continue; - - if ((plane->state->fb != new_state->fb) && new_state->fb) - add_fb(c, new_state->fb); - } - - /* * Wait for pending updates on any of the same crtc's and then * mark our set of crtc's as busy: */ @@ -279,18 +272,12 @@ int msm_atomic_commit(struct drm_device *dev, * current layout. */ - if (async && priv->gpu) { - msm_queue_fence_cb(priv->gpu->fctx, &c->fence_cb, c->fence); + if (async) { + queue_work(priv->atomic_wq, &c->work); return 0; } - timeout = ktime_add_ms(ktime_get(), 1000); - - /* uninterruptible wait */ - if (priv->gpu) - msm_wait_fence(priv->gpu->fctx, c->fence, &timeout, false); - - complete_commit(c); + complete_commit(c, false); return 0; diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c index b623397..281f912 100644 --- a/drivers/gpu/drm/msm/msm_drv.c +++ b/drivers/gpu/drm/msm/msm_drv.c @@ -213,6 +213,9 @@ static int msm_unload(struct drm_device *dev) flush_workqueue(priv->wq); destroy_workqueue(priv->wq); + flush_workqueue(priv->atomic_wq); + destroy_workqueue(priv->atomic_wq); + if (kms) { pm_runtime_disable(dev->dev); kms->funcs->destroy(kms); @@ -339,6 +342,7 @@ static int msm_load(struct drm_device *dev, unsigned long flags) dev->dev_private = priv; priv->wq = alloc_ordered_workqueue("msm", 0); + priv->atomic_wq = alloc_ordered_workqueue("msm:atomic", 0); init_waitqueue_head(&priv->pending_crtcs_event); INIT_LIST_HEAD(&priv->inactive_list); diff --git a/drivers/gpu/drm/msm/msm_drv.h b/drivers/gpu/drm/msm/msm_drv.h index 3df747f..6194450 100644 --- a/drivers/gpu/drm/msm/msm_drv.h +++ b/drivers/gpu/drm/msm/msm_drv.h @@ -109,6 +109,7 @@ struct msm_drm_private { struct list_head inactive_list; struct workqueue_struct *wq; + struct workqueue_struct *atomic_wq; /* crtcs pending async atomic updates: */ uint32_t pending_crtcs; @@ -194,8 +195,8 @@ int msm_gem_queue_inactive_cb(struct drm_gem_object *obj, void msm_gem_move_to_active(struct drm_gem_object *obj, struct msm_gpu *gpu, bool write, uint32_t fence); void msm_gem_move_to_inactive(struct drm_gem_object *obj); -int msm_gem_cpu_prep(struct drm_gem_object *obj, uint32_t op, - ktime_t *timeout); +int msm_gem_cpu_sync(struct drm_gem_object *obj, uint32_t op, ktime_t *timeout); +int msm_gem_cpu_prep(struct drm_gem_object *obj, uint32_t op, ktime_t *timeout); int msm_gem_cpu_fini(struct drm_gem_object *obj); void msm_gem_free_object(struct drm_gem_object *obj); int msm_gem_new_handle(struct drm_device *dev, struct drm_file *file, diff --git a/drivers/gpu/drm/msm/msm_fence.c b/drivers/gpu/drm/msm/msm_fence.c index f0ed6a6..088610c 100644 --- a/drivers/gpu/drm/msm/msm_fence.c +++ b/drivers/gpu/drm/msm/msm_fence.c @@ -33,7 +33,6 @@ msm_fence_context_alloc(struct drm_device *dev, const char *name) fctx->dev = dev; fctx->name = name; init_waitqueue_head(&fctx->event); - INIT_LIST_HEAD(&fctx->fence_cbs); return fctx; } @@ -86,54 +85,12 @@ int msm_wait_fence(struct msm_fence_context *fctx, uint32_t fence, return ret; } -int msm_queue_fence_cb(struct msm_fence_context *fctx, - struct msm_fence_cb *cb, uint32_t fence) -{ - struct msm_drm_private *priv = fctx->dev->dev_private; - int ret = 0; - - mutex_lock(&fctx->dev->struct_mutex); - if (!list_empty(&cb->work.entry)) { - ret = -EINVAL; - } else if (fence > fctx->completed_fence) { - cb->fence = fence; - list_add_tail(&cb->work.entry, &fctx->fence_cbs); - } else { - queue_work(priv->wq, &cb->work); - } - mutex_unlock(&fctx->dev->struct_mutex); - - return ret; -} - /* called from workqueue */ void msm_update_fence(struct msm_fence_context *fctx, uint32_t fence) { - struct msm_drm_private *priv = fctx->dev->dev_private; - mutex_lock(&fctx->dev->struct_mutex); fctx->completed_fence = max(fence, fctx->completed_fence); - - while (!list_empty(&fctx->fence_cbs)) { - struct msm_fence_cb *cb; - - cb = list_first_entry(&fctx->fence_cbs, - struct msm_fence_cb, work.entry); - - if (cb->fence > fctx->completed_fence) - break; - - list_del_init(&cb->work.entry); - queue_work(priv->wq, &cb->work); - } - mutex_unlock(&fctx->dev->struct_mutex); wake_up_all(&fctx->event); } - -void __msm_fence_worker(struct work_struct *work) -{ - struct msm_fence_cb *cb = container_of(work, struct msm_fence_cb, work); - cb->func(cb); -} diff --git a/drivers/gpu/drm/msm/msm_fence.h b/drivers/gpu/drm/msm/msm_fence.h index 3ed2098..2820781 100644 --- a/drivers/gpu/drm/msm/msm_fence.h +++ b/drivers/gpu/drm/msm/msm_fence.h @@ -27,28 +27,12 @@ struct msm_fence_context { uint32_t last_fence; /* last assigned fence */ uint32_t completed_fence; /* last completed fence */ wait_queue_head_t event; - /* callbacks deferred until bo is inactive: */ - struct list_head fence_cbs; }; struct msm_fence_context * msm_fence_context_alloc(struct drm_device *dev, const char *name); void msm_fence_context_free(struct msm_fence_context *fctx); -/* callback from wq once fence has passed: */ -struct msm_fence_cb { - struct work_struct work; - uint32_t fence; - void (*func)(struct msm_fence_cb *cb); -}; - -void __msm_fence_worker(struct work_struct *work); - -#define INIT_FENCE_CB(_cb, _func) do { \ - INIT_WORK(&(_cb)->work, __msm_fence_worker); \ - (_cb)->func = _func; \ - } while (0) - int msm_wait_fence(struct msm_fence_context *fctx, uint32_t fence, ktime_t *timeout, bool interruptible); int msm_queue_fence_cb(struct msm_fence_context *fctx, diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c index 80bb6e2..1aabc41 100644 --- a/drivers/gpu/drm/msm/msm_gem.c +++ b/drivers/gpu/drm/msm/msm_gem.c @@ -451,7 +451,7 @@ void msm_gem_move_to_inactive(struct drm_gem_object *obj) list_add_tail(&msm_obj->mm_list, &priv->inactive_list); } -int msm_gem_cpu_prep(struct drm_gem_object *obj, uint32_t op, ktime_t *timeout) +int msm_gem_cpu_sync(struct drm_gem_object *obj, uint32_t op, ktime_t *timeout) { struct drm_device *dev = obj->dev; struct msm_drm_private *priv = dev->dev_private; @@ -468,6 +468,13 @@ int msm_gem_cpu_prep(struct drm_gem_object *obj, uint32_t op, ktime_t *timeout) ret = msm_wait_fence(priv->gpu->fctx, fence, timeout, true); } + return ret; +} + +int msm_gem_cpu_prep(struct drm_gem_object *obj, uint32_t op, ktime_t *timeout) +{ + int ret = msm_gem_cpu_sync(obj, op, timeout); + /* TODO cache maintenance */ return ret;