My system is running Linux for embedded. At the moment I didn't sync the system clock or gave the user an option to do it but it's going to change.

Different parts in my application are using timestamps, I want to use different clock then the system clock for this timestamps so they will not get affected when the system time is change by ntp/user. I know that the system has the uptime value so it's keeping track on a different clock beside the system clock, but the precision of the uptime is too low (seconds)...

Is there a way to get the uptime with better precision (milliseconds)?

1 Answer 1


/proc/uptime gives the uptime in hundredths of a second.

If you want more precise values, you could write a kernel module based on the /proc/uptime implementation.

  • Thank you. What about the performance, reading system time comparing reading thru kernel module that uses /proc/uptime?
    – Ofir
    Nov 18, 2020 at 13:11
  • 1
    Ultimately the performance would be similar, you’re calling into the kernel in both cases. This could be hosted in the vDSO if performance was really important. Nov 18, 2020 at 13:55
  • Is this a kernel call, or does it use the memory mapped kernel data trick (edit: is that the vDSO that you mentioned). Nov 18, 2020 at 15:15
  • @ctrl-alt-delor reading from /proc always involves kernel calls (read & co.). The vDSO can use the memory-mapped kernel data trick; but that involves adding a vDSO call. Nov 18, 2020 at 15:22
  • 1
    I've changed the implementation. I read the time similar to the /proc/uptime implementation, with ktime_get_boottime_ts64. Reading with u64 ktime_get_ns return the right result but because the return value is in nano sec it will wraparound after 500+ years so it's good to be prepared : )
    – Ofir
    Nov 19, 2020 at 9:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.