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)?


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.


| improve this answer | |
  • Tried it. It seems that they are really in nanoseconds. Thanks a lot. – Seleznev Anton Jul 15 '19 at 9:42

According to the doc the time unit is "jiffies" As in, "I'll be there in a jiffy!" :)

A jiffy is equal to the time it takes light to travel one centimeter in a vacuum or approximately 33.3564 picoseconds. - Wikipedia

But that's not the definition you want. Try this post https://stackoverflow.com/questions/10885685/jiffies-how-to-calculate-seconds-elapsed where the top answer says

The size of a jiffy is determined by the value of the kernel constant HZ.

The value of HZ varies across kernel versions and hardware platforms. On i386 the situation is as follows: on kernels up to and including 2.4.x, HZ was 100, giving a jiffy value of 0.01 seconds; starting with 2.6.0, HZ was raised to 1000, giving a jiffy of 0.001 seconds. Since kernel 2.6.13, the HZ value is a kernel configuration parameter and can be 100, 250 (the default) or 1000, yielding a jiffies value of, respectively, 0.01, 0.004, or 0.001 seconds. Since kernel 2.6.20, a further frequency is available: 300, a number that divides evenly for the common video frame rates (PAL, 25 HZ; NTSC, 30 HZ).

Conclusion: divide a schedstat time value by the system's HZ constant to convert to seconds.

Update: If you're dealing with these times in a programmatic context, the now top answer on that same page points to some system routines that you can call to do conversions (e.g. jiffies to milliseconds).

| improve this answer | |

Changed from jiffies to nanoseconds in Linux 2.6.23, see the commit 425e0968a25f

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.