Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thread-specific monotonic clock source in the kernel

Is there a monotonic clock source for use by a kernel module that can be attached to a thread and that will only increase when the associated thread is running?

I am looking for something that will work like the perf API, except measure the total amount of CPU time consumed so far in nanoseconds rather than measuring cycles or instructions.

In user space, you have the clock_gettime function from librt where you can specify the CLOCK_PROCESS_CPUTIME_ID as the type of clock to get the behavior described above. Looking at the source code of clock_gettime, this function calls another function from the pthread library called __pthread_clock_gettime.

I am looking for something similar that can be setup inside the Linux kernel from a kernel module and attached to a task, given a pointer to the task_struct associated with the task.

like image 323
Safayet Ahmed Avatar asked Nov 11 '22 15:11

Safayet Ahmed


1 Answers

The Performance API gives you access to various hardware events and counters. It has a low and high level API. The PAPI_epc function should fit your needs:

http://icl.cs.utk.edu/papi/docs/db/d93/group__high__api.html#ga2f8766ae458b43d41e57e78b930a4f61

like image 146
rgb122 Avatar answered Dec 17 '22 18:12

rgb122