Roderick Colenbrander : ntdll: Derive number of logical CPU cores from core mask.

Alexandre Julliard julliard at winehq.org
Fri Jun 22 18:32:37 CDT 2018


Module: wine
Branch: master
Commit: 0fd6556ed25282d3d95f1ab2d48de99cfff5bad4
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=0fd6556ed25282d3d95f1ab2d48de99cfff5bad4

Author: Roderick Colenbrander <thunderbird2k at gmail.com>
Date:   Wed Jun 20 22:29:42 2018 -0700

ntdll: Derive number of logical CPU cores from core mask.

Signed-off-by: Roderick Colenbrander <thunderbird2k at gmail.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/ntdll/nt.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/dlls/ntdll/nt.c b/dlls/ntdll/nt.c
index dc0ce04..985f58c 100644
--- a/dlls/ntdll/nt.c
+++ b/dlls/ntdll/nt.c
@@ -1309,6 +1309,23 @@ static DWORD log_proc_ex_size_plus(DWORD size)
     return sizeof(LOGICAL_PROCESSOR_RELATIONSHIP) + sizeof(DWORD) + size;
 }
 
+static DWORD count_bits(ULONG_PTR mask)
+{
+    DWORD count = 0;
+    while (mask > 0)
+    {
+        mask >>= 1;
+        count++;
+    }
+    return count;
+}
+
+/* Store package and core information for a logical processor. Parsing of processor
+ * data may happen in multiple passes; the 'id' parameter is then used to locate
+ * previously stored data. The type of data stored in 'id' depends on 'rel':
+ * - RelationProcessorPackage: package id ('CPU socket').
+ * - RelationProcessorCore: physical core number.
+ */
 static inline BOOL logical_proc_info_add_by_id(SYSTEM_LOGICAL_PROCESSOR_INFORMATION **pdata,
         SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX **pdataex, DWORD *len, DWORD *pmax_len,
         LOGICAL_PROCESSOR_RELATIONSHIP rel, DWORD id, ULONG_PTR mask)
@@ -1643,7 +1660,6 @@ static NTSTATUS create_logical_proc_info(SYSTEM_LOGICAL_PROCESSOR_INFORMATION **
         for(i=0; i<len; i++){
             if((*data)[i].Relationship == RelationProcessorCore){
                 all_cpus_mask |= (*data)[i].ProcessorMask;
-                ++num_cpus;
             }
         }
     }else{
@@ -1651,11 +1667,11 @@ static NTSTATUS create_logical_proc_info(SYSTEM_LOGICAL_PROCESSOR_INFORMATION **
             SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *infoex = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *)(((char *)*dataex) + i);
             if(infoex->Relationship == RelationProcessorCore){
                 all_cpus_mask |= infoex->u.Processor.GroupMask[0].Mask;
-                ++num_cpus;
             }
             i += infoex->Size;
         }
     }
+    num_cpus = count_bits(all_cpus_mask);
 
     fnuma_list = fopen("/sys/devices/system/node/online", "r");
     if(!fnuma_list)




More information about the wine-cvs mailing list