From 9055cf8092c7560b6fffc67e65bbb23cde4c9cae Mon Sep 17 00:00:00 2001 From: Eric Huang Date: Thu, 3 Apr 2025 15:18:57 -0400 Subject: [PATCH] kfdtest: fix ptrace error on multi-gpu mode The parent process can only be ptraced by 1 process once, to avoid the error we have to add mutex to synchronize the ptrace call. Signed-off-by: Eric Huang [ROCm/ROCR-Runtime commit: d3265234e90f4583c7062b340ed460a483a5dcfb] --- .../libhsakmt/tests/kfdtest/src/KFDMemoryTest.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/projects/rocr-runtime/libhsakmt/tests/kfdtest/src/KFDMemoryTest.cpp b/projects/rocr-runtime/libhsakmt/tests/kfdtest/src/KFDMemoryTest.cpp index e1ab26b9a0..abe4af4dce 100644 --- a/projects/rocr-runtime/libhsakmt/tests/kfdtest/src/KFDMemoryTest.cpp +++ b/projects/rocr-runtime/libhsakmt/tests/kfdtest/src/KFDMemoryTest.cpp @@ -42,6 +42,8 @@ /* Captures user specified time (seconds) to sleep */ extern unsigned int g_SleepTime; +static pthread_mutex_t ptrace_mtx; + void KFDMemoryTest::SetUp() { ROUTINE_START @@ -1353,6 +1355,8 @@ static void PtraceAccess(KFDTEST_PARAMETERS* pTestParamters) { prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY, 0, 0, 0); #endif + pthread_mutex_lock(&ptrace_mtx); + // Find current pid so the child can trace it pid_t tracePid = getpid(); @@ -1414,6 +1418,8 @@ static void PtraceAccess(KFDTEST_PARAMETERS* pTestParamters) { EXPECT_EQ_GPU(0, WEXITSTATUS(childStatus), gpuNode); } + pthread_mutex_unlock(&ptrace_mtx); + // Clear gaps in the source that should not have been copied (reinterpret_cast(mem[0]))[ sizeof(long) ] = 0; (reinterpret_cast(mem[0]))[2*sizeof(long) + 1] = 0; @@ -1508,6 +1514,8 @@ static void PtraceAccessInvisibleVram(KFDTEST_PARAMETERS* pTestParamters) { prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY, 0, 0, 0); #endif + pthread_mutex_lock(&ptrace_mtx); + // Find out my pid so the child can trace it pid_t tracePid = getpid(); @@ -1564,6 +1572,8 @@ static void PtraceAccessInvisibleVram(KFDTEST_PARAMETERS* pTestParamters) { EXPECT_EQ_GPU(0, WEXITSTATUS(childStatus), gpuNode); } + pthread_mutex_unlock(&ptrace_mtx); + /* Use shader to read back data to check poke results */ HsaMemoryBuffer isaBuffer(PAGE_SIZE, gpuNode, true/*zero*/, false/*local*/, true/*exec*/); // dstBuffer is cpu accessible gtt memory