[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
@@ -40,21 +40,18 @@ set(_thread_limit_environment
"ROCPROFSYS_TIMEMORY_COMPONENTS=wall_clock,peak_rss,page_rss"
)
# Maximum allowed threads
set(ALLOWED_MAX_THREADS 4096)
math(EXPR THREAD_VAL_1 "${ROCPROFSYS_MAX_THREADS} - 1")
math(EXPR THREAD_VAL_2 "${ROCPROFSYS_MAX_THREADS} + 24")
math(EXPR THREAD_VAL_1 "${ROCPROFSYS_MAX_THREADS} + 24")
math(EXPR THREAD_VAL_2 "${ALLOWED_MAX_THREADS} + 1")
set(THREAD_VALUES ${THREAD_VAL_1} ${THREAD_VAL_2})
set(THREAD_VALUES ${THREAD_VAL_1} ${THREAD_VAL_2} ${ROCPROFSYS_MAX_THREADS})
# Loop over thread values
foreach(THREADS IN LISTS THREAD_VALUES)
set(THREAD_PASS_VALUE ${THREADS})
math(EXPR THREAD_FAIL_VALUE "${THREADS} + 1")
if(${THREADS} GREATER_EQUAL ${ALLOWED_MAX_THREADS})
math(EXPR THREAD_PASS_VALUE "${ALLOWED_MAX_THREADS} - 1")
math(EXPR THREAD_FAIL_VALUE "${THREADS}")
if(${THREADS} GREATER_EQUAL ${ROCPROFSYS_MAX_THREADS})
math(EXPR THREAD_PASS_VALUE "${ROCPROFSYS_MAX_THREADS} - 1")
math(EXPR THREAD_FAIL_VALUE "${ROCPROFSYS_MAX_THREADS} + 1")
endif()
set(_thread_limit_pass_regex "\\|${THREAD_PASS_VALUE}>>>")
@@ -72,9 +69,9 @@ foreach(THREADS IN LISTS THREAD_VALUES)
REWRITE_ARGS -e -v 2 -i 1024 --label return args
RUNTIME_ARGS -e -v 1 -i 1024 --label return args
RUN_ARGS 35 2 ${THREADS}
SAMPLING_TIMEOUT 180
REWRITE_TIMEOUT 180
RUNTIME_TIMEOUT 360
SAMPLING_TIMEOUT 480
REWRITE_TIMEOUT 480
RUNTIME_TIMEOUT 480
RUNTIME_PASS_REGEX "${_thread_limit_pass_regex}"
SAMPLING_PASS_REGEX "${_thread_limit_pass_regex}"
REWRITE_RUN_PASS_REGEX "${_thread_limit_pass_regex}"