How to use Ktime for userspace applications
Try to find a high resolution scalable timer. Read something about ktimer, but could not find code examples of how to use ktimer.
Please provide some information about:
1. Can user space application use ktimer?
2. Is ktimer scalable, such as application can arm tens of thousands timers at the same time?
3. Code examples for how to arm and canel a ktime in C/C++ code?
The include <linux/ktime.h> is not found while I try to compile. I am using Ubuntu with kernel version 2.6.27-14-generic.
Thanks for the help.
thousands of timers... ugh!
Any OS would have an issue in this case. There are a finite number allocated to the kernel and they inhabit resources so 10's of thousands will never be available. Also you have to stop and think about your design. If you need so many timers what you probably want is a single periodic timer operating at the smallest period of you fastest timer. Whenever it goes off you would look at your list of timers pending and service the ones that have expired.
Look at the documentation on timer_create() and all of it's affiliated timer functions. Look closely at your requirements and make sure that you are not taking the requirement description as the actual code implementation, that's a mistake that I make too often and it sends me out into the weeds until I realize that there is an easier and better implementation out there.
The other problem you may be up against is the resolution of the timers. The normal timers have resolution on a PC of about 5ms. If you need something down in the us (microsecond) resolution then you need to use the hr_timers. These will only work if you have a kernel with the hr timer patch which pretty much all of the latest kernels do but you need to check to make sure they are available.
Hope this helps.
Cheers!!