Skip to content

Commit c66cb25

Browse files
authored
Merge pull request swiftlang#521 from adierking/learn-to-count
hw_config: fix Windows CPU detection
2 parents f6e30ed + fa9a334 commit c66cb25

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/shims/hw_config.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ _dispatch_hw_get_config(_dispatch_hw_config_t c)
124124
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION slpiInfo = NULL;
125125
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION slpiCurrent = NULL;
126126
DWORD dwProcessorLogicalCount = 0;
127-
DWORD dwProcessorPackageCount = 0;
128-
DWORD dwProcessorCoreCount = 0;
127+
DWORD dwProcessorPhysicalCount = 0;
129128
DWORD dwSize = 0;
130129

131130
while (true) {
@@ -154,12 +153,10 @@ _dispatch_hw_get_config(_dispatch_hw_config_t c)
154153
slpiCurrent++, dwSize -= sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION)) {
155154
switch (slpiCurrent->Relationship) {
156155
case RelationProcessorCore:
157-
++dwProcessorCoreCount;
156+
++dwProcessorPhysicalCount;
158157
dwProcessorLogicalCount += __popcnt64(slpiCurrent->ProcessorMask);
159158
break;
160159
case RelationProcessorPackage:
161-
++dwProcessorPackageCount;
162-
break;
163160
case RelationNumaNode:
164161
case RelationCache:
165162
case RelationGroup:
@@ -172,11 +169,10 @@ _dispatch_hw_get_config(_dispatch_hw_config_t c)
172169

173170
switch (c) {
174171
case _dispatch_hw_config_logical_cpus:
172+
case _dispatch_hw_config_active_cpus:
175173
return dwProcessorLogicalCount;
176174
case _dispatch_hw_config_physical_cpus:
177-
return dwProcessorPackageCount;
178-
case _dispatch_hw_config_active_cpus:
179-
return dwProcessorCoreCount;
175+
return dwProcessorPhysicalCount;
180176
}
181177
#else
182178
const char *name = NULL;

0 commit comments

Comments
 (0)