https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=281765

--- Comment #16 from Mark Millard <[email protected]> ---
(In reply to Dimitry Andric from comment #2)

Might such points as the below be a source of Danial's
references to "using a single thread" (in various
places under various wordings, not just in this bugzillsa
entry) instead of being up to 4 from the:

  if (ThreadsRequested == 0) {
    return std::min(MaxThreadCount, 4);
  }


The details for the question . . .

If I read the code correctly,

unsigned llvm::ThreadPoolStrategy::compute_thread_count() const {
  int MaxThreadCount =
      UseHyperThreads ? computeHostNumHardwareThreads() : get_physical_cores();
  if (MaxThreadCount <= 0)
    MaxThreadCount = 1;
. . .
  if (ThreadsRequested == 0) {
    return std::min(MaxThreadCount, 4);
  }

for the get_physical_cores case gets to:

lib/Support/Unix/Threading.inc

and its (no FreeSD specific computeHostNumPhysicalCores):

#else
// On other systems, return -1 to indicate unknown.
static int computeHostNumPhysicalCores() { return -1; }
#endif

int llvm::get_physical_cores() {
  static int NumCores = computeHostNumPhysicalCores();
  return NumCores;
}

[I'll note that Linux does not use that "On other systems"
code, for example. It appears that FreeBSD would need
to provide its own implementation since upstream does
not.]

So, if UseHyperThreads ends up false with
ThreadsRequested == 0, then the thread count
will end up being 1.

I'll note that lvm's heavyweight_hardware_concurrency
usage contexts would appear to have
UseHyperThreads == false . Thus those specific
contexts would single thread on FreeBSD from what I
can tell:

 inline ThreadPoolStrategy
  heavyweight_hardware_concurrency(unsigned ThreadCount = 0) {
    ThreadPoolStrategy S;
    S.UseHyperThreads = false;
    S.ThreadsRequested = ThreadCount;
    return S;
  }
. . .
 inline ThreadPoolStrategy heavyweight_hardware_concurrency(StringRef Num) {
    std::optional<ThreadPoolStrategy> S =
        get_threadpool_strategy(Num, heavyweight_hardware_concurrency());
    if (S)
      return *S;
    return heavyweight_hardware_concurrency();
  }

Also:

std::optional<ThreadPoolStrategy>
llvm::get_threadpool_strategy(StringRef Num, ThreadPoolStrategy Default) {
  if (Num == "all")
    return llvm::hardware_concurrency();
  if (Num.empty())
    return Default;
  unsigned V;
  if (Num.getAsInteger(10, V))
    return std::nullopt; // malformed 'Num' value
  if (V == 0)
    return Default;

  // Do not take the Default into account. This effectively disables
  // heavyweight_hardware_concurrency() if the user asks for any number of
  // threads on the cmd-line.
  ThreadPoolStrategy S = llvm::hardware_concurrency();
  S.ThreadsRequested = V;
  return S;
}

Note that last about heavyweight_hardware_concurrency being
in use unless the command line specifies something explicitly.
(That last looks to be FreeBSD specific code?)

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to