linux-clk.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/1] clk: fractional-divider: Move mask calculations out of lock
@ 2024-03-03 12:14 Andy Shevchenko
  2024-03-04  3:28 ` Chen-Yu Tsai
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Andy Shevchenko @ 2024-03-03 12:14 UTC (permalink / raw)
  To: linux-clk, linux-kernel
  Cc: Michael Turquette, Stephen Boyd, Christophe JAILLET,
	Heiko Stuebner, Andy Shevchenko

There is no need to calculate masks under the lock taken.
Move them out of it.

Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
---
 drivers/clk/clk-fractional-divider.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/clk-fractional-divider.c b/drivers/clk/clk-fractional-divider.c
index a0178182fc72..da057172cc90 100644
--- a/drivers/clk/clk-fractional-divider.c
+++ b/drivers/clk/clk-fractional-divider.c
@@ -195,14 +195,14 @@ static int clk_fd_set_rate(struct clk_hw *hw, unsigned long rate,
 		n--;
 	}
 
+	mmask = GENMASK(fd->mwidth - 1, 0) << fd->mshift;
+	nmask = GENMASK(fd->nwidth - 1, 0) << fd->nshift;
+
 	if (fd->lock)
 		spin_lock_irqsave(fd->lock, flags);
 	else
 		__acquire(fd->lock);
 
-	mmask = GENMASK(fd->mwidth - 1, 0) << fd->mshift;
-	nmask = GENMASK(fd->nwidth - 1, 0) << fd->nshift;
-
 	val = clk_fd_readl(fd);
 	val &= ~(mmask | nmask);
 	val |= (m << fd->mshift) | (n << fd->nshift);
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v1 1/1] clk: fractional-divider: Move mask calculations out of lock
  2024-03-03 12:14 [PATCH v1 1/1] clk: fractional-divider: Move mask calculations out of lock Andy Shevchenko
@ 2024-03-04  3:28 ` Chen-Yu Tsai
  2024-03-04  7:05 ` Heiko Stübner
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Chen-Yu Tsai @ 2024-03-04  3:28 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: linux-clk, linux-kernel, Michael Turquette, Stephen Boyd,
	Christophe JAILLET, Heiko Stuebner

On Sun, Mar 3, 2024 at 8:14 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
>
> There is no need to calculate masks under the lock taken.
> Move them out of it.
>
> Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>

Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v1 1/1] clk: fractional-divider: Move mask calculations out of lock
  2024-03-03 12:14 [PATCH v1 1/1] clk: fractional-divider: Move mask calculations out of lock Andy Shevchenko
  2024-03-04  3:28 ` Chen-Yu Tsai
@ 2024-03-04  7:05 ` Heiko Stübner
  2024-03-09  1:06 ` Stephen Boyd
  2024-03-09  7:19 ` Christophe JAILLET
  3 siblings, 0 replies; 7+ messages in thread
From: Heiko Stübner @ 2024-03-04  7:05 UTC (permalink / raw)
  To: linux-clk, linux-kernel, Andy Shevchenko
  Cc: Michael Turquette, Stephen Boyd, Christophe JAILLET,
	Andy Shevchenko

Am Sonntag, 3. März 2024, 13:14:10 CET schrieb Andy Shevchenko:
> There is no need to calculate masks under the lock taken.
> Move them out of it.
> 
> Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>

Reviewed-by: Heiko Stuebner <heiko@sntech.de>

> ---
>  drivers/clk/clk-fractional-divider.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/clk/clk-fractional-divider.c b/drivers/clk/clk-fractional-divider.c
> index a0178182fc72..da057172cc90 100644
> --- a/drivers/clk/clk-fractional-divider.c
> +++ b/drivers/clk/clk-fractional-divider.c
> @@ -195,14 +195,14 @@ static int clk_fd_set_rate(struct clk_hw *hw, unsigned long rate,
>  		n--;
>  	}
>  
> +	mmask = GENMASK(fd->mwidth - 1, 0) << fd->mshift;
> +	nmask = GENMASK(fd->nwidth - 1, 0) << fd->nshift;
> +
>  	if (fd->lock)
>  		spin_lock_irqsave(fd->lock, flags);
>  	else
>  		__acquire(fd->lock);
>  
> -	mmask = GENMASK(fd->mwidth - 1, 0) << fd->mshift;
> -	nmask = GENMASK(fd->nwidth - 1, 0) << fd->nshift;
> -
>  	val = clk_fd_readl(fd);
>  	val &= ~(mmask | nmask);
>  	val |= (m << fd->mshift) | (n << fd->nshift);
> 





^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v1 1/1] clk: fractional-divider: Move mask calculations out of lock
  2024-03-03 12:14 [PATCH v1 1/1] clk: fractional-divider: Move mask calculations out of lock Andy Shevchenko
  2024-03-04  3:28 ` Chen-Yu Tsai
  2024-03-04  7:05 ` Heiko Stübner
@ 2024-03-09  1:06 ` Stephen Boyd
  2024-03-09 16:29   ` Andy Shevchenko
  2024-03-09  7:19 ` Christophe JAILLET
  3 siblings, 1 reply; 7+ messages in thread
