Skip to content

Commit c96c1b0

Browse files
Pass info about system routine in module debug area
Resolves: NEO-6097 Signed-off-by: Mateusz Hoppe <[email protected]>
1 parent 1d1a847 commit c96c1b0

File tree

6 files changed

+83
-0
lines changed

6 files changed

+83
-0
lines changed

level_zero/core/source/debugger/debugger_l0.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ void DebuggerL0::initialize() {
6060
device->getDeviceBitfield()};
6161
moduleDebugArea = device->getMemoryManager()->allocateGraphicsMemoryWithProperties(properties);
6262

63+
bool bindlessSip = NEO::DebugManager.flags.UseBindlessDebugSip.get();
64+
6365
DebugAreaHeader debugArea = {};
66+
debugArea.reserved1 = bindlessSip ? 1 : 0;
6467
debugArea.size = sizeof(DebugAreaHeader);
6568
debugArea.pgsize = 1;
6669
debugArea.isShared = moduleDebugArea->storageInfo.getNumBanks() == 1;

level_zero/core/test/unit_tests/sources/debugger/test_l0_debugger.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,46 @@ HWTEST_F(L0DebuggerTest, givenDebuggerWhenCreatedThenModuleHeapDebugAreaIsCreate
12981298
neoDevice->getMemoryManager()->freeGraphicsMemory(allocation);
12991299
}
13001300

