Why is the sum of /proc/pid/stat CPU greater than /proc/stat

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












0















In /proc/<pid>/stat I add user cpu, system cpu, child user and child system cpu together for all processes. I take a delta from a previous sample.



Immediately after I sum the user, nice and system CPU from /proc/stat which should be for the entire box. Again I take a delta.



The sum from the processes is almost always slightly greater than that for the overall processor and I can't figure out why.










share|improve this question
























  • I ran another test where I drove a single process to have 100% CPU on one of the four cores and measured just that process and /proc/stat. The box was otherwise idle. The process registered 100 clock ticks per second normally (expected) and occasionally 101 ticks. When it registered 101, that extra one never accumulated in /proc/stat which kept going up 100 ticks every second. It appears it sometimes misses them.

    – user331809
    Jan 17 at 15:23















0















In /proc/<pid>/stat I add user cpu, system cpu, child user and child system cpu together for all processes. I take a delta from a previous sample.



Immediately after I sum the user, nice and system CPU from /proc/stat which should be for the entire box. Again I take a delta.



The sum from the processes is almost always slightly greater than that for the overall processor and I can't figure out why.










share|improve this question
























  • I ran another test where I drove a single process to have 100% CPU on one of the four cores and measured just that process and /proc/stat. The box was otherwise idle. The process registered 100 clock ticks per second normally (expected) and occasionally 101 ticks. When it registered 101, that extra one never accumulated in /proc/stat which kept going up 100 ticks every second. It appears it sometimes misses them.

    – user331809
    Jan 17 at 15:23













0












0








0


1






In /proc/<pid>/stat I add user cpu, system cpu, child user and child system cpu together for all processes. I take a delta from a previous sample.



Immediately after I sum the user, nice and system CPU from /proc/stat which should be for the entire box. Again I take a delta.



The sum from the processes is almost always slightly greater than that for the overall processor and I can't figure out why.










share|improve this question
















In /proc/<pid>/stat I add user cpu, system cpu, child user and child system cpu together for all processes. I take a delta from a previous sample.



Immediately after I sum the user, nice and system CPU from /proc/stat which should be for the entire box. Again I take a delta.



The sum from the processes is almost always slightly greater than that for the overall processor and I can't figure out why.







proc






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 17 at 17:01









Guss

6,18111325




6,18111325










asked Jan 16 at 16:04









user331809user331809

41




41












  • I ran another test where I drove a single process to have 100% CPU on one of the four cores and measured just that process and /proc/stat. The box was otherwise idle. The process registered 100 clock ticks per second normally (expected) and occasionally 101 ticks. When it registered 101, that extra one never accumulated in /proc/stat which kept going up 100 ticks every second. It appears it sometimes misses them.

    – user331809
    Jan 17 at 15:23

















  • I ran another test where I drove a single process to have 100% CPU on one of the four cores and measured just that process and /proc/stat. The box was otherwise idle. The process registered 100 clock ticks per second normally (expected) and occasionally 101 ticks. When it registered 101, that extra one never accumulated in /proc/stat which kept going up 100 ticks every second. It appears it sometimes misses them.

    – user331809
    Jan 17 at 15:23
















I ran another test where I drove a single process to have 100% CPU on one of the four cores and measured just that process and /proc/stat. The box was otherwise idle. The process registered 100 clock ticks per second normally (expected) and occasionally 101 ticks. When it registered 101, that extra one never accumulated in /proc/stat which kept going up 100 ticks every second. It appears it sometimes misses them.

– user331809
Jan 17 at 15:23





I ran another test where I drove a single process to have 100% CPU on one of the four cores and measured just that process and /proc/stat. The box was otherwise idle. The process registered 100 clock ticks per second normally (expected) and occasionally 101 ticks. When it registered 101, that extra one never accumulated in /proc/stat which kept going up 100 ticks every second. It appears it sometimes misses them.

– user331809
Jan 17 at 15:23










1 Answer
1






active

oldest

votes


















0














There are a few reasons why that would be the case, the most obvious one is that the per-process accounting uses different logic for counting different things.



Two specific examples:



  1. The system stat has a nice column that counts user time spent in nice tasks (lower priority) - which you didn't specify that you use, so I'm guessing you didn't sum it. In the process this will be counted as standard user time.


  2. iowait time - which also you didn't account for - is likely counted in the process stat as system time. But its a bad idea to also count in iowait time as it is very unreliable account of actual time, as man proc explains:


iowait (since Linux 2.5.41)



