[U-Boot] [PATCH v1 (WIP) 09/16] [Timer]Replace get_timer() usage in drivers/block/
Graeme Russ
graeme.russ at gmail.com
Wed Jun 29 07:19:51 CEST 2011
Hi Reinhard,
On Wed, Jun 29, 2011 at 3:06 PM, Reinhard Meyer
<u-boot at emk-elektronik.de> wrote:
> Dear All,
>>
>> Well I know i have asked this before, but I feel I should ask again
>> because I didn't like the answer much.
>>
>> Imagine we change this code to:
>>
>> ts = time_now_ms() + msec
>> do {
>> ...
>> } while (time_since_ms(ts)< 0);
>>
>> That should be legal, right? But I don't think this can work since the
>> 'since' functions return an unsigned.
>>
>> [aside: this provides for another idiom that I think we talked about:
>>
>> ts = time_future_ms(msec)
>> do {
>> ...
>> } while (!time_passed(ts))
>>
>> which I am not at all suggesting should be in the API :-)
>> end aside]
>
> I still vouch for this concept, which is simple, clean, and easy to
> understand.
It really is a matter of personal taste ;) I find
u32 start = time_now_ms();
do {
...blah...
} while(time_since_ms(start) < timeout);
much easier to understand (Do whatever while time elapsed since I started
is less than the timeout)
u32 end = time_future_ms(timeout);
do {
...blah...
} while(time_now_ms() < end);
to me is a bit more clunky. Yes, it is probably computationally more
efficient, but it does not naturally support:
u32 start = time_now_ms();
u32 duration;
...blah...
duration = time_since_ms(start);
/* or duration = time_max_since_ms(start); */
Which we want for profiling.
Also there are a few instances where there are multiple cascaded timeouts
u32 start = time_now_ms();
do {
...blah...
} while(time_since_ms(start) < timeout_1);
do {
...blah...
} while(time_since_ms(start) < timeout_2);
Which means setting up all your timeouts in advance
Regards,
Graeme
More information about the U-Boot
mailing list