You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The idle value printed above comes directly from the kernel, aka the 4th column of /proc/stat file, so it's the kernel which is at fault here. idle time is used to calculate the system busy time (see psutil source), which is why when idle goes backward it results in a 100% CPU usage value.
What to do?
Still not sure. psutil may keep track of the last idle time, and add the difference if idle time went backwards since last call. There is a precedent for this in disk_io_counters and net_io_counters, see:
defdisk_io_counters(perdisk=False, nowrap=True):
""" ... If *nowrap* is True it detects and adjust the numbers which overflow and wrap (restart from 0) and add "old value" to "new value" so that the returned numbers will always be increasing or remain the same, but never decrease. ... """
Those functions (disk / net IO) are somewhat different though, since they represent cumulative counters, whereas CPU timings have to do with... (passing) time. As such, perhaps it would not be correct to just add the missing time to idle time, without taking other CPU timings (user, system, etc.) into account.
Leaving this open so that we can at least keep track of this (weird) kernel behavior on Linux.
The text was updated successfully, but these errors were encountered:
Summary
Description
When a Linux system is suspended system’s
idle
time goes backwards. This python script launched during / after suspend illustrates the problem:It prints (notice the backwards idle value right after wakeup):
Why this happens?
The idle value printed above comes directly from the kernel, aka the 4th column of
/proc/stat
file, so it's the kernel which is at fault here.idle
time is used to calculate the systembusy
time (see psutil source), which is why when idle goes backward it results in a 100% CPU usage value.What to do?
Still not sure. psutil may keep track of the last
idle
time, and add the difference if idle time went backwards since last call. There is a precedent for this indisk_io_counters
andnet_io_counters
, see:Those functions (disk / net IO) are somewhat different though, since they represent cumulative counters, whereas CPU timings have to do with... (passing) time. As such, perhaps it would not be correct to just add the missing time to
idle
time, without taking other CPU timings (user, system, etc.) into account.Leaving this open so that we can at least keep track of this (weird) kernel behavior on Linux.
The text was updated successfully, but these errors were encountered: