feature(debugger): use linux driver type to create correct debug session imp

Related-to: NEO-8403

Signed-off-by: Brandon Yates <brandon.yates@intel.com>
This commit is contained in:
Brandon Yates
2023-10-19 20:35:35 +00:00
committed by Compute-Runtime-Automation
parent 2e09b5ff66
commit 85d35d5239
12 changed files with 148 additions and 52 deletions

View File

@@ -1,5 +1,5 @@
#
# Copyright (C) 2021-2022 Intel Corporation
# Copyright (C) 2021-2023 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
@@ -8,6 +8,7 @@ if(UNIX)
target_sources(${L0_STATIC_LIB_NAME}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/debug_session.cpp
)
if(NEO_ENABLE_i915_PRELIM_DETECTION)
@@ -17,11 +18,8 @@ if(UNIX)
${CMAKE_CURRENT_SOURCE_DIR}/prelim/debug_session.h
${CMAKE_CURRENT_SOURCE_DIR}/prelim/drm_helper.cpp
)
else()
target_sources(${L0_STATIC_LIB_NAME}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/debug_session.cpp
)
endif()
add_subdirectories()
endif()

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021-2022 Intel Corporation
* Copyright (C) 2021-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -7,12 +7,48 @@
#include "level_zero/tools/source/debug/debug_session.h"
#include "shared/source/os_interface/linux/drm_allocation.h"
#include "shared/source/os_interface/linux/drm_neo.h"
#include "level_zero/core/source/device/device.h"
#include "level_zero/tools/source/debug/linux/debug_session_factory.h"
namespace L0 {
DebugSessionLinuxAllocatorFn DebugSessionLinuxFactory[DEBUG_SESSION_LINUX_TYPE_MAX] = {};
DebugSession *DebugSession::create(const zet_debug_config_t &config, Device *device, ze_result_t &result, bool isRootAttach) {
result = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
return nullptr;
if (!device->getOsInterface().isDebugAttachAvailable()) {
result = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
return nullptr;
}
auto drm = device->getOsInterface().getDriverModel()->as<NEO::Drm>();
auto drmVersion = NEO::Drm::getDrmVersion(drm->getFileDescriptor());
DebugSessionLinuxAllocatorFn allocator = nullptr;
if ("xe" == drmVersion) {
allocator = DebugSessionLinuxFactory[DEBUG_SESSION_LINUX_TYPE_XE];
} else {
allocator = DebugSessionLinuxFactory[DEBUG_SESSION_LINUX_TYPE_I915];
}
if (!allocator) {
result = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
return nullptr;
}
auto debugSession = allocator(config, device, result, isRootAttach);
if (result != ZE_RESULT_SUCCESS) {
return nullptr;
}
debugSession->setAttachMode(isRootAttach);
result = debugSession->initialize();
if (result != ZE_RESULT_SUCCESS) {
debugSession->closeConnection();
delete debugSession;
debugSession = nullptr;
} else {
debugSession->startAsyncThread();
}
return debugSession;
}
} // namespace L0

View File

