clk: fractional-divider: Move mask calculations out of lock
PATCH 1/1 clk: fractional-divider: Move mask calculations out of lock
There is no need to calculate masks under the lock taken. Move them out of it.
--- drivers/clk/clk-fractional-divider.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/clk/clk-fractional-divider.c +3 -3
@@ -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);
Signature · 1 line
2.44.0
Quoted 5 lines · Andy Shevchenko
There is no need to calculate masks under the lock taken. Move them out of it.
Signed-off-by Andy Shevchenko <[email protected]>
Am Sonntag, 3. März 2024, 13:14:10 CET schrieb Andy Shevchenko:
Quoted 4 lines
There is no need to calculate masks under the lock taken. Move them out of it.
Signed-off-by Andy Shevchenko <[email protected]>
Quoted 27 lines
--- drivers/clk/clk-fractional-divider.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/clk/clk-fractional-divider.c +3
-3@@ -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);
Quoting Andy Shevchenko (2024-03-03 04:14:10)
Quoted 5 lines
There is no need to calculate masks under the lock taken. Move them out of it.
Signed-off-by Andy Shevchenko <[email protected]>---
Applied to clk-next
Quoted 12 lines
drivers/clk/clk-fractional-divider.c +3
-0@@ -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)
drivers/clk/clk-fractional-divider.c static int clk_fd_set_rate(struct clk_hw *hw, unsigned long rate, · line 208
Quoted 10 lines
drivers/clk/clk-fractional-divider.c +0
-3spin_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!?
Quoted 1 line · Stephen Boyd
Quoting Andy Shevchenko (2024-03-03 04:14:10)
...
Quoted 1 line
Applied to clk-next
Thank you!
...
Quoted 1 line
Should we pre-calculate the mask and shift values too!?
Not that it's required, but we _can_ do that, of course.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Le 03/03/2024 à 13:14, Andy Shevchenko a écrit :
Quoted 13 lines
There is no need to calculate masks under the lock taken. Move them out of it.
Signed-off-by Andy Shevchenko <[email protected]>--- drivers/clk/clk-fractional-divider.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/clk/clk-fractional-divider.c +0
-0
drivers/clk/clk-fractional-divider.c static int clk_fd_set_rate(struct clk_hw *hw, unsigned long rate, · line 200
Quoted 6 lines
drivers/clk/clk-fractional-divider.c +3
-0@@ -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.
drivers/clk/clk-fractional-divider.c static int clk_fd_set_rate(struct clk_hw *hw, unsigned long rate, · line 207
Quoted 10 lines
drivers/clk/clk-fractional-divider.c +0
-3if (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;
drivers/clk/clk-fractional-divider.c static int clk_fd_set_rate(struct clk_hw *hw, unsigned long rate, · line 208
Quoted 1 line
drivers/clk/clk-fractional-divider.c +0
-0val |= (m << fd->mshift) | (n << fd->nshift);
and pre-compute "(m << fd->mshift) | (n << fd->nshift)" outside of the lock too.
CJ
Quoted 1 line · Christophe JAILLET
Le 03/03/2024 à 13:14, Andy Shevchenko a écrit :
...
Quoted 8 lines
drivers/clk/clk-fractional-divider.c static int clk_fd_set_rate(struct clk_hw *hw, unsigned long rate, · line 199
Quoted 6 lines
drivers/clk/clk-fractional-divider.c +2
-0@@ -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.
Quoted 16 lines
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.
drivers/clk/clk-fractional-divider.c static int clk_fd_set_rate(struct clk_hw *hw, unsigned long rate, · line 207
Quoted 10 lines
drivers/clk/clk-fractional-divider.c +0
-3if (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);
Quoted 6 lines
val &= mask;drivers/clk/clk-fractional-divider.c static int clk_fd_set_rate(struct clk_hw *hw, unsigned long rate, · line 208
Quoted 1 line
drivers/clk/clk-fractional-divider.c +0
-0val |= (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.
Signature · 2 lines
With Best Regards, Andy Shevchenko