diff --git a/level_zero/core/source/debugger/debugger_l0.cpp b/level_zero/core/source/debugger/debugger_l0.cpp index 9aaeaefd89..6020106c78 100644 --- a/level_zero/core/source/debugger/debugger_l0.cpp +++ b/level_zero/core/source/debugger/debugger_l0.cpp @@ -60,7 +60,10 @@ void DebuggerL0::initialize() { device->getDeviceBitfield()}; moduleDebugArea = device->getMemoryManager()->allocateGraphicsMemoryWithProperties(properties); + bool bindlessSip = NEO::DebugManager.flags.UseBindlessDebugSip.get(); + DebugAreaHeader debugArea = {}; + debugArea.reserved1 = bindlessSip ? 1 : 0; debugArea.size = sizeof(DebugAreaHeader); debugArea.pgsize = 1; debugArea.isShared = moduleDebugArea->storageInfo.getNumBanks() == 1; diff --git a/level_zero/core/test/unit_tests/sources/debugger/test_l0_debugger.cpp b/level_zero/core/test/unit_tests/sources/debugger/test_l0_debugger.cpp index a8377fc63f..5468d41df0 100644 --- a/level_zero/core/test/unit_tests/sources/debugger/test_l0_debugger.cpp +++ b/level_zero/core/test/unit_tests/sources/debugger/test_l0_debugger.cpp @@ -1298,6 +1298,46 @@ HWTEST_F(L0DebuggerTest, givenDebuggerWhenCreatedThenModuleHeapDebugAreaIsCreate neoDevice->getMemoryManager()->freeGraphicsMemory(allocation); } +HWTEST_F(L0DebuggerTest, givenBindlessSipWhenModuleHeapDebugAreaIsCreatedThenReservedFieldIsSet) { + DebugManagerStateRestore restorer; + NEO::DebugManager.flags.UseBindlessDebugSip.set(1); + + auto mockBlitMemoryToAllocation = [](const NEO::Device &device, NEO::GraphicsAllocation *memory, size_t offset, const void *hostPtr, + Vec3 size) -> NEO::BlitOperationResult { + memcpy(memory->getUnderlyingBuffer(), hostPtr, size.x); + return BlitOperationResult::Success; + }; + VariableBackup blitMemoryToAllocationFuncBackup( + &NEO::BlitHelperFunctions::blitMemoryToAllocation, mockBlitMemoryToAllocation); + + memoryOperationsHandler->makeResidentCalledCount = 0; + auto debugger = std::make_unique>(neoDevice); + auto debugArea = debugger->getModuleDebugArea(); + + DebugAreaHeader *header = reinterpret_cast(debugArea->getUnderlyingBuffer()); + EXPECT_EQ(1u, header->reserved1); +} + +HWTEST_F(L0DebuggerTest, givenBindfulSipWhenModuleHeapDebugAreaIsCreatedThenReservedFieldIsNotSet) { + DebugManagerStateRestore restorer; + NEO::DebugManager.flags.UseBindlessDebugSip.set(0); + + auto mockBlitMemoryToAllocation = [](const NEO::Device &device, NEO::GraphicsAllocation *memory, size_t offset, const void *hostPtr, + Vec3 size) -> NEO::BlitOperationResult { + memcpy(memory->getUnderlyingBuffer(), hostPtr, size.x); + return BlitOperationResult::Success; + }; + VariableBackup blitMemoryToAllocationFuncBackup( + &NEO::BlitHelperFunctions::blitMemoryToAllocation, mockBlitMemoryToAllocation); + + memoryOperationsHandler->makeResidentCalledCount = 0; + auto debugger = std::make_unique>(neoDevice); + auto debugArea = debugger->getModuleDebugArea(); + + DebugAreaHeader *header = reinterpret_cast(debugArea->getUnderlyingBuffer()); + EXPECT_EQ(0u, header->reserved1); +} + TEST(Debugger, givenNonLegacyDebuggerWhenInitializingDeviceCapsThenUnrecoverableIsCalled) { class MockDebugger : public NEO::Debugger { public: diff --git a/level_zero/tools/source/debug/debug_session.cpp b/level_zero/tools/source/debug/debug_session.cpp index 9cc9acb987..d1cfab1c18 100644 --- a/level_zero/tools/source/debug/debug_session.cpp +++ b/level_zero/tools/source/debug/debug_session.cpp @@ -96,4 +96,11 @@ std::vector RootDebugSession::getSingleThreads(ze_device_thr return threads; } +bool RootDebugSession::isBindlessSystemRoutine() { + if (debugArea.reserved1 &= 1) { + return true; + } + return false; +} + } // namespace L0 diff --git a/level_zero/tools/source/debug/debug_session.h b/level_zero/tools/source/debug/debug_session.h index ee1c999256..9115786d82 100644 --- a/level_zero/tools/source/debug/debug_session.h +++ b/level_zero/tools/source/debug/debug_session.h @@ -47,6 +47,8 @@ struct DebugSession : _zet_debug_session_handle_t { DebugSession(const zet_debug_config_t &config, Device *device) : connectedDevice(device){}; virtual void startAsyncThread() = 0; + virtual bool isBindlessSystemRoutine() = 0; + Device *connectedDevice = nullptr; }; @@ -59,6 +61,7 @@ struct RootDebugSession : DebugSession { virtual bool readModuleDebugArea() = 0; std::vector getSingleThreads(ze_device_thread_t physicalThread, const NEO::HardwareInfo &hwInfo); + bool isBindlessSystemRoutine() override; DebugAreaHeader debugArea; diff --git a/level_zero/tools/test/unit_tests/sources/debug/debug_session_tests.cpp b/level_zero/tools/test/unit_tests/sources/debug/debug_session_tests.cpp index 244b01b1f0..79261a9142 100644 --- a/level_zero/tools/test/unit_tests/sources/debug/debug_session_tests.cpp +++ b/level_zero/tools/test/unit_tests/sources/debug/debug_session_tests.cpp @@ -137,5 +137,33 @@ TEST(RootDebugSession, givenAllSlicesWhenGettingSingleThreadsThenCorrectThreadsA } } +TEST(RootDebugSession, givenBindlessSystemRoutineWhenQueryingIsBindlessThenTrueReturned) { + zet_debug_config_t config = {}; + config.pid = 0x1234; + + auto hwInfo = *NEO::defaultHwInfo.get(); + NEO::Device *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment(&hwInfo, 0)); + Mock deviceImp(neoDevice, neoDevice->getExecutionEnvironment()); + auto debugSession = std::make_unique(config, &deviceImp); + + debugSession->debugArea.reserved1 = 1u; + + EXPECT_TRUE(debugSession->isBindlessSystemRoutine()); +} + +TEST(RootDebugSession, givenBindfulSystemRoutineWhenQueryingIsBindlessThenFalseReturned) { + zet_debug_config_t config = {}; + config.pid = 0x1234; + + auto hwInfo = *NEO::defaultHwInfo.get(); + NEO::Device *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment(&hwInfo, 0)); + Mock deviceImp(neoDevice, neoDevice->getExecutionEnvironment()); + auto debugSession = std::make_unique(config, &deviceImp); + + debugSession->debugArea.reserved1 = 0u; + + EXPECT_FALSE(debugSession->isBindlessSystemRoutine()); +} + } // namespace ult } // namespace L0 diff --git a/level_zero/tools/test/unit_tests/sources/debug/mock_debug_session.h b/level_zero/tools/test/unit_tests/sources/debug/mock_debug_session.h index 6cb318899b..ffe3a0816f 100644 --- a/level_zero/tools/test/unit_tests/sources/debug/mock_debug_session.h +++ b/level_zero/tools/test/unit_tests/sources/debug/mock_debug_session.h @@ -24,7 +24,9 @@ class OsInterfaceWithDebugAttach : public NEO::OSInterface { }; struct DebugSessionMock : public L0::RootDebugSession { + using L0::RootDebugSession::debugArea; using L0::RootDebugSession::getSingleThreads; + using L0::RootDebugSession::isBindlessSystemRoutine; DebugSessionMock(const zet_debug_config_t &config, L0::Device *device) : RootDebugSession(config, device), config(config){}; bool closeConnection() override { return true; }