-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Correctly calculate CPU percentages on linux with guests #940
Conversation
Since guest is already included in user and guest_nice is included in nice, it got included twice in totals. http://unix.stackexchange.com/questions/178045/proc-stat-is-guest-counted-into-user-time Please doublecheck this, as I can test just on recent linux.
Uhm... good catch. I'm not completely certain the explanation given in that SO thread is correct though. The first message talks about times in |
I'm trying to find an official reference which states that |
@giampaolo Good point. I think this is enough proof: https://github.com/torvalds/linux/blob/447976e/kernel/sched/cputime.c#L169 And for explanation see very last paragraph of https://lists.linuxfoundation.org/pipermail/virtualization/2009-August/013459.html |
Thanks, that's enough. =) To push this even further, I'm not sure whether we should adjust the guest time calculation only in |
This is now correctly fixed. Thanks for discovering the original issue. I had no idea the CPU percent related math was not 100% correct. |
Great. Thanks! |
On linux, the cpu timer counters of user and nice include the respective guest and guest_nice counters. This results in improper calculation of percentages. Please see: https://github.com/torvalds/linux/blob/447976e/kernel/sched/cputime.c#L169 https://lists.linuxfoundation.org/pipermail/virtualization/2009-August/013459.html giampaolo/psutil#940
On linux, the cpu timer counters of user and nice include the respective guest and guest_nice counters. This results in improper calculation of percentages. Please see: https://github.com/torvalds/linux/blob/447976e/kernel/sched/cputime.c#L169 https://lists.linuxfoundation.org/pipermail/virtualization/2009-August/013459.html giampaolo/psutil#940
Since guest is already included in user and guest_nice is included in nice, it got included twice in totals.
http://unix.stackexchange.com/questions/178045/proc-stat-is-guest-counted-into-user-time
Please doublecheck this, as I can test just on recent linux.