Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Linux's /proc/PID/stat lists several metrics that are measured in jiffies. Is there a way to get the current # of jiffies since reboot? Jiffies I also assume to be seconds times the USER_HZ value.

Can I get this by summing the first 4 arguments on the cpu line in /proc/stat?


UPDATE:

$ date +"%s.%N" && grep '^jiffies' timer_list
1262103103.162169230
jiffies: 1007865965
jiffies: 1007865965
jiffies: 1007865965
jiffies: 1007865965
$ date +"%s.%N" && grep '^jiffies' timer_list
1262103108.706475051
jiffies: 1007867351
jiffies: 1007867351
jiffies: 1007867351
jiffies: 1007867351

The delta between these is almost exactly 250 jiffies / second. Appears as though all the jiffies lines per CPU are equivalent (though I guess they might not be if a hot | ondemand CPU was provisioned/replaced). I think this gives me the best place to pull a consistent jiffies counter.

share|improve this question
up vote 4 down vote accepted

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.

share|improve this answer
    
How does one activate the timer_stats? Correct, the 'jiffies' is an arbitrary increment in this case as long as the various /proc/PID/stat files report a metric that is equivalent to some total I can use to calculate relative %s. OK, so there is a "jiffies" line in /proc/timer_list, I'll update original post. – Xepoch Dec 29 '09 at 16:16
    
To start collection of stats "echo 1 > /proc/timer_stats", which you can put at the start of your init cycle. – Darren Hall Dec 29 '09 at 18:41

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.

share|improve this answer
    
Is this not only for user time for which the cpu was scheduled? The others being nice, system & idle? – Xepoch Dec 29 '09 at 4:21
    
added the meaning of each column. – John T Dec 29 '09 at 4:25
    
Right, but to find the total # of jiffies since start, would one not do something like awk '/^cpu/{print $2+$3+$4+$5}' /proc/stat? – Xepoch Dec 29 '09 at 5:17
    
You only want user,nice,system and idle? You can do awk '/^cpu\>/{print $2+$3+$4+$5}' /proc/stat – John T Dec 29 '09 at 5:32
    
Appears as though any given time delta is not consistent with a sum across the /proc/stat! – Xepoch Dec 29 '09 at 16:26

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

share|improve this answer
    
I get 75409.1301 so that does not seem stable in general case. uname -a reports Linux semyol-329-b 3.19.0-33-lowlatency #38~14.04.1-Ubuntu SMP PREEMPT Fri Nov 6 19:30:45 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux. – Mikko Rantalainen Nov 20 '15 at 8:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .