diff options
author | Guillaume B <gboucher90@users.noreply.github.com> | 2017-07-21 14:08:11 +0200 |
---|---|---|
committer | Jan Vorlicek <janvorli@microsoft.com> | 2017-07-21 14:08:11 +0200 |
commit | df214e67d3cbccb42d2733f4cbe8097a378a731a (patch) | |
tree | a0cf5dac96b96b590853ea096bebbabe7d62a521 /src/utilcode | |
parent | e6865018d91fd257f05a42fe4fe353beb32c641a (diff) | |
download | coreclr-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.cpp | 45 |
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; } |