win: compute parallelism from process cpu affinity (#4521)

Use GetProcessAffinityMask() to estimate the available parallelism.
Before this commit, it simply used the number of available CPUs.

Fixes: https://github.com/libuv/libuv/issues/4520
This commit is contained in:
Ben Noordhuis 2024-08-26 10:22:42 +02:00 committed by GitHub
parent b5eb41d882
commit 58dfb6c89b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -512,19 +512,23 @@ int uv_uptime(double* uptime) {
unsigned int uv_available_parallelism(void) {
SYSTEM_INFO info;
unsigned rc;
DWORD_PTR procmask;
DWORD_PTR sysmask;
int count;
int i;
/* TODO(bnoordhuis) Use GetLogicalProcessorInformationEx() to support systems
* with > 64 CPUs? See https://github.com/libuv/libuv/pull/3458
*/
GetSystemInfo(&info);
count = 0;
if (GetProcessAffinityMask(GetCurrentProcess(), &procmask, &sysmask))
for (i = 0; i < 64; i++) /* a.k.a. count = popcount(procmask); */
count += 1 & (procmask >> i);
rc = info.dwNumberOfProcessors;
if (rc < 1)
rc = 1;
if (count > 0)
return count;
return rc;
return 1;
}