lib/time - fix "usec_to_tick" calculation for hi freq system timers
PATCH 1/1 lib/time - fix "usec_to_tick" calculation for hi freq system timers
Current implementation works fine if "usec * get_tbclk()" fits in 32 bits. Otherwise result will be cut down to 32-bit.
Fix is obvious - first extend data type of either operand.
--- lib/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/time.c +1 -1
@@ -71,7 +71,7 @@ unsigned long __weak notrace timer_get_us(void) }static unsigned long long usec_to_tick (unsigned long usec) { -uint64_t tick = usec *get_tbclk (); +uint64_t tick = (uint64_t )usec *get_tbclk (); usec *=get_tbclk ();do_div (tick,1000000 );return tick;
Signature · 1 line
1.8.4.2
PATCH 1/1 lib/time - fix "usec_to_tick" calculation for hi freq system timers
Hi Tom,
Quoted 18 lines · Alexey Brodkin
Current implementation works fine if "usec *
get_tbclk()" fits in 32 bits. Otherwise result will be cut down to 32-bit.Fix is obvious - first extend data type of either operand.
Signed-off-by Alexey Brodkin <[email protected]>Cc Rob Herring <[email protected]>Cc Mischa Jonker <[email protected]>--- lib/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/time.c +0
-0
lib/time.c unsigned long __weak notrace timer_get_us(void) · line 77
Quoted 8 lines
lib/time.c +1
-1@@ -71,7 +71,7 @@ unsigned long __weak notrace timer_get_us(void) }static unsigned long long usec_to_tick (unsigned long usec) { -uint64_t tick = usec *get_tbclk (); +uint64_t tick = (uint64_t )usec *get_tbclk (); usec *=get_tbclk ();do_div (tick,1000000 );return tick;
Any chance to get it applied?
Regards,
Alexey
PATCH 1/1 lib/time - fix "usec_to_tick" calculation for hi freq system timers
Quoted 16 lines · Alexey Brodkin
Hi Tom,
Quoted 13 lines · Alexey Brodkin
Current implementation works fine if "usec *
get_tbclk()" fits in 32 bits. Otherwise result will be cut down to 32-bit.Fix is obvious - first extend data type of either operand.
Signed-off-by Alexey Brodkin <[email protected]>Cc Rob Herring <[email protected]>Cc Mischa Jonker <[email protected]>--- lib/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines
lib/time.c unsigned long __weak notrace timer_get_us(void) · line 77
Quoted 13 lines
lib/time.c +1
-1@@ -71,7 +71,7 @@ unsigned long __weak notrace timer_get_us(void) }static unsigned long long usec_to_tick (unsigned long usec) { -uint64_t tick = usec *get_tbclk (); +uint64_t tick = (uint64_t )usec *get_tbclk (); usec *=get_tbclk ();do_div (tick,1000000 );return tick;Any chance to get it applied?
Yes, it's on my TODO list shortly, thanks.
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20131213/7b1a871b/attachment.pgp>
PATCH 1/1 lib/time - fix "usec_to_tick" calculation for hi freq system timers
Quoted 34 lines · Tom Rini
Quoted 16 lines · Alexey Brodkin
Hi Tom,
Quoted 13 lines · Alexey Brodkin
Current implementation works fine if "usec *
get_tbclk()" fits in 32 bits. Otherwise result will be cut down to 32-bit.Fix is obvious - first extend data type of either operand.
Signed-off-by Alexey Brodkin <[email protected]>Cc Rob Herring <[email protected]>Cc Mischa Jonker <[email protected]>--- lib/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 15 lines
lib/time.c unsigned long __weak notrace timer_get_us(void) · line 77
Quoted 13 lines
lib/time.c +1
-1@@ -71,7 +71,7 @@ unsigned long __weak notrace timer_get_us(void) }static unsigned long long usec_to_tick (unsigned long usec) { -uint64_t tick = usec *get_tbclk (); +uint64_t tick = (uint64_t )usec *get_tbclk (); usec *=get_tbclk ();do_div (tick,1000000 );return tick;Any chance to get it applied?
Quoted 1 line
Yes, it's on my TODO list shortly, thanks.
Please note that I'm taking http://patchwork.ozlabs.org/patch/297361/ as the solution for this problem, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20131213/048b52ad/attachment.pgp>
PATCH 1/1 lib/time - fix "usec_to_tick" calculation for hi freq system timers
Quoted 3 lines · Tom Rini
Please note that I'm taking http://patchwork.ozlabs.org/patch/297361/ as the solution for this problem, thanks!
As long as it resolves overflow issue (and from that patch I'd say it should) I'm totally fine with it.
Thanks.
P.S. funny enough this overflow issue bites multiple people these days (but earlier it seems like everybody was happy though).