summaryrefslogtreecommitdiff
path: root/src/utilcode
diff options
context:
space:
mode:
authorGuillaume B <gboucher90@users.noreply.github.com>2017-07-21 14:08:11 +0200
committerJan Vorlicek <janvorli@microsoft.com>2017-07-21 14:08:11 +0200
commitdf214e67d3cbccb42d2733f4cbe8097a378a731a (patch)
treea0cf5dac96b96b590853ea096bebbabe7d62a521 /src/utilcode
parente6865018d91fd257f05a42fe4fe353beb32c641a (diff)
downloadcoreclr-df214e67d3cbccb42d2733f4cbe8097a378a731a.tar.gz
coreclr-df214e67d3cbccb42d2733f4cbe8097a378a731a.tar.bz2
coreclr-df214e67d3cbccb42d2733f4cbe8097a378a731a.zip
Add CGroup CFS CPU limit support (#12797)
Diffstat (limited to 'src/utilcode')
-rw-r--r--src/utilcode/util.cpp45
1 files changed, 28 insertions, 17 deletions
diff --git a/src/utilcode/util.cpp b/src/utilcode/util.cpp
index f0c6b1c96e..8e9979efc2 100644
--- a/src/utilcode/util.cpp
+++ b/src/utilcode/util.cpp
@@ -1269,32 +1269,43 @@ int GetCurrentProcessCpuCount()
if (cCPUs != 0)
return cCPUs;
+ int count = 0;
DWORD_PTR pmask, smask;
if (!GetProcessAffinityMask(GetCurrentProcess(), &pmask, &smask))
- return 1;
+ {
+ count = 1;
+ }
+ else
+ {
+ pmask &= smask;
- pmask &= smask;
+ while (pmask)
+ {
+ pmask &= (pmask - 1);
+ count++;
+ }
- int count = 0;
- while (pmask)
- {
- pmask &= (pmask - 1);
- count++;
+ // GetProcessAffinityMask can return pmask=0 and smask=0 on systems with more
+ // than 64 processors, which would leave us with a count of 0. Since the GC
+ // expects there to be at least one processor to run on (and thus at least one
+ // heap), we'll return 64 here if count is 0, since there are likely a ton of
+ // processors available in that case. The GC also cannot (currently) handle
+ // the case where there are more than 64 processors, so we will return a
+ // maximum of 64 here.
+ if (count == 0 || count > 64)
+ count = 64;
}
- // GetProcessAffinityMask can return pmask=0 and smask=0 on systems with more
- // than 64 processors, which would leave us with a count of 0. Since the GC
- // expects there to be at least one processor to run on (and thus at least one
- // heap), we'll return 64 here if count is 0, since there are likely a ton of
- // processors available in that case. The GC also cannot (currently) handle
- // the case where there are more than 64 processors, so we will return a
- // maximum of 64 here.
- if (count == 0 || count > 64)
- count = 64;
+#ifdef FEATURE_PAL
+ uint32_t cpuLimit;
+
+ if (PAL_GetCpuLimit(&cpuLimit) && cpuLimit < count)
+ count = cpuLimit;
+#endif
cCPUs = count;
-
+
return count;
}