简体   繁体   English

利用亚微秒精度测量Linux内核空间的时间

[英]Measuring Time in Linux Kernel Space With Sub-Microsecond Precision

I am currently using the do_gettimeofday() function to measure time in the kernel, which gives me microsecond precision. 我目前正在使用do_gettimeofday()函数来测量内核中的时间,这给了我微秒的精度。 Is there anything available that is more precise than this (maybe on the order of nanoseconds)? 有没有比这更精确的东西(可能是纳秒级)?

ktime_get()函数返回ktime_t ,其具有纳秒分辨率。

As I know, the most precise timer should be the processor specific counter register (such as TSC in x86). 据我所知,最精确的定时器应该是处理器特定的计数器寄存器(例如x86中的TSC )。 Linux kernel provide rdtsc, rdtscl, rdtscll macros from the "./arch/x86/include/asm/msr.h" file to read this register value. Linux内核从“./arch/x86/include/asm/msr.h”文件中提供rdtsc,rdtscl,rdtscll宏来读取该寄存器值。 For ARM, cycle counter register . 对于ARM, 循环计数器寄存器

These registers are all different from CPU to CPU. 这些寄存器在CPU与CPU之间都有所不同。 Common interface to access it is "get_cycles" function which is declared in file. 访问它的公共接口是“get_cycles”函数,它在文件中声明。

Maybe, this document can be helpful. 也许, 这个文件可能会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM