[PATCH] D75153: [ThinLTO] Allow usage of all SMT threads in the system

Fangrui Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 16 13:26:11 PDT 2020


MaskRay added a comment.

In D75153#1942336 <https://reviews.llvm.org/D75153#1942336>, @aganea wrote:

> In D75153#1906580 <https://reviews.llvm.org/D75153#1906580>, @MaskRay wrote:
>
> > Does `taskset -c 0-3 lld -flavor ...` restrict the number of cores?
> >
> >   cpu_set_t cpu;
> >   sched_getaffinity(0, sizeof(cpu), &cpu);
> >   CPU_COUNT(&cpu)
>
>
> Thanks for raising this! This does not seem to work (I currently only have WSL at hand, no real Linux machine). I don't think it worked before my patch. The current code in LLVM is written such as: (//note the "if" statement//)
>
>   #if defined(HAVE_SCHED_GETAFFINITY) && defined(HAVE_CPU_COUNT)
>     cpu_set_t Set;
>     if (sched_getaffinity(0, sizeof(Set), &Set))
>       return CPU_COUNT(&Set);
>   #endif
>
>
>
>
>   [[ https://linux.die.net/man/2/sched_getaffinity | The doc ]] for `sched_getaffinity` says:
>   
>
> > On success, sched_setaffinity() and sched_getaffinity() return 0. On error, -1 is returned, and errno is set appropriately.
>
> So it would always fall back to `std::thread::hardware_concurrency`, which apparently does not always take affinity into account, according to @respindola (please see rG8c0ff9508da5f02e8ce6580a126a2018c9bf702a <https://reviews.llvm.org/rG8c0ff9508da5f02e8ce6580a126a2018c9bf702a>).
>
> I'll write a follow-up patch to test affinity on Linux and Windows.


Created D78324 <https://reviews.llvm.org/D78324> to fix this pre-existing issue. I remember I saw a related bugs.llvm.org report yesterday but I can't find it now...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75153/new/

https://reviews.llvm.org/D75153





More information about the cfe-commits mailing list