I wrote a little program to test the accuracy of clock_nanosleep under linux. Running SCHED_FIFO at the highest priority I did an absolute clock_nanosleep() followed by a clock_gettime() and took the difference. I noticed that when using a short sleep time the results were very good, but when using larger times the error was several ms. What surprised me was that sometimes the clock_nanosleep would be woken before the requested time, or since this is not allowed, the time was adjusted after the sleep function returned. This was using CLOCK_REALTIME. Is CLOCK_REALTIME constantly adjusted? Linux doesn't seem to have CLOCK_MONOTONIC right?
Is there something that can be easily done about the bad performance of clock_nanosleep at long sleep times? --Martijn
