mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 06:49:52 +08:00
feature: Implement SBA and module debug access for xe debugger
Reuse code from i915 implementation for accesing SBA, module debug, and context save area Related-to: NEO-9161 Signed-off-by: Brandon Yates <brandon.yates@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
0b2e8e2848
commit
df54d67f40
@@ -744,4 +744,98 @@ bool DebugSessionLinux::getIsaInfoForAllInstances(NEO::DeviceBitfield deviceBitf
|
||||
return isaFound > 0;
|
||||
}
|
||||
|
||||
bool DebugSessionLinux::readModuleDebugArea() {
|
||||
auto vm = getClientConnection(clientHandle)->vmToModuleDebugAreaBindInfo.begin()->first;
|
||||
auto gpuVa = getClientConnection(clientHandle)->vmToModuleDebugAreaBindInfo.begin()->second.gpuVa;
|
||||
|
||||
memset(this->debugArea.magic, 0, sizeof(this->debugArea.magic));
|
||||
auto retVal = readGpuMemory(vm, reinterpret_cast<char *>(&this->debugArea), sizeof(this->debugArea), gpuVa);
|
||||
|
||||
if (retVal != ZE_RESULT_SUCCESS || strncmp(this->debugArea.magic, "dbgarea", sizeof(NEO::DebugAreaHeader::magic)) != 0) {
|
||||
PRINT_DEBUGGER_ERROR_LOG("Reading Module Debug Area failed, error = %d\n", retVal);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
ze_result_t DebugSessionLinux::readSbaBuffer(EuThread::ThreadId threadId, NEO::SbaTrackedAddresses &sbaBuffer) {
|
||||
auto vmHandle = allThreads[threadId]->getMemoryHandle();
|
||||
|
||||
if (vmHandle == invalidHandle) {
|
||||
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
auto gpuVa = getSbaBufferGpuVa(vmHandle);
|
||||
if (gpuVa == 0) {
|
||||
return ZE_RESULT_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
return readGpuMemory(vmHandle, reinterpret_cast<char *>(&sbaBuffer), sizeof(sbaBuffer), gpuVa);
|
||||
}
|
||||
|
||||
uint64_t DebugSessionLinux::getSbaBufferGpuVa(uint64_t memoryHandle) {
|
||||
std::lock_guard<std::mutex> lock(asyncThreadMutex);
|
||||
auto bindInfo = getClientConnection(clientHandle)->vmToStateBaseAreaBindInfo.find(memoryHandle);
|
||||
if (bindInfo == getClientConnection(clientHandle)->vmToStateBaseAreaBindInfo.end()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return bindInfo->second.gpuVa;
|
||||
}
|
||||
|
||||
uint64_t DebugSessionLinux::getContextStateSaveAreaGpuVa(uint64_t memoryHandle) {
|
||||
std::lock_guard<std::mutex> lock(asyncThreadMutex);
|
||||
auto bindInfo = getClientConnection(clientHandle)->vmToContextStateSaveAreaBindInfo.find(memoryHandle);
|
||||
if (bindInfo == getClientConnection(clientHandle)->vmToContextStateSaveAreaBindInfo.end()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return bindInfo->second.gpuVa;
|
||||
}
|
||||
|
||||
size_t DebugSessionLinux::getContextStateSaveAreaSize(uint64_t memoryHandle) {
|
||||
std::lock_guard<std::mutex> lock(asyncThreadMutex);
|
||||
if (getClientConnection(clientHandle)->contextStateSaveAreaSize != 0) {
|
||||
return getClientConnection(clientHandle)->contextStateSaveAreaSize;
|
||||
}
|
||||
|
||||
auto bindInfo = getClientConnection(clientHandle)->vmToContextStateSaveAreaBindInfo.find(memoryHandle);
|
||||
if (bindInfo == getClientConnection(clientHandle)->vmToContextStateSaveAreaBindInfo.end()) {
|
||||
return 0;
|
||||
}
|
||||
getClientConnection(clientHandle)->contextStateSaveAreaSize = static_cast<size_t>(bindInfo->second.size);
|
||||
return getClientConnection(clientHandle)->contextStateSaveAreaSize;
|
||||
}
|
||||
|
||||
void DebugSessionLinux::readStateSaveAreaHeader() {
|
||||
if (clientHandle == invalidClientHandle) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint64_t vm = 0;
|
||||
uint64_t gpuVa = 0;
|
||||
size_t totalSize = 0;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(asyncThreadMutex);
|
||||
if (getClientConnection(clientHandle)->vmToContextStateSaveAreaBindInfo.size() > 0) {
|
||||
vm = getClientConnection(clientHandle)->vmToContextStateSaveAreaBindInfo.begin()->first;
|
||||
gpuVa = getClientConnection(clientHandle)->vmToContextStateSaveAreaBindInfo.begin()->second.gpuVa;
|
||||
totalSize = getClientConnection(clientHandle)->vmToContextStateSaveAreaBindInfo.begin()->second.size;
|
||||
}
|
||||
}
|
||||
|
||||
if (gpuVa > 0) {
|
||||
auto headerSize = sizeof(SIP::StateSaveAreaHeader);
|
||||
|
||||
if (totalSize < headerSize) {
|
||||
PRINT_DEBUGGER_ERROR_LOG("Context State Save Area size incorrect\n", "");
|
||||
return;
|
||||
} else {
|
||||
validateAndSetStateSaveAreaHeader(vm, gpuVa);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace L0
|
||||
|
||||
@@ -85,6 +85,13 @@ struct DebugSessionLinux : DebugSessionImp {
|
||||
|
||||
ze_result_t readMemory(ze_device_thread_t thread, const zet_debug_memory_space_desc_t *desc, size_t size, void *buffer) override;
|
||||
ze_result_t writeMemory(ze_device_thread_t thread, const zet_debug_memory_space_desc_t *desc, size_t size, const void *buffer) override;
|
||||
bool readModuleDebugArea() override;
|
||||
ze_result_t readSbaBuffer(EuThread::ThreadId, NEO::SbaTrackedAddresses &sbaBuffer) override;
|
||||
uint64_t getContextStateSaveAreaGpuVa(uint64_t memoryHandle) override;
|
||||
size_t getContextStateSaveAreaSize(uint64_t memoryHandle) override;
|
||||
virtual uint64_t getSbaBufferGpuVa(uint64_t memoryHandle);
|
||||
void readStateSaveAreaHeader() override;
|
||||
|
||||
struct BindInfo {
|
||||
uint64_t gpuVa = 0;
|
||||
uint64_t size = 0;
|
||||
|
||||
@@ -571,51 +571,6 @@ bool DebugSessionLinuxi915::checkAllEventsCollected() {
|
||||
return allEventsCollected;
|
||||
}
|
||||
|
||||
bool DebugSessionLinuxi915::readModuleDebugArea() {
|
||||
auto vm = clientHandleToConnection[clientHandle]->vmToModuleDebugAreaBindInfo.begin()->first;
|
||||
auto gpuVa = clientHandleToConnection[clientHandle]->vmToModuleDebugAreaBindInfo.begin()->second.gpuVa;
|
||||
|
||||
memset(this->debugArea.magic, 0, sizeof(this->debugArea.magic));
|
||||
auto retVal = readGpuMemory(vm, reinterpret_cast<char *>(&this->debugArea), sizeof(this->debugArea), gpuVa);
|
||||
|
||||
if (retVal != ZE_RESULT_SUCCESS || strncmp(this->debugArea.magic, "dbgarea", sizeof(NEO::DebugAreaHeader::magic)) != 0) {
|
||||
PRINT_DEBUGGER_ERROR_LOG("Reading Module Debug Area failed, error = %d\n", retVal);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void DebugSessionLinuxi915::readStateSaveAreaHeader() {
|
||||
if (clientHandle == invalidClientHandle) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint64_t vm = 0;
|
||||
uint64_t gpuVa = 0;
|
||||
size_t totalSize = 0;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(asyncThreadMutex);
|
||||
if (clientHandleToConnection[clientHandle]->vmToContextStateSaveAreaBindInfo.size() > 0) {
|
||||
vm = clientHandleToConnection[clientHandle]->vmToContextStateSaveAreaBindInfo.begin()->first;
|
||||
gpuVa = clientHandleToConnection[clientHandle]->vmToContextStateSaveAreaBindInfo.begin()->second.gpuVa;
|
||||
totalSize = clientHandleToConnection[clientHandle]->vmToContextStateSaveAreaBindInfo.begin()->second.size;
|
||||
}
|
||||
}
|
||||
|
||||
if (gpuVa > 0) {
|
||||
auto headerSize = sizeof(SIP::StateSaveAreaHeader);
|
||||
|
||||
if (totalSize < headerSize) {
|
||||
PRINT_DEBUGGER_ERROR_LOG("Context State Save Area size incorrect\n", "");
|
||||
return;
|
||||
} else {
|
||||
validateAndSetStateSaveAreaHeader(vm, gpuVa);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ze_result_t DebugSessionLinuxi915::readEventImp(prelim_drm_i915_debug_event *drmDebugEvent) {
|
||||
auto ret = ioctl(PRELIM_I915_DEBUG_IOCTL_READ_EVENT, drmDebugEvent);
|
||||
if (ret != 0) {
|
||||
@@ -1488,55 +1443,6 @@ ze_result_t DebugSessionLinuxi915::acknowledgeEvent(const zet_debug_event_t *eve
|
||||
return ZE_RESULT_ERROR_UNINITIALIZED;
|
||||
}
|
||||
|
||||
ze_result_t DebugSessionLinuxi915::readSbaBuffer(EuThread::ThreadId threadId, NEO::SbaTrackedAddresses &sbaBuffer) {
|
||||
auto vmHandle = allThreads[threadId]->getMemoryHandle();
|
||||
|
||||
if (vmHandle == invalidHandle) {
|
||||
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
auto gpuVa = getSbaBufferGpuVa(vmHandle);
|
||||
if (gpuVa == 0) {
|
||||
return ZE_RESULT_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
return readGpuMemory(vmHandle, reinterpret_cast<char *>(&sbaBuffer), sizeof(sbaBuffer), gpuVa);
|
||||
}
|
||||
|
||||
uint64_t DebugSessionLinuxi915::getSbaBufferGpuVa(uint64_t memoryHandle) {
|
||||
std::lock_guard<std::mutex> lock(asyncThreadMutex);
|
||||
auto bindInfo = clientHandleToConnection[clientHandle]->vmToStateBaseAreaBindInfo.find(memoryHandle);
|
||||
if (bindInfo == clientHandleToConnection[clientHandle]->vmToStateBaseAreaBindInfo.end()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return bindInfo->second.gpuVa;
|
||||
}
|
||||
|
||||
uint64_t DebugSessionLinuxi915::getContextStateSaveAreaGpuVa(uint64_t memoryHandle) {
|
||||
std::lock_guard<std::mutex> lock(asyncThreadMutex);
|
||||
auto bindInfo = clientHandleToConnection[clientHandle]->vmToContextStateSaveAreaBindInfo.find(memoryHandle);
|
||||
if (bindInfo == clientHandleToConnection[clientHandle]->vmToContextStateSaveAreaBindInfo.end()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return bindInfo->second.gpuVa;
|
||||
}
|
||||
|
||||
size_t DebugSessionLinuxi915::getContextStateSaveAreaSize(uint64_t memoryHandle) {
|
||||
std::lock_guard<std::mutex> lock(asyncThreadMutex);
|
||||
if (clientHandleToConnection[clientHandle]->contextStateSaveAreaSize != 0) {
|
||||
return clientHandleToConnection[clientHandle]->contextStateSaveAreaSize;
|
||||
}
|
||||
|
||||
auto bindInfo = clientHandleToConnection[clientHandle]->vmToContextStateSaveAreaBindInfo.find(memoryHandle);
|
||||
if (bindInfo == clientHandleToConnection[clientHandle]->vmToContextStateSaveAreaBindInfo.end()) {
|
||||
return 0;
|
||||
}
|
||||
clientHandleToConnection[clientHandle]->contextStateSaveAreaSize = static_cast<size_t>(bindInfo->second.size);
|
||||
return clientHandleToConnection[clientHandle]->contextStateSaveAreaSize;
|
||||
}
|
||||
|
||||
void TileDebugSessionLinuxi915::readStateSaveAreaHeader() {
|
||||
|
||||
const auto header = rootDebugSession->getStateSaveAreaHeader();
|
||||
|
||||
@@ -173,15 +173,9 @@ struct DebugSessionLinuxi915 : DebugSessionLinux {
|
||||
void extractUuidData(uint64_t client, const UuidData &uuidData);
|
||||
uint64_t extractVaFromUuidString(std::string &uuid);
|
||||
|
||||
bool readModuleDebugArea() override;
|
||||
ze_result_t readSbaBuffer(EuThread::ThreadId, NEO::SbaTrackedAddresses &sbaBuffer) override;
|
||||
void readStateSaveAreaHeader() override;
|
||||
int openVmFd(uint64_t vmHandle, bool readOnly) override;
|
||||
|
||||
int threadControl(const std::vector<EuThread::ThreadId> &threads, uint32_t tile, ThreadControlCmd threadCmd, std::unique_ptr<uint8_t[]> &bitmask, size_t &bitmaskSize) override;
|
||||
uint64_t getContextStateSaveAreaGpuVa(uint64_t memoryHandle) override;
|
||||
size_t getContextStateSaveAreaSize(uint64_t memoryHandle) override;
|
||||
virtual uint64_t getSbaBufferGpuVa(uint64_t memoryHandle);
|
||||
void printContextVms();
|
||||
|
||||
bool isTileWithinDeviceBitfield(uint32_t tileIndex) {
|
||||
|
||||
@@ -83,16 +83,6 @@ struct DebugSessionLinuxXe : DebugSessionLinux {
|
||||
static void *asyncThreadFunction(void *arg);
|
||||
void handleEventsAsync();
|
||||
|
||||
bool readModuleDebugArea() override {
|
||||
UNRECOVERABLE_IF(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
ze_result_t readSbaBuffer(EuThread::ThreadId threadId, NEO::SbaTrackedAddresses &sbaBuffer) override {
|
||||
UNRECOVERABLE_IF(true);
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
void cleanRootSessionAfterDetach(uint32_t deviceIndex) override {
|
||||
UNRECOVERABLE_IF(true);
|
||||
}
|
||||
@@ -114,16 +104,6 @@ struct DebugSessionLinuxXe : DebugSessionLinux {
|
||||
UNRECOVERABLE_IF(true);
|
||||
}
|
||||
|
||||
uint64_t getContextStateSaveAreaGpuVa(uint64_t memoryHandle) override {
|
||||
UNRECOVERABLE_IF(true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t getContextStateSaveAreaSize(uint64_t memoryHandle) override {
|
||||
UNRECOVERABLE_IF(true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void attachTile() override {
|
||||
UNRECOVERABLE_IF(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user