[PATCH] Implement getloadavg()
Corinna Vinschen
corinna-cygwin@cygwin.com
Mon Mar 20 10:37:00 GMT 2017
Hi Jon,
neat! But...
On Mar 17 17:50, Jon Turney wrote:
> Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
> ---
> 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
>
> diff --git a/winsup/cygwin/Makefile.in b/winsup/cygwin/Makefile.in
> index c8652b0..5e719a6 100644
> --- a/winsup/cygwin/Makefile.in
> +++ b/winsup/cygwin/Makefile.in
> @@ -147,7 +147,9 @@ EXTRA_OFILES:=
>
> MALLOC_OFILES:=malloc.o
>
> -DLL_IMPORTS:=${shell $(CC) -print-file-name=w32api/libkernel32.a} ${shell $(CC) -print-file-name=w32api/libntdll.a}
> +DLL_IMPORTS:=${shell $(CC) -print-file-name=w32api/libkernel32.a} \
> + ${shell $(CC) -print-file-name=w32api/libntdll.a} \
> + ${shell $(CC) -print-file-name=w32api/libpdh.a}
No, that's not right. Please add the new functions to autoload.cc and
drop static linking to libpdh.a.
> +static double _loadavg[3] = { 0.0, 0.0, 0.0 };
The load average is global, non-critical data. So what about storing it
in shared_info instead? This way, only the first call of the first
Cygwin process returns all zero.
> +static bool load_init (void)
> +{
> + static bool tried = false;
> + static bool initialized = false;
> +
> + if (!tried) {
> + tried = true;
> +
> + if ((PdhOpenQueryA (NULL, 0, &query) == ERROR_SUCCESS) &&
> + (PdhAddEnglishCounterA (query, "\\Processor(_Total)\\% Processor Time",
> + 0, &counter1) == ERROR_SUCCESS) &&
> + (PdhAddEnglishCounterA (query, "\\System\\Processor Queue Length",
> + 0, &counter2) == ERROR_SUCCESS)) {
> + initialized = true;
> + } else {
> + debug_printf("loadavg PDH initialization failed\n");
> + }
> + }
> +
> + return initialized;
> +}
How slow is that initialization? Would it {make sense|hurt} to call it
once in the initalization of Cygwin's shared mem in shared_info::initialize?
As for the declaration problem on x86, what about moving the declarations
to the start of loadavg.cc, until we get a new w32api-headers package?
JonY, any chance for a quick update of w32api-headers to include the
patch from https://sourceforge.net/p/mingw-w64/mailman/message/35727667/?
Thanks,
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Maintainer cygwin AT cygwin DOT com
Red Hat
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20170320/03568120/attachment.sig>
More information about the Cygwin-patches
mailing list