All of lore.kernel.org
 help / color / mirror / Atom feed
From: jbrunet@baylibre.com (Jerome Brunet)
To: linus-amlogic@lists.infradead.org
Subject: [RFC 1/7] clk: take the prepare lock out of clk_core_set_parent
Date: Fri, 12 May 2017 11:54:05 +0200	[thread overview]
Message-ID: <1494582845.21207.3.camel@baylibre.com> (raw)
In-Reply-To: <149228696755.88277.11390638024881688991@resonance>

On Sat, 2017-04-15 at 22:09 +0200, Michael Turquette wrote:
> Hi Jerome,
> 
> Quoting Jerome Brunet (2017-03-21 19:33:24)
> > Rework set_parent core function so it can be called when the prepare lock
> > is already held by the caller.
> > 
> > This rework is done to ease the integration of the "protected" clock
> > functionality.
> > 
> > Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
> > ---
> > ?drivers/clk/clk.c | 38 ++++++++++++++++++++------------------
> > ?1 file changed, 20 insertions(+), 18 deletions(-)
> > 
> > diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> > index 67201f67a14a..e77f03a47da6 100644
> > --- a/drivers/clk/clk.c
> > +++ b/drivers/clk/clk.c
> > @@ -1794,23 +1794,16 @@ static int clk_core_set_parent(struct clk_core
> > *core, struct clk_core *parent)
> 
> Nitpick: rename clk_core_set_parent to clk_core_st_parent_nolock. Drop
> the clk_core_set_parent_lock name below and just call it
> clk_core_set_parent.
> 
> This matches all the other nolock patterns in clk.c.

Indeed, I should tidy up the naming regarding the "_lock" and "_no_lock"
This applies to the rest of the patches.

> 
> > ????????if (!core)
> > ????????????????return 0;
> > ?
> > -???????/* prevent racing with updates to the clock topology */
> > -???????clk_prepare_lock();
> > -
> > ????????if (core->parent == parent)
> > -???????????????goto out;
> > +???????????????return 0;
> > ?
> > ????????/* verify ops for for multi-parent clks */
> > -???????if ((core->num_parents > 1) && (!core->ops->set_parent)) {
> > -???????????????ret = -ENOSYS;
> > -???????????????goto out;
> > -???????}
> > +???????if ((core->num_parents > 1) && (!core->ops->set_parent))
> > +???????????????return -ENOSYS;
> > ?
> > ????????/* check that we are allowed to re-parent if the clock is in use */
> > -???????if ((core->flags & CLK_SET_PARENT_GATE) && core->prepare_count) {
> > -???????????????ret = -EBUSY;
> > -???????????????goto out;
> > -???????}
> > +???????if ((core->flags & CLK_SET_PARENT_GATE) && core->prepare_count)
> > +???????????????return -EBUSY;
> > ?
> > ????????/* try finding the new parent index */
> > ????????if (parent) {
> > @@ -1818,8 +1811,7 @@ static int clk_core_set_parent(struct clk_core *core,
> > struct clk_core *parent)
> > ????????????????if (p_index < 0) {
> > ????????????????????????pr_debug("%s: clk %s can not be parent of clk %s\n",
> > ????????????????????????????????????????__func__, parent->name, core->name);
> > -???????????????????????ret = p_index;
> > -???????????????????????goto out;
> > +???????????????????????return p_index;
> > ????????????????}
> > ????????????????p_rate = parent->rate;
> > ????????}
> > @@ -1829,7 +1821,7 @@ static int clk_core_set_parent(struct clk_core *core,
> > struct clk_core *parent)
> > ?
> > ????????/* abort if a driver objects */
> > ????????if (ret & NOTIFY_STOP_MASK)
> > -???????????????goto out;
> > +???????????????return ret;
> > ?
> > ????????/* do the re-parent */
> > ????????ret = __clk_set_parent(core, parent, p_index);
> > @@ -1842,7 +1834,16 @@ static int clk_core_set_parent(struct clk_core *core,
> > struct clk_core *parent)
> > ????????????????__clk_recalc_accuracies(core);
> > ????????}
> > ?
> > -out:
> > +???????return ret;
> 
> I do not understand the benefit of the code churn above where gotos are
> replaced with returns. This should be a few line patch but it is much
> more than that due to this churn.

I understand, the unified diff is far from being easy to read.
Gotos and labels were useful to centralize the call to clk_prepare_unlock()
on exit (including error case). With this patch, the prepare lock is no longer 
managed in this function (but one level up)

All you would have under the "out" label is "return ret;".
In such case, I think we should call directly return and get rid of the gotos.

Do you agree ? 

