This is an archive of the discontinued LLVM Phabricator instance.

[Support] On Windows, take the affinity mask into account
ClosedPublic

Authored by aganea on Dec 1 2020, 12:27 PM.

Details

Summary

Now using the affinity mask when it's set, thus limiting the number of processors available to the ThreadPool.
For example:

> start /B /AFFINITY 0xF lld-link.exe ...

Would let LLD only use 4 hyper-threads.

This also fixes an issue on a 48-core Windows Server 2019, which was preventing from using both CPU sockets. In that case, ProcessorGroup::AllThreads was retrieved as 64 for each group, but ProcessorGroup::UsableThreads was set to 48 (which is the max possible for each group). The previous code in llvm/lib/Support/Windows/Threading.inc L201 was improperly assuming those values would be equal when the affinity mask was fully set. I've tested the new code on a wide variety of configurations & OSes (Windows Server 2016, 2019 and Windows 10).

Diff Detail

Event Timeline

aganea created this revision.Dec 1 2020, 12:27 PM
aganea requested review of this revision.Dec 1 2020, 12:27 PM
amccarth added inline comments.Dec 10 2020, 5:19 PM
llvm/lib/Support/Windows/Threading.inc
200

nit: In "group boundaries", _group_ should be singular.

llvm/unittests/Support/ThreadPool.cpp
176

I think the generality introduced here may be more complexity than it's worth. It imposes a high boilerplate cost on each caller.

Both tests that currently call this function simply look at the size (population count) of the bit vector. Unless you expect to use this in more ways, it would be simpler to return a copy of the bit vector (or just its size) and let the individual tests inspect it. That would still move the assertions to the individual tests, which is valuable.

aganea updated this revision to Diff 316433.Jan 13 2021, 10:17 AM
aganea marked 2 inline comments as done.

As suggested by Adrian.

amccarth accepted this revision.Jan 13 2021, 3:59 PM

Thanks for the changes!

This revision is now accepted and ready to land.Jan 13 2021, 3:59 PM
aganea marked an inline comment as not done.Jan 13 2021, 5:23 PM

Thank you for your time! :)

This revision was landed with ongoing or failed builds.Jan 13 2021, 6:00 PM
This revision was automatically updated to reflect the committed changes.