Skip to contentSkip to conversation

ppc: Increase precision of ticks2usec

PATCH New Benoit Monin 2 participants 2 messages Mar 4, 2009 – Mar 8, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ppc: Increase precision of ticks2usec

The tick of some PowerPC cpu is running at high frequency and it can be used to get microsecond precision from it. Make use of div64 to achieve this precision in ticks2usec.

---
 lib_ppc/time.c |   15 +++++----------
 1 files changed, 5 insertions(+), 10 deletions(-)
lib_ppc/time.c +5 -10
index 173ffab..ebda13a 100644
@@ -22,6 +22,7 @@
  */
 
 #include <common.h>
+#include <div64.h>
 
 #ifndef CONFIG_WD_PERIOD
 # define CONFIG_WD_PERIOD	(10 * 1000 * 1000)	/* 10 seconds default*/
@@ -71,17 +72,11 @@ void udelay(unsigned long usec)
 unsigned long ticks2usec(unsigned long ticks)
 {
 	ulong tbclk = get_tbclk();
+	u64 tmp;
 
-	/* usec = ticks * 1000000 / tbclk
-	 * Multiplication would overflow at ~4.2e3 ticks,
-	 * so we break it up into
-	 * usec = ( ( ticks * 1000) / tbclk ) * 1000;
-	 */
-	ticks *= 1000L;
-	ticks /= tbclk;
-	ticks *= 1000L;
-
-	return ((ulong)ticks);
+	tmp = ticks * 1000000ULL;
+	do_div (tmp, tbclk);
+	return (unsigned long)tmp;
 }
 #endif
 /* ------------------------------------------------------------------------- */
Signature · 2 lines
 Cr?ez votre adresse ?lectronique prenom.nom at laposte.net 
 1 Go d'espace de stockage, anti-spam et anti-virus int?gr?s.
#1 lore raw

PATCH 1/1 ppc: Increase precision of ticks2usec

Dear Benoit Monin,

Quoted 4 lines · In message <9454366.19868.1236182927234.JavaMail.www@wwinf8202> you wrote:

The tick of some PowerPC cpu is running at high frequency and it can be used to get microsecond precision from it. Make use of div64 to achieve this precision in ticks2usec.

Which problem are you trying to fix?

Where exactly do we need very high accuracy?

What is the overhead of using do_div() versus the old, simple code?

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
On the subject of C program indentation: "In My Egotistical  Opinion,
most  people's  C  programs  should be indented six feet downward and
covered with dirt."                               - Blair P. Houghton