Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Lapounov <antonl@microsoft.com>2021-05-14 06:23:33 +0300
committerGitHub <noreply@github.com>2021-05-14 06:23:33 +0300
commit65bdceb4d47075964bb9d3878c994d020d594068 (patch)
tree253fe51b15e3310732e9f7e147807b6f605f1500 /src/coreclr/utilcode
parent83f64e5908dbd1b8ce07ca4444e94f49f57df699 (diff)
Respect Windows job object's CPU quota (#52690)
Diffstat (limited to 'src/coreclr/utilcode')
-rw-r--r--src/coreclr/utilcode/util.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/coreclr/utilcode/util.cpp b/src/coreclr/utilcode/util.cpp
index 9f19ec53a02..0026d1f619f 100644
--- a/src/coreclr/utilcode/util.cpp
+++ b/src/coreclr/utilcode/util.cpp
@@ -1321,6 +1321,36 @@ int GetCurrentProcessCpuCount()
count = 64;
}
}
+
+ JOBOBJECT_CPU_RATE_CONTROL_INFORMATION cpuRateControl;
+
+ if (QueryInformationJobObject(NULL, JobObjectCpuRateControlInformation, &cpuRateControl,
+ sizeof(cpuRateControl), NULL))
+ {
+ const DWORD HardCapEnabled = JOB_OBJECT_CPU_RATE_CONTROL_ENABLE | JOB_OBJECT_CPU_RATE_CONTROL_HARD_CAP;
+ const DWORD MinMaxRateEnabled = JOB_OBJECT_CPU_RATE_CONTROL_ENABLE | JOB_OBJECT_CPU_RATE_CONTROL_MIN_MAX_RATE;
+ DWORD maxRate = 0;
+
+ if ((cpuRateControl.ControlFlags & HardCapEnabled) == HardCapEnabled)
+ {
+ maxRate = cpuRateControl.CpuRate;
+ }
+ else if ((cpuRateControl.ControlFlags & MinMaxRateEnabled) == MinMaxRateEnabled)
+ {
+ maxRate = cpuRateControl.MaxRate;
+ }
+
+ // The rate is the percentage times 100
+ const DWORD MAXIMUM_CPU_RATE = 10000;
+
+ if (0 < maxRate && maxRate < MAXIMUM_CPU_RATE)
+ {
+ DWORD cpuLimit = (maxRate * GetTotalProcessorCount() + MAXIMUM_CPU_RATE - 1) / MAXIMUM_CPU_RATE;
+ if (cpuLimit < count)
+ count = cpuLimit;
+ }
+ }
+
#else // HOST_WINDOWS
count = PAL_GetLogicalCpuCountFromOS();