From: "Christian König" <ckoenig.leichtzumerken@gmail.com>
To: daniel@ffwll.ch, l.stach@pengutronix.de,
linux+etnaviv@armlinux.org.uk, christian.gmeiner@gmail.com,
yuq825@gmail.com, eric@anholt.net, peterz@infradead.org,
thellstrom@vmware.com, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org,
lima@lists.freedesktop.org
Subject: [PATCH 2/6] drm/ttm: use new ww_mutex_(un)lock_for_each macros
Date: Fri, 14 Jun 2019 14:41:21 +0200 [thread overview]
Message-ID: <20190614124125.124181-3-christian.koenig@amd.com> (raw)
In-Reply-To: <20190614124125.124181-1-christian.koenig@amd.com>
Use the provided macros instead of implementing deadlock handling on our own.
Signed-off-by: Christian König <christian.koenig@amd.com>
---
drivers/gpu/drm/ttm/ttm_execbuf_util.c | 87 +++++++++-----------------
1 file changed, 30 insertions(+), 57 deletions(-)
diff --git a/drivers/gpu/drm/ttm/ttm_execbuf_util.c b/drivers/gpu/drm/ttm/ttm_execbuf_util.c
index 957ec375a4ba..3c3ac6c94d7f 100644
--- a/drivers/gpu/drm/ttm/ttm_execbuf_util.c
+++ b/drivers/gpu/drm/ttm/ttm_execbuf_util.c
@@ -33,16 +33,6 @@
#include <linux/sched.h>
#include <linux/module.h>
-static void ttm_eu_backoff_reservation_reverse(struct list_head *list,
- struct ttm_validate_buffer *entry)
-{
- list_for_each_entry_continue_reverse(entry, list, head) {
- struct ttm_buffer_object *bo = entry->bo;
-
- reservation_object_unlock(bo->resv);
- }
-}
-
static void ttm_eu_del_from_lru_locked(struct list_head *list)
{
struct ttm_validate_buffer *entry;
@@ -96,8 +86,9 @@ int ttm_eu_reserve_buffers(struct ww_acquire_ctx *ticket,
struct list_head *list, bool intr,
struct list_head *dups, bool del_lru)
{
- struct ttm_bo_global *glob;
struct ttm_validate_buffer *entry;
+ struct ww_mutex *contended;
+ struct ttm_bo_global *glob;
int ret;
if (list_empty(list))
@@ -109,68 +100,39 @@ int ttm_eu_reserve_buffers(struct ww_acquire_ctx *ticket,
if (ticket)
ww_acquire_init(ticket, &reservation_ww_class);
- list_for_each_entry(entry, list, head) {
+ ww_mutex_lock_for_each(list_for_each_entry(entry, list, head),
+ &entry->bo->resv->lock, contended, ret,
+ intr, ticket)
+ {
struct ttm_buffer_object *bo = entry->bo;
- ret = __ttm_bo_reserve(bo, intr, (ticket == NULL), ticket);
if (!ret && unlikely(atomic_read(&bo->cpu_writers) > 0)) {
reservation_object_unlock(bo->resv);
-
ret = -EBUSY;
+ goto error;
+ }
- } else if (ret == -EALREADY && dups) {
+ if (ret == -EALREADY && dups) {
struct ttm_validate_buffer *safe = entry;
+
entry = list_prev_entry(entry, head);
list_del(&safe->head);
list_add(&safe->head, dups);
continue;
}
- if (!ret) {
- if (!entry->num_shared)
- continue;
-
- ret = reservation_object_reserve_shared(bo->resv,
- entry->num_shared);
- if (!ret)
- continue;
- }
+ if (unlikely(ret))
+ goto error;
- /* uh oh, we lost out, drop every reservation and try
- * to only reserve this buffer, then start over if
- * this succeeds.
- */
- ttm_eu_backoff_reservation_reverse(list, entry);
-
- if (ret == -EDEADLK) {
- if (intr) {
- ret = ww_mutex_lock_slow_interruptible(&bo->resv->lock,
- ticket);
- } else {
- ww_mutex_lock_slow(&bo->resv->lock, ticket);
- ret = 0;
- }
- }
+ if (!entry->num_shared)
+ continue;
- if (!ret && entry->num_shared)
- ret = reservation_object_reserve_shared(bo->resv,
- entry->num_shared);
-
- if (unlikely(ret != 0)) {
- if (ret == -EINTR)
- ret = -ERESTARTSYS;
- if (ticket) {
- ww_acquire_done(ticket);
- ww_acquire_fini(ticket);
- }
- return ret;
+ ret = reservation_object_reserve_shared(bo->resv,
+ entry->num_shared);
+ if (unlikely(ret)) {
+ reservation_object_unlock(bo->resv);
+ goto error;
}
-
- /* move this item to the front of the list,
- * forces correct iteration of the loop without keeping track
- */
- list_del(&entry->head);
- list_add(&entry->head, list);
}
if (del_lru) {
@@ -179,6 +141,17 @@ int ttm_eu_reserve_buffers(struct ww_acquire_ctx *ticket,
spin_unlock(&glob->lru_lock);
}
return 0;
+
+error:
+ ww_mutex_unlock_for_each(list_for_each_entry(entry, list, head),
+ &entry->bo->resv->lock, contended);
+ if (ret == -EINTR)
+ ret = -ERESTARTSYS;
+ if (ticket) {
+ ww_acquire_done(ticket);
+ ww_acquire_fini(ticket);
+ }
+ return ret;
}
EXPORT_SYMBOL(ttm_eu_reserve_buffers);
--
2.17.1
next prev parent reply other threads:[~2019-06-14 12:41 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-14 12:41 ww_mutex deadlock handling cleanup Christian König
2019-06-14 12:41 ` [PATCH 1/6] locking: add ww_mutex_(un)lock_for_each helpers Christian König
2019-06-14 12:56 ` Peter Zijlstra
2019-06-14 13:04 ` Christian König
2019-06-14 12:41 ` Christian König [this message]
2019-06-14 12:41 ` [PATCH 3/6] drm/gem: use new ww_mutex_(un)lock_for_each macros Christian König
2019-06-14 12:59 ` Peter Zijlstra
2019-06-14 13:06 ` Christian König
2019-06-14 13:21 ` Peter Zijlstra
2019-06-14 13:19 ` Peter Zijlstra
2019-06-14 15:22 ` Daniel Vetter
2019-06-14 18:10 ` Christian König
2019-06-14 18:24 ` Daniel Vetter
2019-06-14 18:51 ` Christian König
2019-06-14 20:30 ` Daniel Vetter
2019-06-15 13:56 ` Daniel Vetter
2019-06-17 9:30 ` Christian König
2019-06-14 12:41 ` [PATCH 4/6] drm/etnaviv: " Christian König
2019-06-14 12:41 ` [PATCH 5/6] drm/lima: " Christian König
2019-06-14 12:41 ` [PATCH 6/6] drm/vc4: " Christian König
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190614124125.124181-3-christian.koenig@amd.com \
--to=ckoenig.leichtzumerken@gmail.com \
--cc=christian.gmeiner@gmail.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=eric@anholt.net \
--cc=etnaviv@lists.freedesktop.org \
--cc=l.stach@pengutronix.de \
--cc=lima@lists.freedesktop.org \
--cc=linux+etnaviv@armlinux.org.uk \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=thellstrom@vmware.com \
--cc=yuq825@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox