Mixing HR timers with itimers
While attempting to come up with an example for how it is difficult to differentiate the High Resolution (HR) timers from user timers – for EINTR purposes – I came across a slightly different problem. One newer kernels (at least >= 2.6.25 but not 2.6.18), a periodically firing HR timer will appear to prevent an itimer from generating an EINTR at all for a blocking system call.
My test program creates an HR timer on a one second frequency and sets an itimer for three seconds. The call immediately blocks on a file lock using the flock system call. The itimer should fire and interrupt the flock with an EINTR, but most of the time the itimer will fire without interrupting the flock. By offsetting the HR timer 0.5 seconds, the itimer will interrupt the flock everytime.
The test program is at github. I’m currently determining which kernels appear to demonstrate this behavior.
Update: The LKML thread here includes followups from Oleg and Roland explaining the observed behavior.