mirror of
https://github.com/intel/compute-runtime.git
synced 2025-11-15 10:14:56 +08:00
Debugger L0 Win - Generate Proc Entry/Exit events
Related-To: NEO-7117 Signed-off-by: Jitendra Sharma <jitendra.sharma@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
b450d3c20b
commit
4a8a93af96
@@ -17,7 +17,9 @@
|
||||
#include "shared/test/common/test_macros/hw_test.h"
|
||||
|
||||
#include "level_zero/core/source/device/device.h"
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h"
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h"
|
||||
#include "level_zero/core/test/unit_tests/sources/debugger/l0_debugger_fixture.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
@@ -76,5 +78,25 @@ TEST_F(L0DebuggerWindowsTest, givenWindowsOSWhenL0DebuggerIsCreatedAddressModeIs
|
||||
EXPECT_TRUE(device->getL0Debugger()->getSingleAddressSpaceSbaTracking());
|
||||
}
|
||||
|
||||
HWTEST_F(L0DebuggerWindowsTest, givenDebuggingEnabledAndCommandQueuesAreCreatedAndDestroyedThanDebuggerL0IsNotified) {
|
||||
auto debuggerL0Hw = static_cast<MockDebuggerL0Hw<FamilyType> *>(device->getL0Debugger());
|
||||
|
||||
neoDevice->getDefaultEngine().commandStreamReceiver->getOsContext().ensureContextInitialized();
|
||||
|
||||
ze_command_queue_desc_t queueDesc = {};
|
||||
ze_result_t returnValue;
|
||||
auto commandQueue1 = CommandQueue::create(productFamily, device, neoDevice->getDefaultEngine().commandStreamReceiver, &queueDesc, false, false, returnValue);
|
||||
EXPECT_EQ(1u, debuggerL0Hw->commandQueueCreatedCount);
|
||||
|
||||
auto commandQueue2 = CommandQueue::create(productFamily, device, neoDevice->getDefaultEngine().commandStreamReceiver, &queueDesc, false, false, returnValue);
|
||||
EXPECT_EQ(2u, debuggerL0Hw->commandQueueCreatedCount);
|
||||
|
||||
commandQueue1->destroy();
|
||||
EXPECT_EQ(1u, debuggerL0Hw->commandQueueDestroyedCount);
|
||||
|
||||
commandQueue2->destroy();
|
||||
EXPECT_EQ(2u, debuggerL0Hw->commandQueueDestroyedCount);
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "level_zero/tools/source/debug/windows/debug_session.h"
|
||||
|
||||
#include "shared/source/helpers/register_offsets.h"
|
||||
#include "shared/source/os_interface/windows/wddm_debug.h"
|
||||
|
||||
#include "common/StateSaveAreaHeader.h"
|
||||
|
||||
@@ -268,12 +269,20 @@ ze_result_t DebugSessionWindows::readAllocationDebugData(uint32_t seqNo, uint64_
|
||||
|
||||
ze_result_t DebugSessionWindows::handleCreateDebugDataEvent(DBGUMD_READ_EVENT_CREATE_DEBUG_DATA_PARAMS &createDebugDataParams) {
|
||||
PRINT_DEBUGGER_INFO_LOG("DBGUMD_READ_EVENT_CREATE_DEBUG_DATA_PARAMS:. Type: %d BufferPtr: 0x%ullx DataSize: 0x%ullx\n", createDebugDataParams.DebugDataType, createDebugDataParams.DataBufferPtr, createDebugDataParams.DataSize);
|
||||
std::unique_lock<std::mutex> lock(asyncThreadMutex);
|
||||
if (createDebugDataParams.DebugDataType == ELF_BINARY) {
|
||||
std::unique_lock<std::mutex> lock(asyncThreadMutex);
|
||||
ElfRange elf;
|
||||
elf.startVA = createDebugDataParams.DataBufferPtr;
|
||||
elf.endVA = elf.startVA + createDebugDataParams.DataSize;
|
||||
allElfs.push_back(elf);
|
||||
} else if (createDebugDataParams.DebugDataType == static_cast<uint32_t>(NEO::DebugDataType::CMD_QUEUE_CREATED)) {
|
||||
zet_debug_event_t debugEvent = {};
|
||||
debugEvent.type = ZET_DEBUG_EVENT_TYPE_PROCESS_ENTRY;
|
||||
pushApiEvent(debugEvent);
|
||||
} else if (createDebugDataParams.DebugDataType == static_cast<uint32_t>(NEO::DebugDataType::CMD_QUEUE_DESTROYED)) {
|
||||
zet_debug_event_t debugEvent = {};
|
||||
debugEvent.type = ZET_DEBUG_EVENT_TYPE_PROCESS_EXIT;
|
||||
pushApiEvent(debugEvent);
|
||||
}
|
||||
|
||||
return ZE_RESULT_SUCCESS;
|
||||
@@ -311,10 +320,6 @@ ze_result_t DebugSessionWindows::translateEscapeReturnStatusToZeResult(uint32_t
|
||||
}
|
||||
}
|
||||
|
||||
ze_result_t DebugSessionWindows::readEvent(uint64_t timeout, zet_debug_event_t *event) {
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
}
|
||||
|
||||
ze_result_t DebugSessionWindows::readElfSpace(const zet_debug_memory_space_desc_t *desc, size_t size, void *buffer) {
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ struct DebugSessionWindows : DebugSessionImp {
|
||||
ze_result_t initialize() override;
|
||||
bool closeConnection() override;
|
||||
|
||||
ze_result_t readEvent(uint64_t timeout, zet_debug_event_t *event) override;
|
||||
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;
|
||||
ze_result_t acknowledgeEvent(const zet_debug_event_t *event) override;
|
||||
@@ -38,6 +37,12 @@ struct DebugSessionWindows : DebugSessionImp {
|
||||
|
||||
protected:
|
||||
ze_result_t resumeImp(const std::vector<EuThread::ThreadId> &threads, uint32_t deviceIndex) override;
|
||||
void pushApiEvent(zet_debug_event_t &debugEvent) {
|
||||
std::unique_lock<std::mutex> lock(asyncThreadMutex);
|
||||
apiEvents.push(debugEvent);
|
||||
apiEventCondition.notify_all();
|
||||
}
|
||||
|
||||
ze_result_t interruptImp(uint32_t deviceIndex) override;
|
||||
|
||||
ze_result_t readGpuMemory(uint64_t memoryHandle, char *output, size_t size, uint64_t gpuVa) override;
|
||||
|
||||
@@ -7,11 +7,13 @@
|
||||
|
||||
#include "shared/source/built_ins/sip.h"
|
||||
#include "shared/source/os_interface/windows/wddm_allocation.h"
|
||||
#include "shared/source/os_interface/windows/wddm_debug.h"
|
||||
#include "shared/test/common/mocks/mock_sip.h"
|
||||
#include "shared/test/common/mocks/windows/mock_wddm_eudebug.h"
|
||||
#include "shared/test/common/test_macros/hw_test.h"
|
||||
|
||||
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
|
||||
#include "level_zero/tools/source/debug/debug_handlers.h"
|
||||
#include "level_zero/tools/source/debug/windows/debug_session.h"
|
||||
|
||||
#include "common/StateSaveAreaHeader.h"
|
||||
@@ -45,6 +47,7 @@ struct MockDebugSessionWindows : DebugSessionWindows {
|
||||
using DebugSessionWindows::stateSaveAreaVA;
|
||||
using DebugSessionWindows::wddm;
|
||||
using DebugSessionWindows::writeGpuMemory;
|
||||
using L0::DebugSessionImp::apiEvents;
|
||||
using L0::DebugSessionImp::getStateSaveAreaHeader;
|
||||
using L0::DebugSessionImp::isValidGpuAddress;
|
||||
|
||||
@@ -482,6 +485,79 @@ TEST_F(DebugApiWindowsTest, givenDebugDataEventTypeWhenReadAndHandleEventCalledT
|
||||
EXPECT_EQ(elf.endVA, 0xa008u);
|
||||
}
|
||||
|
||||
TEST(DebugSessionTest, GivenNullptrEventWhenReadingEventThenErrorNullptrReturned) {
|
||||
zet_debug_config_t config = {};
|
||||
config.pid = 0x1234;
|
||||
|
||||
auto session = std::make_unique<MockDebugSessionWindows>(config, nullptr);
|
||||
ASSERT_NE(nullptr, session);
|
||||
|
||||
auto result = session->readEvent(10, nullptr);
|
||||
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_NULL_POINTER, result);
|
||||
}
|
||||
|
||||
TEST_F(DebugApiWindowsTest, GivenMatchingDebugDataEventsForCommandQueueCreateWhenReadingEventsThenProcessEntryIsReturned) {
|
||||
zet_debug_config_t config = {};
|
||||
config.pid = 0x1234;
|
||||
|
||||
auto session = std::make_unique<MockDebugSessionWindows>(config, device);
|
||||
session->wddm = mockWddm;
|
||||
ASSERT_NE(nullptr, session);
|
||||
|
||||
EXPECT_TRUE(session->apiEvents.empty());
|
||||
mockWddm->numEvents = 1;
|
||||
mockWddm->eventQueue[0].readEventType = DBGUMD_READ_EVENT_CREATE_DEBUG_DATA;
|
||||
mockWddm->eventQueue[0].eventParamsBuffer.eventParamsBuffer.ReadCreateDebugDataParams.DebugDataType = static_cast<uint32_t>(NEO::DebugDataType::CMD_QUEUE_CREATED);
|
||||
mockWddm->eventQueue[0].eventParamsBuffer.eventParamsBuffer.ReadCreateDebugDataParams.DataBufferPtr = 0xa000;
|
||||
mockWddm->eventQueue[0].eventParamsBuffer.eventParamsBuffer.ReadCreateDebugDataParams.DataSize = 8;
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, session->readAndHandleEvent(100));
|
||||
EXPECT_EQ(session->apiEvents.size(), 1u);
|
||||
|
||||
zet_debug_event_t event = {};
|
||||
session->debugHandle = MockDebugSessionWindows::mockDebugHandle;
|
||||
ze_result_t result = zetDebugReadEvent(session->toHandle(), 0, &event);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_EQ(ZET_DEBUG_EVENT_TYPE_PROCESS_ENTRY, event.type);
|
||||
}
|
||||
|
||||
TEST_F(DebugApiWindowsTest, GivenMatchingDebugDataEventsForCommandQueueDestroyWhenReadingEventsThenProcessExitIsReturned) {
|
||||
zet_debug_config_t config = {};
|
||||
config.pid = 0x1234;
|
||||
|
||||
auto session = std::make_unique<MockDebugSessionWindows>(config, device);
|
||||
session->wddm = mockWddm;
|
||||
ASSERT_NE(nullptr, session);
|
||||
|
||||
EXPECT_TRUE(session->apiEvents.empty());
|
||||
mockWddm->numEvents = 1;
|
||||
mockWddm->eventQueue[0].readEventType = DBGUMD_READ_EVENT_CREATE_DEBUG_DATA;
|
||||
mockWddm->eventQueue[0].eventParamsBuffer.eventParamsBuffer.ReadCreateDebugDataParams.DebugDataType = static_cast<uint32_t>(NEO::DebugDataType::CMD_QUEUE_DESTROYED);
|
||||
mockWddm->eventQueue[0].eventParamsBuffer.eventParamsBuffer.ReadCreateDebugDataParams.DataBufferPtr = 0xa000;
|
||||
mockWddm->eventQueue[0].eventParamsBuffer.eventParamsBuffer.ReadCreateDebugDataParams.DataSize = 8;
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, session->readAndHandleEvent(100));
|
||||
EXPECT_EQ(session->apiEvents.size(), 1u);
|
||||
|
||||
zet_debug_event_t event = {};
|
||||
session->debugHandle = MockDebugSessionWindows::mockDebugHandle;
|
||||
ze_result_t result = zetDebugReadEvent(session->toHandle(), 0, &event);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_EQ(ZET_DEBUG_EVENT_TYPE_PROCESS_EXIT, event.type);
|
||||
}
|
||||
|
||||
TEST_F(DebugApiWindowsTest, GivenNoEventsAvailableWhenReadingEventThenResultNotReadyIsReturned) {
|
||||
zet_debug_config_t config = {};
|
||||
config.pid = 0x1234;
|
||||
|
||||
auto session = std::make_unique<MockDebugSessionWindows>(config, device);
|
||||
session->wddm = mockWddm;
|
||||
ASSERT_NE(nullptr, session);
|
||||
|
||||
zet_debug_event_t event = {};
|
||||
session->debugHandle = MockDebugSessionWindows::mockDebugHandle;
|
||||
ze_result_t result = zetDebugReadEvent(session->toHandle(), 0, &event);
|
||||
EXPECT_EQ(result, ZE_RESULT_NOT_READY);
|
||||
}
|
||||
|
||||
TEST_F(DebugApiWindowsTest, givenAllocationEventTypeForStateSaveWhenReadAndHandleEventCalledThenStateSaveIsCaptured) {
|
||||
zet_debug_config_t config = {};
|
||||
config.pid = 0x1234;
|
||||
|
||||
@@ -126,6 +126,7 @@ class DebuggerL0 : public NEO::Debugger, NEO::NonCopyableOrMovableClass {
|
||||
std::atomic<uint32_t> commandQueueCount = 0u;
|
||||
uint32_t uuidL0CommandQueueHandle = 0;
|
||||
bool singleAddressSpaceSbaTracking = false;
|
||||
std::mutex debuggerL0Mutex;
|
||||
};
|
||||
|
||||
using DebugerL0CreateFn = DebuggerL0 *(*)(NEO::Device *device);
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
#include "shared/source/helpers/hw_helper.h"
|
||||
#include "shared/source/kernel/debug_data.h"
|
||||
#include "shared/source/os_interface/windows/wddm/wddm.h"
|
||||
#include "shared/source/os_interface/windows/wddm_debug.h"
|
||||
|
||||
#include "KmEscape.h"
|
||||
|
||||
namespace NEO {
|
||||
bool DebuggerL0::initDebuggingInOs(NEO::OSInterface *osInterface) {
|
||||
@@ -39,10 +42,55 @@ bool DebuggerL0::removeZebinModule(uint32_t moduleHandle) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static NTSTATUS runEscape(NEO::Wddm *wddm, KM_ESCAPE_INFO &escapeInfo) {
|
||||
D3DKMT_ESCAPE escapeCommand = {0};
|
||||
|
||||
escapeInfo.Header.EscapeCode = GFX_ESCAPE_KMD;
|
||||
escapeInfo.Header.Size = sizeof(escapeInfo) - sizeof(escapeInfo.Header);
|
||||
escapeInfo.EscapeOperation = KM_ESCAPE_EUDBG_UMD_CREATE_DEBUG_DATA;
|
||||
|
||||
escapeCommand.Flags.HardwareAccess = 0;
|
||||
escapeCommand.Flags.Reserved = 0;
|
||||
escapeCommand.hAdapter = wddm->getAdapter();
|
||||
escapeCommand.hContext = (D3DKMT_HANDLE)0;
|
||||
escapeCommand.hDevice = wddm->getDeviceHandle();
|
||||
escapeCommand.pPrivateDriverData = &escapeInfo;
|
||||
escapeCommand.PrivateDriverDataSize = sizeof(escapeInfo);
|
||||
escapeCommand.Type = D3DKMT_ESCAPE_DRIVERPRIVATE;
|
||||
|
||||
return wddm->escape(escapeCommand);
|
||||
}
|
||||
|
||||
void DebuggerL0::notifyCommandQueueCreated() {
|
||||
if (device->getRootDeviceEnvironment().osInterface.get() != nullptr) {
|
||||
std::unique_lock<std::mutex> commandQueueCountLock(debuggerL0Mutex);
|
||||
if (++commandQueueCount == 1) {
|
||||
auto pWddm = device->getRootDeviceEnvironment().osInterface->getDriverModel()->as<NEO::Wddm>();
|
||||
int val = 0;
|
||||
KM_ESCAPE_INFO escapeInfo = {0};
|
||||
escapeInfo.KmEuDbgUmdCreateDebugData.DataSize = sizeof(val);
|
||||
escapeInfo.KmEuDbgUmdCreateDebugData.DebugDataType = static_cast<uint32_t>(NEO::DebugDataType::CMD_QUEUE_CREATED);
|
||||
escapeInfo.KmEuDbgUmdCreateDebugData.hElfAddressPtr = reinterpret_cast<uint64_t>(&val);
|
||||
|
||||
runEscape(pWddm, escapeInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DebuggerL0::notifyCommandQueueDestroyed() {
|
||||
if (device->getRootDeviceEnvironment().osInterface.get() != nullptr) {
|
||||
std::unique_lock<std::mutex> commandQueueCountLock(debuggerL0Mutex);
|
||||
if (--commandQueueCount == 0) {
|
||||
auto pWddm = device->getRootDeviceEnvironment().osInterface->getDriverModel()->as<NEO::Wddm>();
|
||||
int val = 0;
|
||||
KM_ESCAPE_INFO escapeInfo = {0};
|
||||
escapeInfo.KmEuDbgUmdCreateDebugData.DataSize = sizeof(val);
|
||||
escapeInfo.KmEuDbgUmdCreateDebugData.DebugDataType = static_cast<uint32_t>(NEO::DebugDataType::CMD_QUEUE_DESTROYED);
|
||||
escapeInfo.KmEuDbgUmdCreateDebugData.hElfAddressPtr = reinterpret_cast<uint64_t>(&val);
|
||||
|
||||
runEscape(pWddm, escapeInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
|
||||
@@ -110,6 +110,7 @@ set(NEO_CORE_OS_INTERFACE_WDDM
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wddm_residency_controller.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wddm_residency_controller.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/windows_defs.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wddm_debug.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/windows_wrapper.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/sys_calls_wrapper.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wddm${BRANCH_DIR_SUFFIX}/init_context_private_data.cpp
|
||||
|
||||
17
shared/source/os_interface/windows/wddm_debug.h
Normal file
17
shared/source/os_interface/windows/wddm_debug.h
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace NEO {
|
||||
enum class DebugDataType : uint32_t {
|
||||
CMD_QUEUE_CREATED = 0x100,
|
||||
CMD_QUEUE_DESTROYED
|
||||
};
|
||||
} // namespace NEO
|
||||
Reference in New Issue
Block a user