Skip to content

Commit

Permalink
win: compute parallelism from process cpu affinity (libuv#4521)
Browse files Browse the repository at this point in the history
Use GetProcessAffinityMask() to estimate the available parallelism.
Before this commit, it simply used the number of available CPUs.

Fixes: libuv#4520
(cherry picked from commit 58dfb6c)
  • Loading branch information
bnoordhuis authored and giordano committed Aug 26, 2024
1 parent ca3a5a4 commit 231e568
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/win/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,19 +513,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;
}


Expand Down

0 comments on commit 231e568

Please sign in to comment.