Reputation: 748
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.
Upvotes: 5
Views: 529
Reputation: 146
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
Upvotes: 1