Page 1 of 1

Strange latency problem in chThdSleepMilliseconds()

Posted: Fri Oct 19, 2012 9:41 pm
by iggarpe
I'm experiencing an strange latency problem in which my high priority threads are being kept from executing for about 1ms (one system tick, might be a clue), and I've traced the problem down to a chThdSleepMilliseconds() call in the main program. Pseudocode would be something like this:

(... removed ...)

[edit 1]

Apparently I rushed to blame chThdSleepMilliseconds(). Turns out some code in mac/mac_lld/lwip is keeping interrupts disabled for too long. I should be able to pinpoint it eventually (I'm using a STM32F407VG).

[edit 2]

Ok. I found it. Like most LLD code, mac_lld_start is called with the systen lock acquired, and it does quite a bunch of no-nos like busy waits (mii_write/read, for example). Definitely the STM32 MAC driver needs some rewriting. Keep in mind a macStart() call in this platform will badly break the OS latency.

I don't have the time at the moment to rewrite the code, so as a workaround I'll move the LWIP thread creation (which is the one calling macInit) BEFORE my other time sensitive threads are started.

Re: Strange latency problem in chThdSleepMilliseconds()

Posted: Sat Oct 20, 2012 7:47 am
by Giovanni
Hi,

Thanks for finding, the best workaround is to start the driver before doing critical operations as you already did.

Giovanni