Skip to contentSkip to conversation

arch/arm: Use constants instead of magic numbers in do_gettimeofday.

PATCH New Corbin Simpson 2 participants 3 messages May 6, 2010 – May 7, 2010 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arch/arm: Use constants instead of magic numbers in do_gettimeofday.

Part of the Didj patch.

---
 arch/arm/kernel/time.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
arch/arm/kernel/time.c +3 -3
index 2875380..5cb4ff9 100644
@@ -104,12 +104,12 @@ void do_gettimeofday(struct timeval *tv)
 		seq = read_seqbegin_irqsave(&xtime_lock, flags);
 		usec = system_timer->offset();
 		sec = xtime.tv_sec;
-		usec += xtime.tv_nsec / 1000;
+		usec += xtime.tv_nsec / NSEC_PER_USEC;
 	} while (read_seqretry_irqrestore(&xtime_lock, seq, flags));
 
 	/* usec may have gone up a lot: be safe */
-	while (usec >= 1000000) {
-		usec -= 1000000;
+	while (usec >=  USEC_PER_SEC) {
+		usec -= USEC_PER_SEC;
 		sec++;
 	}
 
Signature · 1 line
1.6.6.1
#1 lore raw

PATCH 1/1 arch/arm: Use constants instead of magic numbers in do_gettimeofday.

Quoted 1 line · Corbin Simpson

Part of the Didj patch.

how about a better description here please.

Quoted 33 lines
---
 arch/arm/kernel/time.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
arch/arm/kernel/time.c +3 -3
index 2875380..5cb4ff9 100644
@@ -104,12 +104,12 @@ void do_gettimeofday(struct timeval *tv)
 		seq = read_seqbegin_irqsave(&xtime_lock, flags);
 		usec = system_timer->offset();
 		sec = xtime.tv_sec;
-		usec += xtime.tv_nsec / 1000;
+		usec += xtime.tv_nsec / NSEC_PER_USEC;
 	} while (read_seqretry_irqrestore(&xtime_lock, seq, flags));
 
 	/* usec may have gone up a lot: be safe */
-	while (usec >= 1000000) {
-		usec -= 1000000;
+	while (usec >=  USEC_PER_SEC) {
+		usec -= USEC_PER_SEC;
 		sec++;
 	}
 
Signature · 7 lines
1.6.6.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Signature · 5 lines
-- 
Ben

Q:      What's a light-year?
A:      One-third less calories than a regular year.
#2 lore raw

PATCH 1/1 arch/arm: Use constants instead of magic numbers in do_gettimeofday.

Quoted 30 lines · Ben Dooks
Quoted 1 line · Corbin Simpson

Part of the Didj patch.

how about a better description here please.

Quoted 25 lines

---
?arch/arm/kernel/time.c | ? ?6 +++---
?1 files changed, 3 insertions(+), 3 deletions(-)

arch/arm/kernel/time.c +1 -1
index 2875380..5cb4ff9 100644
@@ -104,12 +104,12 @@ void do_gettimeofday(struct timeval *tv)
 ? ? ? ? ? ? ? seq = read_seqbegin_irqsave(&xtime_lock, flags);
 ? ? ? ? ? ? ? usec = system_timer->offset();
 ? ? ? ? ? ? ? sec = xtime.tv_sec;
- ? ? ? ? ? ? usec += xtime.tv_nsec / 1000;
+ ? ? ? ? ? ? usec += xtime.tv_nsec / NSEC_PER_USEC;
 ? ? ? } while (read_seqretry_irqrestore(&xtime_lock, seq, flags));
 

? ? ? /* usec may have gone up a lot: be safe */
- ? ? while (usec >= 1000000) {
- ? ? ? ? ? ? usec -= 1000000;
+ ? ? while (usec >= ?USEC_PER_SEC) {
+ ? ? ? ? ? ? usec -= USEC_PER_SEC;
? ? ? ? ? ? ? sec++;
? ? ? }

Quoted 2 lines
Quoted 2 lines

--
1.6.6.1

Sorry, been out with a bad cold. :C

What would be better? It's a fairly trivial patch that is, at least in my mind, fully explained by the title of the commit. Constants should be preferred to magic numbers, right? The patch comment is a reminder that this comes from the Leapfrog Didj code dump, and the original author is unknown, but probably works at Cozybits.

Would this work?

Prefer constants to magic numbers where applicable and appropriate. With this change, the code is almost self-explanatory and much more readable.
Part of the Leapfrog Didj code dump. Authorship is unknown.

~ C.

Signature · 4 lines
When the facts change, I change my mind. What do you do, sir? ~ Keynes

Corbin Simpson
<[email protected]>