libhsakmt: update thunk api for exception handling
The debugger and debug agent no longer use the Thunk API.
Remove all deprecated functions and keep commented
references for future KFD tests.
Update and the keep the version checks for future use
and hsaKmtRuntimeEnable/Disable.
Signed-off-by: Jonathan Kim <jonathan.kim@amd.com>
Signed-off-by: Laurent Morichetti <laurent.morichetti@amd.com>
Reviewed-by: Felix Kuehling <felix.kuehling@amd.com>
Change-Id: Ia2f10d82f5ac36d0bd1bda233810f26e8a154d55
[ROCm/ROCR-Runtime commit: 31ac82617c]
This commit is contained in:
committed by
Jonathan Kim
parent
fe03b35c8e
commit
1001f27cb5
@@ -271,335 +271,7 @@ int debug_get_reg_status(uint32_t node_id, bool *is_debugged)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static HSAKMT_STATUS debug_trap(HSAuint32 NodeId,
|
||||
HSAuint32 op,
|
||||
HSAuint32 data1,
|
||||
HSAuint32 data2,
|
||||
HSAuint32 data3,
|
||||
HSAuint32 pid,
|
||||
HSAuint64 pointer,
|
||||
struct kfd_ioctl_dbg_trap_args *argout)
|
||||
{
|
||||
uint32_t gpu_id;
|
||||
HSAKMT_STATUS result;
|
||||
HsaNodeProperties NodeProperties = {0};
|
||||
struct kfd_ioctl_dbg_trap_args args = {0};
|
||||
|
||||
CHECK_KFD_OPEN();
|
||||
|
||||
if (op == KFD_IOC_DBG_TRAP_NODE_SUSPEND ||
|
||||
op == KFD_IOC_DBG_TRAP_NODE_RESUME ||
|
||||
op == KFD_IOC_DBG_TRAP_GET_VERSION ||
|
||||
op == KFD_IOC_DBG_TRAP_GET_QUEUE_SNAPSHOT) {
|
||||
if (NodeId != INVALID_NODEID)
|
||||
return HSAKMT_STATUS_INVALID_HANDLE;
|
||||
|
||||
// gpu_id is ignored for suspend/resume queues.
|
||||
gpu_id = INVALID_NODEID;
|
||||
} else {
|
||||
if (validate_nodeid(NodeId, &gpu_id) != HSAKMT_STATUS_SUCCESS)
|
||||
return HSAKMT_STATUS_INVALID_HANDLE;
|
||||
|
||||
result = hsaKmtGetNodeProperties(NodeId, &NodeProperties);
|
||||
|
||||
if (result != HSAKMT_STATUS_SUCCESS)
|
||||
return result;
|
||||
|
||||
if (!NodeProperties.Capability.ui32.DebugTrapSupported)
|
||||
return HSAKMT_STATUS_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
if (pid == INVALID_PID) {
|
||||
pid = (HSAuint32) getpid();
|
||||
}
|
||||
|
||||
memset(&args, 0x00, sizeof(args));
|
||||
args.gpu_id = gpu_id;
|
||||
args.op = op;
|
||||
args.data1 = data1;
|
||||
args.data2 = data2;
|
||||
args.data3 = data3;
|
||||
args.pid = pid;
|
||||
args.ptr = pointer;
|
||||
|
||||
long err = kmtIoctl(kfd_fd, AMDKFD_IOC_DBG_TRAP, &args);
|
||||
|
||||
if (argout)
|
||||
*argout = args;
|
||||
|
||||
if ((op == KFD_IOC_DBG_TRAP_NODE_SUSPEND ||
|
||||
op == KFD_IOC_DBG_TRAP_NODE_RESUME) && err >= 0 &&
|
||||
err <= args.data2)
|
||||
result = HSAKMT_STATUS_SUCCESS;
|
||||
else if (err == 0)
|
||||
result = HSAKMT_STATUS_SUCCESS;
|
||||
else
|
||||
result = HSAKMT_STATUS_ERROR;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
HSAKMT_STATUS HSAKMTAPI hsaKmtEnableDebugTrapWithPollFd(HSAuint32 NodeId,
|
||||
HSA_QUEUEID QueueId,
|
||||
HSAint32 *PollFd) //OUT
|
||||
{
|
||||
int result;
|
||||
struct kfd_ioctl_dbg_trap_args argout = {0};
|
||||
|
||||
if (QueueId != INVALID_QUEUEID)
|
||||
return HSAKMT_STATUS_NOT_SUPPORTED;
|
||||
|
||||
result = debug_trap(NodeId,
|
||||
KFD_IOC_DBG_TRAP_ENABLE,
|
||||
1,
|
||||
QueueId,
|
||||
0,
|
||||
INVALID_PID,
|
||||
0,
|
||||
&argout);
|
||||
|
||||
*PollFd = argout.data3;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
HSAKMT_STATUS HSAKMTAPI hsaKmtEnableDebugTrap(HSAuint32 NodeId,
|
||||
HSA_QUEUEID QueueId)
|
||||
{
|
||||
HSAint32 PollFd = 0;
|
||||
HSAKMT_STATUS status = hsaKmtEnableDebugTrapWithPollFd(NodeId,
|
||||
QueueId,
|
||||
&PollFd);
|
||||
|
||||
if (status == HSAKMT_STATUS_SUCCESS)
|
||||
close(PollFd);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
HSAKMT_STATUS HSAKMTAPI hsaKmtDisableDebugTrap(HSAuint32 NodeId)
|
||||
{
|
||||
return debug_trap(NodeId,
|
||||
KFD_IOC_DBG_TRAP_ENABLE,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
INVALID_PID,
|
||||
0,
|
||||
NULL);
|
||||
}
|
||||
|
||||
HSAKMT_STATUS HSAKMTAPI hsaKmtSetWaveLaunchTrapOverride(
|
||||
HSAuint32 NodeId,
|
||||
HSA_DBG_TRAP_OVERRIDE TrapOverride,
|
||||
HSA_DBG_TRAP_MASK TrapMask)
|
||||
{
|
||||
if (TrapOverride >= HSA_DBG_TRAP_OVERRIDE_NUM)
|
||||
return HSAKMT_STATUS_INVALID_PARAMETER;
|
||||
|
||||
return debug_trap(NodeId,
|
||||
KFD_IOC_DBG_TRAP_SET_WAVE_LAUNCH_OVERRIDE,
|
||||
TrapOverride,
|
||||
TrapMask,
|
||||
0,
|
||||
INVALID_PID,
|
||||
0,
|
||||
NULL);
|
||||
}
|
||||
|
||||
HSAKMT_STATUS HSAKMTAPI hsaKmtSetWaveLaunchMode(
|
||||
HSAuint32 NodeId,
|
||||
HSA_DBG_WAVE_LAUNCH_MODE WaveLaunchMode)
|
||||
{
|
||||
return debug_trap(NodeId,
|
||||
KFD_IOC_DBG_TRAP_SET_WAVE_LAUNCH_MODE,
|
||||
WaveLaunchMode,
|
||||
0,
|
||||
0,
|
||||
INVALID_PID,
|
||||
0,
|
||||
NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Suspend the execution of a set of queues. A queue that is suspended
|
||||
* allows the wave context save state to be inspected and modified. If a
|
||||
* queue is already suspended it remains suspended. A suspended queue
|
||||
* can be resumed by hsaKmtDbgQueueResume().
|
||||
*
|
||||
* For each node that has a queue suspended, a sequentially consistent
|
||||
* system scope release will be performed that synchronizes with a
|
||||
* sequentially consistent system scope acquire performed by this
|
||||
* call. This ensures any memory updates performed by the suspended
|
||||
* queues are visible to the thread calling this operation.
|
||||
*
|
||||
* Pid is the process that owns the queues that are to be supended or
|
||||
* resumed. If the value is -1 then the Pid of the process calling
|
||||
* hsaKmtQueueSuspend or hsaKmtQueueResume is used.
|
||||
*
|
||||
* NumQueues is the number of queues that are being requested to
|
||||
* suspend or resume.
|
||||
*
|
||||
* Queues is a pointer to an array with NumQueues entries of
|
||||
* HSA_QUEUEID. The queues in the list must be for queues the exist
|
||||
* for Pid, and can be a mixture of queues for different nodes.
|
||||
*
|
||||
* GracePeriod is the number of milliseconds to wait after
|
||||
* initialiating context save before forcing waves to context save. A
|
||||
* value of 0 indicates no grace period. It is ignored by
|
||||
* hsaKmtQueueResume.
|
||||
*
|
||||
* Flags is a bit set of the values defined by HSA_DBG_NODE_CONTROL.
|
||||
* Returns:
|
||||
* - HSAKMT_STATUS_SUCCESS if successful.
|
||||
* - HSAKMT_STATUS_INVALID_HANDLE if any QueueId is invalid for Pid.
|
||||
*/
|
||||
|
||||
HSAKMT_STATUS
|
||||
HSAKMTAPI
|
||||
hsaKmtQueueSuspend(
|
||||
HSAuint32 Pid, // IN
|
||||
HSAuint32 NumQueues, // IN
|
||||
HSA_QUEUEID *Queues, // IN
|
||||
HSAuint32 GracePeriod, // IN
|
||||
HSAuint32 Flags) // IN
|
||||
{
|
||||
HSAKMT_STATUS result;
|
||||
uint32_t *queue_ids_ptr;
|
||||
|
||||
CHECK_KFD_OPEN();
|
||||
|
||||
queue_ids_ptr = convert_queue_ids(NumQueues, Queues);
|
||||
if (!queue_ids_ptr)
|
||||
return HSAKMT_STATUS_NO_MEMORY;
|
||||
|
||||
result = debug_trap(INVALID_NODEID,
|
||||
KFD_IOC_DBG_TRAP_NODE_SUSPEND,
|
||||
Flags,
|
||||
NumQueues,
|
||||
GracePeriod,
|
||||
Pid,
|
||||
(HSAuint64)queue_ids_ptr,
|
||||
NULL);
|
||||
|
||||
free(queue_ids_ptr);
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Resume the execution of a set of queues. If a queue is not
|
||||
* suspended by hsaKmtDbgQueueSuspend() then it remains executing. Any
|
||||
* changes to the wave state data will be used when the waves are
|
||||
* restored. Changes to the control stack data will have no effect.
|
||||
*
|
||||
* For each node that has a queue resumed, a sequentially consistent
|
||||
* system scope release will be performed that synchronizes with a
|
||||
* sequentially consistent system scope acquire performed by all
|
||||
* queues being resumed. This ensures any memory updates performed by
|
||||
* the thread calling this operation are visible to the resumed
|
||||
* queues.
|
||||
*
|
||||
* For each node that has a queue resumed, the instruction cache will
|
||||
* be invalidated. This ensures any instruction code updates performed
|
||||
* by the thread calling this operation are visible to the resumed
|
||||
* queues.
|
||||
*
|
||||
* Pid is the process that owns the queues that are to be supended or
|
||||
* resumed. If the value is -1 then the Pid of the process calling
|
||||
* hsaKmtQueueSuspend or hsaKmtQueueResume is used.
|
||||
*
|
||||
* NumQueues is the number of queues that are being requested to
|
||||
* suspend or resume.
|
||||
*
|
||||
* Queues is a pointer to an array with NumQueues entries of
|
||||
* HSA_QUEUEID. The queues in the list must be for queues the exist
|
||||
* for Pid, and can be a mixture of queues for different nodes.
|
||||
*
|
||||
* Flags is a bit set of the values defined by HSA_DBG_NODE_CONTROL.
|
||||
* Returns:
|
||||
* - HSAKMT_STATUS_SUCCESS if successful
|
||||
* - HSAKMT_STATUS_INVALID_HANDLE if any QueueId is invalid.
|
||||
*/
|
||||
|
||||
HSAKMT_STATUS
|
||||
HSAKMTAPI
|
||||
hsaKmtQueueResume(
|
||||
HSAuint32 Pid, // IN
|
||||
HSAuint32 NumQueues, // IN
|
||||
HSA_QUEUEID *Queues, // IN
|
||||
HSAuint32 Flags) // IN
|
||||
{
|
||||
HSAKMT_STATUS result;
|
||||
uint32_t *queue_ids_ptr;
|
||||
|
||||
CHECK_KFD_OPEN();
|
||||
|
||||
queue_ids_ptr = convert_queue_ids(NumQueues, Queues);
|
||||
if (!queue_ids_ptr)
|
||||
return HSAKMT_STATUS_NO_MEMORY;
|
||||
|
||||
result = debug_trap(INVALID_NODEID,
|
||||
KFD_IOC_DBG_TRAP_NODE_RESUME,
|
||||
Flags,
|
||||
NumQueues,
|
||||
0,
|
||||
Pid,
|
||||
(HSAuint64)queue_ids_ptr,
|
||||
NULL);
|
||||
free(queue_ids_ptr);
|
||||
return result;
|
||||
}
|
||||
|
||||
HSAKMT_STATUS
|
||||
HSAKMTAPI
|
||||
hsaKmtQueryDebugEvent(
|
||||
HSAuint32 NodeId, //IN
|
||||
HSAuint32 Pid, // IN
|
||||
HSAuint32 *QueueId, // IN/OUT
|
||||
bool ClearEvents, // IN
|
||||
HSA_DEBUG_EVENT_TYPE *EventsReceived, // OUT
|
||||
bool *IsSuspended, // OUT
|
||||
bool *IsNew // OUT
|
||||
)
|
||||
{
|
||||
HSAKMT_STATUS result;
|
||||
struct kfd_ioctl_dbg_trap_args argout = {0};
|
||||
uint32_t flags = 0;
|
||||
|
||||
if (ClearEvents)
|
||||
flags |= KFD_DBG_EV_FLAG_CLEAR_STATUS;
|
||||
|
||||
result = debug_trap(NodeId,
|
||||
KFD_IOC_DBG_TRAP_QUERY_DEBUG_EVENT,
|
||||
*QueueId,
|
||||
flags,
|
||||
0,
|
||||
Pid,
|
||||
0,
|
||||
&argout);
|
||||
|
||||
if (result)
|
||||
return result;
|
||||
|
||||
*QueueId = argout.data1;
|
||||
*EventsReceived = argout.data3 &
|
||||
(KFD_DBG_EV_STATUS_TRAP | KFD_DBG_EV_STATUS_VMFAULT);
|
||||
*IsSuspended = argout.data3 & KFD_DBG_EV_STATUS_SUSPENDED;
|
||||
*IsNew = argout.data3 & KFD_DBG_EV_STATUS_NEW_QUEUE;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the major and minor version of the kernel debugger support.
|
||||
*
|
||||
* Returns:
|
||||
* - HSAKMT_STATUS_SUCCESS if successful.
|
||||
*
|
||||
* - HSAKMT_STATUS_INVALID_HANDLE if NodeId is invalid.
|
||||
*
|
||||
* - HSAKMT_STATUS_NOT_SUPPORTED if debug trap not supported for NodeId.
|
||||
*/
|
||||
/* Get the major and minor version of the kernel debugger support. */
|
||||
HSAKMT_STATUS
|
||||
HSAKMTAPI
|
||||
hsaKmtGetKernelDebugTrapVersionInfo(
|
||||
@@ -607,148 +279,18 @@ hsaKmtGetKernelDebugTrapVersionInfo(
|
||||
HSAuint32 *Minor //Out
|
||||
)
|
||||
{
|
||||
HSAKMT_STATUS result;
|
||||
struct kfd_ioctl_dbg_trap_args argout = {0};
|
||||
struct kfd_ioctl_dbg_trap_args args = {0};
|
||||
|
||||
result = debug_trap(INVALID_NODEID,
|
||||
KFD_IOC_DBG_TRAP_GET_VERSION,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
INVALID_PID,
|
||||
0,
|
||||
&argout);
|
||||
memset(&args, 0x00, sizeof(args));
|
||||
args.op = KFD_IOC_DBG_TRAP_GET_VERSION;
|
||||
args.pid = getpid();
|
||||
|
||||
*Major = argout.data1;
|
||||
*Minor = argout.data2;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the major and minor version of the Thunk debugger support.
|
||||
*/
|
||||
void
|
||||
HSAKMTAPI
|
||||
hsaKmtGetThunkDebugTrapVersionInfo(
|
||||
HSAuint32 *Major, //Out
|
||||
HSAuint32 *Minor //Out
|
||||
)
|
||||
{
|
||||
*Major = KFD_IOCTL_DBG_MAJOR_VERSION;
|
||||
*Minor = KFD_IOCTL_DBG_MINOR_VERSION;
|
||||
}
|
||||
|
||||
HSAKMT_STATUS
|
||||
HSAKMTAPI
|
||||
hsaKmtGetQueueSnapshot(
|
||||
HSAuint32 NodeId, //IN
|
||||
HSAuint32 Pid, // IN
|
||||
bool ClearEvents, //IN
|
||||
void *SnapshotBuf, //IN
|
||||
HSAuint32 *QssEntries //IN/OUT
|
||||
)
|
||||
{
|
||||
HSAKMT_STATUS result;
|
||||
struct kfd_ioctl_dbg_trap_args argout = {0};
|
||||
uint32_t flags = 0;
|
||||
|
||||
if (ClearEvents)
|
||||
flags |= KFD_DBG_EV_FLAG_CLEAR_STATUS;
|
||||
|
||||
result = debug_trap(NodeId,
|
||||
KFD_IOC_DBG_TRAP_GET_QUEUE_SNAPSHOT,
|
||||
flags,
|
||||
*QssEntries,
|
||||
0,
|
||||
Pid,
|
||||
(HSAuint64)SnapshotBuf,
|
||||
&argout);
|
||||
|
||||
if (result)
|
||||
return result;
|
||||
|
||||
*QssEntries = argout.data2;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
HSAKMT_STATUS HSAKMTAPI hsaKmtSetAddressWatch(
|
||||
HSAuint32 NodeId,
|
||||
HSAuint32 Pid,
|
||||
HSA_DBG_WATCH_MODE WatchMode,
|
||||
void *WatchAddress,
|
||||
HSAuint64 WatchAddrMask,
|
||||
HSAuint32 *WatchId
|
||||
)
|
||||
{
|
||||
|
||||
HSAKMT_STATUS result;
|
||||
HSAuint32 TruncatedWatchAddressMask;
|
||||
struct kfd_ioctl_dbg_trap_args argout = {0};
|
||||
|
||||
/* Right now we only support 32 bit watch address masks, so we need
|
||||
* to check that we aren't losing data when we truncate the mask
|
||||
* to be passed to the kernel.
|
||||
*/
|
||||
if (WatchAddrMask > (HSAuint64) UINT_MAX)
|
||||
{
|
||||
return HSAKMT_STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
TruncatedWatchAddressMask = (HSAuint32) WatchAddrMask;
|
||||
|
||||
if (WatchId == NULL)
|
||||
return HSAKMT_STATUS_INVALID_PARAMETER;
|
||||
|
||||
result = debug_trap(NodeId,
|
||||
KFD_IOC_DBG_TRAP_SET_ADDRESS_WATCH, // op
|
||||
*WatchId,
|
||||
WatchMode,
|
||||
TruncatedWatchAddressMask,
|
||||
Pid,
|
||||
(HSAuint64) WatchAddress,
|
||||
&argout);
|
||||
*WatchId = argout.data1;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
HSAKMT_STATUS HSAKMTAPI hsaKmtClearAddressWatch(
|
||||
HSAuint32 NodeId,
|
||||
HSAuint32 Pid,
|
||||
HSAuint32 WatchId
|
||||
)
|
||||
{
|
||||
|
||||
HSAKMT_STATUS result;
|
||||
|
||||
result = debug_trap(NodeId,
|
||||
KFD_IOC_DBG_TRAP_CLEAR_ADDRESS_WATCH, // op
|
||||
WatchId,
|
||||
0,
|
||||
0,
|
||||
Pid,
|
||||
0,
|
||||
NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
HSAKMT_STATUS
|
||||
HSAKMTAPI
|
||||
hsaKmtSendHostTrap(
|
||||
HSAuint32 NodeId, //IN
|
||||
HSAuint32 Pid //IN
|
||||
)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = debug_trap(NodeId,
|
||||
KFD_IOC_DBG_TRAP_SEND_HOST_TRAP,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
Pid,
|
||||
0,
|
||||
NULL);
|
||||
|
||||
return result;
|
||||
long err = kmtIoctl(kfd_fd, AMDKFD_IOC_DBG_TRAP, &args);
|
||||
|
||||
if (err)
|
||||
return HSAKMT_STATUS_ERROR;
|
||||
|
||||
*Major = args.data1;
|
||||
*Minor = args.data2;
|
||||
return HSAKMT_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -57,21 +57,8 @@ hsaKmtGetTileConfig;
|
||||
hsaKmtQueryPointerInfo;
|
||||
hsaKmtSetMemoryUserData;
|
||||
hsaKmtGetQueueInfo;
|
||||
hsaKmtEnableDebugTrap;
|
||||
hsaKmtEnableDebugTrapWithPollFd;
|
||||
hsaKmtDisableDebugTrap;
|
||||
hsaKmtQueryDebugEvent;
|
||||
hsaKmtSendHostTrap;
|
||||
hsaKmtGetQueueSnapshot;
|
||||
hsaKmtSetWaveLaunchTrapOverride;
|
||||
hsaKmtSetWaveLaunchMode;
|
||||
hsaKmtQueueSuspend;
|
||||
hsaKmtQueueResume;
|
||||
hsaKmtAllocQueueGWS;
|
||||
hsaKmtGetKernelDebugTrapVersionInfo;
|
||||
hsaKmtGetThunkDebugTrapVersionInfo;
|
||||
hsaKmtSetAddressWatch;
|
||||
hsaKmtClearAddressWatch;
|
||||
hsaKmtSPMAcquire;
|
||||
hsaKmtSPMRelease;
|
||||
hsaKmtSPMSetDestBuffer;
|
||||
|
||||
Reference in New Issue
Block a user