(5) Time waiting for I/O to complete. This value is not reliable, for the following reasons:



  1. The CPU will not wait for I/O to complete; iowait is the time that a task is waiting for I/O to complete. When a CPU goes into idle state for outstanding task I/O, another task will be scheduled on this CPU.


  2. On a multi-core CPU, the task waiting for I/O to complete is not running on any CPU, so the iowait of each CPU is difficult to calculate.


  3. The value in this field may decrease in certain conditions.




Lastly, I have to note that I believe this type of accounting is useless as it can never be accurate enough for any serious purpose - system and process counters are processed in different parts of the system for different purposes and will never match to any useful degree.






share|improve this answer























  • Thank you, I suspect the last paragraph is the answer sadly though it boggles me that we just skip clock ticks sometimes. As for nice, yes I did say that I added it. And iowait, not added but I actually checked all the counters to make sure nothing unexpected was getting incremented and it was not. It would be a bug if this was counted as real CPU in the process.

    – user331809
    Jan 18 at 18:08












  • As far as I understand, iowait (D state in ps) is counted as process system time.

    – Guss
    Jan 18 at 19:20










Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f494868%2fwhy-is-the-sum-of-proc-pid-stat-cpu-greater-than-proc-stat%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














There are a few reasons why that would be the case, the most obvious one is that the per-process accounting uses different logic for counting different things.



Two specific examples:



  1. The system stat has a nice column that counts user time spent in nice tasks (lower priority) - which you didn't specify that you use, so I'm guessing you didn't sum it. In the process this will be counted as standard user time.


  2. iowait time - which also you didn't account for - is likely counted in the process stat as system time. But its a bad idea to also count in iowait time as it is very unreliable account of actual time, as man proc explains:


iowait (since Linux 2.5.41)



(5) Time waiting for I/O to complete. This value is not reliable, for the following reasons:



  1. The CPU will not wait for I/O to complete; iowait is the time that a task is waiting for I/O to complete. When a CPU goes into idle state for outstanding task I/O, another task will be scheduled on this CPU.


  2. On a multi-core CPU, the task waiting for I/O to complete is not running on any CPU, so the iowait of each CPU is difficult to calculate.


  3. The value in this field may decrease in certain conditions.




Lastly, I have to note that I believe this type of accounting is useless as it can never be accurate enough for any serious purpose - system and process counters are processed in different parts of the system for different purposes and will never match to any useful degree.






share|improve this answer























  • Thank you, I suspect the last paragraph is the answer sadly though it boggles me that we just skip clock ticks sometimes. As for nice, yes I did say that I added it. And iowait, not added but I actually checked all the counters to make sure nothing unexpected was getting incremented and it was not. It would be a bug if this was counted as real CPU in the process.

    – user331809
    Jan 18 at 18:08












  • As far as I understand, iowait (D state in ps) is counted as process system time.

    – Guss
    Jan 18 at 19:20















0














There are a few reasons why that would be the case, the most obvious one is that the per-process accounting uses different logic for counting different things.



Two specific examples:



  1. The system stat has a nice column that counts user time spent in nice tasks (lower priority) - which you didn't specify that you use, so I'm guessing you didn't sum it. In the process this will be counted as standard user time.


  2. iowait time - which also you didn't account for - is likely counted in the process stat as system time. But its a bad idea to also count in iowait time as it is very unreliable account of actual time, as man proc explains:


iowait (since Linux 2.5.41)



(5) Time waiting for I/O to complete. This value is not reliable, for the following reasons:



  1. The CPU will not wait for I/O to complete; iowait is the time that a task is waiting for I/O to complete. When a CPU goes into idle state for outstanding task I/O, another task will be scheduled on this CPU.


  2. On a multi-core CPU, the task waiting for I/O to complete is not running on any CPU, so the iowait of each CPU is difficult to calculate.


  3. The value in this field may decrease in certain conditions.




Lastly, I have to note that I believe this type of accounting is useless as it can never be accurate enough for any serious purpose - system and process counters are processed in different parts of the system for different purposes and will never match to any useful degree.






share|improve this answer























  • Thank you, I suspect the last paragraph is the answer sadly though it boggles me that we just skip clock ticks sometimes. As for nice, yes I did say that I added it. And iowait, not added but I actually checked all the counters to make sure nothing unexpected was getting incremented and it was not. It would be a bug if this was counted as real CPU in the process.

    – user331809
    Jan 18 at 18:08












  • As far as I understand, iowait (D state in ps) is counted as process system time.

    – Guss
    Jan 18 at 19:20













