Is it possible to execute tasks on a Linux host with microsecond precision? I.e., I\'d like to execute a task at a specific instant of time. I know, Linux is no real-time sy
You can do what you want from user space
CLOCK_REALTIME
to get the time-of-day with nano
-second resolutionmilli
-second resolution).clock_gettime()
until you reach the desired timeThe clock_gettime()
function is implemented as a VDSO in recent kernels and modern x86 processors - it takes 20-30 nano
seconds to get the time-of-day with nano
-second resolution - you should be able to call clock_gettime()
over 30 times per micro
-second. Using this method your task should dispatch within 1/30th of a micro
-second of the intended time.
The default Linux kernel timer ticks each millisecond. Microseconds is way beyond anything current user hardware is capable of.
The jitter you see is due to a host of factors, like interrupt handling and servicing higher priority tasks. You can cut that down somewhat by selecting hardware carefully, only enabling what is really needed. The real-time patchseries to the kernel (see the HOWTO) might be an option to reduce it a bit further.
Always keep in mind that any gain has a definite cost in terms of interactiveness, stability, and (last, but by far not least) your time in building, tuning, troubleshooting, and keeping the house of cards from falling apart.