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:
signature.asc
Description: OpenPGP digital signature
- Follow-Ups:
- Re: division and cpu usage
- From: Jan Engelhardt <[email protected]>
- Re: division and cpu usage
- References:
- division and cpu usage
- From: Luka Napotnik <[email protected]>
- Re: division and cpu usage
- From: "linux-os \(Dick Johnson\)" <[email protected]>
- Re: division and cpu usage
- From: Jan Engelhardt <[email protected]>
- Re: division and cpu usage
- From: Luka Napotnik <[email protected]>
- Re: division and cpu usage
- From: Jan Engelhardt <[email protected]>
- division and cpu usage
- Prev by Date: pdflush preemption
- Next by Date: Re: Linux 2.6.23-rc4
- Previous by thread: Re: division and cpu usage
- Next by thread: Re: division and cpu usage
- Index(es):