This is an archive of the discontinued LLVM Phabricator instance.

Implement computeHostNumHardwareThreads() for FreeBSD
ClosedPublic

Authored by dim on Nov 28 2020, 12:05 PM.

Details

Summary

This retrieves CPU affinity via FreeBSD's cpuset(2) API, and makes LLVM
respect affinity settings configured by the user via the cpuset(1)
command.

In particular, this allows to reduce the number of threads used on
machines with high core counts, which can interact badly with
parallelized build systems. This is particularly noticable with lld,
which spawns lots of threads even for linking e.g. hello_world!

This fix is related to PR48193, but does not adress the more fundamental
problem, which is that LLVM by default grabs as many CPUs and/or threads
as possible.

Diff Detail

Event Timeline

dim created this revision.Nov 28 2020, 12:05 PM
dim requested review of this revision.Nov 28 2020, 12:05 PM
MaskRay added inline comments.Nov 28 2020, 12:24 PM
llvm/lib/Support/Unix/Threading.inc
30

Should this be merged with the following block?

292

Use #elif

dim updated this revision to Diff 308187.Nov 28 2020, 12:44 PM

Address comments from review:

  • Move FreeBSD specific include under common block
  • Use #if #elif #endif for OS specific implementations
MaskRay accepted this revision.Nov 28 2020, 12:51 PM

Looks great!

This revision is now accepted and ready to land.Nov 28 2020, 12:51 PM
This revision was landed with ongoing or failed builds.Nov 28 2020, 3:50 PM
This revision was automatically updated to reflect the committed changes.

It would be nice if this was covered by a test. I essentially did what you did, but for Windows and added a test in D92419. @dim do you think that test makes sense for Unix as well? (it would need the 'AffinityMask' to be implemented in llvm/lib/Support/Unix/Program.inc)

cem added a comment.Dec 3 2020, 12:38 PM

@aganea That seems reasonable to me.