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 <jinhuieric.huang@amd.com>


[ROCm/ROCR-Runtime commit: d3265234e9]
Cette révision appartient à :
Eric Huang
2025-04-03 15:18:57 -04:00
révisé par Huang, JinHuiEric
Parent 480ca4d5e7
révision 9055cf8092
+10
Voir le fichier
@@ -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<uint8_t*>(mem[0]))[ sizeof(long) ] = 0;
(reinterpret_cast<uint8_t*>(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