linux-mips.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] MIPS: ralink: Avoid x/x division in rt_timer_config()
@ 2025-04-08  8:28 Thorsten Blum
  2025-04-27  8:18 ` Thomas Bogendoerfer
  0 siblings, 1 reply; 3+ messages in thread
From: Thorsten Blum @ 2025-04-08  8:28 UTC (permalink / raw)
  To: John Crispin, Sergio Paracuellos, Thomas Bogendoerfer
  Cc: Thorsten Blum, David Laight, linux-mips, linux-kernel

Avoid the 'rt->timer_freq / rt->timer_freq' division when the divisor is
larger than the timer frequency and use '1' directly.

No functional changes intended.

Suggested-by: David Laight <david.laight.linux@gmail.com>
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 arch/mips/ralink/timer.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/arch/mips/ralink/timer.c b/arch/mips/ralink/timer.c
index 54094f6e033e..5d8286603584 100644
--- a/arch/mips/ralink/timer.c
+++ b/arch/mips/ralink/timer.c
@@ -75,12 +75,16 @@ static int rt_timer_request(struct rt_timer *rt)
 
 static int rt_timer_config(struct rt_timer *rt, unsigned long divisor)
 {
-	if (rt->timer_freq < divisor)
+	u32 t;
+
+	if (rt->timer_freq < divisor) {
 		rt->timer_div = rt->timer_freq;
-	else
+		t = 1;
+	} else {
 		rt->timer_div = divisor;
-
-	rt_timer_w32(rt, TIMER_REG_TMR0LOAD, rt->timer_freq / rt->timer_div);
+		t = rt->timer_freq / rt->timer_div;
+	}
+	rt_timer_w32(rt, TIMER_REG_TMR0LOAD, t);
 
 	return 0;
 }
-- 
2.49.0


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

* Re: [PATCH] MIPS: ralink: Avoid x/x division in rt_timer_config()
  2025-04-08  8:28 [PATCH] MIPS: ralink: Avoid x/x division in rt_timer_config() Thorsten Blum
@ 2025-04-27  8:18 ` Thomas Bogendoerfer
  2025-04-27  9:25   ` Sergio Paracuellos
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Bogendoerfer @ 2025-04-27  8:18 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: John Crispin, Sergio Paracuellos, David Laight, linux-mips,
	linux-kernel

On Tue, Apr 08, 2025 at 10:28:05AM +0200, Thorsten Blum wrote:
> Avoid the 'rt->timer_freq / rt->timer_freq' division when the divisor is
> larger than the timer frequency and use '1' directly.
> 
> No functional changes intended.
> 
> Suggested-by: David Laight <david.laight.linux@gmail.com>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
>  arch/mips/ralink/timer.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/mips/ralink/timer.c b/arch/mips/ralink/timer.c
> index 54094f6e033e..5d8286603584 100644
> --- a/arch/mips/ralink/timer.c
> +++ b/arch/mips/ralink/timer.c
> @@ -75,12 +75,16 @@ static int rt_timer_request(struct rt_timer *rt)
>  
>  static int rt_timer_config(struct rt_timer *rt, unsigned long divisor)
>  {
> -	if (rt->timer_freq < divisor)
> +	u32 t;
> +
> +	if (rt->timer_freq < divisor) {
>  		rt->timer_div = rt->timer_freq;
> -	else
> +		t = 1;
> +	} else {
>  		rt->timer_div = divisor;
> -
> -	rt_timer_w32(rt, TIMER_REG_TMR0LOAD, rt->timer_freq / rt->timer_div);
> +		t = rt->timer_freq / rt->timer_div;
> +	}
> +	rt_timer_w32(rt, TIMER_REG_TMR0LOAD, t);

I really don't see the point for this change. IMHO, this isn't really 
runtime critical and I prefer the code like it is at the moment.

Thomas.

-- 
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]

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

* Re: [PATCH] MIPS: ralink: Avoid x/x division in rt_timer_config()
  2025-04-27  8:18 ` Thomas Bogendoerfer
@ 2025-04-27  9:25   ` Sergio Paracuellos
  0 siblings, 0 replies; 3+ messages in thread
From: Sergio Paracuellos @ 2025-04-27  9:25 UTC (permalink / raw)
  To: Thomas Bogendoerfer
  Cc: Thorsten Blum, John Crispin, David Laight, linux-mips,
	linux-kernel

Hi,

First of all, sorry for missing this patch.

On Sun, Apr 27, 2025 at 10:19 AM Thomas Bogendoerfer
<tsbogend@alpha.franken.de> wrote:
>
> On Tue, Apr 08, 2025 at 10:28:05AM +0200, Thorsten Blum wrote:
> > Avoid the 'rt->timer_freq / rt->timer_freq' division when the divisor is
> > larger than the timer frequency and use '1' directly.
> >
> > No functional changes intended.
> >
> > Suggested-by: David Laight <david.laight.linux@gmail.com>
> > Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> > ---
> >  arch/mips/ralink/timer.c | 12 ++++++++----
> >  1 file changed, 8 insertions(+), 4 deletions(-)
> >
> > diff --git a/arch/mips/ralink/timer.c b/arch/mips/ralink/timer.c
> > index 54094f6e033e..5d8286603584 100644
> > --- a/arch/mips/ralink/timer.c
> > +++ b/arch/mips/ralink/timer.c
> > @@ -75,12 +75,16 @@ static int rt_timer_request(struct rt_timer *rt)
> >
> >  static int rt_timer_config(struct rt_timer *rt, unsigned long divisor)
> >  {
> > -     if (rt->timer_freq < divisor)
> > +     u32 t;
> > +
> > +     if (rt->timer_freq < divisor) {
> >               rt->timer_div = rt->timer_freq;
> > -     else
> > +             t = 1;
> > +     } else {
> >               rt->timer_div = divisor;
> > -
> > -     rt_timer_w32(rt, TIMER_REG_TMR0LOAD, rt->timer_freq / rt->timer_div);
> > +             t = rt->timer_freq / rt->timer_div;
> > +     }
> > +     rt_timer_w32(rt, TIMER_REG_TMR0LOAD, t);
>
> I really don't see the point for this change. IMHO, this isn't really
> runtime critical and I prefer the code like it is at the moment.

Yes, I agree with you. I also prefer the code as it is.

Thanks,
    Sergio Paracuellos

>
> Thomas.
>
> --
> Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
> good idea.                                                [ RFC1925, 2.3 ]

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

end of thread, other threads:[~2025-04-27  9:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-08  8:28 [PATCH] MIPS: ralink: Avoid x/x division in rt_timer_config() Thorsten Blum
2025-04-27  8:18 ` Thomas Bogendoerfer
2025-04-27  9:25   ` Sergio Paracuellos

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