0












0








0







There are a few reasons why that would be the case, the most obvious one is that the per-process accounting uses different logic for counting different things.



Two specific examples:



  1. The system stat has a nice column that counts user time spent in nice tasks (lower priority) - which you didn't specify that you use, so I'm guessing you didn't sum it. In the process this will be counted as standard user time.


  2. iowait time - which also you didn't account for - is likely counted in the process stat as system time. But its a bad idea to also count in iowait time as it is very unreliable account of actual time, as man proc explains:


iowait (since Linux 2.5.41)



(5) Time waiting for I/O to complete. This value is not reliable, for the following reasons:



  1. The CPU will not wait for I/O to complete; iowait is the time that a task is waiting for I/O to complete. When a CPU goes into idle state for outstanding task I/O, another task will be scheduled on this CPU.


  2. On a multi-core CPU, the task waiting for I/O to complete is not running on any CPU, so the iowait of each CPU is difficult to calculate.


  3. The value in this field may decrease in certain conditions.




Lastly, I have to note that I believe this type of accounting is useless as it can never be accurate enough for any serious purpose - system and process counters are processed in different parts of the system for different purposes and will never match to any useful degree.






share|improve this answer













There are a few reasons why that would be the case, the most obvious one is that the per-process accounting uses different logic for counting different things.



Two specific examples:



  1. The system stat has a nice column that counts user time spent in nice tasks (lower priority) - which you didn't specify that you use, so I'm guessing you didn't sum it. In the process this will be counted as standard user time.


  2. iowait time - which also you didn't account for - is likely counted in the process stat as system time. But its a bad idea to also count in iowait time as it is very unreliable account of actual time, as man proc explains:


iowait (since Linux 2.5.41)



(5) Time waiting for I/O to complete. This value is not reliable, for the following reasons:



  1. The CPU will not wait for I/O to complete; iowait is the time that a task is waiting for I/O to complete. When a CPU goes into idle state for outstanding task I/O, another task will be scheduled on this CPU.


  2. On a multi-core CPU, the task waiting for I/O to complete is not running on any CPU, so the iowait of each CPU is difficult to calculate.


  3. The value in this field may decrease in certain conditions.




Lastly, I have to note that I believe this type of accounting is useless as it can never be accurate enough for any serious purpose - system and process counters are processed in different parts of the system for different purposes and will never match to any useful degree.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 17 at 17:11









GussGuss

6,18111325




6,18111325












  • Thank you, I suspect the last paragraph is the answer sadly though it boggles me that we just skip clock ticks sometimes. As for nice, yes I did say that I added it. And iowait, not added but I actually checked all the counters to make sure nothing unexpected was getting incremented and it was not. It would be a bug if this was counted as real CPU in the process.

    – user331809
    Jan 18 at 18:08












  • As far as I understand, iowait (D state in ps) is counted as process system time.

    – Guss
    Jan 18 at 19:20

















  • Thank you, I suspect the last paragraph is the answer sadly though it boggles me that we just skip clock ticks sometimes. As for nice, yes I did say that I added it. And iowait, not added but I actually checked all the counters to make sure nothing unexpected was getting incremented and it was not. It would be a bug if this was counted as real CPU in the process.

    – user331809
    Jan 18 at 18:08












  • As far as I understand, iowait (D state in ps) is counted as process system time.

    – Guss
    Jan 18 at 19:20
















Thank you, I suspect the last paragraph is the answer sadly though it boggles me that we just skip clock ticks sometimes. As for nice, yes I did say that I added it. And iowait, not added but I actually checked all the counters to make sure nothing unexpected was getting incremented and it was not. It would be a bug if this was counted as real CPU in the process.

– user331809
Jan 18 at 18:08






Thank you, I suspect the last paragraph is the answer sadly though it boggles me that we just skip clock ticks sometimes. As for nice, yes I did say that I added it. And iowait, not added but I actually checked all the counters to make sure nothing unexpected was getting incremented and it was not. It would be a bug if this was counted as real CPU in the process.

– user331809
Jan 18 at 18:08














As far as I understand, iowait (D state in ps) is counted as process system time.

– Guss
Jan 18 at 19:20





As far as I understand, iowait (D state in ps) is counted as process system time.

– Guss
Jan 18 at 19:20

















draft saved

draft discarded
















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f494868%2fwhy-is-the-sum-of-proc-pid-stat-cpu-greater-than-proc-stat%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown






Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay