diff --git a/projects/rocr-runtime/include/hsakmt.h b/projects/rocr-runtime/include/hsakmt.h index 39b1a0c792..615ebafef8 100644 --- a/projects/rocr-runtime/include/hsakmt.h +++ b/projects/rocr-runtime/include/hsakmt.h @@ -634,296 +634,7 @@ hsaKmtDbgAddressWatch( ); /** - 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 that exist - for Pid, and can be a mixture of queues for different nodes. - - GracePeriod 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 - -/** - 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 that 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 - -/** - Enable debug trap for NodeId. If QueueId is INVALID_QUEUEID then - enable for all queues on NodeId, otherwise enable only for QueueId. - Return file descriptor PollFd where on poll wake, fd has readable - FIFO data for pending debug events. - - When debug trap is enabled the trap handler behavior changes - depending on architecture of the node and can include the following: - - - Initialize Trap Temp Registers: All new waves are launched with - specific trap temp registers initialized with: - - - HSA dispatch packet address of the wave. - - - X, Y, Z grid and work-group position of the wave within the - dispatch. - - - The scratch backing memory address. - - - Enable wave launch trap override. hsaKmtEnableDebugTrap() sets the - TrapMask to 0 and the TrapOverride to HSA_DBG_TRAP_OVERRIDE_OR and - they can be changed by hsaKmtSetWaveLaunchTrapOverride(). - - If debug trap is already enabled for NodeId, any features controlled - by it are still reset to their default values as defined above. - - Returns: - - HSAKMT_STATUS_SUCCESS if successful. - - - HSAKMT_STATUS_INVALID_HANDLE if: - - - NodeId is invalid - - - QueueId is not INVALID_QUEUE, or is not a valid queue of - NodeId. - - - HSAKMT_STATUS_UNAVAILABLE if debugging is not available to this - process. For example, there may be a limit on number of - processes that can perform debugging at the same time. - - - HSAKMT_STATUS_NOT_SUPPORTED if debug trap is not supported by - NodeId, or if QueueId is not INVALID_QUEUEID and NodeId does not - support per queue enabling. -*/ -HSAKMT_STATUS -HSAKMTAPI -hsaKmtEnableDebugTrap( - HSAuint32 NodeId, //IN - HSA_QUEUEID QueueId //IN - ); - - -/* Similar to EnableDebugTrap with polling fd return*/ -HSAKMT_STATUS -HSAKMTAPI -hsaKmtEnableDebugTrapWithPollFd( - HSAuint32 NodeId, //IN - HSA_QUEUEID QueueId, //IN - HSAint32 *PollFd //OUT - ); - -/** - Disable debug trap enabled by hsaKmtEnableDebugTrap(). If debug trap - is not currently enabled not action is taken. - - 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. -*/ -HSAKMT_STATUS -HSAKMTAPI -hsaKmtDisableDebugTrap( - HSAuint32 NodeId //IN - ); - - -/** - Query pending debug event set by ptrace. - - Can query by target QueueId. If QueueId is INVALID_QUEUEID, return the - first queue id that has a pending event. Option to clear pending event - after query is used by the ClearEvents parameter. - - Pending debug event type will be returned in EventsReceived parameter and is - defined by HSA_DEBUG_EVENT_TYPE. Suspended state of queue is returned in - IsSuspended. - - Returns: - - HSAKMT_STATUS_SUCCESS if successful - */ -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 - ); - -/** - Newly created queue snapshot per ptraced process. - - Returns queue snapshot including queue id, gpuid, context save base address, - queue status word, queue address and size, and queue read and write pointer. - - ClearEvents set will clear new queue bit and queue status word bits. - - Returns: - - HSAKMT_STATUS_SUCCESS if successful - */ -HSAKMT_STATUS -HSAKMTAPI -hsaKmtGetQueueSnapshot( - HSAuint32 NodeId, // IN - HSAuint32 Pid, // IN - bool ClearEvents, // IN - void *SnapshotBuf, // IN - HSAuint32 *QssEntries // IN/OUT - ); - -/** - Send the host trap -*/ -HSAKMT_STATUS -HSAKMTAPI -hsaKmtSendHostTrap( - HSAuint32 NodeId, //IN - HSAuint32 Pid //IN - ); - -/** - Set the trap override mask. When debug trap is enabled by - hsaKmtEnableDebugTrap() each wave launched has its initial - MODE.excp_en register overriden by TrapMask as specified by - TrapOverride. - - An error is returned if debug trap is not currently enabled for - NodeId. Debug trap is enabled by hsaKmtEnableDebugTrap() which - initializes TrapMask to 0 and TrapOverride to - HSA_DBG_TRAP_OVERRIDE_OR. - - Returns: - - HSAKMT_STATUS_SUCCESS if successful. - - - HSAKMT_STATUS_NOT_SUPPORTED if wave launch trap override is not - supported by NodeId. - - - HSAKMT_STATUS_INVALID_HANDLE if NodeId is invalid. - - - HSAKMT_STATUS_INVALID_PARAMETER if TrapOverride is invalid. - - - HSAKMT_STATUS_ERROR if debug trap is not currently enabled by - hsaKmtEnableDebugTrap() for NodeId. -*/ -HSAKMT_STATUS -HSAKMTAPI -hsaKmtSetWaveLaunchTrapOverride( - HSAuint32 NodeId, //IN - HSA_DBG_TRAP_OVERRIDE TrapOverride, //IN - HSA_DBG_TRAP_MASK TrapMask //IN - ); - -/** - Set the mode in which all future waves will be launched for - NodeId. - - Returns: - - HSAKMT_STATUS_SUCCESS if successful. - - - HSAKMT_STATUS_UNAVAILABLE if debugging is not available to this - process. For example, there may be a limit on number of - processes that can perform debugging at the same time. - - - HSAKMT_STATUS_NOT_SUPPORTED if the WaveLaunchMode requested is - not supported by the NodeId. Different implementations and - different nodes within an implementation can support different - sets of launch modes. Only HSA_DBG_WAVE_LAUNCH_MODE_NORMAL mode - is supported by all. - - - HSAKMT_STATUS_INVALID_HANDLE if NodeId is not a valid node. - - - HSAKMT_STATUS_INVALID_PARAMETER if WaveLaunchMode is not a valid - value. -*/ -HSAKMT_STATUS -HSAKMTAPI -hsaKmtSetWaveLaunchMode( - HSAuint32 NodeId, //IN - HSA_DBG_WAVE_LAUNCH_MODE WaveLaunchMode //IN - ); - -/** - * 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 @@ -932,147 +643,6 @@ hsaKmtGetKernelDebugTrapVersionInfo( HSAuint32 *Minor //Out ); -/** - * Get the major and minor version of the thunk debugger support. -*/ -void -HSAKMTAPI -hsaKmtGetThunkDebugTrapVersionInfo( - HSAuint32 *Major, //Out - HSAuint32 *Minor //Out - ); - - - - -/** - Set a debug memory access watch point. A memory access of the kind - specified by WatchMode to an matching address will cause the trap - handler to be entered. An address matches if, after ANDing the - watch-addr-mask-lo..watch-addr-mask-hi bits of WatchAddrMask, it - equals the WatchAddress with the bottom watch-addr-mask-lo bits - cleared. - - WatchId will be in the range 0 to watch-count - 1. The WatchId - value will match the address watch exception reported to the trap - handler. - - hsaKmtGetNodeProperties() can be used to obtain HsaNodeProperties. - watch-addr-mask-lo and watch-addr-mask-hi can be obtained from - HsaNodeProperties.Capabilities.WatchAddrMaskLoBit and - HsaNodeProperties.Capabilities.WatchAddrMaskHiBit respectively. - watch-count can be obtained from - 2^HsaNodeProperties.Capabilities.WatchPointsTotalBits. - - To cause debug memory address watch points to be reported to the - trap handler the address watch exception must be enabled. This can - be accomplished by using hsaKmtSetWaveLaunchTrapOverride() with a - TrapMask that includes HSA_DBG_TRAP_MASK_DBG_ADDRESS_WATCH. - - Returns: - - HSAKMT_STATUS_SUCCESS if successful. - - - HSAKMT_STATUS_NOT_SUPPORTED if debug memory watch points are - not supported for NodeId. - - - HSAKMT_STATUS_UNAVAILABLE if debugging is not available to this - process. For example, there may be a limit on number of - processes that can perform debugging at the same time. - - - HSAKMT_STATUS_INVALID_HANDLE if NodeId or WatchId* is invalid. - - - HSAKMT_STATUS_INVALID_PARAMETER if: - - - WatchAddrMask contains non-0 bits outside the inclusive range - watch-addr-mask-lo to watch-addr-mask-hi. - - - If WatchAddress contain non-0 bits in the inclusive range 0 to - watch-addr-mask-lo. - - - If WatchMode is not one of the values of HSA_DBG_WATCH_MODE. - - - WatchId is NULL. - - - HSAKMT_STATUS_OUT_OF_RESOURCES if no more watch points are - available to set currently. -*/ -HSAKMT_STATUS -HSAKMTAPI -hsaKmtSetAddressWatch( - HSAuint32 NodeId, //IN - HSAuint32 Pid, //IN - HSA_DBG_WATCH_MODE WatchMode, //IN - void* WatchAddress, //IN - HSAuint64 WatchAddrMask, //IN - HSAuint32* WatchId //OUT - ); - -/** - Clear a debug memory access watch point set by - hsaKmtSetAddressWatch(). - - Returns: - - HSAKMT_STATUS_SUCCESS if successful. - - - HSAKMT_STATUS_NOT_SUPPORTED if debug memory watch points are - not supported for NodeId. - - - HSAKMT_STATUS_INVALID_HANDLE if NodeId is invalid or WatchId is not valid for this - NodeId. -*/ -HSAKMT_STATUS -HSAKMTAPI -hsaKmtClearAddressWatch( - HSAuint32 NodeId, //IN - HSAuint32 Pid, //IN - HSAuint32 WatchId //IN - ); - -/** - Enable precise memory operations. - - When precise memory operations are enabled a wave waits for each - memory operation to complete before executing further - operations. This results in more precise reporting of memory related - events such as memory violation or address watch points. - - Returns: - - HSAKMT_STATUS_SUCCESS if successful. - - - HSAKMT_STATUS_UNAVAILABLE if precise memory operations is not - available to this process. For example, the feature may require - specific privileges. - - - HSAKMT_STATUS_NOT_SUPPORTED if precise memory operations is not - supported by NodeId. - - - HSAKMT_STATUS_INVALID_HANDLE if NodeId is invalid. -*/ -HSAKMT_STATUS -HSAKMTAPI -hsaKmtEnablePreciseMemoryOperations( - HSAuint32 NodeId //IN - ); - -/** - Disable precise memory operations enabled by - hsaKmtEnablePreciseMemoryOperations(). If precise memory operations - are not currently enabled no action is taken. - - Returns: - - HSAKMT_STATUS_SUCCESS if successful. - - - HSAKMT_STATUS_INVALID_HANDLE if NodeId is invalid. - - - HSAKMT_STATUS_NOT_SUPPORTED if precise memory operations is not - supported by NodeId. -*/ -HSAKMT_STATUS -HSAKMTAPI -hsaKmtDisablePreciseMemoryOperations( - HSAuint32 NodeId //IN - ); - /** Gets GPU and CPU clock counters for particular Node */ diff --git a/projects/rocr-runtime/include/linux/kfd_ioctl.h b/projects/rocr-runtime/include/linux/kfd_ioctl.h index 868fbdd370..9bb1fb8a64 100644 --- a/projects/rocr-runtime/include/linux/kfd_ioctl.h +++ b/projects/rocr-runtime/include/linux/kfd_ioctl.h @@ -23,7 +23,7 @@ #ifndef KFD_IOCTL_H_INCLUDED #define KFD_IOCTL_H_INCLUDED -#include +#include #include /* @@ -44,15 +44,29 @@ * 1.1 - Allow attaching to processes that have not opened /dev/kfd yet * 1.2 - Allow flag option to clear queue status on queue suspend * 1.3 - Fix race condition between clear on suspend and trap event handling - * 1.3 - Fix race condition between clear on suspend and trap event handling * 1.4 - Fix bad kfifo free * 1.5 - Fix ABA issue between queue snapshot and suspend * 2.0 - Return number of queues suspended/resumed and mask invalid/error - * array slots + * array slots * 2.1 - Add Set Address Watch, and Clear Address Watch support. + * 3.0 - Overhaul set wave launch override API + * 3.1 - Add support for GFX10 + * 3.2 - Add support for GFX10.3 + * 3.3 - Add precise memory operations enable + * 4.0 - Remove gpu_id from api + * 5.0 - Report exception codes to the debugger + * 6.0 - Pass event file descriptor from userspace. + * 6.1 - Add KFD_IOC_DBG_TRAP_QUERY_EXCEPTION_INFO. + * 6.2 - Add KFD_IOC_DBG_TRAP_DEVICE_SNAPSHOT. + * 7.0 - Redefine exception codes + * 7.1 - Add KFD_IOC_DBG_TRAP_RUNTIME_ENABLE + * 7.2 - Add KFD_IOC_DBG_TRAP_SEND_RUNTIME_EVENT + * 8.0 - Expand runtime information given to the debugger + * 8.1 - Allow the debugger to set the exception mask + * 9.0 - Handle multiple exceptions from single trap signal */ -#define KFD_IOCTL_DBG_MAJOR_VERSION 2 -#define KFD_IOCTL_DBG_MINOR_VERSION 1 +#define KFD_IOCTL_DBG_MAJOR_VERSION 9 +#define KFD_IOCTL_DBG_MINOR_VERSION 0 struct kfd_ioctl_get_version_args { __u32 major_version; /* from KFD */ @@ -117,6 +131,7 @@ struct kfd_ioctl_get_queue_wave_state_args { }; struct kfd_queue_snapshot_entry { + __u64 exception_status; __u64 ring_base_address; __u64 write_pointer_address; __u64 read_pointer_address; @@ -125,8 +140,19 @@ struct kfd_queue_snapshot_entry { __u32 gpu_id; __u32 ring_size; __u32 queue_type; - __u32 queue_status; - __u32 reserved[19]; + __u32 reserved[18]; +}; + +struct kfd_dbg_device_info_entry { + __u64 exception_status; + __u64 lds_base; + __u64 lds_limit; + __u64 scratch_base; + __u64 scratch_limit; + __u64 gpuvm_base; + __u64 gpuvm_limit; + __u32 gpu_id; + __u32 pad; }; /* For kfd_ioctl_set_memory_policy_args.default_policy and alternate_policy */ @@ -224,114 +250,323 @@ struct kfd_ioctl_dbg_wave_control_args { __u32 gpu_id; /* to KFD */ __u32 buf_size_in_bytes; /*including gpu_id and buf_size */ }; - -/* mapping event types to API spec */ -#define KFD_DBG_EV_STATUS_TRAP 1 -#define KFD_DBG_EV_STATUS_VMFAULT 2 -#define KFD_DBG_EV_STATUS_SUSPENDED 4 -#define KFD_DBG_EV_STATUS_NEW_QUEUE 8 -#define KFD_DBG_EV_STATUS_HOST_TRAP_TIMEDOUT 16 #define KFD_DBG_EV_FLAG_CLEAR_STATUS 1 +/* queue states for suspend/resume */ +#define KFD_DBG_QUEUE_ERROR_BIT 30 +#define KFD_DBG_QUEUE_INVALID_BIT 31 +#define KFD_DBG_QUEUE_ERROR_MASK (1 << KFD_DBG_QUEUE_ERROR_BIT) +#define KFD_DBG_QUEUE_INVALID_MASK (1 << KFD_DBG_QUEUE_INVALID_BIT) + +#define KFD_INVALID_GPUID 0xffffffff #define KFD_INVALID_QUEUEID 0xffffffff +enum kfd_dbg_trap_override_mode { + KFD_DBG_TRAP_OVERRIDE_OR = 0, + KFD_DBG_TRAP_OVERRIDE_REPLACE = 1 +}; +enum kfd_dbg_trap_mask { + KFD_DBG_TRAP_MASK_FP_INVALID = 1, + KFD_DBG_TRAP_MASK_FP_INPUT_DENORMAL = 2, + KFD_DBG_TRAP_MASK_FP_DIVIDE_BY_ZERO = 4, + KFD_DBG_TRAP_MASK_FP_OVERFLOW = 8, + KFD_DBG_TRAP_MASK_FP_UNDERFLOW = 16, + KFD_DBG_TRAP_MASK_FP_INEXACT = 32, + KFD_DBG_TRAP_MASK_INT_DIVIDE_BY_ZERO = 64, + KFD_DBG_TRAP_MASK_DBG_ADDRESS_WATCH = 128, + KFD_DBG_TRAP_MASK_DBG_MEMORY_VIOLATION = 256 +}; + +enum kfd_dbg_trap_exception_code { + EC_NONE = 0, + /* per queue */ + EC_QUEUE_WAVE_ABORT = 1, + EC_QUEUE_WAVE_TRAP = 2, + EC_QUEUE_WAVE_MATH_ERROR = 3, + EC_QUEUE_WAVE_ILLEGAL_INSTRUCTION = 4, + EC_QUEUE_WAVE_MEMORY_VIOLATION = 5, + EC_QUEUE_WAVE_APERTURE_VIOLATION = 6, + EC_QUEUE_PACKET_DISPATCH_DIM_INVALID = 16, + EC_QUEUE_PACKET_DISPATCH_GROUP_SEGMENT_SIZE_INVALID = 17, + EC_QUEUE_PACKET_DISPATCH_CODE_INVALID = 18, + EC_QUEUE_PACKET_RESERVED = 19, + EC_QUEUE_PACKET_UNSUPPORTED = 20, + EC_QUEUE_PACKET_DISPATCH_WORK_GROUP_SIZE_INVALID = 21, + EC_QUEUE_PACKET_DISPATCH_REGISTER_INVALID = 22, + EC_QUEUE_PACKET_VENDOR_UNSUPPORTED = 23, + EC_QUEUE_PREEMPTION_ERROR = 30, + EC_QUEUE_NEW = 31, + /* per device */ + EC_DEVICE_QUEUE_DELETE = 32, + EC_DEVICE_MEMORY_VIOLATION = 33, + EC_DEVICE_RAS_ERROR = 34, + EC_DEVICE_FATAL_HALT = 35, + EC_DEVICE_NEW = 36, + /* per process */ + EC_PROCESS_RUNTIME = 48, + EC_PROCESS_DEVICE_REMOVE = 49, + EC_MAX +}; + +/* Mask generated by ecode defined in enum above. */ +#define KFD_EC_MASK(ecode) (1ULL << (ecode - 1)) + +/* Masks for exception code type checks below. */ +#define KFD_EC_MASK_QUEUE (KFD_EC_MASK(EC_QUEUE_WAVE_ABORT) | \ + KFD_EC_MASK(EC_QUEUE_WAVE_TRAP) | \ + KFD_EC_MASK(EC_QUEUE_WAVE_MATH_ERROR) | \ + KFD_EC_MASK(EC_QUEUE_WAVE_ILLEGAL_INSTRUCTION) | \ + KFD_EC_MASK(EC_QUEUE_WAVE_MEMORY_VIOLATION) | \ + KFD_EC_MASK(EC_QUEUE_WAVE_APERTURE_VIOLATION) | \ + KFD_EC_MASK(EC_QUEUE_PACKET_DISPATCH_DIM_INVALID) | \ + KFD_EC_MASK(EC_QUEUE_PACKET_DISPATCH_GROUP_SEGMENT_SIZE_INVALID) | \ + KFD_EC_MASK(EC_QUEUE_PACKET_DISPATCH_CODE_INVALID) | \ + KFD_EC_MASK(EC_QUEUE_PACKET_UNSUPPORTED) | \ + KFD_EC_MASK(EC_QUEUE_PACKET_DISPATCH_WORK_GROUP_SIZE_INVALID) | \ + KFD_EC_MASK(EC_QUEUE_PACKET_DISPATCH_REGISTER_INVALID) | \ + KFD_EC_MASK(EC_QUEUE_PACKET_VENDOR_UNSUPPORTED) | \ + KFD_EC_MASK(EC_QUEUE_PREEMPTION_ERROR) | \ + KFD_EC_MASK(EC_QUEUE_NEW)) +#define KFD_EC_MASK_DEVICE (KFD_EC_MASK(EC_DEVICE_QUEUE_DELETE) | \ + KFD_EC_MASK(EC_DEVICE_RAS_ERROR) | \ + KFD_EC_MASK(EC_DEVICE_FATAL_HALT) | \ + KFD_EC_MASK(EC_DEVICE_MEMORY_VIOLATION) | \ + KFD_EC_MASK(EC_DEVICE_NEW)) +#define KFD_EC_MASK_PROCESS (KFD_EC_MASK(EC_PROCESS_RUNTIME) | \ + KFD_EC_MASK(EC_PROCESS_DEVICE_REMOVE)) + +/* Checks for exception code types for KFD search. */ +#define KFD_DBG_EC_TYPE_IS_QUEUE(ecode) \ + (!!(KFD_EC_MASK(ecode) & KFD_EC_MASK_QUEUE)) +#define KFD_DBG_EC_TYPE_IS_DEVICE(ecode) \ + (!!(KFD_EC_MASK(ecode) & KFD_EC_MASK_DEVICE)) +#define KFD_DBG_EC_TYPE_IS_PROCESS(ecode) \ + (!!(KFD_EC_MASK(ecode) & KFD_EC_MASK_PROCESS)) + +enum kfd_dbg_runtime_state { + DEBUG_RUNTIME_STATE_DISABLED = 0, + DEBUG_RUNTIME_STATE_ENABLED = 1, + DEBUG_RUNTIME_STATE_ENABLED_BUSY = 2, + DEBUG_RUNTIME_STATE_ENABLED_ERROR = 3 +}; + +struct kfd_runtime_info { + __u64 r_debug; + __u32 runtime_state; + __u32 ttmp_setup; +}; + /* KFD_IOC_DBG_TRAP_ENABLE: - * ptr: unused + * exception_mask: exceptions to be reported to the debugger + * ptr: runtime info buffer to copy to (IN) * data1: 0=disable, 1=enable - * data2: queue ID (for future use) - * data3: return value for fd + * data2: return value for fd + * data3: runtime info size + * data4: unused + * */ #define KFD_IOC_DBG_TRAP_ENABLE 0 /* KFD_IOC_DBG_TRAP_SET_WAVE_LAUNCH_OVERRIDE: + * exception_mask: unused * ptr: unused - * data1: override mode: 0=OR, 1=REPLACE - * data2: mask - * data3: unused + * data1: override mode (see enum kfd_dbg_trap_override_mode) + * data2: [in/out] trap mask (see enum kfd_dbg_trap_mask) + * data3: [in] requested mask, [out] supported mask + * data4: unused + * + * May fail with -EPERM if the requested mode is not supported. + * + * May fail with -EACCES if requested trap mask bits are not supported. + * In that case the supported trap mask bits are returned in data3. + * + * If successful, output parameters return the previous trap mask + * value and the hardware-dependent mask of supported trap mask bits. */ #define KFD_IOC_DBG_TRAP_SET_WAVE_LAUNCH_OVERRIDE 1 /* KFD_IOC_DBG_TRAP_SET_WAVE_LAUNCH_MODE: + * exception_mask: unused * ptr: unused * data1: 0=normal, 1=halt, 2=kill, 3=singlestep, 4=disable * data2: unused * data3: unused + * data4: unused */ #define KFD_IOC_DBG_TRAP_SET_WAVE_LAUNCH_MODE 2 /* KFD_IOC_DBG_TRAP_NODE_SUSPEND: - * ptr: pointer to an array of Queues IDs - * data1: flags - * data2: number of queues - * data3: grace period + * exception_mask: exceptions to clear on suspend + * ptr: pointer to an array of Queues IDs (IN/OUT) + * data1: number of queues (IN) + * data2: grace period (IN) + * data3: unused + * data4: unused + * + * Returns the number of queues suspended from array of Queue IDs (ptr). + * Requested queues that fail to suspend are masked in the array: + * + * KFD_DBG_QUEUE_INVALID_MASK - requested queue does not exist or cannot be + * suspended (new or being destroyed). + * + * KFD_DBG_QUEUE_ERROR_MASK - bad internal operation occurred on requested + * queue. + * + * NOTE! All queue destroy requests will be blocked on a suspended queue. + * Queue resume will unblock. + * + * Grace period (data2) is time allowed for waves to complete before CWSR. + * 0 can be entered for immediate preemption. */ #define KFD_IOC_DBG_TRAP_NODE_SUSPEND 3 /* KFD_IOC_DBG_TRAP_NODE_RESUME: - * ptr: pointer to an array of Queues IDs - * data1: flags - * data2: number of queues + * exception_mask: unused + * ptr: pointer to an array of Queues IDs (IN/OUT) + * data1: number of queues (IN) + * data2: unused * data3: unused + * data4: unused + * + * Returns the number of queues resumed from array of Queue IDs (ptr). + * Requested queues that fail to resume are masked in the array: + * + * KFD_DBG_QUEUE_INVALID_MASK - requested queue does not exist. + * + * KFD_DBG_QUEUE_ERROR_MASK - bad internal operation occurred on requested + * queue. */ #define KFD_IOC_DBG_TRAP_NODE_RESUME 4 /* KFD_IOC_DBG_TRAP_QUERY_DEBUG_EVENT: + * exception_mask: exception to clear (IN) on query and report (OUT) * ptr: unused - * data1: queue id (IN/OUT) - * data2: flags (IN) - * data3: suspend[2:2], event type [1:0] (OUT) + * data1: source id (OUT) + * data2: unused + * data3: unused + * data4: unused + * + * Source ID (data 1 - OUT) returns the queue_id for a queue event, the gpu_id + * for a device event or 0 for a process event. + * + * Returns EAGAIN if no event is found and 0 otherwise. */ - #define KFD_IOC_DBG_TRAP_QUERY_DEBUG_EVENT 5 /* KFD_IOC_DBG_TRAP_GET_QUEUE_SNAPSHOT: + * exception_mask: exception to clear on snapshot * ptr: user buffer (IN) - * data1: flags (IN) - * data2: number of queue snapshot entries (IN/OUT) + * data1: number of queue snapshots (IN/OUT) - 0 for IN ignores buffer writes + * data2: unused * data3: unused + * data4: unused */ #define KFD_IOC_DBG_TRAP_GET_QUEUE_SNAPSHOT 6 /* KFD_IOC_DBG_TRAP_GET_VERSION: + * exception_mask: unused * ptr: unsused * data1: major version (OUT) * data2: minor version (OUT) * data3: unused + * data4: unused */ #define KFD_IOC_DBG_TRAP_GET_VERSION 7 /* KFD_IOC_DBG_TRAP_CLEAR_ADDRESS_WATCH: + * exception_mask: unused * ptr: unused * data1: watch ID * data2: unused * data3: unused + * data4: unused */ #define KFD_IOC_DBG_TRAP_CLEAR_ADDRESS_WATCH 8 /* KFD_IOC_DBG_TRAP_SET_ADDRESS_WATCH: + * exception_mask: unused * ptr: Watch address * data1: Watch ID (OUT) * data2: watch_mode: 0=read, 1=nonread, 2=atomic, 3=all * data3: watch address mask + * data4: unused */ #define KFD_IOC_DBG_TRAP_SET_ADDRESS_WATCH 9 -/* KFD_IOC_DBG_SEND_HOST_TRAP: +/* KFD_IOC_DBG_TRAP_SET_PRECISE_MEM_OPS + * exception_mask: unused + * ptr: unused + * data1: 0=disable, 1=enable (IN) + * data2: unused + * data3: unused + * data4: unused + */ +#define KFD_IOC_DBG_TRAP_SET_PRECISE_MEM_OPS 10 + +/* KFD_IOC_DBG_TRAP_QUERY_EXCEPTION_INFO + * exception_mask: unused + * ptr: exception info pointer to copy to + * data1: source_id + * data2: exception_code + * data3: clear_exception (1 == true, 0 == false) + * data4: exception info data size + * + * NOTE: If data2 == EC_PROCESS_RUNTIME, the saved runtime info will be copied + * to the exception info pointer. + */ +#define KFD_IOC_DBG_TRAP_QUERY_EXCEPTION_INFO 11 + +/* KFD_IOC_DBG_TRAP_DEVICE_SNAPSHOT + * exception_mask: exception to clear on snapshot + * ptr: user buffer for 'struct kfd_dbg_device_info_entry' entries (IN) + * data1: number of devices in snapshot (IN/OUT) + * data2: unused + * data3: unused + * data4: unused + */ +#define KFD_IOC_DBG_TRAP_DEVICE_SNAPSHOT 12 + +/* KFD_IOC_DBG_TRAP_RUNTIME_ENABLE + * exception_mask: unused + * ptr: r_debug info to save + * data1: enable (0=disable, 1=enable) + * data2: enable ttmp save (0=disable, 1=enable) + * data3: unused + * data4: unused + * + * FIXME: This option is temporary. Future upstream will use a separate IOCTL. + */ +#define KFD_IOC_DBG_TRAP_RUNTIME_ENABLE 13 + +/* KFD_IOC_DBG_TRAP_SEND_RUNTIME_EVENT + * exception_mask: exception to send + * ptr: unused + * data1: destination device id + * data2: destination queue id + * data3: usused + * data4: unused + */ +#define KFD_IOC_DBG_TRAP_SEND_RUNTIME_EVENT 14 + +/* KFD_IOC_DBG_TRAP_SET_EXCEPTION_ENABLED + * exception_mask: exception to set * ptr: unused * data1: unused * data2: unused - * data3: unused + * data3: usused + * data4: unused */ -#define KFD_IOC_DBG_TRAP_SEND_HOST_TRAP 10 +#define KFD_IOC_DBG_TRAP_SET_EXCEPTIONS_ENABLED 15 struct kfd_ioctl_dbg_trap_args { - __u64 ptr; /* to KFD -- used for pointer arguments: queue arrays */ + __u64 exception_mask; /* to KFD */ + __u64 ptr; /* to KFD */ __u32 pid; /* to KFD */ - __u32 gpu_id; /* to KFD */ __u32 op; /* to KFD */ __u32 data1; /* to KFD */ __u32 data2; /* to KFD */ __u32 data3; /* to KFD */ + __u32 data4; /* to KFD */ }; /* Matching HSA_EVENTTYPE */ @@ -569,7 +804,7 @@ struct kfd_ioctl_alloc_queue_gws_args { __u32 queue_id; /* to KFD */ __u32 num_gws; /* to KFD */ __u32 first_gws; /* from KFD */ - __u32 pad; /* to KFD */ + __u32 pad; }; struct kfd_ioctl_get_dmabuf_info_args { @@ -737,7 +972,6 @@ struct kfd_ioctl_cross_memory_copy_args { __u64 bytes_copied; }; - /* Guarantee host access to memory */ #define KFD_IOCTL_SVM_FLAG_HOST_ACCESS 0x00000001 /* Fine grained coherency between all devices with access */ @@ -749,7 +983,7 @@ struct kfd_ioctl_cross_memory_copy_args { /* Allow execution on GPU */ #define KFD_IOCTL_SVM_FLAG_GPU_EXEC 0x00000010 /* GPUs mostly read, may allow similar optimizations as RO, but writes fault */ -#define KFD_IOCTL_SVM_FLAG_GPU_READ_MOSTLY 0x00000020 +#define KFD_IOCTL_SVM_FLAG_GPU_READ_MOSTLY 0x00000020 /** * kfd_ioctl_svm_op - SVM ioctl operations @@ -762,6 +996,17 @@ enum kfd_ioctl_svm_op { KFD_IOCTL_SVM_OP_GET_ATTR }; +/** kfd_ioctl_svm_location - Enum for preferred and prefetch locations + * + * GPU IDs are used to specify GPUs as preferred and prefetch locations. + * Below definitions are used for system memory or for leaving the preferred + * location unspecified. + */ +enum kfd_ioctl_svm_location { + KFD_IOCTL_SVM_LOCATION_SYSMEM = 0, + KFD_IOCTL_SVM_LOCATION_UNDEFINED = 0xffffffff +}; + /** * kfd_ioctl_svm_attr_type - SVM attribute types * @@ -791,17 +1036,6 @@ enum kfd_ioctl_svm_attr_type { KFD_IOCTL_SVM_ATTR_GRANULARITY }; -/** kfd_ioctl_svm_location - Enum for preferred and prefetch locations - * - * GPU IDs are used to specify GPUs as preferred and prefetch locations. - * Below definitions are used for system memory or for leaving the preferred - * location unspecified. - */ -enum kfd_ioctl_svm_location { - KFD_IOCTL_SVM_LOCATION_SYSMEM = 0, - KFD_IOCTL_SVM_LOCATION_UNDEFINED = 0xffffffff -}; - /** * kfd_ioctl_svm_attribute - Attributes as pairs of type and value * @@ -882,16 +1116,16 @@ struct kfd_ioctl_svm_args { * functionality. * * Enabling XNACK mode requires shader programs to be compiled - * differently. Furthermore, not all GPUs support changing the mode + * differently. Furthermore, not all GPUs support changing the mode * per-process. Therefore changing the mode is only allowed while no * user mode queues exist in the process. This ensure that no shader * code is running that may be compiled for the wrong mode. And GPUs - * that cannot change to the requested mode will be disabled by - * failing subsequent requests to create user mode queues. - * - * This ioctl returns the status of the requested xnack mode. + * that cannot change to the requested mode will prevent the XNACK + * mode from occurring. All GPUs used by the process must be in the + * same XNACK mode. * * GFXv8 or older GPUs do not support 48 bit virtual addresses or SVM. + * Therefore those GPUs are not considered for the XNACK mode switch. * * Return: 0 on success, -errno on failure */ @@ -956,7 +1190,7 @@ struct kfd_ioctl_set_xnack_mode_args { #define AMDKFD_IOC_SET_SCRATCH_BACKING_VA \ AMDKFD_IOWR(0x11, struct kfd_ioctl_set_scratch_backing_va_args) -#define AMDKFD_IOC_GET_TILE_CONFIG \ +#define AMDKFD_IOC_GET_TILE_CONFIG \ AMDKFD_IOWR(0x12, struct kfd_ioctl_get_tile_config_args) #define AMDKFD_IOC_SET_TRAP_HANDLER \ @@ -996,6 +1230,9 @@ struct kfd_ioctl_set_xnack_mode_args { #define AMDKFD_IOC_ALLOC_QUEUE_GWS \ AMDKFD_IOWR(0x1E, struct kfd_ioctl_alloc_queue_gws_args) +#define AMDKFD_IOC_SMI_EVENTS \ + AMDKFD_IOWR(0x1F, struct kfd_ioctl_smi_events_args) + #define AMDKFD_IOC_SVM AMDKFD_IOWR(0x20, struct kfd_ioctl_svm_args) #define AMDKFD_IOC_SET_XNACK_MODE \ @@ -1021,7 +1258,6 @@ struct kfd_ioctl_set_xnack_mode_args { AMDKFD_IOWR(0x84, struct kfd_ioctl_spm_args) - #define AMDKFD_COMMAND_START_2 0x80 #define AMDKFD_COMMAND_END_2 0x85 diff --git a/projects/rocr-runtime/src/debug.c b/projects/rocr-runtime/src/debug.c index 5ed6631932..484fd4d16e 100644 --- a/projects/rocr-runtime/src/debug.c +++ b/projects/rocr-runtime/src/debug.c @@ -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; } diff --git a/projects/rocr-runtime/src/libhsakmt.ver b/projects/rocr-runtime/src/libhsakmt.ver index 66ca6ea5b3..f423e505cf 100644 --- a/projects/rocr-runtime/src/libhsakmt.ver +++ b/projects/rocr-runtime/src/libhsakmt.ver @@ -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; diff --git a/projects/rocr-runtime/tests/kfdtest/src/KFDDBGTest.cpp b/projects/rocr-runtime/tests/kfdtest/src/KFDDBGTest.cpp index 9e7d93cc4c..b7a38bbd46 100644 --- a/projects/rocr-runtime/tests/kfdtest/src/KFDDBGTest.cpp +++ b/projects/rocr-runtime/tests/kfdtest/src/KFDDBGTest.cpp @@ -285,6 +285,8 @@ TEST_F(KFDDBGTest, BasicAddressWatch) { } #endif +#if 0 +// Deprecated - Reference Use Only /** * checkDebugVersion: * Inputs: @@ -333,7 +335,10 @@ static bool checkDebugVersion(HSAuint32 requiredMajor, HSAuint32 requiredMinor) return true; } +#endif +#if 0 +// Deprecated - Reference Use Only TEST_F(KFDDBGTest, BasicDebuggerSuspendResume) { TEST_START(TESTPROFILE_RUNALL) if (m_FamilyId >= FAMILY_AI) { @@ -431,7 +436,10 @@ exit: LOG() << std::endl; TEST_END } +#endif +#if 0 +// Deprecated - Reference Use Only TEST_F(KFDDBGTest, BasicDebuggerQueryQueueStatus) { TEST_START(TESTPROFILE_RUNALL) if (m_FamilyId >= FAMILY_AI) { @@ -574,8 +582,11 @@ exit: LOG() << std::endl; TEST_END } +#endif +#if 0 // clean up routine +// Deprecated - Reference Use Only static void ExitVMFaultQueryChild(std::string errMsg, int exitStatus, HSAint32 pollFd, @@ -613,7 +624,10 @@ static void ExitVMFaultQueryChild(std::string errMsg, exit(exitStatus); } +#endif +#if 0 +// Deprecated - Reference Use Only TEST_F(KFDDBGTest, BasicDebuggerQueryVMFaultQueueStatus) { TEST_START(TESTPROFILE_RUNALL) if (m_FamilyId >= FAMILY_AI) { @@ -811,3 +825,4 @@ exit: LOG() << std::endl; TEST_END } +#endif