All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>,
	Intel Graphics Development <intel-gfx@lists.freedesktop.org>,
	DRI Development <dri-devel@lists.freedesktop.org>,
	Daniel Vetter <daniel.vetter@intel.com>
Subject: Re: [PATCH 05/13] drm: locking&new iterators for connector_list
Date: Wed, 14 Dec 2016 13:26:06 +0100	[thread overview]
Message-ID: <20161214122606.sifkk7qnb7wupwvl@phenom.ffwll.local> (raw)
In-Reply-To: <874m26sql4.fsf@intel.com>

On Wed, Dec 14, 2016 at 01:22:15PM +0200, Jani Nikula wrote:
> On Wed, 14 Dec 2016, Daniel Vetter <daniel.vetter@ffwll.ch> wrote:
> > +/**
> > + * drm_for_each_connector_iter - connector_list iterator macro
> > + * @connector: struct &drm_connector pointer used as cursor
> > + * @iter: struct &drm_connector_list_iter
> > + *
> > + * Note that @connector is only valid within the list body, if you want to use
> > + * @connector after calling drm_connector_list_iter_put() then you need to grab
> > + * your own reference first using drm_connector_reference().
> > + */
> > +#define drm_for_each_connector_iter(connector, iter) \
> > +	while ((connector = drm_connector_list_iter_next(iter)))
> > +
> 
> Observe that in most, if not all, cases you lock over the for loop, but
> not more. That means you always get/put right around the loop.
> 
> You could have a variant of get() that returns the first item, and a
> variant of next() that does put() automatically when it's about to
> return NULL, and implement most of the loops like this:
> 
> #define drm_for_each_connector_simple(dev, iter, connector) \
> 	for (connector = drm_connector_list_iter_get_first(dev, iter); \
> 	     connector != NULL; \
> 	     connector = drm_connector_list_iter_next_put(iter))
> 
> In the long run, that should be called just drm_for_each_connector.
> 
> The only case where you'd have to call put() explicitly is when you
> break out of the loop early. Otherwise all looping would be dead simple,
> without all the gets and puts, just like they are now. Perhaps the
> naming of the functions should be such that this is the most common
> case. Perhaps you don't actually need the versions with "manual" locking
> at all.

I had this in an earlier iteration of this patch series. The implemenation
was somewhat misguided (as in it used srcu and some other wizzardry that I
now managed to remove), but otherwise was exactly what you've asking for
here.

The amount of leaking was mindboggling.

And that was only me being sloppyin in converting the piles of existing
loop, not even ongoing maintenance of new loops additions done by people
who're not well versed in the finer details of connector_list walking and
the refcounting dance involved.

Given that I've concluded that hiding those details is a bad choice, and
to top it off the new code enforces matching get/put using lockdep. We do
pay a price in that simple loops become a bit more verbose, but
unfortunately there's no way to create something which is guarnateed to
get destructed when leaving a code block (unlike in C++). And without that
guarantee I don't think it'll be maintainable long-term.

I expect that drm_for_each_connector will stay around for a long time
(maybe even forever). As long as your driver doesn't hotplug connectors,
it's perfectly fine. Only core + helpers + any driver supporting mst
really need to switch over.

Overall not the prettiest thing, but still an acceptable tradeoff imo.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2016-12-14 12:26 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-13 23:08 [PATCH 00/13] some stuff, and then connector_list locking Daniel Vetter
2016-12-13 23:08 ` [PATCH 01/13] drm/irq: drm_legacy_ prefix for legacy ioctls Daniel Vetter
2016-12-16 15:02   ` Sean Paul
2016-12-13 23:08 ` [PATCH 02/13] drm: Move atomic debugfs functions into drm_crtc_internal.h Daniel Vetter
2016-12-16 15:02   ` Sean Paul
2016-12-13 23:08 ` [PATCH 03/13] drm/radeon|amdgpu: Remove redundant num_connectors check Daniel Vetter
2016-12-14 16:59   ` Alex Deucher
2016-12-13 23:08 ` [PATCH 04/13] drm: Drop locking cargo-cult from drm_mode_config_init Daniel Vetter
2016-12-14  9:23   ` [Intel-gfx] " Daniel Stone
2016-12-16 15:03   ` Sean Paul
2016-12-13 23:08 ` [PATCH 05/13] drm: locking&new iterators for connector_list Daniel Vetter
2016-12-14  8:35   ` Chris Wilson
2016-12-14 11:22   ` Jani Nikula
2016-12-14 12:26     ` Daniel Vetter [this message]
2016-12-14 15:04       ` [Intel-gfx] " Jani Nikula
2016-12-16 15:03   ` Sean Paul
2016-12-13 23:08 ` [PATCH 06/13] drm: Convert all helpers to drm_connector_list_iter Daniel Vetter
2016-12-15 14:34   ` Harry Wentland
2016-12-15 15:58   ` [PATCH] " Daniel Vetter
2016-12-15 16:32     ` Harry Wentland
2016-12-15 22:47     ` kbuild test robot
2016-12-15 22:59     ` kbuild test robot
2016-12-16  7:29       ` Daniel Vetter
2016-12-16  7:41         ` [kbuild-all] " Fengguang Wu
2016-12-18 18:04           ` Ye Xiaolong
2016-12-16 15:03     ` Sean Paul
2016-12-13 23:08 ` [PATCH 07/13] drm: Clean up connectors by unreferencing them Daniel Vetter
2016-12-15 15:45   ` Harry Wentland
2016-12-16 15:03   ` Sean Paul
2016-12-13 23:08 ` [PATCH 08/13] drm: prevent double-(un)registration for connectors Daniel Vetter
2016-12-13 23:52   ` Chris Wilson
2016-12-16 15:03   ` Sean Paul
2016-12-13 23:08 ` [PATCH 09/13] drm: Tighten locking in drm_mode_getconnector Daniel Vetter
2016-12-16 15:03   ` Sean Paul
2016-12-18 13:40     ` Daniel Vetter
2016-12-13 23:08 ` [PATCH 10/13] drm/i915: Use drm_connector_list_iter in debugfs Daniel Vetter
2016-12-14 14:44   ` Jani Nikula
2016-12-14 14:51     ` [Intel-gfx] " Daniel Vetter
2016-12-13 23:08 ` [PATCH 11/13] drm/i915: use drm_connector_list_iter in intel_hotplug.c Daniel Vetter
2016-12-13 23:08 ` [PATCH 12/13] drm/i915: use drm_connector_list_iter in intel_opregion.c Daniel Vetter
2016-12-13 23:08 ` [PATCH 13/13] drm/i915: Make intel_get_pipe_from_connector atomic Daniel Vetter

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=20161214122606.sifkk7qnb7wupwvl@phenom.ffwll.local \
    --to=daniel@ffwll.ch \
    --cc=daniel.vetter@ffwll.ch \
    --cc=daniel.vetter@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.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.