[U-Boot] [PATCH] 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.
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 /* ------------------------------------------------------------------------- */

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
participants (2)
-
Benoit Monin
-
Wolfgang Denk