All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: christian.koenig@amd.com
Cc: daniel@ffwll.ch, l.stach@pengutronix.de,
	linux+etnaviv@armlinux.org.uk, christian.gmeiner@gmail.com,
	yuq825@gmail.com, eric@anholt.net, thellstrom@vmware.com,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	etnaviv@lists.freedesktop.org, lima@lists.freedesktop.org
Subject: Re: [PATCH 3/6] drm/gem: use new ww_mutex_(un)lock_for_each macros
Date: Fri, 14 Jun 2019 15:21:53 +0200	[thread overview]
Message-ID: <20190614132153.GR3436@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <6f2084ae-61d5-8cb9-c975-901456eed7e3@gmail.com>

On Fri, Jun 14, 2019 at 03:06:10PM +0200, Christian König wrote:
> Am 14.06.19 um 14:59 schrieb Peter Zijlstra:
> > +#define ww_mutex_lock_for_each(loop, pos, contended, ret, intr, ctx)   \
> > +       for (contended = ERR_PTR(-ENOENT); ({                           \
> > +               __label__ relock, next;                                 \
> > +               ret = -ENOENT;                                          \
> > +               if (contended == ERR_PTR(-ENOENT))                      \
> > +                       contended = NULL;                               \
> > +               else if (contended == ERR_PTR(-EDEADLK))                \
> > +                       contended = (pos);                              \
> > +               else                                                    \
> > +                       goto next;                                      \
> > +               loop {                                                  \
> > +                       if (contended == (pos)) {                       \
> > +                               contended = NULL;                       \
> > +                               continue;                               \
> > +                       }                                               \
> > +relock:                                                                        \
> > +                       ret = !(intr) ? ww_mutex_lock(pos, ctx) :       \
> > +                               ww_mutex_lock_interruptible(pos, ctx);  \
> > +                       if (ret == -EDEADLK) {                          \
> > +                               ww_mutex_unlock_for_each(loop, pos,     \
> > +                                                        contended);    \
> > +                               contended = ERR_PTR(-EDEADLK);          \
> > +                               goto relock;                            \
> > 
> > while relock here continues where it left of and doesn't restart @loop.
> > Or am I reading this monstrosity the wrong way?
> 
> contended = ERR_PTR(-EDEADLK) makes sure that the whole loop is restarted
> after retrying to acquire the lock.
> 
> See the "if" above "loop".

ARGH, the loop inside the loop... Yeah, maybe, brain hurts.

  reply	other threads:[~2019-06-14 13:22 UTC|newest]

Thread overview: 28+ 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 12:56     ` Peter Zijlstra
2019-06-14 13:04     ` Christian König
2019-06-14 12:41 ` [PATCH 2/6] drm/ttm: use new ww_mutex_(un)lock_for_each macros Christian König
2019-06-14 12:41 ` [PATCH 3/6] drm/gem: " Christian König
2019-06-14 12:41   ` Christian König
2019-06-14 12:59   ` Peter Zijlstra
2019-06-14 12:59     ` Peter Zijlstra
2019-06-14 13:06     ` Christian König
2019-06-14 13:21       ` Peter Zijlstra [this message]
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:24           ` Daniel Vetter
2019-06-14 18:51           ` Christian König
2019-06-14 20:30             ` Daniel Vetter
2019-06-14 20:30               ` Daniel Vetter
2019-06-15 13:56               ` 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   ` Christian König
2019-06-14 12:41 ` [PATCH 5/6] drm/lima: " Christian König
2019-06-14 12:41   ` 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=20190614132153.GR3436@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=christian.gmeiner@gmail.com \
    --cc=christian.koenig@amd.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=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.