From 765b6cc2ed4394104623ab14e6ef80f6d6cac0c3 Mon Sep 17 00:00:00 2001 From: Mateusz Hoppe Date: Thu, 19 Nov 2020 14:11:37 +0000 Subject: [PATCH] Initialize debugging in Os before creating debugger Related-To: NEO-4516 Signed-off-by: Mateusz Hoppe --- .../core/source/debugger/debugger_l0.cpp | 3 +++ level_zero/core/source/debugger/debugger_l0.h | 4 +++- .../debugger/linux/debugger_l0_linux.cpp | 7 +++---- .../debugger/windows/debugger_l0_windows.cpp | 8 +------ .../source/dll/linux/debugger_l0_linux.cpp | 6 +++++- .../unit_tests/mocks/debugger_l0_create.cpp | 4 +++- .../mocks/linux/mock_drm_allocation.h | 7 +++++++ .../linux/drm_memory_manager_tests.cpp | 21 +++++++++++++++++++ .../os_interface/linux/drm_allocation.h | 2 +- .../os_interface/linux/drm_memory_manager.cpp | 2 +- 10 files changed, 48 insertions(+), 16 deletions(-) diff --git a/level_zero/core/source/debugger/debugger_l0.cpp b/level_zero/core/source/debugger/debugger_l0.cpp index 033ce71090..f0d69d3a03 100644 --- a/level_zero/core/source/debugger/debugger_l0.cpp +++ b/level_zero/core/source/debugger/debugger_l0.cpp @@ -23,7 +23,10 @@ DebugerL0CreateFn debuggerL0Factory[IGFX_MAX_CORE] = {}; DebuggerL0::DebuggerL0(NEO::Device *device) : device(device) { isLegacyMode = false; + initialize(); +} +void DebuggerL0::initialize() { auto &engines = device->getEngines(); sbaTrackingGpuVa = device->getMemoryManager()->reserveGpuAddress(MemoryConstants::pageSize, device->getRootDeviceIndex()); diff --git a/level_zero/core/source/debugger/debugger_l0.h b/level_zero/core/source/debugger/debugger_l0.h index f10143e3e9..ff34ed9a2b 100644 --- a/level_zero/core/source/debugger/debugger_l0.h +++ b/level_zero/core/source/debugger/debugger_l0.h @@ -17,6 +17,7 @@ namespace NEO { class Device; class GraphicsAllocation; class LinearStream; +class OSInterface; } // namespace NEO namespace L0 { @@ -80,8 +81,9 @@ class DebuggerL0 : public NEO::Debugger, NEO::NonCopyableOrMovableClass { sba.SurfaceStateBaseAddress != 0 || sba.BindlessSurfaceStateBaseAddress != 0; } + static void initDebuggingInOs(NEO::OSInterface *osInterface); - MOCKABLE_VIRTUAL void registerResourceClasses(); + void initialize(); NEO::Device *device = nullptr; NEO::GraphicsAllocation *sbaAllocation = nullptr; diff --git a/level_zero/core/source/debugger/linux/debugger_l0_linux.cpp b/level_zero/core/source/debugger/linux/debugger_l0_linux.cpp index 467cc7890c..95b172de51 100644 --- a/level_zero/core/source/debugger/linux/debugger_l0_linux.cpp +++ b/level_zero/core/source/debugger/linux/debugger_l0_linux.cpp @@ -13,10 +13,9 @@ #include "level_zero/core/source/debugger/debugger_l0.h" namespace L0 { - -void DebuggerL0::registerResourceClasses() { - if (device->getRootDeviceEnvironment().osInterface.get() != nullptr) { - auto drm = device->getRootDeviceEnvironment().osInterface->get()->getDrm(); +void DebuggerL0::initDebuggingInOs(NEO::OSInterface *osInterface) { + if (osInterface != nullptr) { + auto drm = osInterface->get()->getDrm(); drm->registerResourceClasses(); } } diff --git a/level_zero/core/source/debugger/windows/debugger_l0_windows.cpp b/level_zero/core/source/debugger/windows/debugger_l0_windows.cpp index e520b956c7..ff5ef303dc 100644 --- a/level_zero/core/source/debugger/windows/debugger_l0_windows.cpp +++ b/level_zero/core/source/debugger/windows/debugger_l0_windows.cpp @@ -5,15 +5,9 @@ * */ -#include "shared/source/device/device.h" -#include "shared/source/helpers/hw_helper.h" -#include "shared/source/os_interface/linux/os_interface.h" - #include "level_zero/core/source/debugger/debugger_l0.h" namespace L0 { - -void DebuggerL0::registerResourceClasses() { +void DebuggerL0::initDebuggingInOs(NEO::OSInterface *osInterface) { } - } // namespace L0 \ No newline at end of file diff --git a/level_zero/core/source/dll/linux/debugger_l0_linux.cpp b/level_zero/core/source/dll/linux/debugger_l0_linux.cpp index 5edad2cb8e..f460c3554a 100644 --- a/level_zero/core/source/dll/linux/debugger_l0_linux.cpp +++ b/level_zero/core/source/dll/linux/debugger_l0_linux.cpp @@ -5,12 +5,16 @@ * */ +#include "shared/source/device/device.h" +#include "shared/source/os_interface/linux/drm_neo.h" +#include "shared/source/os_interface/linux/os_interface.h" + #include "level_zero/core/source/debugger/debugger_l0.h" namespace L0 { std::unique_ptr DebuggerL0::create(NEO::Device *device) { + initDebuggingInOs(device->getRootDeviceEnvironment().osInterface.get()); auto debugger = debuggerL0Factory[device->getHardwareInfo().platform.eRenderCoreFamily](device); - debugger->registerResourceClasses(); return std::unique_ptr(debugger); } diff --git a/level_zero/core/test/unit_tests/mocks/debugger_l0_create.cpp b/level_zero/core/test/unit_tests/mocks/debugger_l0_create.cpp index e98374067f..9e0bb028db 100644 --- a/level_zero/core/test/unit_tests/mocks/debugger_l0_create.cpp +++ b/level_zero/core/test/unit_tests/mocks/debugger_l0_create.cpp @@ -5,6 +5,8 @@ * */ +#include "shared/source/device/device.h" + #include "level_zero/core/test/unit_tests/mocks/mock_l0_debugger.h" namespace L0 { @@ -15,8 +17,8 @@ DebugerL0CreateFn mockDebuggerL0HwFactory[IGFX_MAX_CORE]; namespace L0 { std::unique_ptr DebuggerL0::create(NEO::Device *device) { + initDebuggingInOs(device->getRootDeviceEnvironment().osInterface.get()); auto debugger = ult::mockDebuggerL0HwFactory[device->getHardwareInfo().platform.eRenderCoreFamily](device); - debugger->registerResourceClasses(); return std::unique_ptr(debugger); } diff --git a/opencl/test/unit_test/mocks/linux/mock_drm_allocation.h b/opencl/test/unit_test/mocks/linux/mock_drm_allocation.h index bcd02d4102..a3fa4835ab 100644 --- a/opencl/test/unit_test/mocks/linux/mock_drm_allocation.h +++ b/opencl/test/unit_test/mocks/linux/mock_drm_allocation.h @@ -30,6 +30,13 @@ class MockDrmAllocation : public DrmAllocation { MockDrmAllocation(AllocationType allocationType, MemoryPool::Type pool) : DrmAllocation(0, allocationType, nullptr, nullptr, 0, static_cast(0), pool) { } + + void registerBOBindExtHandle(Drm *drm) override { + registerBOBindExtHandleCalled = true; + DrmAllocation::registerBOBindExtHandle(drm); + } + + bool registerBOBindExtHandleCalled = false; }; } // namespace NEO diff --git a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp index b175b39945..f825076b1c 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp @@ -4008,6 +4008,27 @@ TEST(DrmAllocationTest, givenResourceRegistrationNotEnabledWhenRegisteringBindEx EXPECT_EQ(Drm::ResourceClass::MaxSize, drm.registeredClass); } +TEST(DrmMemoryManager, givenTrackedAllocationTypeAndDisabledRegistrationInDrmWhenAllocatingThenRegisterBoBindExtHandleIsNotCalled) { + auto executionEnvironment = std::make_unique(); + executionEnvironment->prepareRootDeviceEnvironments(1u); + executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get()); + auto memoryManager = std::make_unique(false, false, false, *executionEnvironment); + auto mockDrm = new DrmMockResources(*executionEnvironment->rootDeviceEnvironments[0]); + executionEnvironment->rootDeviceEnvironments[0]->osInterface = std::make_unique(); + executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setDrm(mockDrm); + + EXPECT_FALSE(mockDrm->resourceRegistrationEnabled()); + + mockDrm->registeredDataSize = 0; + + MockDrmAllocation allocation(GraphicsAllocation::AllocationType::DEBUG_CONTEXT_SAVE_AREA, MemoryPool::System4KBPages); + + memoryManager->registerAllocationInOs(&allocation); + + EXPECT_FALSE(allocation.registerBOBindExtHandleCalled); + EXPECT_EQ(Drm::ResourceClass::MaxSize, mockDrm->registeredClass); +} + TEST(DrmMemoryManager, givenTrackedAllocationTypeWhenAllocatingThenAllocationIsRegistered) { auto executionEnvironment = std::make_unique(); executionEnvironment->prepareRootDeviceEnvironments(1u); diff --git a/shared/source/os_interface/linux/drm_allocation.h b/shared/source/os_interface/linux/drm_allocation.h index d2850c3a5b..bbffd430dc 100644 --- a/shared/source/os_interface/linux/drm_allocation.h +++ b/shared/source/os_interface/linux/drm_allocation.h @@ -71,7 +71,7 @@ class DrmAllocation : public GraphicsAllocation { void makeBOsResident(OsContext *osContext, uint32_t vmHandleId, std::vector *bufferObjects, bool bind); void bindBO(BufferObject *bo, OsContext *osContext, uint32_t vmHandleId, std::vector *bufferObjects, bool bind); void bindBOs(OsContext *osContext, uint32_t vmHandleId, std::vector *bufferObjects, bool bind); - void registerBOBindExtHandle(Drm *drm); + MOCKABLE_VIRTUAL void registerBOBindExtHandle(Drm *drm); void freeRegisteredBOBindExtHandles(Drm *drm); protected: diff --git a/shared/source/os_interface/linux/drm_memory_manager.cpp b/shared/source/os_interface/linux/drm_memory_manager.cpp index a87b39a0b7..097161f353 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.cpp +++ b/shared/source/os_interface/linux/drm_memory_manager.cpp @@ -968,7 +968,7 @@ void DrmMemoryManager::unregisterAllocation(GraphicsAllocation *allocation) { } void DrmMemoryManager::registerAllocationInOs(GraphicsAllocation *allocation) { - if (allocation) { + if (allocation && getDrm(allocation->getRootDeviceIndex()).resourceRegistrationEnabled()) { auto drmAllocation = static_cast(allocation); drmAllocation->registerBOBindExtHandle(&getDrm(drmAllocation->getRootDeviceIndex())); }