Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions extension/threadpool/threadpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <executorch/extension/threadpool/threadpool.h>

#include <algorithm>
#include <atomic>
#include <memory>

#include <executorch/extension/threadpool/threadpool_guard.h>
Expand Down Expand Up @@ -101,17 +100,20 @@ ThreadPool* get_threadpool() {
return nullptr; // NOLINT(facebook-hte-NullableReturn)
}

int num_threads = cpuinfo_get_processors_count();
/*
* For llvm-tsan, holding limit for the number of locks for a single thread
* is 63 (because of comparison < 64 instead of <=). pthreadpool's worst
* case is the number of threads in a pool. So we want to limit the threadpool
* size to 64 when running with tsan. However, sometimes it is tricky to
* detect if we are running under tsan, for now capping the default
* threadcount to the tsan limit unconditionally.
*/
constexpr int tsan_thread_limit = 63;
num_threads = std::min(num_threads, tsan_thread_limit);
static const int num_threads = ([]() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pinged you to get link to tsan failure to understand the issue better

int result = cpuinfo_get_processors_count();

/*
* For llvm-tsan, holding limit for the number of locks for a single thread
* is 63 (because of comparison < 64 instead of <=). pthreadpool's worst
* case is the number of threads in a pool. So we want to limit the
* threadpool size to 64 when running with tsan. However, sometimes it is
* tricky to detect if we are running under tsan, for now capping the
* default threadcount to the tsan limit unconditionally.
*/
constexpr int tsan_thread_limit = 63;
return std::min(result, tsan_thread_limit);
})();
static auto threadpool = std::make_unique<ThreadPool>(num_threads);

// Inheriting from old threadpool to get around segfault issue
Expand Down
Loading