How to obtain the current number of jiffies since reboot in Linux?
Technically jiffy in computer parlance is the duration of 1 tick of the system timer interrupt. It's not absolute though. For Linux 2.6.13+ on Intel x86 jiffy is 4ms, but can range from 1ms to 10ms depending upon architecture and kernel version.
From the Kernel Timer Systems page:
Historically, the kernel used 100 as the value for HZ, yielding a jiffy interval of 10 ms. With 2.4, the HZ value for i386 was changed to 1000, yeilding a jiffy interval of 1 ms. Recently (2.6.13) the kernel changed HZ for i386 to 250. (1000 was deemed too high).
It lists /proc/timer_list
and /proc/timer_stats
.
You can activate the timer_stats at boot time, then cat this file to print stats.
No, you only need the first line. The first line aggregates everything else in the other cpu lines.
Example output:
[john@awesome]$cat /proc/stat cpu 35024984 1771325 94153391 1810948613 2648063 352387 557232 cpu0 13955475 927654 59431476 895791946 1910028 318618 438048 cpu1 21069509 843671 34721915 915156667 738035 33769 119184 intr 1403502159 1138402452 597 0 3 3 0 5 0 1 0 0 0 12315 0 92119425 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 57676632 0 0 0 0 0 0 0 115290726 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ctxt 21043582666 btime 1252332786 processes 25663823 procs_running 1 procs_blocked 0
What each column means (left to right):
- user: normal processes executing in user mode
- nice: niced processes executing in user mode
- system: processes executing in kernel mode
- idle: idle time
- iowait: waiting for I/O to complete
- irq: servicing interrupts
- softirq: servicing softirqs
as you can see, the first column after cpu (user mode processes) is equal to the 2 numbers beneath it added together.
In later Linux Kernels you can query /proc/timer_list
and find out the number of jiffies since reboot from each CPU that's present within the system. They should always match.
$ grep -E "^cpu|^jiff" /proc/timer_list
cpu: 0
jiffies: 4299690231
cpu: 1
jiffies: 4299690231
If you take a look at the code behind timer_list.c
the bit that prints the above:
...
...
P_ns(iowait_sleeptime);
P(last_jiffies);
P(next_timer);
P_ns(idle_expires);
SEQ_printf(m, "jiffies: %Lu\n",
(unsigned long long)jiffies);
Notice that it's unsigned long long
.
jiffies per second:
awk 'BEGIN {"cat /proc/timer_list | grep '\''^jiffies'\'' | awk '\''{print $2}'\''" | getline a; "cat /proc/uptime | awk '\''{print $1}'\''" | getline b ;printf "%.4f\n", a/b}'
Explanation: It divides jiffies since boot found in /proc/timer_list by the seconds since boot found in /proc/uptime