From c5a76cac3aed466fc311c31bd10812bdef44ab65 Mon Sep 17 00:00:00 2001 From: Jitendra Sharma Date: Thu, 18 Apr 2024 14:54:30 +0000 Subject: [PATCH] fix: Reduce code duplicity by reusing closeConnection Related-To: NEO-11188 Signed-off-by: Jitendra Sharma --- .../source/debug/linux/debug_session.cpp | 36 +++++++++++++++- .../tools/source/debug/linux/debug_session.h | 2 + .../debug/linux/prelim/debug_session.cpp | 41 ------------------- .../source/debug/linux/prelim/debug_session.h | 3 -- .../source/debug/linux/xe/debug_session.cpp | 5 --- .../source/debug/linux/xe/debug_session.h | 6 --- .../linux/xe/test_debug_api_linux_xe.cpp | 1 + 7 files changed, 38 insertions(+), 56 deletions(-) diff --git a/level_zero/tools/source/debug/linux/debug_session.cpp b/level_zero/tools/source/debug/linux/debug_session.cpp index 825f3dc62a..df20f2d548 100644 --- a/level_zero/tools/source/debug/linux/debug_session.cpp +++ b/level_zero/tools/source/debug/linux/debug_session.cpp @@ -126,7 +126,6 @@ std::unique_ptr DebugSessionLinux::getInternalEvent() { void DebugSessionLinux::closeAsyncThread() { asyncThread.close(); - internalEventThread.close(); } bool DebugSessionLinux::checkForceExceptionBit(uint64_t memoryHandle, EuThread::ThreadId threadId, uint32_t *cr0, const SIP::regset_desc *regDesc) { @@ -918,4 +917,39 @@ ze_result_t DebugSessionLinux::acknowledgeEvent(const zet_debug_event_t *event) return ZE_RESULT_ERROR_UNINITIALIZED; } +bool DebugSessionLinux::closeConnection() { + closeAsyncThread(); + closeInternalEventsThread(); + + if (clientHandle != invalidClientHandle) { + auto numTiles = std::max(1u, connectedDevice->getNEODevice()->getNumSubDevices()); + for (uint32_t tileIndex = 0; tileIndex < numTiles; tileIndex++) { + for (const auto &eventToAck : eventsToAck) { + auto moduleHandle = eventToAck.second; + ackModuleEvents(tileIndex, moduleHandle); + } + cleanRootSessionAfterDetach(tileIndex); + } + } + + return closeFd(); +} + +void DebugSessionLinux::cleanRootSessionAfterDetach(uint32_t deviceIndex) { + auto connection = getClientConnection(clientHandle).get(); + + for (const auto &isa : connection->isaMap[deviceIndex]) { + + // zebin modules do not store ackEvents per ISA + UNRECOVERABLE_IF(isa.second->ackEvents.size() > 0 && isa.second->perKernelModule == false); + + for (auto &event : isa.second->ackEvents) { + eventAckIoctl(event); + } + + isa.second->ackEvents.clear(); + isa.second->moduleLoadEventAck = true; + } +} + } // namespace L0 diff --git a/level_zero/tools/source/debug/linux/debug_session.h b/level_zero/tools/source/debug/linux/debug_session.h index 934a14e672..6405e3e66d 100644 --- a/level_zero/tools/source/debug/linux/debug_session.h +++ b/level_zero/tools/source/debug/linux/debug_session.h @@ -24,6 +24,7 @@ struct DebugSessionLinux : DebugSessionImp { static ze_result_t translateDebuggerOpenErrno(int error); bool closeFd(); void closeAsyncThread(); + bool closeConnection() override; int fd = 0; std::atomic internalThreadHasStarted{false}; @@ -162,6 +163,7 @@ struct DebugSessionLinux : DebugSessionImp { }; protected: + void cleanRootSessionAfterDetach(uint32_t deviceIndex) override; virtual std::shared_ptr getClientConnection(uint64_t clientHandle) = 0; enum class ThreadControlCmd { diff --git a/level_zero/tools/source/debug/linux/prelim/debug_session.cpp b/level_zero/tools/source/debug/linux/prelim/debug_session.cpp index 6b9231423c..7276b51e78 100644 --- a/level_zero/tools/source/debug/linux/prelim/debug_session.cpp +++ b/level_zero/tools/source/debug/linux/prelim/debug_session.cpp @@ -277,24 +277,6 @@ void DebugSessionLinuxi915::readInternalEventsAsync() { } } -bool DebugSessionLinuxi915::closeConnection() { - closeAsyncThread(); - closeInternalEventsThread(); - - if (clientHandle != invalidClientHandle) { - auto numTiles = std::max(1u, connectedDevice->getNEODevice()->getNumSubDevices()); - for (uint32_t i = 0; i < numTiles; i++) { - for (const auto &eventToAck : eventsToAck) { - auto moduleUUID = eventToAck.second; - ackModuleEvents(i, moduleUUID); - } - cleanRootSessionAfterDetach(i); - } - } - - return closeFd(); -} - void DebugSessionLinuxi915::handleEvent(prelim_drm_i915_debug_event *event) { auto type = event->type; @@ -1331,29 +1313,6 @@ int DebugSessionLinuxi915::eventAckIoctl(EventToAck &event) { return ret; } -void DebugSessionLinuxi915::cleanRootSessionAfterDetach(uint32_t deviceIndex) { - auto connection = clientHandleToConnection[clientHandle].get(); - - for (const auto &isa : connection->isaMap[deviceIndex]) { - - // zebin modules do not store ackEvents per ISA - UNRECOVERABLE_IF(isa.second->ackEvents.size() > 0 && isa.second->perKernelModule == false); - - for (auto &event : isa.second->ackEvents) { - prelim_drm_i915_debug_event_ack eventToAck = {}; - eventToAck.type = event.type; - eventToAck.seqno = event.seqno; - eventToAck.flags = 0; - - auto ret = ioctl(PRELIM_I915_DEBUG_IOCTL_ACK_EVENT, &eventToAck); - PRINT_DEBUGGER_INFO_LOG("PRELIM_I915_DEBUG_IOCTL_ACK_EVENT seqno = %llu, ret = %d errno = %d\n", (uint64_t)event.seqno, ret, ret != 0 ? errno : 0); - } - - isa.second->ackEvents.clear(); - isa.second->moduleLoadEventAck = true; - } -} - void TileDebugSessionLinuxi915::readStateSaveAreaHeader() { const auto header = rootDebugSession->getStateSaveAreaHeader(); diff --git a/level_zero/tools/source/debug/linux/prelim/debug_session.h b/level_zero/tools/source/debug/linux/prelim/debug_session.h index 47a89f2481..04a43947a2 100644 --- a/level_zero/tools/source/debug/linux/prelim/debug_session.h +++ b/level_zero/tools/source/debug/linux/prelim/debug_session.h @@ -41,8 +41,6 @@ struct DebugSessionLinuxi915 : DebugSessionLinux { static DebugSession *createLinuxSession(const zet_debug_config_t &config, Device *device, ze_result_t &result, bool isRootAttach); ze_result_t initialize() override; - bool closeConnection() override; - struct IoctlHandleri915 : DebugSessionLinux::IoctlHandler { int ioctl(int fd, unsigned long request, void *arg) override { int ret = 0; @@ -146,7 +144,6 @@ struct DebugSessionLinuxi915 : DebugSessionLinux { void detachTile() override { UNRECOVERABLE_IF(true); } - void cleanRootSessionAfterDetach(uint32_t deviceIndex) override; void extractUuidData(uint64_t client, const UuidData &uuidData); uint64_t extractVaFromUuidString(std::string &uuid); diff --git a/level_zero/tools/source/debug/linux/xe/debug_session.cpp b/level_zero/tools/source/debug/linux/xe/debug_session.cpp index 2ed2d8a6cf..c457f22aeb 100644 --- a/level_zero/tools/source/debug/linux/xe/debug_session.cpp +++ b/level_zero/tools/source/debug/linux/xe/debug_session.cpp @@ -180,11 +180,6 @@ ze_result_t DebugSessionLinuxXe::readEventImp(drm_xe_eudebug_event *drmDebugEven return ZE_RESULT_SUCCESS; } -bool DebugSessionLinuxXe::closeConnection() { - closeInternalEventsThread(); - return closeFd(); -} - void DebugSessionLinuxXe::handleEvent(drm_xe_eudebug_event *event) { auto type = event->type; diff --git a/level_zero/tools/source/debug/linux/xe/debug_session.h b/level_zero/tools/source/debug/linux/xe/debug_session.h index 824d77c6a2..c5dcca0e09 100644 --- a/level_zero/tools/source/debug/linux/xe/debug_session.h +++ b/level_zero/tools/source/debug/linux/xe/debug_session.h @@ -27,8 +27,6 @@ struct DebugSessionLinuxXe : DebugSessionLinux { ze_result_t initialize() override; - bool closeConnection() override; - struct IoctlHandlerXe : DebugSessionLinux::IoctlHandler { int ioctl(int fd, unsigned long request, void *arg) override { int ret = 0; @@ -85,10 +83,6 @@ struct DebugSessionLinuxXe : DebugSessionLinux { static void *asyncThreadFunction(void *arg); void handleEventsAsync(); - void cleanRootSessionAfterDetach(uint32_t deviceIndex) override { - UNRECOVERABLE_IF(true); - } - int openVmFd(uint64_t vmHandle, bool readOnly) override; int flushVmCache(int vmfd) override; diff --git a/level_zero/tools/test/unit_tests/sources/debug/linux/xe/test_debug_api_linux_xe.cpp b/level_zero/tools/test/unit_tests/sources/debug/linux/xe/test_debug_api_linux_xe.cpp index 0f3e22016c..2c9a4758df 100644 --- a/level_zero/tools/test/unit_tests/sources/debug/linux/xe/test_debug_api_linux_xe.cpp +++ b/level_zero/tools/test/unit_tests/sources/debug/linux/xe/test_debug_api_linux_xe.cpp @@ -214,6 +214,7 @@ TEST_F(DebugApiLinuxTestXe, GivenDebugSessionWhenClosingConnectionThenSysCallClo EXPECT_EQ(1u, NEO::SysCalls::closeFuncCalled); EXPECT_EQ(10, NEO::SysCalls::closeFuncArgPassed); EXPECT_FALSE(session->internalEventThread.threadActive); + EXPECT_FALSE(session->asyncThread.threadActive); NEO::SysCalls::closeFuncCalled = 0; NEO::SysCalls::closeFuncArgPassed = 0;