@@ -0,0 +1,28 @@
/*
* Copyright (C) 2021-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "level_zero/tools/source/debug/debug_session.h"
namespace L0 {
enum DebugSessionLinuxType {
DEBUG_SESSION_LINUX_TYPE_I915 = 0,
DEBUG_SESSION_LINUX_TYPE_XE = 1,
DEBUG_SESSION_LINUX_TYPE_MAX = 2
};
using DebugSessionLinuxAllocatorFn = DebugSession *(*)(const zet_debug_config_t &, Device *, ze_result_t &, bool);
extern DebugSessionLinuxAllocatorFn DebugSessionLinuxFactory[];
template <uint32_t driverType, typename DebugSessionType>
struct DebugSessionLinuxPopulateFactory {
DebugSessionLinuxPopulateFactory() {
DebugSessionLinuxFactory[driverType] = DebugSessionType::createLinuxSession;
}
};
} // namespace L0

View File

@@ -25,6 +25,7 @@
#include "level_zero/core/source/device/device_imp.h"
#include "level_zero/core/source/gfx_core_helpers/l0_gfx_core_helper.h"
#include "level_zero/include/zet_intel_gpu_debug.h"
#include "level_zero/tools/source/debug/linux/debug_session_factory.h"
#include "level_zero/tools/source/debug/linux/prelim/drm_helper.h"
#include <level_zero/ze_api.h>
@@ -35,6 +36,9 @@
namespace L0 {
static DebugSessionLinuxPopulateFactory<DEBUG_SESSION_LINUX_TYPE_I915, DebugSessionLinuxi915>
populatei915Debugger;
DebugSession *createDebugSessionHelper(const zet_debug_config_t &config, Device *device, int debugFd, void *params);
DebugSessionLinuxi915::DebugSessionLinuxi915(const zet_debug_config_t &config, Device *device, int debugFd, void *params) : DebugSessionImp(config, device), fd(debugFd) {
@@ -62,38 +66,22 @@ DebugSessionLinuxi915::~DebugSessionLinuxi915() {
closeFd();
}
DebugSession *DebugSession::create(const zet_debug_config_t &config, Device *device, ze_result_t &result, bool isRootAttach) {
if (device->getOsInterface().isDebugAttachAvailable()) {
struct prelim_drm_i915_debugger_open_param open = {};
open.pid = config.pid;
open.events = 0;
open.version = 0;
DebugSession *DebugSessionLinuxi915::createLinuxSession(const zet_debug_config_t &config, Device *device, ze_result_t &result, bool isRootAttach) {
struct prelim_drm_i915_debugger_open_param open = {};
open.pid = config.pid;
open.events = 0;
open.version = 0;
auto debugFd = DrmHelper::ioctl(device, NEO::DrmIoctl::DebuggerOpen, &open);
if (debugFd >= 0) {
PRINT_DEBUGGER_INFO_LOG("PRELIM_DRM_IOCTL_I915_DEBUGGER_OPEN: open.pid: %d, open.events: %d, debugFd: %d\n",
open.pid, open.events, debugFd);
auto debugFd = DrmHelper::ioctl(device, NEO::DrmIoctl::DebuggerOpen, &open);
if (debugFd >= 0) {
PRINT_DEBUGGER_INFO_LOG("PRELIM_DRM_IOCTL_I915_DEBUGGER_OPEN: open.pid: %d, open.events: %d, debugFd: %d\n",
open.pid, open.events, debugFd);
auto debugSession = createDebugSessionHelper(config, device, debugFd, &open);
debugSession->setAttachMode(isRootAttach);
result = debugSession->initialize();
if (result != ZE_RESULT_SUCCESS) {
debugSession->closeConnection();
delete debugSession;
debugSession = nullptr;
} else {
debugSession->startAsyncThread();
}
return debugSession;
} else {
auto reason = DrmHelper::getErrno(device);
PRINT_DEBUGGER_ERROR_LOG("PRELIM_DRM_IOCTL_I915_DEBUGGER_OPEN failed: open.pid: %d, open.events: %d, retCode: %d, errno: %d\n",
open.pid, open.events, debugFd, reason);
result = DebugSessionLinuxi915::translateDebuggerOpenErrno(reason);
}
return createDebugSessionHelper(config, device, debugFd, &open);
} else {
result = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
auto reason = DrmHelper::getErrno(device);
PRINT_DEBUGGER_ERROR_LOG("PRELIM_DRM_IOCTL_I915_DEBUGGER_OPEN failed: open.pid: %d, open.events: %d, retCode: %d, errno: %d\n",
open.pid, open.events, debugFd, reason);
result = DebugSessionLinuxi915::translateDebuggerOpenErrno(reason);
}
return nullptr;
}

View File

@@ -37,6 +37,7 @@ struct DebugSessionLinuxi915 : DebugSessionImp {
~DebugSessionLinuxi915() override;
DebugSessionLinuxi915(const zet_debug_config_t &config, Device *device, int debugFd, void *params);
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;

View File

@@ -1,17 +1,14 @@
#
# Copyright (C) 2022 Intel Corporation
# Copyright (C) 2023 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
if(UNIX)
if(NEO_ENABLE_i915_PRELIM_DETECTION)
target_sources(${TARGET_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/debug_session_fixtures_linux.cpp
${CMAKE_CURRENT_SOURCE_DIR}/debug_session_fixtures_linux.h
${CMAKE_CURRENT_SOURCE_DIR}/test_debug_api_linux.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tile_debug_session_linux_tests.cpp
)
endif()
target_sources(${TARGET_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/test_debug_session_linux_create.cpp
)
endif()
add_subdirectories()

View File

@@ -0,0 +1,17 @@
#
# Copyright (C) 2022-2023 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
if(UNIX)
if(NEO_ENABLE_i915_PRELIM_DETECTION)
target_sources(${TARGET_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/debug_session_fixtures_linux.cpp
${CMAKE_CURRENT_SOURCE_DIR}/debug_session_fixtures_linux.h
${CMAKE_CURRENT_SOURCE_DIR}/test_debug_api_linux.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tile_debug_session_linux_tests.cpp
)
endif()
endif()

View File

@@ -5,7 +5,7 @@
*
*/
#include "level_zero/tools/test/unit_tests/sources/debug/linux/debug_session_fixtures_linux.h"
#include "level_zero/tools/test/unit_tests/sources/debug/linux/prelim/debug_session_fixtures_linux.h"
#include "shared/source/os_interface/linux/engine_info.h"

