linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rafael@kernel.org>
To: Saravana Kannan <saravanak@google.com>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	LKML <linux-kernel@vger.kernel.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	chenxiang <chenxiang66@hisilicon.com>
Subject: Re: [PATCH v1 2/2] drivers: base: Reduce device link removal code duplication
Date: Fri, 14 May 2021 20:33:33 +0200	[thread overview]
Message-ID: <CAJZ5v0ik0GMYg9ru7G=P3-=vmg-LEQo1ZO0Sn99=DJwsPN5-uw@mail.gmail.com> (raw)
In-Reply-To: <CAGETcx87y-tpSaKRpugons1RZaPC-rdvdueUPuNFJHWDDyrNwQ@mail.gmail.com>

On Fri, May 14, 2021 at 6:05 PM Saravana Kannan <saravanak@google.com> wrote:
>
> On Fri, May 14, 2021 at 5:12 AM Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
> >
> > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> >
> > Reduce device link removal code duplication between the cases when
> > SRCU is enabled and when it is disabled by moving the only differing
> > piece of it (which is the removal of the link from the consumer and
> > supplier lists) into a separate wrapper function (defined differently
> > for each of the cases in question).
> >
> > No intentional functional impact.
> >
> > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> > ---
> >  drivers/base/core.c |   31 +++++++++++++------------------
> >  1 file changed, 13 insertions(+), 18 deletions(-)
> >
> > Index: linux-pm/drivers/base/core.c
> > ===================================================================
> > --- linux-pm.orig/drivers/base/core.c
> > +++ linux-pm/drivers/base/core.c
> > @@ -198,6 +198,12 @@ static void device_link_synchronize_remo
> >  {
> >         synchronize_srcu(&device_links_srcu);
> >  }
> > +
> > +static void device_link_remove_from_lists(struct device_link *link)
> > +{
> > +       list_del_rcu(&link->s_node);
> > +       list_del_rcu(&link->c_node);
> > +}
> >  #else /* !CONFIG_SRCU */
> >  static DECLARE_RWSEM(device_links_lock);
> >
> > @@ -232,6 +238,12 @@ int device_links_read_lock_held(void)
> >  static inline void device_link_synchronize_removal(void)
> >  {
> >  }
> > +
> > +static void device_link_remove_from_lists(struct device_link *link)
> > +{
> > +       list_del(&link->s_node);
> > +       list_del(&link->c_node);
> > +}
> >  #endif /* !CONFIG_SRCU */
> >
> >  static bool device_is_ancestor(struct device *dev, struct device *target)
> > @@ -854,7 +866,6 @@ out:
> >  }
> >  EXPORT_SYMBOL_GPL(device_link_add);
> >
> > -#ifdef CONFIG_SRCU
> >  static void __device_link_del(struct kref *kref)
> >  {
> >         struct device_link *link = container_of(kref, struct device_link, kref);
> > @@ -864,25 +875,9 @@ static void __device_link_del(struct kre
> >
> >         pm_runtime_drop_link(link);
> >
> > -       list_del_rcu(&link->s_node);
> > -       list_del_rcu(&link->c_node);
> > +       device_link_remove_from_lists(link);
>
> Remind me again why we can't do the synchronize_srcu() here (I'm not
> too familiar with the SRCU API semantics)? Is it because
> synchronize_srcu() can take indefinitely long?

Not indefinitely, but it may take time.  And because it is not
actually useful before we end up freeing the device link memory.  And
I'd rather not do it under the device links write lock.

> I just vaguely remember
> it does some checks during CPUs going idle (which can be a long time
> later) but I'm not sure if that's the earliest you can synchronize. If
> it's not indefinitely long and we just need to wait for other SRCU
> critical sections to exit, maybe we can just synchronize here and make
> the code a lot simpler?

Well, maybe not  "a lot".

> This function is anyway called in a sleepable context.

But I'm not sure how long this context expects to be sleeping and
sleeping under a mutex potentially blocks others.

  reply	other threads:[~2021-05-14 18:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-14 12:08 [PATCH v1 0/2] drivers: base: Device links removal fix and cleanup Rafael J. Wysocki
2021-05-14 12:10 ` [PATCH v1 1/2] drivers: base: Fix device link removal Rafael J. Wysocki
2021-05-14 12:11 ` [PATCH v1 2/2] drivers: base: Reduce device link removal code duplication Rafael J. Wysocki
2021-05-14 16:04   ` Saravana Kannan
2021-05-14 18:33     ` Rafael J. Wysocki [this message]
2021-05-14 18:38       ` Saravana Kannan
2021-05-14 12:34 ` [PATCH v1 0/2] drivers: base: Device links removal fix and cleanup Greg Kroah-Hartman
2021-05-14 12:56   ` Rafael J. Wysocki

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='CAJZ5v0ik0GMYg9ru7G=P3-=vmg-LEQo1ZO0Sn99=DJwsPN5-uw@mail.gmail.com' \
    --to=rafael@kernel.org \
    --cc=chenxiang66@hisilicon.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rjw@rjwysocki.net \
    --cc=saravanak@google.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;
as well as URLs for NNTP newsgroup(s).