diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2024-08-26 10:22:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-26 10:22:42 +0200 |
commit | 58dfb6c89ba3deb23301ddbdd4a8769f4c767dff (patch) | |
tree | fbc1639a28093e4d833571d85de514015c101361 /src | |
parent | b5eb41d882f72e4f74fad599b20c0c8ec69c0c57 (diff) | |
download | libuv-58dfb6c89ba3deb23301ddbdd4a8769f4c767dff.tar.gz libuv-58dfb6c89ba3deb23301ddbdd4a8769f4c767dff.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/win/util.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/win/util.c b/src/win/util.c index deed2e35..72cb7492 100644 --- a/src/win/util.c +++ b/src/win/util.c @@ -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; } |