How do I manually convert jiffies to milliseconds and vice versa in Linux? I know kernel 2.6 has a function for this, but I’m working on 2.4 (homework) and though I looked at the code it uses lots of macro constants which I have no idea if they’re defined in 2.4.
Share
As a previous answer said, the rate at which
jiffiesincrements is fixed.The standard way of specifying time for a function that accepts
jiffiesis using the constantHZ.That’s the abbreviation for Hertz, or the number of ticks per second. On a system with a timer tick set to 1ms, HZ=1000. Some distributions or architectures may use another number (100 used to be common).
The standard way of specifying a
jiffiescount for a function is usingHZ, like this:In most simple cases, this works fine.
Those last two have a bit of a problem, however, as on a system with a 10 ms timer tick,
HZ/100is 1, and the precision starts to suffer. You may get a delay anywhere between 0.0001 and 1.999 timer ticks (0-2 ms, essentially). If you tried to useHZ/200on a 10ms tick system, the integer division gives you 0 jiffies!So the rule of thumb is, be very careful using HZ for tiny values (those approaching 1 jiffie).
To convert the other way, you would use:
You shouldn’t expect anything better than millisecond precision.