This is the answer to the call - I do not know the corresponding internal components of Linux, I hope that the expert can come and remove it.
One possibility is that 69us is just the raw overhead of assembling and then reconfiguring the stream. Although the dream is short, the kernel can do a great job to execute the context switch (or half the context switch if there is no graph) and then cancel it almost immediately. I do not know how long this “should” take on Linux on a typical PC.
If this does not explain this, the scheduler usually has the concept of a “time list”, that is, how long the scheduled thread will be left to run before the scheduler thinks about switching it, unless it performs self-targeting, otherwise something with a higher priority becomes planned. The kernel will have low-level timers that interrupt interrupts at the end of the time fragment (in addition to interrupts that fire for some other events, such as I / O, which can unlock the stream). When the time list ends, the scheduler can decide whether to continue with the same stream or switch to another.
Thus, it seems that when you are sleeping, either (a) the scheduler does not actually set a timer that will make your thread scheduled at the specified time, it just waits for a time-out, and therefore the processor will work longer than necessary; or (b) it makes your thread scheduled at the indicated time, but when you refused to sleep, it entered some other thread with equal priority, and the scheduler has no reason to prefer it until it’s “your move” "again according to any rules that the scheduler usually uses to decide which thread to schedule.
69us is quite short to be an artifact of time.
You seem to have a rudimentary solution - you can linger for very short periods, sitting in the loop, checking the time, just like a spin lock. However, as everyone else says, in a system other than real time, more or less by definition you cannot require the scheduler to start your thread at any particular time. Even in real time, if you compete with threads of equal priority, you can lose, and if you compete with threads with higher priority, you will lose.
Steve jessop
source share