From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: Mark Geisert <mark@maxrnd.com>, cygwin-developers@cygwin.com
Subject: Re: load average calculation failing
Date: Mon, 9 May 2022 10:53:38 +0200 [thread overview]
Message-ID: <YnjWksOyNjmZt0ID@calimero.vinschen.de> (raw)
In-Reply-To: <YnjUxi/IsgkTInKL@calimero.vinschen.de>
On May 9 10:45, Corinna Vinschen wrote:
> Mark, did you try to add the computer name to the path by calling
> GetComputerName() in load_init?
>
> I tried the patch I pasted to the end of this mail, but it did not help
> the first PdhGetFormattedCounterValue call in get_load to return
> success.
>
> > > above) calls debug_printf() to conditionally display the error, which is
> > > what leads to the strace.h and _sigbe; that's fine.
> > >
> > > The weird PDH_CSTATUS_NO_MACHINE is the problem. I'll try running the
> > > example from an elevated shell. Or rebooting the machine. After that
> > > it's consulting some oracle TBD. :-(
> > >
> >
> > Thanks for looking into this.
> > You can find the user space version of this code I initially wrote at
> > https://github.com/jon-turney/windows-loadavg, which might save you some
> > time.
> >
> > I can't reproduce this on W10 21H1, so I think this must be due to some
> > change in later Windows...
>
> I can reproduce this on W10 21H1, too, and the problem is the one
> I outlined above, with load_init working fine and just the
> PdhGetFormattedCounterValue failing in get_load.
Btw, the other patch, which makes loadavg work for me, is the
below one. It just doesn't really make me happy.
diff --git a/winsup/cygwin/loadavg.cc b/winsup/cygwin/loadavg.cc
index 127591a2e1f5..e08c13c86de6 100644
--- a/winsup/cygwin/loadavg.cc
+++ b/winsup/cygwin/loadavg.cc
@@ -40,6 +40,7 @@
#include <time.h>
#include <sys/strace.h>
#include <pdh.h>
+#include <pdhmsg.h>
static PDH_HQUERY query;
static PDH_HCOUNTER counter1;
@@ -95,18 +96,33 @@ static bool load_init (void)
/* estimate the current load */
static bool get_load (double *load)
{
+ PDH_STATUS ret;
+ PDH_FMT_COUNTERVALUE fmtvalue1;
+ bool tried_again = false;
+
*load = 0.0;
- PDH_STATUS ret = PdhCollectQueryData (query);
+try_again:
+
+ ret = PdhCollectQueryData (query);
if (ret != ERROR_SUCCESS)
return false;
/* Estimate the number of running processes as (NumberOfProcessors) * (%
Processor Time) */
- PDH_FMT_COUNTERVALUE fmtvalue1;
ret = PdhGetFormattedCounterValue (counter1, PDH_FMT_DOUBLE, NULL, &fmtvalue1);
if (ret != ERROR_SUCCESS)
- return false;
+ {
+ if (ret == (PDH_STATUS) PDH_INVALID_DATA
+ && fmtvalue1.CStatus == PDH_CSTATUS_INVALID_DATA
+ && !tried_again)
+ {
+ tried_again = true;
+ Sleep (1000L);
+ goto try_again;
+ }
+ return false;
+ }
double running = fmtvalue1.doubleValue * wincap.cpu_count () / 100;
next prev parent reply other threads:[~2022-05-09 8:53 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <Pine.BSF.4.63.2205051618470.42373@m0.truegem.net>
2022-05-08 7:01 ` Mark Geisert
[not found] ` <223aa826-7bf9-281a-aed8-e16349de5b96@dronecode.org.uk>
2022-05-09 8:45 ` Corinna Vinschen
2022-05-09 8:53 ` Corinna Vinschen [this message]
2022-05-10 8:34 ` Mark Geisert
2022-05-10 13:37 ` Jon Turney
2022-05-11 23:40 ` load average calculation failing -- fixed by Windows update Mark Geisert
2022-05-12 8:17 ` Corinna Vinschen
2022-05-12 8:24 ` Mark Geisert
2022-05-12 8:43 ` Corinna Vinschen
2022-05-12 9:48 ` Corinna Vinschen
2022-05-13 10:34 ` Jon Turney
2022-05-13 11:04 ` Corinna Vinschen
2022-05-13 11:05 ` Corinna Vinschen
2022-05-16 5:25 ` load average calculation imperfections Mark Geisert
2022-05-16 16:49 ` Jon Turney
2022-05-17 5:39 ` Mark Geisert
2022-05-17 14:48 ` load average calculation failing -- fixed by Windows update Jon Turney
2022-05-17 19:48 ` Mark Geisert
2022-05-09 11:29 ` load average calculation failing Jon Turney
2022-05-10 8:21 ` Mark Geisert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YnjWksOyNjmZt0ID@calimero.vinschen.de \
--to=corinna-cygwin@cygwin.com \
--cc=cygwin-developers@cygwin.com \
--cc=mark@maxrnd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).