While going through Proc::ProcessTable I noticed these comments by Dan Urist regarding clock tick rates. I just used sysconf for one of my own modules that needed that info, but Mr. Urist has come up with a rather interesting alternative.
While interesting, I find this serious overkill for a module. I don't know about you, but I'm not going to use a pre-compiled version of a module on my system. Doesn't *everyone* just build from scratch?* Anyway, here are his comments. If you really want to look at the code solution, just download his module.
Thoughts anyone?
/***********************************************************************
* Some values in /proc are expressed in units of 1/HZ seconds, where HZ
* is the kernel clock tick rate. One of these units is called a jiffy.
* The HZ value used in the kernel may vary according to hacker desire.
* According to Linus Torvalds, this is not true. He considers the values
* in /proc as being in architecture-dependant units that have no relation
* to the kernel clock tick rate. Examination of the kernel source code
* reveals that opinion as wishful thinking.
*
* In any case, we need the HZ constant as used in /proc. (the real HZ value
* may differ, but we don't care) There are several ways we could get HZ:
*
* 1. Include the kernel header file. If it changes, recompile this library.
* 2. Use the sysconf() function. When HZ changes, recompile the C library!
* 3. Ask the kernel. This is obviously correct...
*
* Linus Torvalds won't let us ask the kernel, because he thinks we should
* not know the HZ value. Oh well, we don't have to listen to him.
* Someone smuggled out the HZ value. :-)
*
* This code should work fine, even if Linus fixes the kernel to match his
* stated behavior. The code only fails in case of a partial conversion.
***************************************************************************/
*Hmmm...I suppose it's possible that you could recompile a kernel that ends up having a new clock tick rate, and all of your current modules that used sysconf would break (right?)