mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-28 07:31:15 +00:00
time: move the CONFIG_SYS_TIMER_RATE handling to the compiler
CONFIG_SYS_TIMER_RATE might be a dynamic value, i.e. a function call instead of a static value, thus it has to be evaluated at runtime. If it is a static value, the compiler should be able to optimize the unused branches out. This will be needed for kirkwoods dynamic CONFIG_SYS_TCLK setting. Cc: Pali Rohár <pali@kernel.org> Signed-off-by: Michael Walle <michael@walle.cc> Reviewed-by: Pali Rohár <pali@kernel.org> Reviewed-by: Stefan Roese <sr@denx.de>
This commit is contained in:
parent
7875f8019c
commit
616278bd2c
1 changed files with 9 additions and 6 deletions
15
lib/time.c
15
lib/time.c
|
@ -47,12 +47,15 @@ ulong timer_get_boot_us(void)
|
||||||
{
|
{
|
||||||
ulong count = timer_read_counter();
|
ulong count = timer_read_counter();
|
||||||
|
|
||||||
#if CONFIG_SYS_TIMER_RATE == 1000000
|
#ifdef CONFIG_SYS_TIMER_RATE
|
||||||
return count;
|
const ulong timer_rate = CONFIG_SYS_TIMER_RATE;
|
||||||
#elif CONFIG_SYS_TIMER_RATE > 1000000
|
|
||||||
return lldiv(count, CONFIG_SYS_TIMER_RATE / 1000000);
|
if (timer_rate == 1000000)
|
||||||
#elif defined(CONFIG_SYS_TIMER_RATE)
|
return count;
|
||||||
return (unsigned long long)count * 1000000 / CONFIG_SYS_TIMER_RATE;
|
else if (timer_rate > 1000000)
|
||||||
|
return lldiv(count, timer_rate / 1000000);
|
||||||
|
else
|
||||||
|
return (unsigned long long)count * 1000000 / timer_rate;
|
||||||
#else
|
#else
|
||||||
/* Assume the counter is in microseconds */
|
/* Assume the counter is in microseconds */
|
||||||
return count;
|
return count;
|
||||||
|
|
Loading…
Reference in a new issue