mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-06 10:26:29 +08:00
L0Debug - close debug fd when DebugSession is destroyed
- after last tile DebugSession is detached, root DebugSession must close fd Related-To: NEO-5784 Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
ca0686b404
commit
aa59ee94b2
@@ -47,6 +47,7 @@ DebugSessionLinux::~DebugSessionLinux() {
|
|||||||
delete session.first;
|
delete session.first;
|
||||||
}
|
}
|
||||||
tileSessions.resize(0);
|
tileSessions.resize(0);
|
||||||
|
closeFd();
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugSession *DebugSession::create(const zet_debug_config_t &config, Device *device, ze_result_t &result) {
|
DebugSession *DebugSession::create(const zet_debug_config_t &config, Device *device, ze_result_t &result) {
|
||||||
@@ -341,6 +342,21 @@ void DebugSessionLinux::closeAsyncThread() {
|
|||||||
internalEventThread.close();
|
internalEventThread.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DebugSessionLinux::closeFd() {
|
||||||
|
if (fd == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto res = NEO::SysCalls::close(fd);
|
||||||
|
|
||||||
|
if (res != 0) {
|
||||||
|
PRINT_DEBUGGER_ERROR_LOG("Debug connection close() on fd: %d failed: retCode: %d\n", fd, res);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
fd = 0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<uint64_t[]> DebugSessionLinux::getInternalEvent() {
|
std::unique_ptr<uint64_t[]> DebugSessionLinux::getInternalEvent() {
|
||||||
std::unique_ptr<uint64_t[]> eventMemory;
|
std::unique_ptr<uint64_t[]> eventMemory;
|
||||||
|
|
||||||
@@ -427,18 +443,8 @@ void DebugSessionLinux::readInternalEventsAsync() {
|
|||||||
|
|
||||||
bool DebugSessionLinux::closeConnection() {
|
bool DebugSessionLinux::closeConnection() {
|
||||||
closeAsyncThread();
|
closeAsyncThread();
|
||||||
internalEventThread.close();
|
closeInternalEventsThread();
|
||||||
if (fd == 0) {
|
return closeFd();
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto res = NEO::SysCalls::close(fd);
|
|
||||||
|
|
||||||
if (res != 0) {
|
|
||||||
PRINT_DEBUGGER_ERROR_LOG("Debug connection close() on fd: %d failed: retCode: %d\n", fd, res);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DebugSessionLinux::handleEvent(prelim_drm_i915_debug_event *event) {
|
void DebugSessionLinux::handleEvent(prelim_drm_i915_debug_event *event) {
|
||||||
|
|||||||
@@ -211,6 +211,8 @@ struct DebugSessionLinux : DebugSessionImp {
|
|||||||
internalEventThread.close();
|
internalEventThread.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool closeFd();
|
||||||
|
|
||||||
virtual std::vector<uint64_t> getAllMemoryHandles() {
|
virtual std::vector<uint64_t> getAllMemoryHandles() {
|
||||||
std::vector<uint64_t> allVms;
|
std::vector<uint64_t> allVms;
|
||||||
std::unique_lock<std::mutex> memLock(asyncThreadMutex);
|
std::unique_lock<std::mutex> memLock(asyncThreadMutex);
|
||||||
|
|||||||
@@ -256,6 +256,7 @@ struct MockDebugSessionLinux : public L0::DebugSessionLinux {
|
|||||||
using L0::DebugSessionLinux::euControlInterruptSeqno;
|
using L0::DebugSessionLinux::euControlInterruptSeqno;
|
||||||
using L0::DebugSessionLinux::eventsToAck;
|
using L0::DebugSessionLinux::eventsToAck;
|
||||||
using L0::DebugSessionLinux::extractVaFromUuidString;
|
using L0::DebugSessionLinux::extractVaFromUuidString;
|
||||||
|
using L0::DebugSessionLinux::fd;
|
||||||
using L0::DebugSessionLinux::getRegisterSetProperties;
|
using L0::DebugSessionLinux::getRegisterSetProperties;
|
||||||
using L0::DebugSessionLinux::getSbaBufferGpuVa;
|
using L0::DebugSessionLinux::getSbaBufferGpuVa;
|
||||||
using L0::DebugSessionLinux::getStateSaveAreaHeader;
|
using L0::DebugSessionLinux::getStateSaveAreaHeader;
|
||||||
|
|||||||
@@ -954,6 +954,8 @@ TEST_F(DebugApiLinuxTest, GivenDebugSessionWhenClosingConnectionThenSysCallClose
|
|||||||
EXPECT_NE(nullptr, session);
|
EXPECT_NE(nullptr, session);
|
||||||
|
|
||||||
NEO::SysCalls::closeFuncCalled = 0;
|
NEO::SysCalls::closeFuncCalled = 0;
|
||||||
|
NEO::SysCalls::closeFuncArgPassed = 0;
|
||||||
|
|
||||||
auto ret = session->closeConnection();
|
auto ret = session->closeConnection();
|
||||||
EXPECT_TRUE(ret);
|
EXPECT_TRUE(ret);
|
||||||
|
|
||||||
@@ -965,6 +967,24 @@ TEST_F(DebugApiLinuxTest, GivenDebugSessionWhenClosingConnectionThenSysCallClose
|
|||||||
NEO::SysCalls::closeFuncArgPassed = 0;
|
NEO::SysCalls::closeFuncArgPassed = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(DebugApiLinuxTest, GivenDebugSessionWhenDestroyedThenSysCallCloseOnFdIsCalled) {
|
||||||
|
zet_debug_config_t config = {};
|
||||||
|
config.pid = 0x1234;
|
||||||
|
|
||||||
|
auto session = std::make_unique<MockDebugSessionLinux>(config, device, 10);
|
||||||
|
EXPECT_NE(nullptr, session);
|
||||||
|
|
||||||
|
NEO::SysCalls::closeFuncCalled = 0;
|
||||||
|
NEO::SysCalls::closeFuncArgPassed = 0;
|
||||||
|
|
||||||
|
session.reset(nullptr);
|
||||||
|
EXPECT_EQ(1u, NEO::SysCalls::closeFuncCalled);
|
||||||
|
EXPECT_EQ(10, NEO::SysCalls::closeFuncArgPassed);
|
||||||
|
|
||||||
|
NEO::SysCalls::closeFuncCalled = 0;
|
||||||
|
NEO::SysCalls::closeFuncArgPassed = 0;
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(DebugApiLinuxTest, GivenDebugSessionWithFdEqualZeroWhenClosingConnectionThenSysCallIsNotCalledAndFalseReturned) {
|
TEST_F(DebugApiLinuxTest, GivenDebugSessionWithFdEqualZeroWhenClosingConnectionThenSysCallIsNotCalledAndFalseReturned) {
|
||||||
zet_debug_config_t config = {};
|
zet_debug_config_t config = {};
|
||||||
config.pid = 0x1234;
|
config.pid = 0x1234;
|
||||||
|
|||||||
@@ -15,6 +15,15 @@
|
|||||||
#include "level_zero/tools/test/unit_tests/sources/debug/mock_debug_session.h"
|
#include "level_zero/tools/test/unit_tests/sources/debug/mock_debug_session.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
namespace NEO {
|
||||||
|
namespace SysCalls {
|
||||||
|
extern uint32_t closeFuncCalled;
|
||||||
|
extern int closeFuncArgPassed;
|
||||||
|
extern int closeFuncRetVal;
|
||||||
|
} // namespace SysCalls
|
||||||
|
} // namespace NEO
|
||||||
|
|
||||||
namespace L0 {
|
namespace L0 {
|
||||||
namespace ult {
|
namespace ult {
|
||||||
|
|
||||||
@@ -190,6 +199,29 @@ TEST_F(TileAttachTest, GivenTileAttachDisabledAndMultitileDeviceWhenCreatingTile
|
|||||||
ASSERT_EQ(0u, session->tileSessions.size());
|
ASSERT_EQ(0u, session->tileSessions.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(TileAttachTest, givenTileDeviceWhenCallingDebugDetachOnLastSessionThenRootSessionIsClosed) {
|
||||||
|
zet_debug_config_t config = {};
|
||||||
|
config.pid = 0x1234;
|
||||||
|
zet_debug_session_handle_t debugSession0 = nullptr;
|
||||||
|
|
||||||
|
auto result = zetDebugAttach(neoDevice->getSubDevice(0)->getSpecializedDevice<L0::Device>()->toHandle(), &config, &debugSession0);
|
||||||
|
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||||
|
EXPECT_NE(nullptr, debugSession0);
|
||||||
|
|
||||||
|
NEO::SysCalls::closeFuncCalled = 0;
|
||||||
|
NEO::SysCalls::closeFuncArgPassed = 0;
|
||||||
|
|
||||||
|
auto debugFd = rootSession->fd;
|
||||||
|
result = zetDebugDetach(debugSession0);
|
||||||
|
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||||
|
|
||||||
|
EXPECT_EQ(1u, NEO::SysCalls::closeFuncCalled);
|
||||||
|
EXPECT_EQ(debugFd, NEO::SysCalls::closeFuncArgPassed);
|
||||||
|
|
||||||
|
NEO::SysCalls::closeFuncCalled = 0;
|
||||||
|
NEO::SysCalls::closeFuncArgPassed = 0;
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(TileAttachTest, givenTileDeviceWhenCallingDebugAttachAndDetachThenSuccessAndValidSessionHandleAreReturned) {
|
TEST_F(TileAttachTest, givenTileDeviceWhenCallingDebugAttachAndDetachThenSuccessAndValidSessionHandleAreReturned) {
|
||||||
zet_debug_config_t config = {};
|
zet_debug_config_t config = {};
|
||||||
config.pid = 0x1234;
|
config.pid = 0x1234;
|
||||||
|
|||||||
Reference in New Issue
Block a user