Skip to content

Commit 60d6505

Browse files
L0 debugger - reports process ENTER/EXIT events for zeCommandQueues
- PROCESS_ENTRY - triggered by first zeCommandQueueCreate() - PROCESS_EXIT - triggered by last zeCommandQueueDestroy() Resolves: NEO-6503 Signed-off-by: Igor Venevtsev <[email protected]>
1 parent dbe1779 commit 60d6505

File tree

11 files changed

+105
-4
lines changed

11 files changed

+105
-4
lines changed

level_zero/core/source/cmdqueue/cmdqueue.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ ze_result_t CommandQueueImp::initialize(bool copyOnly, bool isInternal) {
5757
if (!isInternal) {
5858
partitionCount = csr->getActivePartitions();
5959
}
60+
if (NEO::Debugger::isDebugEnabled(internalUsage) && device->getL0Debugger()) {
61+
device->getL0Debugger()->notifyCommandQueueCreated();
62+
}
6063
}
6164
return returnValue;
6265
}

level_zero/core/source/cmdqueue/cmdqueue_hw.inl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ ze_result_t CommandQueueHw<gfxCoreFamily>::destroy() {
5656
commandStream = nullptr;
5757
}
5858
buffers.destroy(this->getDevice());
59+
if (NEO::Debugger::isDebugEnabled(internalUsage) && device->getL0Debugger()) {
60+
device->getL0Debugger()->notifyCommandQueueDestroyed();
61+
}
5962
delete this;
6063
return ZE_RESULT_SUCCESS;
6164
}

level_zero/core/source/debugger/debugger_l0.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ class DebuggerL0 : public NEO::Debugger, NEO::NonCopyableOrMovableClass {
8686
void captureStateBaseAddress(NEO::CommandContainer &container, SbaAddresses sba) override;
8787
void printTrackedAddresses(uint32_t contextId);
8888
MOCKABLE_VIRTUAL void registerElf(NEO::DebugData *debugData, NEO::GraphicsAllocation *isaAllocation);
89+
MOCKABLE_VIRTUAL void notifyCommandQueueCreated();
90+
MOCKABLE_VIRTUAL void notifyCommandQueueDestroyed();
8991

9092
virtual size_t getSbaTrackingCommandsSize(size_t trackedAddressCount) = 0;
9193
virtual void programSbaTrackingCommands(NEO::LinearStream &cmdStream, const SbaAddresses &sba) = 0;
@@ -108,6 +110,8 @@ class DebuggerL0 : public NEO::Debugger, NEO::NonCopyableOrMovableClass {
108110
std::unordered_map<uint32_t, NEO::GraphicsAllocation *> perContextSbaAllocations;
109111
NEO::AddressRange sbaTrackingGpuVa;
110112
NEO::GraphicsAllocation *moduleDebugArea = nullptr;
113+
std::atomic<uint32_t> commandQueueCount = 0u;
114+
uint32_t uuidL0CommandQueueHandle = 0;
111115
};
112116

113117
using DebugerL0CreateFn = DebuggerL0 *(*)(NEO::Device *device);
@@ -132,4 +136,4 @@ struct DebuggerL0PopulateFactory {
132136
}
133137
};
134138

135-
} // namespace L0
139+
} // namespace L0

level_zero/core/source/debugger/linux/debugger_l0_linux.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,23 @@ bool DebuggerL0::removeZebinModule(uint32_t moduleHandle) {
5858
drm->unregisterResource(moduleHandle);
5959
return true;
6060
}
61+
62+
void DebuggerL0::notifyCommandQueueCreated() {
63+
if (device->getRootDeviceEnvironment().osInterface.get() != nullptr) {
64+
if (++commandQueueCount == 1) {
65+
auto drm = device->getRootDeviceEnvironment().osInterface->getDriverModel()->as<NEO::Drm>();
66+
uuidL0CommandQueueHandle = drm->notifyFirstCommandQueueCreated();
67+
}
68+
}
69+
}
70+
71+
void DebuggerL0::notifyCommandQueueDestroyed() {
72+
if (device->getRootDeviceEnvironment().osInterface.get() != nullptr) {
73+
if (--commandQueueCount == 0) {
74+
auto drm = device->getRootDeviceEnvironment().osInterface->getDriverModel()->as<NEO::Drm>();
75+
drm->notifyLastCommandQueueDestroyed(uuidL0CommandQueueHandle);
76+
}
77+
}
78+
}
79+
6180
} // namespace L0

