[PATCH v2] fhandler_proc.cc(format_proc_cpuinfo): fix issues, add fields, flags

2019-10-05 Thread Brian Inglis
fix cache size return code handling and make AMD/Intel code common;
fix cpuid level count as number of non-zero leafs excluding sub-leafs;
fix AMD physical cores count to be documented nc + 1;
round cpu MHz to correct Windows and match Linux cpuinfo;
add microcode from Windows registry Update Revision REG_BINARY;
add bogomips which has been cpu MHz*2 since Pentium MMX;
handle as common former Intel only feature flags also supported on AMD;
add 88 feature flags inc. AVX512 extensions, AES, SHA with 20 cpuid calls;
commented out flags are mostly not reported by Linux in cpuinfo but some
may not be used by Linux

---
 winsup/cygwin/fhandler_proc.cc | 747 +++--
 1 file changed, 442 insertions(+), 305 deletions(-)

diff --git a/winsup/cygwin/fhandler_proc.cc b/winsup/cygwin/fhandler_proc.cc
index 48476beb8..386bd20d5 100644
--- a/winsup/cygwin/fhandler_proc.cc
+++ b/winsup/cygwin/fhandler_proc.cc
@@ -609,6 +609,8 @@ format_proc_stat (void *, char *)
 }
 
 #define print(x) { bufptr = stpcpy (bufptr, (x)); }
+/* feature test bit position (0-32) and conditional print */
+#define ftcprint(feat,bitno,msg) if ((feat) & (1 << (bitno))) { print (" " 
msg); }
 
 static inline uint32_t
 get_msb (uint32_t in)
@@ -686,15 +688,36 @@ format_proc_cpuinfo (void *, char *)
 to be rescheduled */
   yield ();
 
-  DWORD cpu_mhz = 0;
-  RTL_QUERY_REGISTRY_TABLE tab[2] = {
-   { NULL, RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_NOSTRING,
- L"~Mhz", _mhz, REG_NONE, NULL, 0 },
-   { NULL, 0, NULL, NULL, 0, NULL, 0 }
-  };
+  DWORD cpu_mhz;
+  DWORD bogomips;
+  long long microcode; /* at least 8 bytes for AMD */
+  union
+{
+ LONG uc_len;  /* -max size of buffer before call */
+ char uc_microcode[16];
+} uc;
+
+  cpu_mhz = 0;
+  bogomips = 0;
+  microcode = 0;
+  memset (, 0, sizeof (uc.uc_microcode));
+  uc.uc_len = -16; /* -max length of microcode buffer */
+
+  RTL_QUERY_REGISTRY_TABLE tab[3] =
+{
+ { NULL, RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_NOSTRING,
+   L"~Mhz", _mhz, REG_NONE, NULL, 0 },
+ { NULL, RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_NOSTRING,
+   L"Update Revision", , REG_NONE, NULL, 0 },
+ { NULL, 0, NULL, NULL, 0, NULL, 0 }
+};
 
   RtlQueryRegistryValues (RTL_REGISTRY_ABSOLUTE, cpu_key, tab,
  NULL, NULL);
+  cpu_mhz = ((cpu_mhz - 1) / 10 + 1) * 10; /* round up to multiple of 10 */
+  bogomips = cpu_mhz * 2;  /* bogomips is double cpu MHz since MMX */
+  memcpy (, , sizeof (microcode));
+
   bufptr += __small_sprintf (bufptr, "processor\t: %d\n", cpu_number);
   uint32_t maxf, vendor_id[4], unused;
 
@@ -720,9 +743,9 @@ format_proc_cpuinfo (void *, char *)
   stepping = cpuid_sig   & 0x000f,
   apic_id  = (extra_info & 0xff00) >> 24;
   if (family == 15)
-   family += (cpuid_sig >> 20) & 0xff;
+   family += (cpuid_sig >> 20) & 0xff; /* ext family + family */
   if (family >= 6)
-   model += ((cpuid_sig >> 16) & 0x0f) << 4;
+   model |= ((cpuid_sig >> 16) & 0x0f) << 4; /* ext model << 4 | model */
 
   uint32_t maxe = 0;
   cpuid (, , , , 0x8000);
@@ -744,6 +767,8 @@ format_proc_cpuinfo (void *, char *)
   int cache_size = -1,
  clflush = 64,
  cache_alignment = 64;