View File

@@ -35,7 +35,7 @@
#include "level_zero/tools/source/debug/debug_handlers.h"
#include "level_zero/tools/source/debug/linux/prelim/debug_session.h"
#include "level_zero/tools/test/unit_tests/sources/debug/debug_session_common.h"
#include "level_zero/tools/test/unit_tests/sources/debug/linux/debug_session_fixtures_linux.h"
#include "level_zero/tools/test/unit_tests/sources/debug/linux/prelim/debug_session_fixtures_linux.h"
#include "level_zero/tools/test/unit_tests/sources/debug/mock_debug_session.h"
#include "common/StateSaveAreaHeader.h"

View File

@@ -13,7 +13,7 @@
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
#include "level_zero/tools/source/debug/linux/prelim/debug_session.h"
#include "level_zero/tools/test/unit_tests/sources/debug/debug_session_common.h"
#include "level_zero/tools/test/unit_tests/sources/debug/linux/debug_session_fixtures_linux.h"
#include "level_zero/tools/test/unit_tests/sources/debug/linux/prelim/debug_session_fixtures_linux.h"
#include "level_zero/tools/test/unit_tests/sources/debug/mock_debug_session.h"
#include <memory>

View File

@@ -0,0 +1,31 @@
/*
* Copyright (C) 2022-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/test/common/os_interface/linux/sys_calls_linux_ult.h"
#include "level_zero/tools/test/unit_tests/sources/debug/linux/prelim/debug_session_fixtures_linux.h"
namespace L0 {
namespace ult {
using DebugSessionLinuxCreateTest = Test<DebugApiLinuxFixture>;
TEST_F(DebugSessionLinuxCreateTest, GivenDebuggerDriverTypeXeThenErrorReturned) {
zet_debug_config_t config = {};
config.pid = 0x1234;
mockDrm->setFileDescriptor(SysCalls::fakeFileDescriptor);
VariableBackup<const char *> backup(&SysCalls::drmVersion);
SysCalls::drmVersion = "xe";
ze_result_t result = ZE_RESULT_SUCCESS;
auto session = std::unique_ptr<DebugSession>(DebugSession::create(config, device, result, false));
EXPECT_EQ(result, ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
}
} // namespace ult
} // namespace L0