From: Reinhard Meyer <u-boot@emk-elektronik.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC] ARM timing code refactoring
Date: Sat, 22 Jan 2011 11:42:21 +0100 [thread overview]
Message-ID: <4D3AB48D.4090101@emk-elektronik.de> (raw)
In-Reply-To: <4D3AAF63.1030600@free.fr>
Dear Albert ARIBAUD,
> Hi All,
>
> I am starting this thread to revive and, hopefully, come to a general
> agreement on how timers should be implemented and used in the ARM
> architecture, and get rid of current quick fixes. Let us start with
> Reinhard's proposal:
>
>> There were several suggestions about that in the past (including from
>> me) that involve rework everywhere HZ related timeouts are used. I
>> still prefer a method as follows (because it does not need repeated
>> mul/div calculations nor necessarily 64 bit arithmetic):
>
> Agreed for unnecessary mult-div, but 64-bit we would not avoid, and
> should not IMO, when the HW has it.
>
>> u32 timeout = timeout_init(100); /* 100ms timeout */
>>
>> do {...} while (!timed_out(timeout));
>>
>> Internally it would be like:
>>
>> timeout_init(x):
>> return fast_tick + (x * fast_tick_rate) / CONFIG_SYS_HZ;
>> /* this might need 64 bit precision in some implementations */
>>
>> time_out(x):
>> return ((i32)(x - fast_tick))< 0;
>>
>> If the tick were really high speed (and then 64 bits), fast_tick
>> could be derived by shifting the tick some bits to the right.
>
> The only thing I slightly dislike about the overall idea is the signed
> rather than unsigned comparison in the timeout function (I prefer using
> the full 32-bit range, even if only as an academic point) and the fact
> that the value of the timeout is encoded in advance in the loop control
> variable 'timeout'.
1. you always need signed compares there, unless you never anticipate a
rollover of your timer value to zero.
2. whats the problem with initializing the timeout value at the beginning?
>
> I'd rather have a single 'time(x)' (or 'ticks_elapsed(x)', names are
> negotiable) macro which subtract its argument from the current ticks,
> e.g. 'then = time(0)' would set 'then' to the number of ticks elapsed
> from boot, while 'now = time(then)' would set 'now' the ticks elapsed
> from 'then'; and a 'ms_to_ticks(x)' (again, or 'milliseconds(x)') :
>
> #define time(x) (ticks - x)
> #define ms_to_ticks(m) ( (m * fast_tick_rate) / CONFIG_SYS_HZ)
We have exactly an equivalent of this in use at AT91.
It works only as long as the ticks value does not roll back to zero -
which in the current 64 bit implementation I did is after the end of
the universe...
Note also that "fast_tick_rate" would not be a constant in AT91, it is
dynamically calculated from main xtal frequency measured against the 32kHz
xtal and PLL settings.
>
> Note that time(x) assumes unsigned arguments and amounts to an unsigned
> compare, because we're always computing an difference time, i.e. even
> with x = 2 and ticks = 1, the result is correct -- that's assuming ticks
> is monotonous 32-bits (or 64-bits for the platforms that can support it
> as an atomic value)
Assume: Monotonous AND never wrapping back to zero!
>
> Your example would then become
>
> then = time(0);
> do {...} while ( time(then)< ms_to_ticks(100) );
That looks ugly to me. We don't want to see the high speed(64 bit) values
in the drivers - I think.
>
> ... moving the actual timeout value impact from the time sample before
> the 'while' to the 'while' condition at then end.
Which does a multiply and a divide in 64 bit each loop iteration...
(fast_tick_rate being a variable)
>
> For expressiveness, added macros such as:
>
> #define now() time(0)
> #define ms_elapsed(then,ms) ( time(then)< ms_to_ticks(ms) )
>
> ... would allow writing the same example as:
>
> then = now();
> do {...} while ( !ms_elapsed(then,100) );
>
Why make everything so complicated???
>> But, as long as we cannot agree on something, there will be no
>> time spent to make patches...
>
> Makes sense, hence this specific thread. :)
The how-many-th thread about timers is this ? :)
Best Regards,
Reinhard
next prev parent reply other threads:[~2011-01-22 10:42 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-22 10:20 [U-Boot] [RFC] ARM timing code refactoring Albert ARIBAUD
2011-01-22 10:42 ` Reinhard Meyer [this message]
2011-01-22 11:32 ` Albert ARIBAUD
2011-01-22 11:00 ` [U-Boot] [RFC] U-boot (was: ARM) " Reinhard Meyer
2011-01-22 12:22 ` [U-Boot] [RFC] U-boot Albert ARIBAUD
2011-01-22 19:19 ` [U-Boot] [RFC] ARM timing code refactoring Wolfgang Denk
2011-01-22 20:17 ` Albert ARIBAUD
2011-01-22 21:26 ` Wolfgang Denk
2011-01-22 21:51 ` Reinhard Meyer
2011-01-23 10:12 ` Wolfgang Denk
2011-01-23 10:26 ` Reinhard Meyer
2011-01-23 16:23 ` Wolfgang Denk
2011-01-23 18:47 ` Reinhard Meyer
2011-01-23 19:35 ` Wolfgang Denk
2011-01-23 20:59 ` Albert ARIBAUD
2011-01-23 21:22 ` Reinhard Meyer
2011-01-23 22:01 ` Reinhard Meyer
2011-01-23 22:57 ` Wolfgang Denk
2011-01-24 1:42 ` J. William Campbell
2011-01-24 7:24 ` Albert ARIBAUD
2011-01-24 7:50 ` Reinhard Meyer
2011-01-24 12:59 ` Wolfgang Denk
2011-01-24 8:25 ` Andreas Bießmann
2011-01-24 11:58 ` Albert ARIBAUD
2011-01-24 12:06 ` Albert ARIBAUD
2011-01-24 12:58 ` Andreas Bießmann
2011-01-24 12:54 ` Wolfgang Denk
2011-01-24 13:02 ` Wolfgang Denk
2011-01-24 16:23 ` J. William Campbell
2011-01-22 22:13 ` Albert ARIBAUD
2011-01-23 16:15 ` Wolfgang Denk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4D3AB48D.4090101@emk-elektronik.de \
--to=u-boot@emk-elektronik.de \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox