Calculating the optimum timer interval (timer_settime)
In Linux API timer_settime, we all know that we can set the timer interval using the API timer_settime. The minimum value we can set is 1 ns, 开发者_运维百科but it is not necessary that the CPU will take this, because it depends a lot on the frequency of the CPU too.
I want to calculate this and set this optimum interval to my timer (which should be least).
Any ideas how to calculate this?
Thanks in advance.
The optimum interval is "as long as possible, given the constraints of your application". In other words, don't fire any more often than you need to.
Have you tried "man clock_getres"?
Also, don't forget that there's a kernel and a C library between the caller and the CPU. I think what you really want to know is "what is the shortest interval I can put my process to sleep for inside the kernel?" I'm not sure, but that may depend on the clocksource being used by the kernel (which is only somewhat related to the clockid_t you pass to the timer_* and clock_* functions).
Looks like the kernel 3.15 will support deferred timers. Should be exactly what you are looking for.
精彩评论