kfdtest: add base debug class and debug attach/detach operation
Add base debug class and attach/detach operations.
Signed-off-by: Jonathan Kim <jonathan.kim@amd.com>
Change-Id: I60f3c166646f05838fec208ac2f59bba998c63f8
[ROCm/ROCR-Runtime commit: dd56b38c2f]
此提交包含在:
@@ -774,6 +774,15 @@ hsaKmtDbgGetQueueData(
|
||||
bool suspend_queues //In
|
||||
);
|
||||
|
||||
/**
|
||||
Check whether gpu firmware and kernel support debugging
|
||||
*/
|
||||
HSAKMT_STATUS
|
||||
HSAKMTAPI
|
||||
hsaKmtCheckRuntimeDebugSupport(
|
||||
void
|
||||
);
|
||||
|
||||
/**
|
||||
Debug ops call primarily used for KFD testing
|
||||
*/
|
||||
|
||||
@@ -268,7 +268,7 @@ HSAKMT_STATUS HSAKMTAPI hsaKmtDbgAddressWatch(HSAuint32 NodeId,
|
||||
#define HSA_RUNTIME_ENABLE_MAX_MAJOR 1
|
||||
#define HSA_RUNTIME_ENABLE_MIN_MINOR 13
|
||||
|
||||
static HSAKMT_STATUS checkRuntimeDebugSupport(void) {
|
||||
HSAKMT_STATUS hsaKmtCheckRuntimeDebugSupport(void) {
|
||||
HsaNodeProperties node = {0};
|
||||
HsaSystemProperties props = {0};
|
||||
HsaVersionInfo versionInfo = {0};
|
||||
@@ -306,7 +306,7 @@ HSAKMT_STATUS HSAKMTAPI hsaKmtRuntimeEnable(void *rDebug,
|
||||
bool setupTtmp)
|
||||
{
|
||||
struct kfd_ioctl_runtime_enable_args args = {0};
|
||||
HSAKMT_STATUS result = checkRuntimeDebugSupport();
|
||||
HSAKMT_STATUS result = hsaKmtCheckRuntimeDebugSupport();
|
||||
|
||||
if (result)
|
||||
return result;
|
||||
@@ -332,7 +332,7 @@ HSAKMT_STATUS HSAKMTAPI hsaKmtRuntimeEnable(void *rDebug,
|
||||
HSAKMT_STATUS HSAKMTAPI hsaKmtRuntimeDisable(void)
|
||||
{
|
||||
struct kfd_ioctl_runtime_enable_args args = {0};
|
||||
HSAKMT_STATUS result = checkRuntimeDebugSupport();
|
||||
HSAKMT_STATUS result = hsaKmtCheckRuntimeDebugSupport();
|
||||
|
||||
if (result)
|
||||
return result;
|
||||
|
||||
@@ -65,6 +65,7 @@ hsaKmtGetQueueInfo;
|
||||
hsaKmtAllocQueueGWS;
|
||||
hsaKmtRuntimeEnable;
|
||||
hsaKmtRuntimeDisable;
|
||||
hsaKmtCheckRuntimeDebugSupport;
|
||||
hsaKmtGetRuntimeCapabilities;
|
||||
hsaKmtDebugTrapIoctl;
|
||||
hsaKmtSPMAcquire;
|
||||
|
||||
@@ -167,6 +167,7 @@ set (SRC_FILES gtest-1.6.0/gtest-all.cpp
|
||||
|
||||
src/AqlQueue.cpp
|
||||
src/BasePacket.cpp
|
||||
src/BaseDebug.cpp
|
||||
src/BaseQueue.cpp
|
||||
src/Dispatch.cpp
|
||||
src/GoogleTestExtension.cpp
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Advanced Micro Devices, Inc. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "BaseDebug.hpp"
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <linux/kfd_ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include "unistd.h"
|
||||
|
||||
BaseDebug::BaseDebug(void) {
|
||||
}
|
||||
|
||||
BaseDebug::~BaseDebug(void) {
|
||||
/*
|
||||
* If the process is still attached, close and destroy the polling file
|
||||
* descriptor. Note that on process termination, the KFD automatically
|
||||
* disables processes that are still runtime enabled and debug enabled
|
||||
* so we don't do it here.
|
||||
*/
|
||||
if (m_Pid) {
|
||||
close(m_Fd.fd);
|
||||
unlink(m_Fd_Name);
|
||||
}
|
||||
}
|
||||
|
||||
// Creates temp file descriptor and debug attaches.
|
||||
HSAKMT_STATUS BaseDebug::Attach(struct kfd_runtime_info *rInfo,
|
||||
int rInfoSize,
|
||||
unsigned int pid,
|
||||
uint64_t exceptionEnable) {
|
||||
struct kfd_ioctl_dbg_trap_args args = {0};
|
||||
char fd_name[32];
|
||||
|
||||
memset(&args, 0x00, sizeof(args));
|
||||
|
||||
mkfifo(m_Fd_Name, 0666);
|
||||
m_Fd.fd = open(m_Fd_Name, O_CLOEXEC | O_NONBLOCK | O_RDWR);
|
||||
m_Fd.events = POLLIN | POLLRDNORM;
|
||||
|
||||
args.pid = pid;
|
||||
args.op = KFD_IOC_DBG_TRAP_ENABLE;
|
||||
args.enable.rinfo_ptr = (uint64_t)rInfo;
|
||||
args.enable.rinfo_size = rInfoSize;
|
||||
args.enable.dbg_fd = m_Fd.fd;
|
||||
args.enable.exception_mask = exceptionEnable;
|
||||
|
||||
if (hsaKmtDebugTrapIoctl(&args, NULL)) {
|
||||
close(m_Fd.fd);
|
||||
unlink(m_Fd_Name);
|
||||
return HSAKMT_STATUS_ERROR;
|
||||
}
|
||||
|
||||
m_Pid = pid;
|
||||
|
||||
return HSAKMT_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
void BaseDebug::Detach(void) {
|
||||
struct kfd_ioctl_dbg_trap_args args = {0};
|
||||
|
||||
memset(&args, 0x00, sizeof(args));
|
||||
|
||||
args.pid = m_Pid;
|
||||
args.op = KFD_IOC_DBG_TRAP_DISABLE;
|
||||
|
||||
hsaKmtDebugTrapIoctl(&args, NULL);
|
||||
|
||||
close(m_Fd.fd);
|
||||
unlink(m_Fd_Name);
|
||||
|
||||
m_Pid = 0;
|
||||
m_Fd.fd = 0;
|
||||
m_Fd.events = 0;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Advanced Micro Devices, Inc. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __KFD_BASE_DEBUG__H__
|
||||
#define __KFD_BASE_DEBUG__H__
|
||||
|
||||
#include "hsakmt.h"
|
||||
#include <poll.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// @class BaseDebug
|
||||
class BaseDebug {
|
||||
public:
|
||||
BaseDebug(void);
|
||||
virtual ~BaseDebug(void);
|
||||
|
||||
HSAKMT_STATUS Attach(struct kfd_runtime_info *rInfo,
|
||||
int rInfoSize,
|
||||
unsigned int pid,
|
||||
uint64_t exceptionEnable);
|
||||
|
||||
void Detach(void);
|
||||
|
||||
private:
|
||||
unsigned int m_Pid;
|
||||
struct pollfd m_Fd;
|
||||
const char *m_Fd_Name = "/tmp/dbg_fifo";
|
||||
};
|
||||
|
||||
#endif // __KFD_BASE_DEBUG__H__
|
||||
新增問題並參考
封鎖使用者