[rocprof-sys] Fix segfault from thread ID array overflow (#2172)

**Thread limit configuration and enforcement: **

* Added a check in `CMakeLists.txt` to ensure `ROCPROFSYS_MAX_THREADS` is at least 128, automatically setting it to 128 with a warning if a lower value is provided.
* Replaced hardcoded thread limit (`allowed_max_threads`) in `pthread_create_gotcha.cpp` with the configurable `ROCPROFSYS_MAX_THREADS` value, ensuring all runtime checks and warnings use the actual configured limit.

**Documentation improvements: **

* Updated the development guide to explain the new thread limit behavior, including how exceeding the limit is handled gracefully, how to configure it, and the build-time validation rules.

**Test updates: **

* Modified thread limit tests to use the configurable `ROCPROFSYS_MAX_THREADS` value instead of a hardcoded limit and expanded the range of tested thread values.
* Increased test timeouts to accommodate larger thread counts and ensure reliability with higher limits.
This commit is contained in:
anujshuk-amd
2026-01-08 00:33:37 +05:30
committed by GitHub
parent 050e88ee71
commit 596ffce5fe
5 changed files with 60 additions and 25 deletions
@@ -64,9 +64,6 @@ 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
{
@@ -187,7 +184,7 @@ pthread_create_gotcha::wrapper::operator()() const
const auto& _parent_info = thread_info::get(m_config.parent_tid, InternalTID);
const auto& _info = thread_info::init(m_config.offset);
auto _sequent_value = _info->index_data ? _info->index_data->sequent_value : -1;
if(static_cast<size_t>(_sequent_value) >= allowed_max_threads)
if(static_cast<size_t>(_sequent_value) >= ROCPROFSYS_MAX_THREADS)
{
static std::once_flag thread_limit_warning_flag;
std::call_once(thread_limit_warning_flag, []() {
@@ -196,7 +193,7 @@ pthread_create_gotcha::wrapper::operator()() const
"[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);
static_cast<size_t>(ROCPROFSYS_MAX_THREADS));
});
return m_routine(m_arg);
}