From: Stephen Boyd @ 2024-03-09  1:06 UTC (permalink / raw)
  To: Andy Shevchenko, linux-clk, linux-kernel
  Cc: Michael Turquette, Christophe JAILLET, Heiko Stuebner,
	Andy Shevchenko

Quoting Andy Shevchenko (2024-03-03 04:14:10)
> There is no need to calculate masks under the lock taken.
> Move them out of it.
> 
> Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> ---

Applied to clk-next

> diff --git a/drivers/clk/clk-fractional-divider.c b/drivers/clk/clk-fractional-divider.c
> index a0178182fc72..da057172cc90 100644
> --- a/drivers/clk/clk-fractional-divider.c
> +++ b/drivers/clk/clk-fractional-divider.c
> @@ -195,14 +195,14 @@ static int clk_fd_set_rate(struct clk_hw *hw, unsigned long rate,
>                 n--;
>         }
>  
> +       mmask = GENMASK(fd->mwidth - 1, 0) << fd->mshift;
> +       nmask = GENMASK(fd->nwidth - 1, 0) << fd->nshift;
> +
>         if (fd->lock)
>                 spin_lock_irqsave(fd->lock, flags);
>         else
>                 __acquire(fd->lock);
>  
> -       mmask = GENMASK(fd->mwidth - 1, 0) << fd->mshift;
> -       nmask = GENMASK(fd->nwidth - 1, 0) << fd->nshift;
> -
>         val = clk_fd_readl(fd);
>         val &= ~(mmask | nmask);
>         val |= (m << fd->mshift) | (n << fd->nshift);

Should we pre-calculate the mask and shift values too!?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v1 1/1] clk: fractional-divider: Move mask calculations out of lock
  2024-03-03 12:14 [PATCH v1 1/1] clk: fractional-divider: Move mask calculations out of lock Andy Shevchenko
                   ` (2 preceding siblings ...)
  2024-03-09  1:06 ` Stephen Boyd
@ 2024-03-09  7:19 ` Christophe JAILLET
  2024-03-09 16:27   ` Andy Shevchenko
  3 siblings, 1 reply; 7+ messages in thread
From: Christophe JAILLET @ 2024-03-09  7:19 UTC (permalink / raw)
  To: Andy Shevchenko, linux-clk, linux-kernel
  Cc: Michael Turquette, Stephen Boyd, Heiko Stuebner

Le 03/03/2024 à 13:14, Andy Shevchenko a écrit :
> There is no need to calculate masks under the lock taken.
> Move them out of it.
> 
> Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> ---
>   drivers/clk/clk-fractional-divider.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/clk/clk-fractional-divider.c b/drivers/clk/clk-fractional-divider.c
> index a0178182fc72..da057172cc90 100644
> --- a/drivers/clk/clk-fractional-divider.c
> +++ b/drivers/clk/clk-fractional-divider.c
> @@ -195,14 +195,14 @@ static int clk_fd_set_rate(struct clk_hw *hw, unsigned long rate,
>   		n--;
>   	}
>   
> +	mmask = GENMASK(fd->mwidth - 1, 0) << fd->mshift;
> +	nmask = GENMASK(fd->nwidth - 1, 0) << fd->nshift;
> +

