Create DebuggerL0 only when debugging is supported

Related-To: NEO-5239

Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
Mateusz Hoppe
2020-11-23 14:31:20 +00:00
committed by Compute-Runtime-Automation
parent 8fdc35bb4b
commit 8aacad1854
19 changed files with 173 additions and 37 deletions

View File

@ -81,7 +81,7 @@ class DebuggerL0 : public NEO::Debugger, NEO::NonCopyableOrMovableClass {
sba.SurfaceStateBaseAddress != 0 ||
sba.BindlessSurfaceStateBaseAddress != 0;
}
static void initDebuggingInOs(NEO::OSInterface *osInterface);
static bool initDebuggingInOs(NEO::OSInterface *osInterface);
void initialize();

View File

@ -13,10 +13,14 @@
#include "level_zero/core/source/debugger/debugger_l0.h"
namespace L0 {
void DebuggerL0::initDebuggingInOs(NEO::OSInterface *osInterface) {
bool DebuggerL0::initDebuggingInOs(NEO::OSInterface *osInterface) {
if (osInterface != nullptr) {
auto drm = osInterface->get()->getDrm();
drm->registerResourceClasses();
if (drm->isVmBindAvailable() && drm->isPerContextVMRequired()) {
drm->registerResourceClasses();
return true;
}
}
return false;
}
} // namespace L0

View File

@ -8,6 +8,7 @@
#include "level_zero/core/source/debugger/debugger_l0.h"
namespace L0 {
void DebuggerL0::initDebuggingInOs(NEO::OSInterface *osInterface) {
bool DebuggerL0::initDebuggingInOs(NEO::OSInterface *osInterface) {
return false;
}
} // namespace L0

View File

@ -13,9 +13,12 @@
namespace L0 {
std::unique_ptr<NEO::Debugger> DebuggerL0::create(NEO::Device *device) {
initDebuggingInOs(device->getRootDeviceEnvironment().osInterface.get());
auto debugger = debuggerL0Factory[device->getHardwareInfo().platform.eRenderCoreFamily](device);
return std::unique_ptr<DebuggerL0>(debugger);
auto success = initDebuggingInOs(device->getRootDeviceEnvironment().osInterface.get());
if (success) {
auto debugger = debuggerL0Factory[device->getHardwareInfo().platform.eRenderCoreFamily](device);
return std::unique_ptr<DebuggerL0>(debugger);
}
return std::unique_ptr<DebuggerL0>(nullptr);
}
} // namespace L0

View File

@ -46,7 +46,7 @@ void DriverImp::initialize(ze_result_t *result) {
UNRECOVERABLE_IF(nullptr == executionEnvironment);
if (envVariables.programDebugging) {
executionEnvironment->setPerContextMemorySpace();
executionEnvironment->setDebuggingEnabled();
}
executionEnvironment->incRefInternal();

View File

@ -7,6 +7,7 @@
#pragma once
#include "level_zero/core/source/debugger/debugger_l0.h"
#include "level_zero/core/test/unit_tests/white_box.h"
namespace L0 {
namespace ult {
@ -52,5 +53,11 @@ struct MockDebuggerL0HwPopulateFactory {
}
};
template <>
struct WhiteBox<::L0::DebuggerL0> : public ::L0::DebuggerL0 {
using BaseClass = ::L0::DebuggerL0;
using BaseClass::initDebuggingInOs;
};
} // namespace ult
} // namespace L0

View File

@ -49,8 +49,7 @@ struct L0DebuggerFixture {
struct L0DebuggerHwFixture : public L0DebuggerFixture {
void SetUp() {
L0DebuggerFixture::SetUp();
debuggerHw = mockDebuggerL0HwFactory[neoDevice->getHardwareInfo().platform.eRenderCoreFamily](neoDevice);
neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[neoDevice->getRootDeviceIndex()]->debugger.reset(debuggerHw);
debuggerHw = static_cast<DebuggerL0 *>(neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[neoDevice->getRootDeviceIndex()]->debugger.get());
neoDevice->setPreemptionMode(PreemptionMode::Disabled);
}

View File

@ -23,7 +23,7 @@ struct L0DebuggerLinuxFixture {
auto executionEnvironment = new NEO::ExecutionEnvironment();
auto mockBuiltIns = new MockBuiltins();
executionEnvironment->prepareRootDeviceEnvironments(1);
executionEnvironment->setDebuggingEnabled();
executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns);
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
executionEnvironment->initializeMemoryManager();
@ -67,5 +67,68 @@ TEST_F(L0DebuggerLinuxTest, whenDebuggerIsCreatedThenItCallsDrmToRegisterResourc
EXPECT_TRUE(drmMock->registerClassesCalled);
}
TEST(L0DebuggerLinux, givenVmBindAndPerContextVmEnabledInDrmWhenInitializingDebuggingInOsThenRegisterResourceClassesIsCalled) {
auto executionEnvironment = std::make_unique<NEO::ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
executionEnvironment->setDebuggingEnabled();
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
executionEnvironment->initializeMemoryManager();
auto osInterface = new OSInterface();
auto drmMock = new DrmMockResources(*executionEnvironment->rootDeviceEnvironments[0]);
drmMock->bindAvailable = true;
drmMock->setPerContextVMRequired(true);
executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(osInterface);
executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setDrm(static_cast<Drm *>(drmMock));
auto result = WhiteBox<::L0::DebuggerL0>::initDebuggingInOs(osInterface);
EXPECT_TRUE(result);
EXPECT_TRUE(drmMock->registerClassesCalled);
}
TEST(L0DebuggerLinux, givenVmBindNotAvailableInDrmWhenInitializingDebuggingInOsThenRegisterResourceClassesIsNotCalled) {
auto executionEnvironment = std::make_unique<NEO::ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
executionEnvironment->setDebuggingEnabled();
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
executionEnvironment->initializeMemoryManager();
auto osInterface = new OSInterface();
auto drmMock = new DrmMockResources(*executionEnvironment->rootDeviceEnvironments[0]);
drmMock->bindAvailable = false;
drmMock->setPerContextVMRequired(true);
executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(osInterface);
executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setDrm(static_cast<Drm *>(drmMock));
auto result = WhiteBox<::L0::DebuggerL0>::initDebuggingInOs(osInterface);
EXPECT_FALSE(result);
EXPECT_FALSE(drmMock->registerClassesCalled);
}
TEST(L0DebuggerLinux, givenPerContextVmNotEnabledWhenInitializingDebuggingInOsThenRegisterResourceClassesIsNotCalled) {
auto executionEnvironment = std::make_unique<NEO::ExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(1);
executionEnvironment->setDebuggingEnabled();
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
executionEnvironment->initializeMemoryManager();
auto osInterface = new OSInterface();
auto drmMock = new DrmMockResources(*executionEnvironment->rootDeviceEnvironments[0]);
drmMock->bindAvailable = true;
drmMock->setPerContextVMRequired(false);
executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(osInterface);
executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->setDrm(static_cast<Drm *>(drmMock));
auto result = WhiteBox<::L0::DebuggerL0>::initDebuggingInOs(osInterface);
EXPECT_FALSE(result);
EXPECT_FALSE(drmMock->registerClassesCalled);
}
} // namespace ult
} // namespace L0

View File

@ -183,7 +183,7 @@ TEST(DriverImpTest, DISABLED_givenMissingMetricApiDependenciesWhenInitializingDr
EXPECT_EQ(nullptr, L0::GlobalDriver);
}
TEST(DriverImpTest, givenEnabledProgramDebuggingWhenCreatingExecutionEnvironmentThenPerContextMemorySpaceIsTrue) {
TEST(DriverImpTest, givenEnabledProgramDebuggingWhenCreatingExecutionEnvironmentThenDebuggingEnabledIsTrue) {
NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get();
hwInfo.capabilityTable.levelZeroSupported = true;
@ -197,14 +197,14 @@ TEST(DriverImpTest, givenEnabledProgramDebuggingWhenCreatingExecutionEnvironment
ASSERT_NE(nullptr, L0::GlobalDriver);
ASSERT_NE(0u, L0::GlobalDriver->numDevices);
EXPECT_TRUE(L0::GlobalDriver->devices[0]->getNEODevice()->getExecutionEnvironment()->isPerContextMemorySpaceRequired());
EXPECT_TRUE(L0::GlobalDriver->devices[0]->getNEODevice()->getExecutionEnvironment()->isDebuggingEnabled());
delete L0::GlobalDriver;
L0::GlobalDriverHandle = nullptr;
L0::GlobalDriver = nullptr;
}
TEST(DriverImpTest, givenNoProgramDebuggingEnvVarWhenCreatingExecutionEnvironmentThenPerContextMemorySpaceIsFalse) {
TEST(DriverImpTest, givenNoProgramDebuggingEnvVarWhenCreatingExecutionEnvironmentThenDebuggingEnabledIsFalse) {
NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get();
hwInfo.capabilityTable.levelZeroSupported = true;
@ -214,7 +214,7 @@ TEST(DriverImpTest, givenNoProgramDebuggingEnvVarWhenCreatingExecutionEnvironmen
ASSERT_NE(nullptr, L0::GlobalDriver);
ASSERT_NE(0u, L0::GlobalDriver->numDevices);
EXPECT_FALSE(L0::GlobalDriver->devices[0]->getNEODevice()->getExecutionEnvironment()->isPerContextMemorySpaceRequired());
EXPECT_FALSE(L0::GlobalDriver->devices[0]->getNEODevice()->getExecutionEnvironment()->isDebuggingEnabled());
delete L0::GlobalDriver;
L0::GlobalDriverHandle = nullptr;

View File

@ -108,7 +108,15 @@ Drm *Drm::create(std::unique_ptr<HwDeviceId> hwDeviceId, RootDeviceEnvironment &
}
}
if (!rootDeviceEnvironment.executionEnvironment.isPerContextMemorySpaceRequired()) {
if (rootDeviceEnvironment.executionEnvironment.isDebuggingEnabled()) {
if (drmObject->isVmBindAvailable()) {
drmObject->setPerContextVMRequired(true);
} else {
printDebugString(DebugManager.flags.PrintDebugMessages.get(), stderr, "%s", "WARNING: Debugging not supported\n");
}
}
if (!drmObject->isPerContextVMRequired()) {
if (!drmObject->createVirtualMemoryAddressSpace(HwHelper::getSubDevicesCount(rootDeviceEnvironment.getHardwareInfo()))) {
printDebugString(DebugManager.flags.PrintDebugMessages.get(), stderr, "%s", "INFO: Device doesn't support GEM Virtual Memory\n");
}

View File

@ -462,21 +462,53 @@ TEST_F(DrmTests, whenDrmIsCreatedWithMultipleSubDevicesThenCreateMultipleVirtual
}
}
TEST_F(DrmTests, givenRequiredPerContextMemorySpaceWhenDrmIsCreatedThenGetVirtualMemoryAddressSpaceReturnsZeroAndVMsAreNotCreated) {
TEST_F(DrmTests, givenDebuggingEnabledWhenDrmIsCreatedThenPerContextVMIsTrueGetVirtualMemoryAddressSpaceReturnsZeroAndVMsAreNotCreated) {
DebugManagerStateRestore restore;
DebugManager.flags.CreateMultipleSubDevices.set(2);
DebugManager.flags.UseVmBind.set(1);
rootDeviceEnvironment->executionEnvironment.setPerContextMemorySpace();
rootDeviceEnvironment->executionEnvironment.setDebuggingEnabled();
auto drm = DrmWrap::createDrm(*rootDeviceEnvironment);
ASSERT_NE(drm, nullptr);
if (drm->isVmBindAvailable()) {
EXPECT_TRUE(drm->isPerContextVMRequired());
auto numSubDevices = HwHelper::getSubDevicesCount(rootDeviceEnvironment->getHardwareInfo());
for (auto id = 0u; id < numSubDevices; id++) {
EXPECT_EQ(0u, drm->getVirtualMemoryAddressSpace(id));
}
EXPECT_EQ(0u, static_cast<DrmWrap *>(drm.get())->virtualMemoryIds.size());
}
}
TEST_F(DrmTests, givenEnabledDebuggingAndVmBindNotAvailableWhenDrmIsCreatedThenPerContextVMIsFalseVMsAreCreatedAndDebugMessageIsPrinted) {
DebugManagerStateRestore restore;
::testing::internal::CaptureStderr();
::testing::internal::CaptureStdout();
DebugManager.flags.CreateMultipleSubDevices.set(2);
DebugManager.flags.UseVmBind.set(0);
DebugManager.flags.PrintDebugMessages.set(true);
rootDeviceEnvironment->executionEnvironment.setDebuggingEnabled();
auto drm = DrmWrap::createDrm(*rootDeviceEnvironment);
EXPECT_NE(drm, nullptr);
EXPECT_TRUE(drm->isPerContextVMRequired());
EXPECT_FALSE(drm->isPerContextVMRequired());
auto numSubDevices = HwHelper::getSubDevicesCount(rootDeviceEnvironment->getHardwareInfo());
for (auto id = 0u; id < numSubDevices; id++) {
EXPECT_EQ(0u, drm->getVirtualMemoryAddressSpace(id));
EXPECT_NE(0u, drm->getVirtualMemoryAddressSpace(id));
}
EXPECT_EQ(0u, static_cast<DrmWrap *>(drm.get())->virtualMemoryIds.size());
EXPECT_NE(0u, static_cast<DrmWrap *>(drm.get())->virtualMemoryIds.size());
DebugManager.flags.PrintDebugMessages.set(false);
::testing::internal::GetCapturedStdout();
std::string errStr = ::testing::internal::GetCapturedStderr();
EXPECT_THAT(errStr, ::testing::HasSubstr(std::string("WARNING: Debugging not supported\n")));
}
TEST_F(DrmTests, givenDrmIsCreatedWhenCreateVirtualMemoryFailsThenReturnVirtualMemoryIdZeroAndPrintDebugMessage) {

View File

@ -357,7 +357,7 @@ TEST_F(DrmBufferObjectTest, givenDeleterWhenBufferObjectIsCreatedAndDeletedThenC
TEST(DrmBufferObject, givenPerContextVmRequiredWhenBoCreatedThenBindInfoIsInitializedToOsContextCount) {
auto device = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
device->getRootDeviceEnvironment().executionEnvironment.setPerContextMemorySpace();
device->getRootDeviceEnvironment().executionEnvironment.setDebuggingEnabled();
device->getExecutionEnvironment()->calculateMaxOsContextCount();
DrmMock drm(*(device->getExecutionEnvironment()->rootDeviceEnvironments[0].get()));
EXPECT_TRUE(drm.isPerContextVMRequired());
@ -375,7 +375,7 @@ TEST(DrmBufferObject, givenPerContextVmRequiredWhenBoCreatedThenBindInfoIsInitia
TEST(DrmBufferObject, givenPerContextVmRequiredWhenBoBoundAndUnboundThenCorrectBindInfoIsUpdated) {
auto executionEnvironment = new ExecutionEnvironment;
executionEnvironment->setPerContextMemorySpace();
executionEnvironment->setDebuggingEnabled();
executionEnvironment->prepareRootDeviceEnvironments(1);
executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get());
executionEnvironment->calculateMaxOsContextCount();

View File

@ -45,7 +45,12 @@ class DrmMock : public Drm {
DrmMock(int fd, RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique<HwDeviceId>(fd, ""), rootDeviceEnvironment) {
sliceCountChangeSupported = true;
if (!rootDeviceEnvironment.executionEnvironment.isPerContextMemorySpaceRequired()) {
if (rootDeviceEnvironment.executionEnvironment.isDebuggingEnabled()) {
setPerContextVMRequired(true);
}
if (!isPerContextVMRequired()) {
createVirtualMemoryAddressSpace(HwHelper::getSubDevicesCount(rootDeviceEnvironment.getHardwareInfo()));
}
}
@ -222,7 +227,9 @@ class DrmMockEngine : public DrmMock {
class DrmMockResources : public DrmMock {
public:
using DrmMock::DrmMock;
DrmMockResources(RootDeviceEnvironment &rootDeviceEnvironment) : DrmMock(mockFd, rootDeviceEnvironment) {
setBindAvailable();
}
bool registerResourceClasses() override {
registerClassesCalled = true;
@ -245,6 +252,10 @@ class DrmMockResources : public DrmMock {
return currentCookie++;
}
bool isVmBindAvailable() override {
return bindAvailable;
}
static const uint32_t registerResourceReturnHandle;
uint32_t unregisteredHandle = 0;

View File

@ -36,7 +36,12 @@ Drm *Drm::create(std::unique_ptr<HwDeviceId> hwDeviceId, RootDeviceEnvironment &
return *pDrmToReturnFromCreateFunc;
}
auto drm = new DrmMockDefault(rootDeviceEnvironment);
if (!rootDeviceEnvironment.executionEnvironment.isPerContextMemorySpaceRequired()) {
if (drm->isVmBindAvailable() && rootDeviceEnvironment.executionEnvironment.isDebuggingEnabled()) {
drm->setPerContextVMRequired(true);
}
if (!drm->isPerContextVMRequired()) {
drm->createVirtualMemoryAddressSpace(HwHelper::getSubDevicesCount(rootDeviceEnvironment.getHardwareInfo()));
}
return drm;

View File

@ -439,7 +439,7 @@ TEST(DrmTest, givenDrmWhenCreatingOsContextThenCreateDrmContextWithVmId) {
TEST(DrmTest, givenDrmWithPerContextVMRequiredWhenCreatingOsContextsThenImplicitVmIdPerContextIsUsed) {
auto &rootEnv = *platform()->peekExecutionEnvironment()->rootDeviceEnvironments[0];
rootEnv.executionEnvironment.setPerContextMemorySpace();
rootEnv.executionEnvironment.setDebuggingEnabled();
DrmMock drmMock(rootEnv);
EXPECT_TRUE(drmMock.requirePerContextVM);
@ -453,7 +453,7 @@ TEST(DrmTest, givenDrmWithPerContextVMRequiredWhenCreatingOsContextsThenImplicit
TEST(DrmTest, givenDrmWithPerContextVMRequiredWhenCreatingOsContextsThenImplicitVmIdPerContextIsQueriedAndStored) {
auto &rootEnv = *platform()->peekExecutionEnvironment()->rootDeviceEnvironments[0];
rootEnv.executionEnvironment.setPerContextMemorySpace();
rootEnv.executionEnvironment.setDebuggingEnabled();
DrmMock drmMock(rootEnv);
EXPECT_TRUE(drmMock.requirePerContextVM);

View File

@ -52,13 +52,14 @@ bool Device::createDeviceImpl() {
auto &hwInfo = getHardwareInfo();
preemptionMode = PreemptionHelper::getDefaultPreemptionMode(hwInfo);
if (!getDebugger()) {
this->executionEnvironment->rootDeviceEnvironments[getRootDeviceIndex()]->initDebugger();
}
auto &hwHelper = HwHelper::get(hwInfo.platform.eRenderCoreFamily);
hwHelper.setupHardwareCapabilities(&this->hardwareCapabilities, hwInfo);
executionEnvironment->rootDeviceEnvironments[getRootDeviceIndex()]->initGmm();
if (!getDebugger()) {
this->executionEnvironment->rootDeviceEnvironments[getRootDeviceIndex()]->initDebugger();
}
if (!createEngines()) {
return false;
}

View File

@ -24,16 +24,16 @@ class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment>
MOCKABLE_VIRTUAL bool initializeMemoryManager();
void calculateMaxOsContextCount();
void prepareRootDeviceEnvironments(uint32_t numRootDevices);
void setPerContextMemorySpace() {
requirePerContextMemorySpace = true;
void setDebuggingEnabled() {
debuggingEnabled = true;
}
bool isPerContextMemorySpaceRequired() { return requirePerContextMemorySpace; }
bool isDebuggingEnabled() { return debuggingEnabled; }
std::unique_ptr<MemoryManager> memoryManager;
std::unique_ptr<OsEnvironment> osEnvironment;
std::vector<std::unique_ptr<RootDeviceEnvironment>> rootDeviceEnvironments;
protected:
bool requirePerContextMemorySpace = false;
bool debuggingEnabled = false;
};
} // namespace NEO

View File

@ -59,7 +59,6 @@ constexpr const char *getIoctlParamString(int param) {
} // namespace IoctlHelper
Drm::Drm(std::unique_ptr<HwDeviceId> hwDeviceIdIn, RootDeviceEnvironment &rootDeviceEnvironment) : hwDeviceId(std::move(hwDeviceIdIn)), rootDeviceEnvironment(rootDeviceEnvironment) {
requirePerContextVM = rootDeviceEnvironment.executionEnvironment.isPerContextMemorySpaceRequired();
}
int Drm::ioctl(unsigned long request, void *arg) {

View File

@ -112,8 +112,11 @@ class Drm {
bool isPerContextVMRequired() {
return requirePerContextVM;
}
void setPerContextVMRequired(bool required) {
requirePerContextVM = required;
}
bool isVmBindAvailable();
MOCKABLE_VIRTUAL bool isVmBindAvailable();
MOCKABLE_VIRTUAL bool registerResourceClasses();
MOCKABLE_VIRTUAL uint32_t registerResource(ResourceClass classType, void *data, size_t size);