[PATCH] Implement getloadavg()

Jon Turney jon.turney@dronecode.org.uk
Fri Mar 17 18:37:00 GMT 2017

On 17/03/2017 17:50, Jon Turney wrote:
>  winsup/cygwin/Makefile.in              |   5 +-
>  winsup/cygwin/common.din               |   1 +
>  winsup/cygwin/fhandler_proc.cc         |  10 ++-
>  winsup/cygwin/include/cygwin/stdlib.h  |   4 +
>  winsup/cygwin/include/cygwin/version.h |   3 +-
>  winsup/cygwin/loadavg.cc               | 135 +++++++++++++++++++++++++++++++++
>  winsup/doc/posix.xml                   |   1 +
>  7 files changed, 154 insertions(+), 5 deletions(-)
>  create mode 100644 winsup/cygwin/loadavg.cc

Note that this doesn't build for x86 at the moment, due to an issue with 
pdh.h in w32api (See [1])

Furthermore, there are a few problems with this implementation:

The first time a process calls getloadavg(), it always gets 0 (so 'cat 
/proc/loadavg' always shows a load of 0).  This is a consequence of 
having no global state, and the fact that we can't measure %CPU 
instantaneously, only over an interval.

I'm not the only person on the internet who thinks that 
(%CPU*#cores)+PQL is they way to calculate a load value, and while this 
gives reasonable values when when the load is between 0 and (number of 
cores), the PQL seems to get unexpectedly large when CPU is saturated on 
an otherwise idle system.

e.g. if I saturate the CPU with tasks of "normal" priority, PQL goes to 
~20; saturate with tasks of "below normal" priority, PQL goes to ~5, but 
there isn't actually any real demand there; if the CPU saturating tasks 
are killed, load drops close to 0.  I don't know how to interpret that...

[1] https://sourceforge.net/p/mingw-w64/mailman/message/35727667/

More information about the Cygwin-patches mailing list