Find the answer to your Linux question:
Results 1 to 5 of 5
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    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.

  2. #2


    ktimer stands for kernel timers so no, you can not use them in user space. You seem to need your standard timer_t timers which are POSIX standard and there are all sorts of examples on the internet on how to use them.


  3. #3
    Thanks for the quick reply.

    Does POSIX timer have performance issue for arming tens of thousands of timers at the same time, or one has to implement a user space wrapper around POSIX timer for performance?

  4. $spacer_open
  5. #4

    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.


  6. #5
    Thanks. It helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts