From bfb0d15ee8f651b0b0d50e61fc49d076f4c62d8e Mon Sep 17 00:00:00 2001 From: Jonathan Kim Date: Fri, 13 May 2022 12:35:45 -0400 Subject: [PATCH] kfdtest: add query operations Add polling query debug event operation. Signed-off-by: Jonathan Kim Change-Id: Ic82ce4a393bfb28c9f32e7920f80c12da7f627d5 --- tests/kfdtest/src/BaseDebug.cpp | 35 +++++++++++++++++++++++++++++++++ tests/kfdtest/src/BaseDebug.hpp | 3 +++ 2 files changed, 38 insertions(+) diff --git a/tests/kfdtest/src/BaseDebug.cpp b/tests/kfdtest/src/BaseDebug.cpp index 912150ee51..a673ad8448 100644 --- a/tests/kfdtest/src/BaseDebug.cpp +++ b/tests/kfdtest/src/BaseDebug.cpp @@ -111,3 +111,38 @@ HSAKMT_STATUS BaseDebug::SendRuntimeEvent(uint64_t exceptions, int gpuId, int qu return hsaKmtDebugTrapIoctl(&args, NULL); } + +HSAKMT_STATUS BaseDebug::QueryDebugEvent(uint64_t *exceptions, + uint32_t *gpuId, uint32_t *queueId, + int timeoutMsec) +{ + struct kfd_ioctl_dbg_trap_args args = {0}; + HSAKMT_STATUS result; + int r = poll(&m_Fd, 1, timeoutMsec); + + if (r > 0) { + char tmp[r]; + + read(m_Fd.fd, tmp, sizeof(tmp)); + } else { + return HSAKMT_STATUS_ERROR; + } + + memset(&args, 0x00, sizeof(args)); + + args.pid = m_Pid; + args.op = KFD_IOC_DBG_TRAP_QUERY_DEBUG_EVENT; + args.query_debug_event.exception_mask = *exceptions; + + result = hsaKmtDebugTrapIoctl(&args, NULL); + + *exceptions = args.query_debug_event.exception_mask; + + if (gpuId) + *gpuId = args.query_debug_event.gpu_id; + + if (queueId) + *queueId = args.query_debug_event.queue_id; + + return result; +} diff --git a/tests/kfdtest/src/BaseDebug.hpp b/tests/kfdtest/src/BaseDebug.hpp index 3b8d2098d1..eede721a7c 100644 --- a/tests/kfdtest/src/BaseDebug.hpp +++ b/tests/kfdtest/src/BaseDebug.hpp @@ -41,6 +41,9 @@ class BaseDebug { void Detach(void); HSAKMT_STATUS SendRuntimeEvent(uint64_t exceptions, int gpuId, int queueId); + HSAKMT_STATUS QueryDebugEvent(uint64_t *exceptions, + uint32_t *gpuId, uint32_t *queueId, + int timeoutMsec); private: unsigned int m_Pid;