This is the mail archive of the cygwin-patches mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Implement getloadavg()


On 20/03/2017 10:37, Corinna Vinschen wrote:
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.

Ah, I see.  Ok.

+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.

Ok.

+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?

I don't think that's particularly heavyweight, and I didn't see anything to suggest that PDH query handles can be shared between processes, but I'll look into it.

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?

It's only one prototype, so that should be ok.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]