Below is a function from my coworker. It runs well at X86. I ran it at iMX6 and it didn't work because the program usually slept just half or twice the time as I expected. The inaccuracy is too large. How come?
inline void uusleep(int usecs) {
struct timeval tpstart,tpend;
gettimeofday(&tpstart,NULL);
long ss = tpstart.tv_sec*1000000 + tpstart.tv_usec + usecs;
while(1) {
gettimeofday(&tpend,NULL);
if( (tpend.tv_sec*1000000 + tpend.tv_usec) >= ss) break;
}
}