Skip to content

Commit

Permalink
Improve detection of CPU limits when running inside a Container
Browse files Browse the repository at this point in the history
This focuse on better supporting `--cpuset-cpus` which limits the number of processors we have access to on the CPU; it also specifies which specific processor we have access to, but that’s irrelevant here

The work has been done here for all runtime components except `Environment.ProcessorCount`. The work consist in fixing `PAL_GetLogicalCpuCountFromOS` to use `sched_getaffinity`.

Fixes https://github.com/dotnet/coreclr/issues/22302
  • Loading branch information
luhenry committed Mar 22, 2019
1 parent 29dc90c commit 06d7406
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/pal/src/misc/sysinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,17 @@ PAL_GetLogicalCpuCountFromOS()
{
int nrcpus = 0;

#if HAVE_SYSCONF
#if HAVE_SCHED_GETAFFINITY

cpu_set_t cpuSet;
int st = sched_getaffinity(0, sizeof(cpu_set_t), &cpuSet);
if (st != 0)
{
ASSERT("sched_getaffinity failed (%d)\n", errno);
}

nrcpus = CPU_COUNT(&cpuSet);
#elif HAVE_SYSCONF

#if defined(_ARM_) || defined(_ARM64_)
#define SYSCONF_GET_NUMPROCS _SC_NPROCESSORS_CONF
Expand Down

0 comments on commit 06d7406

Please sign in to comment.