> 
> > +}
> > +
> > +static int clk_core_set_parent_lock(struct clk_core *core,
> > +???????????????????????????????????struct clk_core *parent)
> > +{
> > +???????int ret;
> > +
> > +???????clk_prepare_lock();
> > +???????ret = clk_core_set_parent(core, parent);
> 
> Above line should be nolock.
> 
> > ????????clk_prepare_unlock();
> > ?
> > ????????return ret;
> > @@ -1870,7 +1871,8 @@ int clk_set_parent(struct clk *clk, struct clk
> > *parent)
> > ????????if (!clk)
> > ????????????????return 0;
> > ?
> > -???????return clk_core_set_parent(clk->core, parent ? parent->core : NULL);
> > +???????return clk_core_set_parent_lock(clk->core,
> > +???????????????????????????????????????parent ? parent->core : NULL);
> 
> We can avoid this line by using the nolock pattern.
> 
> Basic premise of the patch is OK though.
> 
> Regards,
> Mike
> 
> > ?}
> > ?EXPORT_SYMBOL_GPL(clk_set_parent);
> > ?
> > @@ -2720,7 +2722,7 @@ void clk_unregister(struct clk *clk)
> > ????????????????/* Reparent all children to the orphan list. */
> > ????????????????hlist_for_each_entry_safe(child, t, &clk->core->children,
> > ??????????????????????????????????????????child_node)
> > -???????????????????????clk_core_set_parent(child, NULL);
> > +???????????????????????clk_core_set_parent_lock(child, NULL);
> > ????????}
> > ?
> > ????????hlist_del_init(&clk->core->child_node);
> > --?
> > 2.9.3
> > 

WARNING: multiple messages have this Message-ID (diff)
From: Jerome Brunet <jbrunet@baylibre.com>
To: Michael Turquette <mturquette@baylibre.com>,
	Stephen Boyd <sboyd@codeaurora.org>,
	Kevin Hilman <khilman@baylibre.com>
Cc: linux-clk@vger.kernel.org, linux-amlogic@lists.infradead.org
Subject: Re: [RFC 1/7] clk: take the prepare lock out of clk_core_set_parent
Date: Fri, 12 May 2017 11:54:05 +0200	[thread overview]
Message-ID: <1494582845.21207.3.camel@baylibre.com> (raw)
In-Reply-To: <149228696755.88277.11390638024881688991@resonance>

On Sat, 2017-04-15 at 22:09 +0200, Michael Turquette wrote:
> Hi Jerome,
> 
> Quoting Jerome Brunet (2017-03-21 19:33:24)
> > Rework set_parent core function so it can be called when the prepare lock
> > is already held by the caller.
> > 
> > This rework is done to ease the integration of the "protected" clock
> > functionality.
> > 
> > Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
> > ---
> >  drivers/clk/clk.c | 38 ++++++++++++++++++++------------------
> >  1 file changed, 20 insertions(+), 18 deletions(-)
> > 
> > diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> > index 67201f67a14a..e77f03a47da6 100644
> > --- a/drivers/clk/clk.c
> > +++ b/drivers/clk/clk.c
> > @@ -1794,23 +1794,16 @@ static int clk_core_set_parent(struct clk_core
> > *core, struct clk_core *parent)
> 
> Nitpick: rename clk_core_set_parent to clk_core_st_parent_nolock. Drop
> the clk_core_set_parent_lock name below and just call it
> clk_core_set_parent.
> 
> This matches all the other nolock patterns in clk.c.

Indeed, I should tidy up the naming regarding the "_lock" and "_no_lock"
This applies to the rest of the patches.

> 
> >         if (!core)
> >                 return 0;
> >  
> > -       /* prevent racing with updates to the clock topology */
> > -       clk_prepare_lock();
> > -
> >         if (core->parent == parent)
> > -               goto out;
> > +               return 0;
> >  
> >         /* verify ops for for multi-parent clks */
> > -       if ((core->num_parents > 1) && (!core->ops->set_parent)) {
> > -               ret = -ENOSYS;
> > -               goto out;
> > -       }
> > +       if ((core->num_parents > 1) && (!core->ops->set_parent))
> > +               return -ENOSYS;
> >  
> >         /* check that we are allowed to re-parent if the clock is in use */
> > -       if ((core->flags & CLK_SET_PARENT_GATE) && core->prepare_count) {
> > -               ret = -EBUSY;
> > -               goto out;
> > -       }
> > +       if ((core->flags & CLK_SET_PARENT_GATE) && core->prepare_count)
> > +               return -EBUSY;
> >  
> >         /* try finding the new parent index */
> >         if (parent) {
> > @@ -1818,8 +1811,7 @@ static int clk_core_set_parent(struct clk_core *core,
> > struct clk_core *parent)
> >                 if (p_index < 0) {
> >                         pr_debug("%s: clk %s can not be parent of clk %s\n",
> >                                         __func__, parent->name, core->name);
> > -                       ret = p_index;
> > -                       goto out;
> > +                       return p_index;
> >                 }
> >                 p_rate = parent->rate;
> >         }
> > @@ -1829,7 +1821,7 @@ static int clk_core_set_parent(struct clk_core *core,
> > struct clk_core *parent)
> >  
> >         /* abort if a driver objects */
> >         if (ret & NOTIFY_STOP_MASK)
> > -               goto out;
> > +               return ret;
> >  
> >         /* do the re-parent */
> >         ret = __clk_set_parent(core, parent, p_index);
> > @@ -1842,7 +1834,16 @@ static int clk_core_set_parent(struct clk_core *core,
> > struct clk_core *parent)
> >                 __clk_recalc_accuracies(core);
> >         }
> >  
> > -out:
> > +       return ret;
> 
> I do not understand the benefit of the code churn above where gotos are
> replaced with returns. This should be a few line patch but it is much
> more than that due to this churn.

