Skip to contentSkip to conversation

MIPS: ralink: Avoid x/x division in rt_timer_config()

PATCH In review Thorsten Blum 3 participants 3 messages Apr 8, 2025 – Apr 27, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 MIPS: ralink: Avoid x/x division in rt_timer_config()

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.

---
 arch/mips/ralink/timer.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
arch/mips/ralink/timer.c +8 -4
index 54094f6e033e..5d8286603584 100644
@@ -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;
 }
Signature · 1 line
2.49.0
#1 lore raw
Quoted 23 lines · Thorsten Blum

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.

---
 arch/mips/ralink/timer.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
arch/mips/ralink/timer.c +3 -1
index 54094f6e033e..5d8286603584 100644
@@ -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) {

arch/mips/ralink/timer.c static int rt_timer_request(struct rt_timer *rt) · line 87

Quoted 10 lines
arch/mips/ralink/timer.c +5 -3
 		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.

Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]
#2 lore raw

Hi,

First of all, sorry for missing this patch.

Quoted 30 lines · Thomas Bogendoerfer
Quoted 28 lines · Thorsten Blum

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.

---
 arch/mips/ralink/timer.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
arch/mips/ralink/timer.c +5 -2
index 54094f6e033e..5d8286603584 100644
@@ -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;
Quoted 8 lines

arch/mips/ralink/timer.c static int rt_timer_request(struct rt_timer *rt) · line 87

Quoted 5 lines
arch/mips/ralink/timer.c +3 -2
-
-     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

Quoted 6 lines

Thomas.

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