level_zero/core/source/debugger/windows/debugger_l0_windows.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,10 @@ bool DebuggerL0::removeZebinModule(uint32_t moduleHandle) {
2727
return false;
2828
}
2929

30+
void DebuggerL0::notifyCommandQueueCreated() {
31+
}
32+
33+
void DebuggerL0::notifyCommandQueueDestroyed() {
34+
}
35+
3036
} // namespace L0

level_zero/core/test/unit_tests/mocks/mock_l0_debugger.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,28 @@ class MockDebuggerL0Hw : public L0::DebuggerL0Hw<GfxFamily> {
5757
}
5858
return L0::DebuggerL0Hw<GfxFamily>::attachZebinModuleToSegmentAllocations(allocs, moduleHandle);
5959
}
60+
6061
bool removeZebinModule(uint32_t moduleHandle) override {
6162
removedZebinModuleHandle = moduleHandle;
6263
return L0::DebuggerL0Hw<GfxFamily>::removeZebinModule(moduleHandle);
6364
}
6465

66+
void notifyCommandQueueCreated() override {
67+
commandQueueCreatedCount++;
68+
L0::DebuggerL0Hw<GfxFamily>::notifyCommandQueueCreated();
69+
}
70+
71+
void notifyCommandQueueDestroyed() override {
72+
commandQueueDestroyedCount++;
73+
L0::DebuggerL0Hw<GfxFamily>::notifyCommandQueueDestroyed();
74+
}
75+
6576
uint32_t captureStateBaseAddressCount = 0;
6677
uint32_t programSbaTrackingCommandsCount = 0;
6778
uint32_t getSbaTrackingCommandsSizeCount = 0;
6879
uint32_t registerElfCount = 0;
80+
uint32_t commandQueueCreatedCount = 0;
81+
uint32_t commandQueueDestroyedCount = 0;
6982
const char *lastReceivedElf = nullptr;
7083

7184
uint32_t segmentCountWithAttachedModuleHandle = 0;

level_zero/core/test/unit_tests/sources/debugger/linux/test_l0_debugger_linux.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "shared/test/common/mocks/linux/mock_drm_allocation.h"
1313
#include "shared/test/common/test_macros/test.h"
1414

15+
#include "level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h"
1516
#include "level_zero/core/test/unit_tests/sources/debugger/l0_debugger_fixture.h"
1617

1718
#include <algorithm>
@@ -219,5 +220,30 @@ TEST_F(L0DebuggerLinuxTest, givenModuleHandleWhenRemoveZebinModuleIsCalledThenHa
219220
EXPECT_EQ(20u, drmMock->unregisteredHandle);
220221
}
221222

223+
HWTEST_F(L0DebuggerLinuxTest, givenDebuggingEnabledAndCommandQueuesAreCreatedAndDestroyedThanDebuggerL0IsNotified) {
224+
auto debuggerL0Hw = static_cast<MockDebuggerL0Hw<FamilyType> *>(device->getL0Debugger());
225+
226+
neoDevice->getDefaultEngine().commandStreamReceiver->getOsContext().ensureContextInitialized();
227+
drmMock->ioctlCallsCount = 0;
228+
229+
ze_command_queue_desc_t queueDesc = {};
230+
ze_result_t returnValue;
231+
auto commandQueue1 = CommandQueue::create(productFamily, device, neoDevice->getDefaultEngine().commandStreamReceiver, &queueDesc, false, false, returnValue);
232+
EXPECT_EQ(1u, drmMock->ioctlCallsCount);
233+
EXPECT_EQ(1u, debuggerL0Hw->commandQueueCreatedCount);
234+
235+
auto commandQueue2 = CommandQueue::create(productFamily, device, neoDevice->getDefaultEngine().commandStreamReceiver, &queueDesc, false, false, returnValue);
236+
EXPECT_EQ(1u, drmMock->ioctlCallsCount);
237+
EXPECT_EQ(2u, debuggerL0Hw->commandQueueCreatedCount);
238+
239+
commandQueue1->destroy();
240+
EXPECT_EQ(1u, drmMock->ioctlCallsCount);
241+
EXPECT_EQ(1u, debuggerL0Hw->commandQueueDestroyedCount);
242+
243+
commandQueue2->destroy();
244+
EXPECT_EQ(1u, drmMock->unregisterCalledCount);
245+
EXPECT_EQ(2u, debuggerL0Hw->commandQueueDestroyedCount);
246+
}
247+
222248
} // namespace ult
223249
} // namespace L0

