All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] ppc: Increase precision of ticks2usec
@ 2009-03-04 16:08 Benoit Monin
  2009-03-08 22:46 ` Wolfgang Denk
  0 siblings, 1 reply; 3+ messages in thread
From: Benoit Monin @ 2009-03-04 16:08 UTC (permalink / raw)
  To: u-boot


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.

Signed-off-by: Beno?t Monin <bmonin@adeneo.eu>
---
 lib_ppc/time.c |   15 +++++----------
 1 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/lib_ppc/time.c b/lib_ppc/time.c
index 173ffab..ebda13a 100644
--- a/lib_ppc/time.c
+++ b/lib_ppc/time.c
@@ -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
 /* ------------------------------------------------------------------------- */
-- 


 Cr?ez votre adresse ?lectronique prenom.nom at laposte.net 
 1 Go d'espace de stockage, anti-spam et anti-virus int?gr?s.

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

* [U-Boot] [PATCH] ppc: Increase precision of ticks2usec
  2009-03-04 16:08 [U-Boot] [PATCH] ppc: Increase precision of ticks2usec Benoit Monin
@ 2009-03-08 22:46 ` Wolfgang Denk
  0 siblings, 0 replies; 3+ messages in thread
From: Wolfgang Denk @ 2009-03-08 22:46 UTC (permalink / raw)
  To: u-boot

Dear Benoit Monin,

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

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

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

* [U-Boot] [PATCH] ppc: Increase precision of ticks2usec
@ 2009-03-10 14:20 Benoit Monin
  0 siblings, 0 replies; 3+ messages in thread
From: Benoit Monin @ 2009-03-10 14:20 UTC (permalink / raw)
  To: u-boot

> De : "Wolfgang Denk"
> 
> Dear Benoit Monin,
> 
> 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?
> 
Well, that was more some icing on the cake for CONFIG_PRINT_TIME,
so you can discard this patch.

> Best regards,
> 
> Wolfgang Denk
> 
Sincerely,
Beno?t.
--


 Cr?ez votre adresse ?lectronique prenom.nom at laposte.net 
 1 Go d'espace de stockage, anti-spam et anti-virus int?gr?s.

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

end of thread, other threads:[~2009-03-10 14:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-04 16:08 [U-Boot] [PATCH] ppc: Increase precision of ticks2usec Benoit Monin
2009-03-08 22:46 ` Wolfgang Denk
  -- strict thread matches above, loose matches on Subject: below --
2009-03-10 14:20 Benoit Monin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.