From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.17.10]) by sourceware.org (Postfix) with ESMTPS id DBFA33858427 for ; Mon, 9 May 2022 08:53:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DBFA33858427 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=cygwin.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=cygwin.com Received: from calimero.vinschen.de ([24.134.7.25]) by mrelayeu.kundenserver.de (mreue107 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MnZwp-1oFeTE2ebV-00jYmx; Mon, 09 May 2022 10:53:45 +0200 Received: by calimero.vinschen.de (Postfix, from userid 500) id 70F12A80885; Mon, 9 May 2022 10:53:38 +0200 (CEST) Date: Mon, 9 May 2022 10:53:38 +0200 From: Corinna Vinschen To: Mark Geisert , cygwin-developers@cygwin.com Subject: Re: load average calculation failing Message-ID: Reply-To: cygwin-developers@cygwin.com Mail-Followup-To: Mark Geisert , cygwin-developers@cygwin.com References: <3a3edd10-2617-0919-4eb0-7ca965b48963@maxrnd.com> <223aa826-7bf9-281a-aed8-e16349de5b96@dronecode.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Provags-ID: V03:K1:0UaSkGCxLa3QeKIpx49JDyn6Z3c8StZ1qt50Wl3qRQMGEnYF6Rx QWzf6vJIjF8GE9Z3RJ9fkhnRIbyzycL26Pls25svdCc3am+UFi36BLhJEuCYlG0ydhw3zMD Eki7Tmf5diNXQMZ5S93dG3NDOz5/X4E6uUpHXTm+a2XBFEE9iQLx1zs5TrQLvJol6d0sc0A tbWRuRAC9L0GXvzRomYHw== X-UI-Out-Filterresults: notjunk:1;V03:K0:NqlxleY2SrA=:Fq1+P5t9+6svaTu322zeUI riFdN+3luBSJdq6/jp8Md/tPzXadPm6NVF7sL5XG2OpK7Nl/z1vNU2HtKm6sCZ4QdH1xnFJB8 3iJMOn4XqB94jF4ha0zA89CWpKQeeni22vcjjJD3+YCtOwbNb1B5WSLU91G+tT1iXsjMy7FQL 6ymOCmNtzEC9nNOhkzjk+YSeZ6CcS0jrS9h2YElJUganKgrD0jRjxw5XdcPN8SdFHxAC630Ay OMqAGJtZ4zGlUWarnHqclpSbP+0nAT508TcDSIKsTGyf3mTBEB3Rhc3S7NfqViUVuZrgv78eU U0aQDCdiqiwQwa0uVcgGiWcXkDgVmq4IV6zdmymwVIK/xz6f9JHzd2pK8j4Nr09lzAZ+kwGAX h5ZYiFvljzONDwRqLXKyErMKr800yXLL+fRyutycrg69hxpwr2bvLT8WM0p8XnE1f9F9+ouaW cfMYzSyHLtMIIcPxQmR8YSnFNpNPojApKY+3SF2fhIkD/f2Zk5n5gGqiaeZDWkAVLiA/tBWqk AZ4eBmtnHvf5dksYh2+i+dzKuazt5udzGP6t1dsdp8r4p77FYtLMRWBSOmIBsG8UnjXWmWX3z gcOiI1V7xwKuPy6alrpWCREA79Azm6QdK/RkhE+6QtjpB7N0RhMSh31hJRYS1mmcIaIiwpzgG pXgRoqAKJ1s8LRfwgLWZdfGk0AerJmNJmBU3waJA6d/9Uc0c8UmBjzcEkt7dJXo6m98EhIi9t fY5sj9pANjLVrbAJ X-Spam-Status: No, score=-101.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, GOOD_FROM_CORINNA_CYGWIN, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H2, SPF_FAIL, SPF_HELO_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: cygwin-developers@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component developers mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 May 2022 08:53:55 -0000 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 #include #include +#include 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;