Linux – Measure units in /proc//schedstat

linuxproc

I need to get statistics from /proc/pid/schedstat for a particular process.

Here https://www.kernel.org/doc/Documentation/scheduler/sched-stats.txt I found the description of fields.

What are measure units of (1) time spent on the cpu and of (2) time spent waiting on a runqueue? How convert them to seconds? Are they measured in clock ticks and I should divide them by sysconf(_SC_CLK_TCK)?

Best Answer

The documentation says they are in "jiffies", but the documentation is outdated. Try running a CPU-intensive task and sampling the counters a few seconds apart, and you'll see they increment too quickly to feasibly be in jiffies.

The documentation became wrong with the adoption of the Completely Fair Scheduler (CFS) which is the default on modern kernels, so divide by 1000000000 to convert to seconds.

https://lkml.org/lkml/2019/7/24/906

Related Question