public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* wrong count of CPU usage
@ 2012-05-16 14:33 Azat Khuzhin
  2012-05-21 20:20 ` Azat Khuzhin
  0 siblings, 1 reply; 3+ messages in thread
From: Azat Khuzhin @ 2012-05-16 14:33 UTC (permalink / raw)
  To: Linux Kernel Mailing List

[-- Attachment #1: Type: text/plain, Size: 2739 bytes --]

Hi all

I have machine that have uptime 212 days, kernel version: Linux
2.6.35.14-97.fc14.x86_64 #1 SMP Sat Sep 17 00:15:37 UTC 2011 x86_64
x86_64 x86_64 GNU/Linux
Before top (1) utility shows some activity per process, as it should
be (sort by %CPU column)

But from some time, no activity in top (1) per process at all
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
    1 root      20   0 19420 1548 1240 S  0.0  0.0  17:48.09 init
    2 root      20   0     0    0    0 S  0.0  0.0   0:09.72 kthreadd
    3 root      20   0     0    0    0 S  0.0  0.0  20:34.76 ksoftirqd/0

But load avg > 10
top (1) shows some activity on cores (I mean not processes, that
created by kernel)
top - 09:58:26 up 212 days,  7:06,  8 users,  load average: 13.27, 12.20, 11.37
Tasks: 815 total,   9 running, 803 sleeping,   2 stopped,   1 zombie
Cpu0  : 47.5%us,  8.0%sy,  0.3%ni, 26.4%id, 16.9%wa,  0.0%hi,  0.9%si,  0.0%st
Cpu1  : 39.7%us,  5.2%sy,  0.0%ni, 48.0%id,  6.8%wa,  0.0%hi,  0.3%si,  0.0%st
Cpu2  : 29.8%us,  3.1%sy,  0.0%ni, 59.7%id,  7.4%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu3  : 15.9%us,  2.8%sy,  0.0%ni, 77.3%id,  3.7%wa,  0.0%hi,  0.3%si,  0.0%st
Cpu4  : 39.3%us,  5.2%sy,  0.0%ni, 37.4%id, 17.8%wa,  0.0%hi,  0.3%si,  0.0%st
Cpu5  : 29.6%us,  4.0%sy,  0.0%ni, 62.3%id,  3.7%wa,  0.0%hi,  0.3%si,  0.0%st
Cpu6  : 20.4%us,  5.0%sy,  0.0%ni, 74.3%id,  0.0%wa,  0.0%hi,  0.3%si,  0.0%st
Cpu7  : 17.3%us,  2.8%sy,  0.0%ni, 76.8%id,  3.1%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu8  : 32.8%us,  6.5%sy,  0.0%ni, 31.6%id, 29.1%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu9  : 27.6%us,  3.1%sy,  0.0%ni, 69.3%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu10 :  6.8%us,  2.5%sy,  0.0%ni, 87.9%id,  2.8%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu11 :  8.7%us,  1.9%sy,  0.0%ni, 89.4%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu12 : 27.3%us,  2.8%sy,  0.0%ni, 52.8%id, 17.1%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu13 : 18.2%us,  3.7%sy,  0.0%ni, 77.5%id,  0.6%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu14 : 21.4%us,  3.8%sy,  0.0%ni, 74.8%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Cpu15 : 10.0%us,  1.9%sy,  0.0%ni, 87.9%id,  0.3%wa,  0.0%hi,  0.0%si,  0.0%st

So seems like after some time kernel not updating /proc/PID/stat properly

I wrote shell script (attach), that count CPU usage, and it also shows 0
This script base on 14, 15 columns from /proc/PID/stat (as man proc
says, that it utime and stime clocks, and /proc/stat summary), but for
newly created processes

Summarize
/proc/PID/stat seems not change counters utime, stime
/proc/stat updated

--
Azat Khuzhin

[-- Attachment #2: cpu_usage --]
[-- Type: application/octet-stream, Size: 1271 bytes --]

#!/bin/bash

PID=$1

if [ "x$PID" = "x" ] ; then
	exit 1
fi

# utime
USER_START=`awk '{print $14}' /proc/$PID/stat`
USER_ALL_START=`head -n1 /proc/stat | awk 'BEGIN {sum = 0} { for (i = 1; i <= NF; ++i) { sum += $i } } END {print sum}'`
sleep 1
USER_END=`awk '{print $14}' /proc/$PID/stat`
USER_ALL_END=`head -n1 /proc/stat | awk 'BEGIN {sum = 0} { for (i = 1; i <= NF; ++i) { sum += $i } } END {print sum}'`
USER=`echo "sacle=5; 100 * ($USER_END - $USER_START) / ($USER_ALL_END - $USER_ALL_START)" | bc`
echo "[process] jiffies for 1 sec: $(( $USER_END - $USER_START ))"
echo "[    all] jiffies for 1 sec: $(( $USER_ALL_END - $USER_ALL_START ))"
echo "[   cpu%] $USER %"

# stime
SYS_START=`awk '{print $15}' /proc/$PID/stat`
SYS_ALL_START=`head -n1 /proc/stat | awk 'BEGIN {sum = 0} { for (i = 1; i <= NF; ++i) { sum += $i } } END {print sum}'`
sleep 1
SYS_END=`awk '{print $15}' /proc/$PID/stat`
SYS_ALL_END=`head -n1 /proc/stat | awk 'BEGIN {sum = 0} { for (i = 1; i <= NF; ++i) { sum += $i } } END {print sum}'`
SYS=`echo "scale=5; 100 * ($SYS_END - $SYS_START) / ($SYS_ALL_END - $SYS_ALL_START)" | bc`
echo "[process] jiffies for 1 sec: $(( $SYS_END - $SYS_START ))"
echo "[    all] jiffies for 1 sec: $(( $SYS_ALL_END - $SYS_ALL_START ))"
echo "[   cpu%] $SYS %"


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-06-13  9:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-16 14:33 wrong count of CPU usage Azat Khuzhin
2012-05-21 20:20 ` Azat Khuzhin
2012-06-13  9:24   ` [utime/stime times have stalled] Walter Doekes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox