lib: time: Add microsecond timer
PATCH 1/1 lib: time: Add microsecond timer
Add get_timer_us(), which is useful e.g. when we need higher precision timestamps.
--- include/time.h | 1 + lib/time.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+)
include/time.h +1 -0
@@ -13,6 +13,7 @@ unsigned long get_timer(unsigned long base);* Granularity may be larger than 1us if hardware does not support this. */ unsigned long timer_get_us (void ); +uint64_t get_timer_us (uint64_t base);/* * timer_test_add_offset()
lib/time.c +14 -0
@@ -134,6 +134,20 @@ ulong __weak get_timer(ulong base)return tick_to_time (get_ticks ()) - base; } +static uint64_t notrace tick_to_time_us(uint64_t tick) +{ +ulong div =get_tbclk () /1000 ; + + tick *=CONFIG_SYS_HZ ; +do_div (tick, div); +return tick; +} + +uint64_t __weak get_timer_us (uint64_t base) +{ +return tick_to_time_us (get_ticks ()) - base; +} +unsigned long __weak notrace timer_get_us (void ) {return tick_to_time (get_ticks () *1000 );
Signature · 1 line
2.23.0
PATCH 1/1 lib: time: Add microsecond timer
Hi Marek,
Quoted 3 lines · Marek Vasut
Add
get_timer_us(), which is useful e.g. when we need higher precision timestamps.
Can we use timer_get_us()? It seems confusing to have two.
Quoted 8 lines
Signed-off-by Marek Vasut <[email protected]>Cc Tom Rini <[email protected]>Cc Simon Glass <[email protected]>--- include/time.h | 1 + lib/time.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+)
Regards,
Simon
PATCH 1/1 lib: time: Add microsecond timer
Quoted 1 line · Simon Glass
Hi Marek,
Hi,
Quoted 6 lines · Marek Vasut
Quoted 3 lines
Add
get_timer_us(), which is useful e.g. when we need higher precision timestamps.Can we use
timer_get_us()? It seems confusing to have two.
Nope, that one doesn't have the range (unsigned long vs. u64) and also doesn't behave the same way as old get_timer(). I wanted something which is similar, just for uS instead of mS.
Signature · 2 lines
Best regards, Marek Vasut
PATCH 1/1 lib: time: Add microsecond timer
Hi Marek,
Quoted 8 lines · Marek Vasut
Quoted 1 line · Simon Glass
Hi Marek,
Hi,
Quoted 2 lines · Marek Vasut
Quoted 1 line
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Add
get_timer_us(), which is useful e.g. when we need higher precision timestamps.Can we use
timer_get_us()? It seems confusing to have two.Nope, that one doesn't have the range (unsigned long vs. u64) and also doesn't behave the same way as old
get_timer(). I wanted something which is similar, just for uS instead of mS.
Can you add comments to your patch to indicate what is going on any why to use this?
Bootstage uses ulong which is enough for about an hour. How long is U-Boot running?
If you are using differential times, presumably for timeouts, then there seems to be little reason to need u64.
Regards,
Simon
PATCH 1/1 lib: time: Add microsecond timer
Quoted 1 line · Simon Glass
Hi Marek,
Hi,
Quoted 18 lines · Marek Vasut
Quoted 8 lines · Simon Glass
Quoted 1 line
Hi Marek,
Hi,
Quoted 2 lines · Marek Vasut
Quoted 1 line
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Add
get_timer_us(), which is useful e.g. when we need higher precision timestamps.Can we use
timer_get_us()? It seems confusing to have two.Nope, that one doesn't have the range (unsigned long vs. u64) and also doesn't behave the same way as old
get_timer(). I wanted something which is similar, just for uS instead of mS.
Quoted 5 lines
Can you add comments to your patch to indicate what is going on any why to use this?
Bootstage uses ulong which is enough for about an hour. How long is U-Boot running?
It can run as long as anyone needs.
Quoted 2 lines
If you are using differential times, presumably for timeouts, then there seems to be little reason to need u64.
I use it for logging timestamps during profiling, e.g. of the EHCI driver.
Signature · 2 lines
Best regards, Marek Vasut
PATCH 1/1 lib: time: Add microsecond timer
Hi Marek,
Quoted 30 lines · Marek Vasut
Quoted 1 line · Simon Glass
Hi Marek,
Hi,
Quoted 18 lines · Marek Vasut
Quoted 8 lines · Simon Glass
Quoted 1 line
Hi Marek,
Hi,
Quoted 2 lines · Marek Vasut
Quoted 1 line
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Add
get_timer_us(), which is useful e.g. when we need higher precision timestamps.Can we use
timer_get_us()? It seems confusing to have two.Nope, that one doesn't have the range (unsigned long vs. u64) and also doesn't behave the same way as old
get_timer(). I wanted something which is similar, just for uS instead of mS.Quoted 5 lines
Can you add comments to your patch to indicate what is going on any why to use this?
Bootstage uses ulong which is enough for about an hour. How long is U-Boot running?
Quoted 6 lines
It can run as long as anyone needs.
Quoted 2 lines
If you are using differential times, presumably for timeouts, then there seems to be little reason to need u64.
I use it for logging timestamps during profiling, e.g. of the EHCI driver.
Have you tried bootstage?
Regards,
Simon
PATCH 1/1 lib: time: Add microsecond timer
Quoted 1 line · Simon Glass
Hi Marek,
Hello Simon,
Quoted 31 lines · Marek Vasut
Quoted 30 lines · Simon Glass
Quoted 1 line
Hi Marek,
Hi,
Quoted 23 lines · Marek Vasut
Quoted 8 lines · Simon Glass
Quoted 1 line
Hi Marek,
Hi,
Quoted 2 lines · Marek Vasut
Quoted 1 line
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Add
get_timer_us(), which is useful e.g. when we need higher precision timestamps.Can we use
timer_get_us()? It seems confusing to have two.Nope, that one doesn't have the range (unsigned long vs. u64) and also doesn't behave the same way as old
get_timer(). I wanted something which is similar, just for uS instead of mS.Can you add comments to your patch to indicate what is going on any why to use this?
Bootstage uses ulong which is enough for about an hour. How long is U-Boot running?
Quoted 8 lines
Quoted 6 lines
It can run as long as anyone needs.
Quoted 2 lines
If you are using differential times, presumably for timeouts, then there seems to be little reason to need u64.
I use it for logging timestamps during profiling, e.g. of the EHCI driver.
Have you tried bootstage?
What for ? I need to debug the EHCI driver performance across the EHCI driver and USB storage implementation. Bootstage is not helpful here.
Signature · 2 lines
Best regards, Marek Vasut
PATCH 1/1 lib: time: Add microsecond timer
Hi Marek,
Quoted 42 lines · Marek Vasut
Quoted 1 line · Simon Glass
Hi Marek,
Hello Simon,
Quoted 36 lines · Marek Vasut
Quoted 35 lines · Simon Glass
Quoted 1 line
Hi Marek,
Hi,
Quoted 18 lines · Marek Vasut
Quoted 8 lines · Simon Glass
Quoted 1 line
Hi Marek,
Hi,
Quoted 2 lines · Marek Vasut
Quoted 1 line
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Add
get_timer_us(), which is useful e.g. when we need higher precision timestamps.Can we use
timer_get_us()? It seems confusing to have two.Nope, that one doesn't have the range (unsigned long vs. u64) and also doesn't behave the same way as old
get_timer(). I wanted something which is similar, just for uS instead of mS.Quoted 5 lines
Can you add comments to your patch to indicate what is going on any why to use this?
Bootstage uses ulong which is enough for about an hour. How long is U-Boot running?
It can run as long as anyone needs.
Quoted 2 lines
If you are using differential times, presumably for timeouts, then there seems to be little reason to need u64.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
I use it for logging timestamps during profiling, e.g. of the EHCI driver.
Have you tried bootstage?
What for ? I need to debug the EHCI driver performance across the EHCI driver and USB storage implementation. Bootstage is not helpful here.
It can track the time spent in particular parts of the code, accumulating it over multiple calls, etc. E.g. how much is FS, how much is driver, how much is waiting for replies...
Regards,
Simon
PATCH 1/1 lib: time: Add microsecond timer
On 10/16/19 6:58 PM, Simon Glass wrote:
[...]
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Have you tried bootstage?
What for ? I need to debug the EHCI driver performance across the EHCI driver and USB storage implementation. Bootstage is not helpful here.
It can track the time spent in particular parts of the code, accumulating it over multiple calls, etc. E.g. how much is FS, how much is driver, how much is waiting for replies...
And how much overhead does it add compared to calling get_timer{,_us}() directly ? It was about uSecs in this case, so this was the best approach.
Signature · 2 lines
Best regards, Marek Vasut
PATCH 1/1 lib: time: Add microsecond timer
In reply to Marek VasutQuoted 6 lines · Marek Vasut
Add
get_timer_us(), which is useful e.g. when we need higher precision timestamps.Signed-off-by Marek Vasut <[email protected]>Cc Tom Rini <[email protected]>Cc Simon Glass <[email protected]>
FWIW, I agree with Simon that bootstage [1] can be an awesome tool for profiling and boot time measurements. With a bit of instrumentation and host-side scripting, it allows to produce accurate bootcharts like [2].
[1] https://patchwork.ozlabs.org/patch/1177393/#2281091
[2] https://i.ibb.co/mG6Xc1p/2019-10-16-190251.png
Signature · 2 lines
Best Regards, Eugeniu
PATCH 1/1 lib: time: Add microsecond timer
Quoted 10 lines · Eugeniu Rosca
Quoted 2 lines · Marek Vasut
Add
get_timer_us(), which is useful e.g. when we need higher precision timestamps.FWIW, I agree with Simon that bootstage [1] can be an awesome tool for profiling and boot time measurements. With a bit of instrumentation and host-side scripting, it allows to produce accurate bootcharts like [2].
[1] https://patchwork.ozlabs.org/patch/1177393/#2281091
[2] https://i.ibb.co/mG6Xc1p/2019-10-16-190251.png
I don't need that though, I really only need to know how long the code spent between two points in code.
Signature · 2 lines
Best regards, Marek Vasut
PATCH 1/1 lib: time: Add microsecond timer
Quoted 9 lines · Marek Vasut
Quoted 8 lines · Eugeniu Rosca
Quoted 2 lines · Marek Vasut
Add
get_timer_us(), which is useful e.g. when we need higher precision timestamps.FWIW, I agree with Simon that bootstage [1] can be an awesome tool for profiling and boot time measurements. With a bit of instrumentation and host-side scripting, it allows to produce accurate bootcharts like [2].
Quoted 5 lines
Quoted 2 lines
[1] https://patchwork.ozlabs.org/patch/1177393/#2281091
[2] https://i.ibb.co/mG6Xc1p/2019-10-16-190251.pngI don't need that though, I really only need to know how long the code spent between two points in code.
It can be accomplished in N ways. A quick and dirty way to use "bootstage" would be to add below instrumentation:
----------8<----------bootstage_mark_name(BOOTSTAGE_ID_ALLOC, "count/time from here"); /*
* my-precious-code
*/bootstage_mark_name(BOOTSTAGE_ID_ALLOC, "duration of my-precious-code");
----------8<----------
It's likely orthogonal to what's being proposed in your patch.
Signature · 2 lines
Best Regards, Eugeniu
PATCH 1/1 lib: time: Add microsecond timer
Quoted 27 lines · Eugeniu Rosca
Quoted 9 lines · Marek Vasut
Quoted 8 lines · Eugeniu Rosca
Quoted 2 lines · Marek Vasut
Add
get_timer_us(), which is useful e.g. when we need higher precision timestamps.FWIW, I agree with Simon that bootstage [1] can be an awesome tool for profiling and boot time measurements. With a bit of instrumentation and host-side scripting, it allows to produce accurate bootcharts like [2].
Quoted 5 lines
Quoted 2 lines
[1] https://patchwork.ozlabs.org/patch/1177393/#2281091
[2] https://i.ibb.co/mG6Xc1p/2019-10-16-190251.pngI don't need that though, I really only need to know how long the code spent between two points in code.
It can be accomplished in N ways. A quick and dirty way to use "bootstage" would be to add below instrumentation:
----------8<----------
bootstage_mark_name(BOOTSTAGE_ID_ALLOC, "count/time from here"); /*
* my-precious-code
*/bootstage_mark_name(BOOTSTAGE_ID_ALLOC, "duration of my-precious-code");
----------8<----------
Quoted 1 line
It's likely orthogonal to what's being proposed in your patch.
Bottom line is "bootstage" already makes use of timer_get_boot_us(), so it's not entirely clear to me why another us-resolution timer API would be needed.
Signature · 2 lines
Best Regards, Eugeniu
PATCH 1/1 lib: time: Add microsecond timer
Quoted 28 lines · Eugeniu Rosca
Quoted 27 lines · Eugeniu Rosca
Quoted 9 lines · Marek Vasut
Quoted 8 lines · Eugeniu Rosca
Quoted 2 lines · Marek Vasut
Add
get_timer_us(), which is useful e.g. when we need higher precision timestamps.FWIW, I agree with Simon that bootstage [1] can be an awesome tool for profiling and boot time measurements. With a bit of instrumentation and host-side scripting, it allows to produce accurate bootcharts like [2].
Quoted 5 lines
Quoted 2 lines
[1] https://patchwork.ozlabs.org/patch/1177393/#2281091
[2] https://i.ibb.co/mG6Xc1p/2019-10-16-190251.pngI don't need that though, I really only need to know how long the code spent between two points in code.
It can be accomplished in N ways. A quick and dirty way to use "bootstage" would be to add below instrumentation:
----------8<----------
bootstage_mark_name(BOOTSTAGE_ID_ALLOC, "count/time from here"); /*
* my-precious-code
*/bootstage_mark_name(BOOTSTAGE_ID_ALLOC, "duration of my-precious-code");
----------8<----------
Quoted 5 lines
Quoted 1 line
It's likely orthogonal to what's being proposed in your patch.
Bottom line is "bootstage" already makes use of
timer_get_boot_us(), so it's not entirely clear to me why another us-resolution timer API would be needed.
Because the new API is actually aligned with the old one. I don't need the machinery behind the bootstage either.
Signature · 2 lines
Best regards, Marek Vasut
PATCH 1/1 lib: time: Add microsecond timer
In reply to Marek VasutQuoted 6 lines · Marek Vasut
Add
get_timer_us(), which is useful e.g. when we need higher precision timestamps.Signed-off-by Marek Vasut <[email protected]>Cc Tom Rini <[email protected]>Cc Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20191101/a36908b5/attachment.sig>