From 72bd0f3a8d6e43c2bfbadb48b54d719e64b8a491 Mon Sep 17 00:00:00 2001 From: Jonathan Kim Date: Mon, 21 Mar 2022 12:46:01 -0400 Subject: [PATCH] libhsakmt: add debug trap thunk call for testing Add generic thunk call for debug testing that assumes caller populations trap arguments correctly. Signed-off-by: Jonathan Kim Change-Id: I33a0bc66ca77e29f5b663d4bfe73f8684df8bfb6 [ROCm/ROCR-Runtime commit: aaab019960d3eb2721b87ce2d8a265bf269a1b47] --- projects/rocr-runtime/include/hsakmt.h | 9 ++++++- projects/rocr-runtime/src/debug.c | 35 +++++++++++++++++++++++++ projects/rocr-runtime/src/libhsakmt.ver | 1 + 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/projects/rocr-runtime/include/hsakmt.h b/projects/rocr-runtime/include/hsakmt.h index c95afb8a07..1c3cd84a78 100644 --- a/projects/rocr-runtime/include/hsakmt.h +++ b/projects/rocr-runtime/include/hsakmt.h @@ -774,6 +774,14 @@ hsaKmtDbgGetQueueData( bool suspend_queues //In ); +/** + Debug ops call primarily used for KFD testing + */ +HSAKMT_STATUS HSAKMTAPI hsaKmtDebugTrapIoctl( + struct kfd_ioctl_dbg_trap_args *arg, + HSA_QUEUEID *Queues + ); + /** Gets GPU and CPU clock counters for particular Node */ @@ -1031,4 +1039,3 @@ hsaKmtReturnAsanHeaderPage( #endif #endif //_HSAKMT_H_ - diff --git a/projects/rocr-runtime/src/debug.c b/projects/rocr-runtime/src/debug.c index e97b809844..d12dc4a260 100644 --- a/projects/rocr-runtime/src/debug.c +++ b/projects/rocr-runtime/src/debug.c @@ -512,3 +512,38 @@ free_data: return HSAKMT_STATUS_ERROR; } + +HSAKMT_STATUS HSAKMTAPI hsaKmtDebugTrapIoctl(struct kfd_ioctl_dbg_trap_args *args, + HSA_QUEUEID *Queues) +{ + HSAKMT_STATUS result; + + CHECK_KFD_OPEN(); + + if (Queues) { + int num_queues = args->op == KFD_IOC_DBG_TRAP_SUSPEND_QUEUES ? + args->suspend_queues.num_queues : + args->resume_queues.num_queues; + void *queue_ptr = args->op == KFD_IOC_DBG_TRAP_SUSPEND_QUEUES ? + (void *)args->suspend_queues.queue_array_ptr : + (void *)args->resume_queues.queue_array_ptr; + + memcpy(queue_ptr, convert_queue_ids(num_queues, Queues), + num_queues * sizeof(uint32_t)); + } + + long err = kmtIoctl(kfd_fd, AMDKFD_IOC_DBG_TRAP, args); + + if (args->op == KFD_IOC_DBG_TRAP_SUSPEND_QUEUES && + err >= 0 && err <= args->suspend_queues.num_queues) + result = HSAKMT_STATUS_SUCCESS; + else if (args->op == KFD_IOC_DBG_TRAP_RESUME_QUEUES && + err >= 0 && err <= args->resume_queues.num_queues) + result = HSAKMT_STATUS_SUCCESS; + else if (err == 0) + result = HSAKMT_STATUS_SUCCESS; + else + result = HSAKMT_STATUS_ERROR; + + return result; +} diff --git a/projects/rocr-runtime/src/libhsakmt.ver b/projects/rocr-runtime/src/libhsakmt.ver index dc17215263..c720476beb 100644 --- a/projects/rocr-runtime/src/libhsakmt.ver +++ b/projects/rocr-runtime/src/libhsakmt.ver @@ -66,6 +66,7 @@ hsaKmtAllocQueueGWS; hsaKmtRuntimeEnable; hsaKmtRuntimeDisable; hsaKmtGetRuntimeCapabilities; +hsaKmtDebugTrapIoctl; hsaKmtSPMAcquire; hsaKmtSPMRelease; hsaKmtSPMSetDestBuffer;