All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Rafael C. de Almeida" <almeidaraf@gmail.com>
To: linux-kernel@vger.kernel.org
Subject: Weird behaviour on /proc/stat
Date: Wed, 06 Aug 2008 17:35:51 -0300	[thread overview]
Message-ID: <489A0B27.80604@gmail.com> (raw)

I've executed the following code on a intel core 2 quad (linux 2.6.21.5):

for (( x=0; x < 1800; x = x+1 )); do
        head -n5 /proc/stat |
        awk '{ print $2+$3+$4+$5+$6+$7+$8+$9 }' |
        awk 'BEGIN { x=0 } { if (NR == 1) y=$0; else x=x+$1; } END {
print y, x }' |
        awk '{ print $0, $1-$2 }' >> values
        sleep 1;
done

My expectation was that the values file would have only 0s on the second
field. It didn't happen. Actually, it was always a value greater than 0.
So I went to the kernel code. The utilization is summed up here:

	http://lxr.linux.no/linux+v2.6.21.5/fs/proc/proc_misc.c#L463

Reading that file, if anything the sum of all the cpuX fields should be
greater than the cpu line. After all, it happens later and, if
information regarding the utilization is updated during the generation
of the output, then the cpuX lines should have a greater value.

I also noted that on
	http://lxr.linux.no/linux+v2.6.21.5/fs/proc/proc_misc.c#L463
for_each_possible_cpu is used. While on
	http://lxr.linux.no/linux+v2.6.21.5/fs/proc/proc_misc.c#L487
for_each_online_cpu is used. All the cores on the system are online, so
where could be the extra utilization that's being added to the first
line result?

I wish I had a machine with 4 cores which I could test changes on that
code, so I could investigate things a little further. But the only
machine I can change the kernel is my home computer which has only one
core  :(.

             reply	other threads:[~2008-08-06 20:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-06 20:35 Rafael C. de Almeida [this message]
2008-08-06 21:51 ` Weird behaviour on /proc/stat Sven Wegener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=489A0B27.80604@gmail.com \
    --to=almeidaraf@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.