Reputation: 5966
I am currently using the do_gettimeofday()
function to measure time in the kernel, which gives me microsecond precision. Is there anything available that is more precise than this (maybe on the order of nanoseconds)?
Upvotes: 11
Views: 12090
Reputation: 6717
As I know, the most precise timer should be the processor specific counter register (such as TSC in x86). Linux kernel provide rdtsc, rdtscl, rdtscll macros from the "./arch/x86/include/asm/msr.h" file to read this register value. For ARM, cycle counter register.
These registers are all different from CPU to CPU. Common interface to access it is "get_cycles" function which is declared in <linux/timex.h> file.
Maybe, this document can be helpful.
Upvotes: 5
Reputation: 239011
The ktime_get()
function returns ktime_t
, which has nanosecond resolution.
Upvotes: 15