As far as I know, "jiffies" in Linux kernel is the number of ticks since boot, and the number of ticks in one second is defined by "HZ", so in theory:
(uptime in seconds) = jiffies / HZ
But based on my tests, the above is not true. For example:
$ uname -r
2.6.32-504.el6.x86_64
$ grep CONFIG_HZ /boot/config-2.6.32-504.el6.x86_64
# CONFIG_HZ_100 is not set
# CONFIG_HZ_250 is not set
# CONFIG_HZ_300 is not set
CONFIG_HZ_1000=y
CONFIG_HZ=1000
So "HZ" is 1000, now look at the jiffies and uptime:
$ grep ^jiffies /proc/timer_list
jiffies: 8833841974
jiffies: 8833841974
...
$ cat /proc/uptime
4539183.14 144549693.77
As we can see, "jiffies" is far different to uptime. I have tested on many boxes, none of the jiffies was even close to uptime. What did I do wrong?
The jiffies variable has always been an unsigned long, and therefore 32 bits in size on 32-bit architectures and 64-bits on 64-bit architectures.
A jiffy is a kernel unit of time declared in <linux/jiffies. h> . To understand jiffies, we need to introduce a new constant, HZ, which is the number of times jiffies is incremented in one second. Each increment is called a tick. In other words, HZ represents the size of a jiffy.
What you're trying to do is how Linux used to work -- 10 years ago.
It's become more complicated since then. Some of the complications that I know of are:
That's why the kernel has functions designed to tell you the time. Use them or figure out what they are doing and copy it.
Well, I hit the same problem. After some research, I finally find the reason why jiffies looks so large compared to uptime.
It is simply because of
#define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
The real value of INITIAL_JIFFIES is 0xfffb6c20, if HZ is 1000. It's not 0xfffffffffffb6c20.
So if you want compute uptime from jiffies; you have to do
(jiffies - 0xfffb6c20)/HZ
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With