LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   Adding times from "top" command doesn't match uptime minus sleep time (https://www.linuxquestions.org/questions/linux-kernel-70/adding-times-from-top-command-doesnt-match-uptime-minus-sleep-time-4175611111/)

David PREVOT 08-02-2017 03:45 AM

Adding times from "top" command doesn't match uptime minus sleep time
 
Hi all,

I'm running top on an atom N270 cpu (single core).
When the uptime reaches 10 hours
1) I run "top -b -n 1 -c -S" to get all the cpu time used by all processes ... Assuming that "init" receives gets the time spent by all dead processes (due to the "cumulative mode ON" option).
2) I run "cat /proc/uptime" to get the uptime and the sleep time

When I add the cumulative time and the sleep time I get (more or less) 9 hours.

I believe that the "lost time" is used by the kernel itself (task scheduling, IP forwarding, ... can't be attributed to userspace processes). But it's only a feeling :(
Am I wrong in my deduction ?
Is there a tool like "top" that works for the kernel ?

Thanks in advance,
Best regards,
David.

AwesomeMachine 08-02-2017 05:33 PM

Those figures are approximate. /proc/uptime does not specify time sleeping. It specifies time idle. What exactly constitutes idle I don't know.

sundialsvcs 08-04-2017 12:50 PM

"idle" is the time spent when the dispatcher has no work of any kind to dispatch.

All of the statistics are approximate and are calculated in different ways which are not intended to "add up."

The init process ("process #1" by any name) does not receive all unallocated time. Instead, if there's nothing for the CPU to do, the CPU generally halts, so that it gets off of the DMA bus.

Interrupt-processing time may or may not be fully accounted for but is ordinarily comparatively slight.

rigor 08-06-2017 04:03 PM

If you just run top without command line arguments and look at the top outline line labeled "%Cpu" you can see a breakdown of some of the specific categories about where time was spent, including to some extent, in the kernel. For me, they usually add up reasonably well, but they can be rounded before being displayed, so they can add up to somewhat more than 100%.


All times are GMT -5. The time now is 12:48 AM.