[newlib-cygwin] Cygwin: wincap: expose more SYSTEM_INFO members and use as appropriate

Corinna Vinschen corinna@sourceware.org
Wed Apr 11 10:01:00 GMT 2018


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=92f4e0500b1a8c138f3fd4539b1a9c76d3185a93

commit 92f4e0500b1a8c138f3fd4539b1a9c76d3185a93
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Wed Apr 11 11:59:35 2018 +0200

    Cygwin: wincap: expose more SYSTEM_INFO members and use as appropriate
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/loadavg.cc |  5 +----
 winsup/cygwin/uname.cc   | 12 ++++--------
 winsup/cygwin/wincap.h   |  5 +++++
 3 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/winsup/cygwin/loadavg.cc b/winsup/cygwin/loadavg.cc
index a7e5f61..bef80e1 100644
--- a/winsup/cygwin/loadavg.cc
+++ b/winsup/cygwin/loadavg.cc
@@ -98,10 +98,7 @@ static bool get_load (double *load)
   if (ret != ERROR_SUCCESS)
     return false;
 
-  SYSTEM_INFO sysinfo;
-  GetSystemInfo (&sysinfo);
-
-  double running = fmtvalue1.doubleValue * sysinfo.dwNumberOfProcessors / 100;
+  double running = fmtvalue1.doubleValue * wincap.cpu_count () / 100;
 
   /* Estimate the number of runnable processes using ProcessorQueueLength */
   PDH_FMT_COUNTERVALUE fmtvalue2;
diff --git a/winsup/cygwin/uname.cc b/winsup/cygwin/uname.cc
index 479cc44..778ca57 100644
--- a/winsup/cygwin/uname.cc
+++ b/winsup/cygwin/uname.cc
@@ -19,8 +19,6 @@ extern "C" int cygwin_gethostname (char *__name, size_t __len);
 extern "C" int
 uname (struct utsname *name)
 {
-  SYSTEM_INFO sysinfo;
-
   __try
     {
       char *snp = strstr  (cygwin_version.dll_build_date, "SNP");
@@ -34,8 +32,6 @@ uname (struct utsname *name)
 	strncat (name->sysname, "-WOW",
 		 sizeof name->sysname - strlen (name->sysname) - 1);
 
-      GetSystemInfo (&sysinfo);
-
       /* Computer name */
       cygwin_gethostname (name->nodename, sizeof (name->nodename) - 1);
 
@@ -56,16 +52,16 @@ uname (struct utsname *name)
 	name->version[snp - cygwin_version.dll_build_date] = '\0';
 
       /* CPU type */
-      switch (sysinfo.wProcessorArchitecture)
+      switch (wincap.cpu_arch ())
 	{
 	  case PROCESSOR_ARCHITECTURE_INTEL:
 	    unsigned int ptype;
-	    if (sysinfo.wProcessorLevel < 3) /* Shouldn't happen. */
+	    if (wincap.cpu_level () < 3) /* Shouldn't happen. */
 	      ptype = 3;
-	    else if (sysinfo.wProcessorLevel > 9) /* P4 */
+	    else if (wincap.cpu_level () > 9) /* P4 */
 	      ptype = 6;
 	    else
-	      ptype = sysinfo.wProcessorLevel;
+	      ptype = wincap.cpu_level ();
 	    __small_sprintf (name->machine, "i%d86", ptype);
 	    break;
 	  case PROCESSOR_ARCHITECTURE_IA64:
diff --git a/winsup/cygwin/wincap.h b/winsup/cygwin/wincap.h
index 990a3a4..9dc0000 100644
--- a/winsup/cygwin/wincap.h
+++ b/winsup/cygwin/wincap.h
@@ -42,6 +42,11 @@ public:
   void init ();
 
   const DWORD cpu_count () const { return system_info.dwNumberOfProcessors; }
+  const DWORD_PTR cpu_mask () const { return system_info.dwActiveProcessorMask;}
+
+  const WORD cpu_arch () const { return system_info.wProcessorArchitecture; }
+  const WORD cpu_level () const { return system_info.wProcessorLevel; }
+
   /* The casts to size_t make sure that the returned value has the size of
      a pointer on any system.  This is important when using them for bit
      mask operations, like in roundup2. */



More information about the Cygwin-cvs mailing list