+  long (*get_cpu_cache) (int, uint32_t) = NULL;
+  uint32_t max;
   if (features1 & (1 << 19)) /* CLFSH */
clflush = ((extra_info >> 8) & 0xff) << 3;
   if (is_intel && family == 15)
@@ -751,56 +776,47 @@ format_proc_cpuinfo (void *, char *)
   if (is_intel)
{
  extern long get_cpu_cache_intel (int sysc, uint32_t maxf);
- long cs;
-
- cs = get_cpu_cache_intel (_SC_LEVEL3_CACHE_SIZE, maxf);
- if (cs == -1)
-   cs = get_cpu_cache_intel (_SC_LEVEL2_CACHE_SIZE, maxf);
- if (cs == -1)
-   {
- cs = get_cpu_cache_intel (_SC_LEVEL1_ICACHE_SIZE, maxf);
- if (cs != -1)
-   cache_size = cs;
- cs = get_cpu_cache_intel (_SC_LEVEL1_DCACHE_SIZE, maxf);
- if (cs != -1)
-   cache_size += cs;
-   }
- else
-   cache_size = cs;
- if (cache_size != -1)
-   cache_size >>= 10;
+ get_cpu_cache = get_cpu_cache_intel;
+ max = maxf;   /* Intel uses normal cpuid levels */
}
   else if (is_amd)