opencl/test/unit_test/os_interface/linux/drm_debug_tests.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2021 Intel Corporation
2+
* Copyright (C) 2020-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -43,7 +43,7 @@ TEST(DrmTest, whenRegisterIsaCookieCalledThenImplementationIsEmpty) {
4343
EXPECT_EQ(0u, drmMock.ioctlCallsCount);
4444
}
4545

46-
TEST(DrmTest, WhenCheckingContextDebugSupportThenNoIoctlIsCalled) {
46+
TEST(DrmTest, whenCheckingContextDebugSupportThenNoIoctlIsCalled) {
4747
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
4848
executionEnvironment->prepareRootDeviceEnvironments(1);
4949
DrmMock drmMock(*executionEnvironment->rootDeviceEnvironments[0]);
@@ -52,3 +52,16 @@ TEST(DrmTest, WhenCheckingContextDebugSupportThenNoIoctlIsCalled) {
5252

5353
EXPECT_EQ(0u, drmMock.ioctlCallsCount);
5454
}
55+
56+
TEST(DrmTest, whenNotifyCommandQueueCreateDestroyAreCalledThenImplementationsAreEmpty) {
57+
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
58+
executionEnvironment->prepareRootDeviceEnvironments(1);
59+
DrmMock drmMock(*executionEnvironment->rootDeviceEnvironments[0]);
60+
61+
auto handle = drmMock.notifyFirstCommandQueueCreated();
62+
EXPECT_EQ(0u, handle);
63+
EXPECT_EQ(0u, drmMock.ioctlCallsCount);
64+
65+
drmMock.notifyLastCommandQueueDestroyed(0);
66+
EXPECT_EQ(0u, drmMock.ioctlCallsCount);
67+
}

shared/source/os_interface/linux/drm_debug.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2021 Intel Corporation
2+
* Copyright (C) 2020-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -45,5 +45,7 @@ std::string Drm::generateElfUUID(const void *data) {
4545

4646
void Drm::checkContextDebugSupport() {}
4747
void Drm::setContextDebugFlag(uint32_t drmContextId) {}
48+
uint32_t Drm::notifyFirstCommandQueueCreated() { return 0; }
49+
void Drm::notifyLastCommandQueueDestroyed(uint32_t handle) {}
4850

4951
} // namespace NEO

shared/source/os_interface/linux/drm_neo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ class Drm : public DriverModel {
249249

250250
MOCKABLE_VIRTUAL bool completionFenceSupport();
251251

252+
MOCKABLE_VIRTUAL uint32_t notifyFirstCommandQueueCreated();
253+
MOCKABLE_VIRTUAL void notifyLastCommandQueueDestroyed(uint32_t handle);
254+
252255
protected:
253256
Drm(std::unique_ptr<HwDeviceIdDrm> &&hwDeviceIdIn, RootDeviceEnvironment &rootDeviceEnvironment);
254257

shared/test/common/libult/linux/drm_mock.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,15 @@ class DrmMockResources : public DrmMock {
288288
return bindAvailable;
289289
}
290290

291+
uint32_t notifyFirstCommandQueueCreated() override {
292+
ioctlCallsCount++;
293+
return 4;
294+
}
295+
296+
void notifyLastCommandQueueDestroyed(uint32_t handle) override {
297+
unregisterResource(handle);
298+
}
299+
291300
static const uint32_t registerResourceReturnHandle;
292301

293302
uint32_t unregisteredHandle = 0;

0 commit comments

Comments
 (0)