[U-Boot] [PATCH v2] mmc: omap: timeout counter fix

Reinhard Meyer u-boot at emk-elektronik.de
Tue Oct 26 03:14:20 CEST 2010


Dear Nishanth Menon,
> Having a loop with a counter is no timing guarentee for timing
> accuracy or compiler optimizations. For e.g. the same loop counter
> which runs when the MPU is running at 600MHz will timeout in around
> half the time when running at 1GHz. or the example where GCC 4.5
> compiles with different optimization compared to GCC 4.4.
> use a udelay(10) to ensure we have a predictable delay.
> use an emperical number - 100000 uSec ~= 1sec for a worst case timeout.
> This should never happen, and is adequate imaginary condition for us
> to fail with timeout.

In such cases I prefer to use:

	uint64_t etime;
...
	etime = get_ticks() + get_tbclk(); /* 1 second */
	do {
		whatever;
		udelay (xx);
	} while (condition && get_ticks() <= etime);

That is far more accurate than calling udelay() 100000 times.
(depending on implementation and granularity udelay of a few usecs
might be rounded significantly)
You can still call udelay inside the loop if you don't want
to poll the condition too tightly...

Best Regards,
Reinhard


More information about the U-Boot mailing list