From: Luka Napotnik <luka.napotnik@gmail.com>
To: Jan Engelhardt <jengelh@computergmbh.de>
Cc: "linux-os (Dick Johnson)" <linux-os@analogic.com>,
linux-kernel@vger.kernel.org
Subject: Re: division and cpu usage
Date: Tue, 28 Aug 2007 12:41:35 +0200 [thread overview]
Message-ID: <46D3FBDF.3080508@gmail.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0708280843030.11442@fbirervta.pbzchgretzou.qr>
[-- Attachment #1: Type: text/plain, Size: 1112 bytes --]
How about this:
===============================
old_stime = task->stime;
old_utime = task->utime
old_j = jiffies;
set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(1 * HZ);
new_stime = task->stime;
new_utime = task->utime;
new_j = jiffies;
sum = ((new_stime - old_stime) + (new_utime - old_utime)) * 100 / (new_j
- old_j)
===============================
I get how much time the task has spent in 1 sec in the scheduler and
then get the percentage?
Greets,
Luka
Jan Engelhardt pravi:
> On Aug 28 2007 00:07, Luka Napotnik wrote:
>>>>> 2. I'm trying to get the percentage of CPU used for a certain
>>>>> task_struct and figured the following formula:
>>>>>
>>>>> (task->utime + task->stime) / jiffies
>> This formula just doesn't work. I have a task with 99% CPU (top) but the
>> result of that formula is random (4, sometimes 8). What am I doing
>> wrong? Please help.
>
> You are calculating the CPU time the process has used since the start.
> That is definitely not the same as the "%CPU" that top shows, more like
> the "TIME+" top shows by default.
>
>
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 252 bytes --]
next prev parent reply other threads:[~2007-08-28 10:41 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-23 23:43 division and cpu usage Luka Napotnik
2007-08-24 1:04 ` David Schwartz
2007-08-24 11:34 ` linux-os (Dick Johnson)
2007-08-24 12:46 ` Jan Engelhardt
2007-08-25 23:25 ` Luka Napotnik
2007-08-27 22:07 ` Luka Napotnik
2007-08-28 6:45 ` Jan Engelhardt
2007-08-28 10:41 ` Luka Napotnik [this message]
2007-08-28 12:11 ` Jan Engelhardt
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=46D3FBDF.3080508@gmail.com \
--to=luka.napotnik@gmail.com \
--cc=jengelh@computergmbh.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-os@analogic.com \
/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.