I understand, the unified diff is far from being easy to read.
Gotos and labels were useful to centralize the call to clk_prepare_unlock()
on exit (including error case). With this patch, the prepare lock is no longer 
managed in this function (but one level up)

All you would have under the "out" label is "return ret;".
In such case, I think we should call directly return and get rid of the gotos.

Do you agree ? 

> 
> > +}
> > +
> > +static int clk_core_set_parent_lock(struct clk_core *core,
> > +                                   struct clk_core *parent)
> > +{
> > +       int ret;
> > +
> > +       clk_prepare_lock();
> > +       ret = clk_core_set_parent(core, parent);
> 
> Above line should be nolock.
> 
> >         clk_prepare_unlock();
> >  
> >         return ret;
> > @@ -1870,7 +1871,8 @@ int clk_set_parent(struct clk *clk, struct clk
> > *parent)
> >         if (!clk)
> >                 return 0;
> >  
> > -       return clk_core_set_parent(clk->core, parent ? parent->core : NULL);
> > +       return clk_core_set_parent_lock(clk->core,
> > +                                       parent ? parent->core : NULL);
> 
> We can avoid this line by using the nolock pattern.
> 
> Basic premise of the patch is OK though.
> 
> Regards,
> Mike
> 
> >  }
> >  EXPORT_SYMBOL_GPL(clk_set_parent);
> >  
> > @@ -2720,7 +2722,7 @@ void clk_unregister(struct clk *clk)
> >                 /* Reparent all children to the orphan list. */
> >                 hlist_for_each_entry_safe(child, t, &clk->core->children,
> >                                           child_node)
> > -                       clk_core_set_parent(child, NULL);
> > +                       clk_core_set_parent_lock(child, NULL);
> >         }
> >  
> >         hlist_del_init(&clk->core->child_node);
> > -- 
> > 2.9.3
> > 

  reply	other threads:[~2017-05-12  9:54 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-21 18:33 [RFC 0/7] clk: implement clock locking mechanism Jerome Brunet
2017-03-21 18:33 ` Jerome Brunet
2017-03-21 18:33 ` [RFC 1/7] clk: take the prepare lock out of clk_core_set_parent Jerome Brunet
2017-03-21 18:33   ` Jerome Brunet
2017-04-15 20:09   ` Michael Turquette
2017-05-11 18:23     ` Michael Turquette
2017-05-12  9:54     ` Jerome Brunet [this message]
2017-05-12  9:54       ` Jerome Brunet
2017-03-21 18:33 ` [RFC 2/7] clk: add set_phase core function Jerome Brunet
2017-03-21 18:33   ` Jerome Brunet
2017-04-15 20:27   ` Michael Turquette
2017-05-11 18:24     ` Michael Turquette
2017-03-21 18:33 ` [RFC 3/7] clk: rework calls to round and determine rate callbacks Jerome Brunet
2017-03-21 18:33   ` Jerome Brunet
2017-05-11 18:23   ` Michael Turquette
2017-05-11 18:23     ` Michael Turquette
2017-03-21 18:33 ` [RFC 4/7] clk: add support for clock protection Jerome Brunet
2017-03-21 18:33   ` Jerome Brunet
2017-05-11 19:05   ` Michael Turquette
2017-05-11 19:05     ` Michael Turquette
2017-05-12 13:08     ` Jerome Brunet
2017-05-12 13:08       ` Jerome Brunet
2017-05-15 20:03       ` Michael Turquette
2017-05-15 20:03         ` Michael Turquette
2017-05-11 19:07   ` Michael Turquette
2017-05-11 19:07     ` Michael Turquette
2017-03-21 18:33 ` [RFC 5/7] clk: rollback set_rate_range changes on failure Jerome Brunet
2017-03-21 18:33   ` Jerome Brunet
2017-03-21 18:33 ` [RFC 6/7] clk: cosmetic changes to clk_summary debugfs entry Jerome Brunet
2017-03-21 18:33   ` Jerome Brunet
2017-03-21 18:33 ` [RFC 7/7] clk: fix incorrect usage of ENOSYS Jerome Brunet
2017-03-21 18:33   ` Jerome Brunet
2017-03-22  0:07 ` [RFC 0/7] clk: implement clock locking mechanism Michael Turquette
2017-03-22  0:07   ` Michael Turquette
2017-03-22 18:13   ` Jerome Brunet
2017-03-22 18:13     ` Jerome Brunet
2017-04-15 19:50 ` Michael Turquette
2017-05-11 18:23   ` Michael Turquette
2017-05-12 14:04   ` Jerome Brunet
2017-05-12 14:04     ` Jerome Brunet
2017-05-15 20:09     ` Michael Turquette
2017-05-15 20:09       ` Michael Turquette

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=1494582845.21207.3.camel@baylibre.com \
    --to=jbrunet@baylibre.com \
    --cc=linus-amlogic@lists.infradead.org \
    /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.