-   {
+{
  extern long get_cpu_cache_amd (int sysc, uint32_t maxe);
+ get_cpu_cache = get_cpu_cache_amd;
+ max = maxe;   /* AMD uses extended cpuid levels */
+   }
+  if (get_cpu_cache)
+   {
  long cs;
 
- cs = get_cpu_cache_amd (_SC_LEVEL3_CACHE_SIZE, maxe);
- if (cs == -1)
-   cs = get_cpu_cache_amd 

Re: [PATCH] fhandler_proc.cc(format_proc_cpuinfo): fix issues, add fields, flags

2019-10-05 Thread Brian Inglis
On 2019-10-05 15:06, Ken Brown wrote:
> On 10/4/2019 6:44 AM, Brian Inglis wrote:
>> fix cache size return code handling and make AMD/Intel code common;
>> fix cpuid level count as number of non-zero leafs excluding sub-leafs;
>> fix AMD physical cores count to be documented nc + 1;
>> round cpu MHz to correct Windows and match Linux cpuinfo;
>> add microcode from Windows registry Update Revision REG_BINARY;
>> add bogomips which has been cpu MHz*2 since Pentium MMX;
>> handle as common former Intel only feature flags also supported on AMD;
>> add 88 feature flags inc. AVX512 extensions, AES, SHA with 20 cpuid calls;
>> commented out flags are mostly used but not currently reported in cpuinfo
>> but some may not currently be used by Linux
> 
> Thanks!  This must have been a lot of work.

Already had the info in some of my own code, that pointed out the discrepancies
between Cygwin and Linux, and prompted the desired to level up.

> It would be easier to review if you would split it up into smaller patches, 
> each 
> doing one thing, to the extent that this makes sense.  For example, the 
> simplification achieved by using the ftcprint macro could be done in a single 
> patch that's separate from the substantive changes.

Unfortunately, that was added later to make the got it/add it/skip it flag cross
checks in Linux order more certain vs my own sequential tabular source.

> A few nits:
> 
>> -  DWORD cpu_mhz = 0;
>> -  RTL_QUERY_REGISTRY_TABLE tab[2] = {
>> +  DWORD cpu_mhz;
>> +  DWORD bogomips;
>> +  long long microcode = 0x; /* at least 8 bytes for AMD */
>> +  union {
>> +  LONG len;
>> +  char uc_microcode[16];
>> +  } uc;
>> +
>> +  cpu_mhz = 0;
>> +  bogomips = 0;
>> +  microcode = 0;
> 
> Why change the existing intialization style?  How about
> 
>DWORD cpu_mhz = 0;
>DWORD bogomips = 0;
>long long microcode = 0;   /* at least 8 bytes for AMD */

Need to ensure they are initialized each time thru the CPU loop, not just once
on entry, mainly because of what I found out about what I needed to do to get
the variable length REG_BINARY key.

>> +  memset(, 0, sizeof(uc.uc_microcode));
>^  ^
> (Space before parenthesis, here and in several other places.)
> 
>> +  cpu_mhz = ((cpu_mhz - 1)/10 + 1)*10;  /* round up a digit */
> 
> Please surround '/' and '*' by spaces (and similarly in what follows).  Also, 
> the comment is confusing.  Maybe "round up to a multiple of 10"?
> 
>> +  for (uint32_t l = maxf; 1 < l; --l) {
>  ^
> (Brace on next line, and also in one other place.)

Sorry missed the expected style in those places.
Will tweak and submit v2.

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.


Re: [PATCH] fhandler_proc.cc(format_proc_cpuinfo): fix issues, add fields, flags

2019-10-05 Thread Ken Brown
Hi Brian,

On 10/4/2019 6:44 AM, Brian Inglis wrote:
> fix cache size return code handling and make AMD/Intel code common;
> fix cpuid level count as number of non-zero leafs excluding sub-leafs;
> fix AMD physical cores count to be documented nc + 1;
> round cpu MHz to correct Windows and match Linux cpuinfo;
> add microcode from Windows registry Update Revision REG_BINARY;
> add bogomips which has been cpu MHz*2 since Pentium MMX;
> handle as common former Intel only feature flags also supported on AMD;
> add 88 feature flags inc. AVX512 extensions, AES, SHA with 20 cpuid calls;
> commented out flags are mostly used but not currently reported in cpuinfo
> but some may not currently be used by Linux

Thanks!  This must have been a lot of work.

It would be easier to review if you would split it up into smaller patches, 
each 
doing one thing, to the extent that this makes sense.  For example, the 
simplification achieved by using the ftcprint macro could be done in a single 
patch that's separate from the substantive changes.

A few nits:

> -  DWORD cpu_mhz = 0;
> -  RTL_QUERY_REGISTRY_TABLE tab[2] = {
> +  DWORD cpu_mhz;
> +  DWORD bogomips;
> +  long long microcode = 0x;  /* at least 8 bytes for AMD */
> +  union {
> +   LONG len;
> +   char uc_microcode[16];
> +  } uc;
> +
> +  cpu_mhz = 0;
> +  bogomips = 0;
> +  microcode = 0;

Why change the existing intialization style?  How about

   DWORD cpu_mhz = 0;
   DWORD bogomips = 0;
   long long microcode = 0; /* at least 8 bytes for AMD */

> +  memset(, 0, sizeof(uc.uc_microcode));
   ^  ^
(Space before parenthesis, here and in several other places.)

> +  cpu_mhz = ((cpu_mhz - 1)/10 + 1)*10;   /* round up a digit */

Please surround '/' and '*' by spaces (and similarly in what follows).  Also, 
the comment is confusing.  Maybe "round up to a multiple of 10"?

> +  for (uint32_t l = maxf; 1 < l; --l) {
 ^
(Brace on next line, and also in one other place.)

Ken


Re: [PATCH] fhandler_proc.cc(format_proc_cpuinfo): fix issues, add fields, flags

2019-10-05 Thread Brian Inglis
On 2019-10-05 00:30, ASSI wrote:
> Brian Inglis writes:
>> For informal comparison, attached are Cygwin, WSL, and test release cpuinfo
>> output, with diffs against the test release output, and the Windows registry
>> CentralProcessor dump (be careful not to double click on Windows systems!)
> The easiest way to prevent that problem would have been to give that
> file a .txt extension, no?

Could have stripped the header line to disable it doing anything too, and both
would have helped with org milters.
I've had most file types: graphics, PDF, text, etc. treated like HTML, opening
in browser tabs for so long, I just thought of mentioning it right before 
sending.

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.


Re: [PATCH] fhandler_proc.cc(format_proc_cpuinfo): fix issues, add fields, flags

2019-10-05 Thread ASSI
Brian Inglis writes:
> For informal comparison, attached are Cygwin, WSL, and test release cpuinfo
> output, with diffs against the test release output, and the Windows registry
> CentralProcessor dump (be careful not to double click on Windows
> systems!)

The easiest way to prevent that problem would have been to give that
file a .txt extension, no?


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

SD adaptation for Waldorf rackAttack V1.04R1:
http://Synth.Stromeko.net/Downloads.html#WaldorfSDada