Hi,

if this is a hot path, you could maybe even compute:
    mask = ~(GENMASK(fd->mwidth - 1, 0) << fd->mshift |
             GENMASK(fd->nwidth - 1, 0) << fd->nshift)

unless gcc is smart enough to do it by itself.

>   	if (fd->lock)
>   		spin_lock_irqsave(fd->lock, flags);
>   	else
>   		__acquire(fd->lock);
>   
> -	mmask = GENMASK(fd->mwidth - 1, 0) << fd->mshift;
> -	nmask = GENMASK(fd->nwidth - 1, 0) << fd->nshift;
> -
>   	val = clk_fd_readl(fd);
>   	val &= ~(mmask | nmask);

    val &= mask;

>   	val |= (m << fd->mshift) | (n << fd->nshift);

and pre-compute "(m << fd->mshift) | (n << fd->nshift)" outside of the 
lock too.

CJ

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v1 1/1] clk: fractional-divider: Move mask calculations out of lock
  2024-03-09  7:19 ` Christophe JAILLET
@ 2024-03-09 16:27   ` Andy Shevchenko
  0 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2024-03-09 16:27 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: linux-clk, linux-kernel, Michael Turquette, Stephen Boyd,
	Heiko Stuebner

On Sat, Mar 9, 2024 at 9:19 AM Christophe JAILLET
<christophe.jaillet@wanadoo.fr> wrote:
> Le 03/03/2024 à 13:14, Andy Shevchenko a écrit :

...

> > @@ -195,14 +195,14 @@ static int clk_fd_set_rate(struct clk_hw *hw, unsigned long rate,
> >               n--;
> >       }
> >
> > +     mmask = GENMASK(fd->mwidth - 1, 0) << fd->mshift;
> > +     nmask = GENMASK(fd->nwidth - 1, 0) << fd->nshift;

> if this is a hot path, you could maybe even compute:

It's not. set_rate() may be called only on disabled (and unprepared?)
clocks, which makes it already a too slow operation.

>     mask = ~(GENMASK(fd->mwidth - 1, 0) << fd->mshift |
>              GENMASK(fd->nwidth - 1, 0) << fd->nshift)
>
> unless gcc is smart enough to do it by itself.
>
> >       if (fd->lock)
> >               spin_lock_irqsave(fd->lock, flags);
> >       else
> >               __acquire(fd->lock);
> >
> > -     mmask = GENMASK(fd->mwidth - 1, 0) << fd->mshift;
> > -     nmask = GENMASK(fd->nwidth - 1, 0) << fd->nshift;
> > -
> >       val = clk_fd_readl(fd);
> >       val &= ~(mmask | nmask);
>
>     val &= mask;
>
> >       val |= (m << fd->mshift) | (n << fd->nshift);
>
> and pre-compute "(m << fd->mshift) | (n << fd->nshift)" outside of the
> lock too.

All of these sound to me as premature optimisations. I only wanted to
get back to the status quo.

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v1 1/1] clk: fractional-divider: Move mask calculations out of lock
  2024-03-09  1:06 ` Stephen Boyd
@ 2024-03-09 16:29   ` Andy Shevchenko
  0 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2024-03-09 16:29 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: linux-clk, linux-kernel, Michael Turquette, Christophe JAILLET,
	Heiko Stuebner

On Sat, Mar 9, 2024 at 3:06 AM Stephen Boyd <sboyd@kernel.org> wrote:
> Quoting Andy Shevchenko (2024-03-03 04:14:10)

...

> Applied to clk-next

Thank you!

...

> Should we pre-calculate the mask and shift values too!?

Not that it's required, but we _can_ do that, of course.

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-03-09 16:29 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-03 12:14 [PATCH v1 1/1] clk: fractional-divider: Move mask calculations out of lock Andy Shevchenko
2024-03-04  3:28 ` Chen-Yu Tsai
2024-03-04  7:05 ` Heiko Stübner
2024-03-09  1:06 ` Stephen Boyd
2024-03-09 16:29   ` Andy Shevchenko
2024-03-09  7:19 ` Christophe JAILLET
2024-03-09 16:27   ` Andy Shevchenko

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).