1301+
HWTEST_F(L0DebuggerTest, givenBindlessSipWhenModuleHeapDebugAreaIsCreatedThenReservedFieldIsSet) {
1302+
DebugManagerStateRestore restorer;
1303+
NEO::DebugManager.flags.UseBindlessDebugSip.set(1);
1304+
1305+
auto mockBlitMemoryToAllocation = [](const NEO::Device &device, NEO::GraphicsAllocation *memory, size_t offset, const void *hostPtr,
1306+
Vec3<size_t> size) -> NEO::BlitOperationResult {
1307+
memcpy(memory->getUnderlyingBuffer(), hostPtr, size.x);
1308+
return BlitOperationResult::Success;
1309+
};
1310+
VariableBackup<NEO::BlitHelperFunctions::BlitMemoryToAllocationFunc> blitMemoryToAllocationFuncBackup(
1311+
&NEO::BlitHelperFunctions::blitMemoryToAllocation, mockBlitMemoryToAllocation);
1312+
1313+
memoryOperationsHandler->makeResidentCalledCount = 0;
1314+
auto debugger = std::make_unique<MockDebuggerL0Hw<FamilyType>>(neoDevice);
1315+
auto debugArea = debugger->getModuleDebugArea();
1316+
1317+
DebugAreaHeader *header = reinterpret_cast<DebugAreaHeader *>(debugArea->getUnderlyingBuffer());
1318+
EXPECT_EQ(1u, header->reserved1);
1319+
}
1320+
1321+
HWTEST_F(L0DebuggerTest, givenBindfulSipWhenModuleHeapDebugAreaIsCreatedThenReservedFieldIsNotSet) {
1322+
DebugManagerStateRestore restorer;
1323+
NEO::DebugManager.flags.UseBindlessDebugSip.set(0);
1324+
1325+
auto mockBlitMemoryToAllocation = [](const NEO::Device &device, NEO::GraphicsAllocation *memory, size_t offset, const void *hostPtr,
1326+
Vec3<size_t> size) -> NEO::BlitOperationResult {
1327+
memcpy(memory->getUnderlyingBuffer(), hostPtr, size.x);
1328+
return BlitOperationResult::Success;
1329+
};
1330+
VariableBackup<NEO::BlitHelperFunctions::BlitMemoryToAllocationFunc> blitMemoryToAllocationFuncBackup(
1331+
&NEO::BlitHelperFunctions::blitMemoryToAllocation, mockBlitMemoryToAllocation);
1332+
1333+
memoryOperationsHandler->makeResidentCalledCount = 0;
1334+
auto debugger = std::make_unique<MockDebuggerL0Hw<FamilyType>>(neoDevice);
1335+
auto debugArea = debugger->getModuleDebugArea();
1336+
1337+
DebugAreaHeader *header = reinterpret_cast<DebugAreaHeader *>(debugArea->getUnderlyingBuffer());
1338+
EXPECT_EQ(0u, header->reserved1);
1339+
}
1340+
13011341
TEST(Debugger, givenNonLegacyDebuggerWhenInitializingDeviceCapsThenUnrecoverableIsCalled) {
13021342
class MockDebugger : public NEO::Debugger {
13031343
public:

level_zero/tools/source/debug/debug_session.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,11 @@ std::vector<ze_device_thread_t> RootDebugSession::getSingleThreads(ze_device_thr
9696
return threads;
9797
}
9898

99+
bool RootDebugSession::isBindlessSystemRoutine() {
100+
if (debugArea.reserved1 &= 1) {
101+
return true;
102+
}
103+
return false;
104+
}
105+
99106
} // namespace L0

level_zero/tools/source/debug/debug_session.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ struct DebugSession : _zet_debug_session_handle_t {
4747
DebugSession(const zet_debug_config_t &config, Device *device) : connectedDevice(device){};
4848
virtual void startAsyncThread() = 0;
4949

50+
virtual bool isBindlessSystemRoutine() = 0;
51+
5052
Device *connectedDevice = nullptr;
5153
};
5254

@@ -59,6 +61,7 @@ struct RootDebugSession : DebugSession {
5961

6062
virtual bool readModuleDebugArea() = 0;
6163
std::vector<ze_device_thread_t> getSingleThreads(ze_device_thread_t physicalThread, const NEO::HardwareInfo &hwInfo);
64+
bool isBindlessSystemRoutine() override;
6265

6366
DebugAreaHeader debugArea;
6467

level_zero/tools/test/unit_tests/sources/debug/debug_session_tests.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,5 +137,33 @@ TEST(RootDebugSession, givenAllSlicesWhenGettingSingleThreadsThenCorrectThreadsA
137137
}
138138
}
139139

140+
TEST(RootDebugSession, givenBindlessSystemRoutineWhenQueryingIsBindlessThenTrueReturned) {
141+
zet_debug_config_t config = {};
142+
config.pid = 0x1234;
143+
144+
auto hwInfo = *NEO::defaultHwInfo.get();
145+
NEO::Device *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
146+
Mock<L0::DeviceImp> deviceImp(neoDevice, neoDevice->getExecutionEnvironment());
147+
auto debugSession = std::make_unique<DebugSessionMock>(config, &deviceImp);
148+
149+
debugSession->debugArea.reserved1 = 1u;
150+
151+
EXPECT_TRUE(debugSession->isBindlessSystemRoutine());
152+
}
153+
154+
TEST(RootDebugSession, givenBindfulSystemRoutineWhenQueryingIsBindlessThenFalseReturned) {
155+
zet_debug_config_t config = {};
156+
config.pid = 0x1234;
157+
158+
auto hwInfo = *NEO::defaultHwInfo.get();
159+
NEO::Device *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, 0));
160+
Mock<L0::DeviceImp> deviceImp(neoDevice, neoDevice->getExecutionEnvironment());
161+
auto debugSession = std::make_unique<DebugSessionMock>(config, &deviceImp);
162+
163+
debugSession->debugArea.reserved1 = 0u;
164+
165+
EXPECT_FALSE(debugSession->isBindlessSystemRoutine());
166+
}
167+
140168
} // namespace ult
141169
} // namespace L0

level_zero/tools/test/unit_tests/sources/debug/mock_debug_session.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ class OsInterfaceWithDebugAttach : public NEO::OSInterface {
2424
};
2525

2626
struct DebugSessionMock : public L0::RootDebugSession {
27+
using L0::RootDebugSession::debugArea;
2728
using L0::RootDebugSession::getSingleThreads;
29+
using L0::RootDebugSession::isBindlessSystemRoutine;
2830

2931
DebugSessionMock(const zet_debug_config_t &config, L0::Device *device) : RootDebugSession(config, device), config(config){};
3032
bool closeConnection() override { return true; }

0 commit comments

Comments
 (0)