← Back to context

Comment by deng

6 days ago

> Is it just because reading takes time, therefore reading multiple time makes the needed time from writing to reading passes?

Yes.

> If so, it sounds like a worse solution than just extending waiting delay longer like the author did initially.

Yeah, it's a judgement call. Previously, the code called cpu_relax() for waiting, which is also dependent on how this is defined (can be simply NOP or barrier(), for instance). The reading of the timer register maybe has the advantage that it is dependent on the actual memory bus speed, but I wouldn't know for sure. Hardware at that level is just messy, and especially niche platforms have their fair share of bugs where you need to do ugly workarounds like these.

What I'm rather wondering is why they didn't try the other solution that was mentioned by the manufacturer: reading the timer directly two times and compare it, until you get a stable output.