Skip to content

Commit

Permalink
[Support] Fix computeHostNumPhysicalCores() to respect affinity
Browse files Browse the repository at this point in the history
computeHostNumPhysicalCores() is designed to respect CPU affinity.
D84764 used sysconf(_SC_NPROCESSORS_ONLN) which does not respect
affinity.
SupportTests Threading.PhysicalConcurrency may fail if taskset -c is specified.
  • Loading branch information
MaskRay committed Jul 31, 2020
1 parent 8830f11 commit cd53ded
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions llvm/lib/Support/Host.cpp
Expand Up @@ -1271,11 +1271,14 @@ int computeHostNumPhysicalCores() {
}
return CPU_COUNT(&Enabled);
}
#elif (defined(__linux__) && \
(defined(__ppc__) || defined(__powerpc__) || defined(__s390x__)))
#include <unistd.h>

// Gets the number of *physical cores* on the machine.
#elif defined(__linux__) && defined(__powerpc__)
int computeHostNumPhysicalCores() {
cpu_set_t Affinity;
if (sched_getaffinity(0, sizeof(Affinity), &Affinity) != 0)
return -1;
return CPU_COUNT(&Affinity);
}
#elif defined(__linux__) && defined(__s390x__)
int computeHostNumPhysicalCores() { return sysconf(_SC_NPROCESSORS_ONLN); }
#elif defined(__APPLE__) && defined(__x86_64__)
#include <sys/param.h>
Expand Down

0 comments on commit cd53ded

Please sign in to comment.