Fix for thread limit tests (#323)

* Fix for thread limit tests. Which are failing due to exceeding the number of threads allowed.

Signed-off-by: Anuj-Kumar Shukla <AnujKumar.Shukla@amd.com>

* Update CMakeLists.txt

* Stopping thread creation after max thread limit

* Adressed review comments

* Update projects/rocprofiler-systems/tests/source/CMakeLists.txt

---------

Signed-off-by: Anuj-Kumar Shukla <AnujKumar.Shukla@amd.com>
Co-authored-by: anujshuk-amd <anujshuk@amd.com>
This commit is contained in:
David Galiffi
2025-10-09 19:07:14 -04:00
committed by GitHub
parent d195d925e9
commit 182a750c08
2 changed files with 59 additions and 25 deletions
@@ -62,6 +62,9 @@ namespace component
{
using bundle_t = tim::lightweight_tuple<comp::wall_clock>;
using category_region_t = tim::lightweight_tuple<category_region<category::pthread>>;
// The maximum limit for the number of threads is set at 4096. declared and stored in the
// set_storage struct's `types.hpp` file.
constexpr size_t allowed_max_threads = 4096;
namespace
{
@@ -181,7 +184,21 @@ pthread_create_gotcha::wrapper::operator()() const
auto _coverage = (get_mode() == Mode::Coverage);
const auto& _parent_info = thread_info::get(m_config.parent_tid, InternalTID);
const auto& _info = thread_info::init(m_config.offset);
auto _dtor = [&]() {
auto _sequent_value = _info->index_data ? _info->index_data->sequent_value : -1;
if(static_cast<size_t>(_sequent_value) >= allowed_max_threads)
{
static std::once_flag thread_limit_warning_flag;
std::call_once(thread_limit_warning_flag, []() {
ROCPROFSYS_WARNING_F(
1,
"[rocprof-sys][WARNING] Maximum allowed thread limit (%zu) "
"reached. Further thread creation and profiling will be "
"disabled to prevent resource exhaustion.\n",
allowed_max_threads);
});
return m_routine(m_arg);
}
auto _dtor = [&]() {
set_thread_state(ThreadState::Internal);
if(_is_sampling)
{