Converting from jiffies to ticks
jhb at freebsd.org
Fri Aug 20 14:48:31 UTC 2010
On Friday, August 20, 2010 9:14:23 am Jesse Smith wrote:
> I am currently trying to port a program from Linux to FreeBSD which
> detects how much processor time a process is using. The native Linux
> code does this (in part) by reading the number of "jiffies" a given
> process uses. This info is pulled from the /proc/PID/stat file.
> One function is failing on FreeBSD and it's obviously because FreeBSD
> does not have all the same files/data in the /proc directory.
> I've looked around and, as I understand it, FreeBSD uses "ticks" instead
> of "jiffies" to measure process usage. However, how to gather that data
> is a bit lost on me.
> This raises a question for me:
> Where can I find the equivalent information on FreeBSD? I assume
> there's a function call. Maybe in the kvm_* family? I need to be able to
> get the number of ticks a given PID is using, both in the kernel and
> The rest of the program measures everything in "jiffies", so it would be
> ideal for me to get the ticks used on FreeBSD (based on PID), convert it
> to "jiffies" and pass it back to the main program.
FreeBSD saves the total runtime in an architecture-dependent "ticker" count
that is separate from "ticks". ("ticks" tends to run at hz, so by default
1000 times per second, where as the 'ticker' on x86 is the TSC which runs at
the clock speed of the CPU (throttling and turbo boost aside)). You can look
at the calcru() function to see how the kernel converts the runtime "ticker"
count (saved in rux_runtime) into microseconds.
More information about the freebsd-hackers