fix(sysman): Disable sysman API support with zeInit on xe

Related-To: NEO-8426

Signed-off-by: Kulkarni, Ashwin Kumar <ashwin.kumar.kulkarni@intel.com>
This commit is contained in:
Kulkarni, Ashwin Kumar
2023-11-20 05:21:10 +00:00
committed by Compute-Runtime-Automation
parent 023b5070fa
commit 39561aa7e9
9 changed files with 197 additions and 3 deletions

View File

@@ -140,6 +140,15 @@ SysmanDeviceImp *LinuxSysmanImp::getSysmanDeviceImp() {
return pParentSysmanDeviceImp;
}
ze_bool_t LinuxSysmanImp::isDriverModelSupported() {
auto drmVersion = getDrm().getDrmVersion(getDrm().getFileDescriptor());
if ("i915" == drmVersion) {
return true;
} else {
return false;
}
}
static std::string modifyPathOnLevel(std::string realPciPath, uint8_t nLevel) {
size_t loc;
// we need to change the absolute path to 'nLevel' levels up

View File

@@ -57,6 +57,7 @@ class LinuxSysmanImp : public OsSysman, NEO::NonCopyableOrMovableClass {
Device *getDeviceHandle();
std::vector<ze_device_handle_t> &getDeviceHandles() override;
ze_device_handle_t getCoreDeviceHandle() override;
ze_bool_t isDriverModelSupported() override;
SysmanDeviceImp *getSysmanDeviceImp();
std::string getPciCardBusDirectoryPath(std::string realPciPath);
uint32_t getMemoryType();

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2022 Intel Corporation
* Copyright (C) 2020-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -21,6 +21,7 @@ struct OsSysman {
static OsSysman *create(SysmanDeviceImp *pSysmanImp);
virtual std::vector<ze_device_handle_t> &getDeviceHandles() = 0;
virtual ze_device_handle_t getCoreDeviceHandle() = 0;
virtual ze_bool_t isDriverModelSupported() = 0;
};
} // namespace L0

View File

@@ -39,8 +39,10 @@ SysmanDevice *SysmanDeviceHandleContext::init(ze_device_handle_t coreDevice) {
if (ZE_RESULT_SUCCESS != sysmanDevice->init()) {
delete sysmanDevice;
sysmanDevice = nullptr;
sysmanInitFromCore = false;
} else {
sysmanInitFromCore = true;
}
sysmanInitFromCore = true;
L0::DeviceImp *device = static_cast<DeviceImp *>(Device::fromHandle(coreDevice));
for (auto &subDevice : device->subDevices) {

View File

@@ -106,6 +106,12 @@ ze_result_t SysmanDeviceImp::init() {
updateSubDeviceHandlesLocally();
auto result = pOsSysman->init();
if (result == ZE_RESULT_SUCCESS) {
ze_bool_t driverModelSupported = pOsSysman->isDriverModelSupported();
if (!driverModelSupported) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
}
return result;
}

View File

@@ -53,6 +53,11 @@ FirmwareUtil *WddmSysmanImp::getFwUtilInterface() {
Device *WddmSysmanImp::getDeviceHandle() {
return pDevice;
}
ze_bool_t WddmSysmanImp::isDriverModelSupported() {
return true;
}
std::vector<ze_device_handle_t> &WddmSysmanImp::getDeviceHandles() {
return pParentSysmanDeviceImp->deviceHandles;
}

View File

@@ -35,6 +35,7 @@ class WddmSysmanImp : public OsSysman, NEO::NonCopyableOrMovableClass {
void releaseFwUtilInterface();
std::vector<ze_device_handle_t> &getDeviceHandles() override;
ze_device_handle_t getCoreDeviceHandle() override;
ze_bool_t isDriverModelSupported() override;
protected:
FirmwareUtil *pFwUtilInterface = nullptr;

View File

@@ -16,6 +16,7 @@
#include "level_zero/tools/source/sysman/ras/ras_imp.h"
#include "level_zero/tools/test/unit_tests/sources/sysman/linux/mock_sysman_fixture.h"
#include "drm/drm.h"
#include "drm/intel_hwconfig_types.h"
namespace NEO {
@@ -155,6 +156,53 @@ TEST_F(SysmanDeviceFixture, GivenValidDeviceHandleAndIfSysmanDeviceInitFailsThen
static_cast<DeviceImp *>(device)->setSysmanHandle(pSysmanDeviceOriginal);
}
TEST_F(SysmanDeviceFixture, GivenValidDeviceHandleAndSysmanHandleIsSetToNullWhenSysmanAPICalledThenErrorIsReturned) {
ze_device_handle_t hSysman = device->toHandle();
auto pSysmanDeviceOriginal = static_cast<DeviceImp *>(device)->getSysmanHandle();
static_cast<DeviceImp *>(device)->setSysmanHandle(nullptr);
uint32_t count = 0;
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, L0::SysmanDevice::schedulerGet(hSysman, &count, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, L0::SysmanDevice::processesGetState(hSysman, &count, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, L0::SysmanDevice::pciGetBars(hSysman, &count, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, L0::SysmanDevice::powerGet(hSysman, &count, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, L0::SysmanDevice::frequencyGet(hSysman, &count, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, L0::SysmanDevice::engineGet(hSysman, &count, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, L0::SysmanDevice::standbyGet(hSysman, &count, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, L0::SysmanDevice::firmwareGet(hSysman, &count, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, L0::SysmanDevice::memoryGet(hSysman, &count, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, L0::SysmanDevice::fabricPortGet(hSysman, &count, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, L0::SysmanDevice::temperatureGet(hSysman, &count, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, L0::SysmanDevice::rasGet(hSysman, &count, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, L0::SysmanDevice::fanGet(hSysman, &count, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, L0::SysmanDevice::diagnosticsGet(hSysman, &count, nullptr));
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, L0::SysmanDevice::performanceGet(hSysman, &count, nullptr));
zes_device_properties_t properties;
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, L0::SysmanDevice::deviceGetProperties(hSysman, &properties));
zes_device_state_t state;
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, L0::SysmanDevice::deviceGetState(hSysman, &state));
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, L0::SysmanDevice::deviceReset(hSysman, true));
zes_pci_properties_t pciProperties;
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, L0::SysmanDevice::pciGetProperties(hSysman, &pciProperties));
zes_pci_state_t pciState;
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, L0::SysmanDevice::pciGetState(hSysman, &pciState));
zes_pci_stats_t pciStats;
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, L0::SysmanDevice::pciGetStats(hSysman, &pciStats));
zes_event_type_flags_t events = ZES_EVENT_TYPE_FLAG_DEVICE_DETACH;
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, L0::SysmanDevice::deviceEventRegister(hSysman, events));
zes_pwr_handle_t phPower = {};
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, L0::SysmanDevice::powerGetCardDomain(hSysman, &phPower));
ze_bool_t eccAvailable = false;
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, L0::SysmanDevice::deviceEccAvailable(device, &eccAvailable));
ze_bool_t eccConfigurable = false;
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, L0::SysmanDevice::deviceEccConfigurable(device, &eccConfigurable));
zes_device_ecc_desc_t newState = {};
zes_device_ecc_properties_t props = {};
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, L0::SysmanDevice::deviceSetEccState(device, &newState, &props));
EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, L0::SysmanDevice::deviceGetEccState(device, &props));
static_cast<DeviceImp *>(device)->setSysmanHandle(pSysmanDeviceOriginal);
}
using MockDeviceSysmanGetTest = Test<DeviceFixture>;
TEST_F(MockDeviceSysmanGetTest, GivenValidSysmanHandleSetInDeviceStructWhenGetThisSysmanHandleThenHandlesShouldBeSimilar) {
SysmanDeviceImp *sysman = new SysmanDeviceImp(device->toHandle());
@@ -890,5 +938,84 @@ TEST_F(SysmanUnknownDriverModelTest, GivenDriverModelTypeIsNotDrmWhenExecutingSy
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pLinuxSysmanImp->init());
}
class MockOsSysman : public L0::OsSysman {
L0::SysmanDeviceImp *pParentSysmanDeviceImp;
public:
ze_bool_t mockDriverVersionSupported = false;
ze_result_t mockInitResult = ZE_RESULT_SUCCESS;
MockOsSysman(L0::SysmanDeviceImp *pParentSysmanDeviceImp) {
this->pParentSysmanDeviceImp = pParentSysmanDeviceImp;
}
ze_result_t init() override { return mockInitResult; }
ze_bool_t isDriverModelSupported() override { return mockDriverVersionSupported; }
std::vector<ze_device_handle_t> &getDeviceHandles() override {
return pParentSysmanDeviceImp->deviceHandles;
}
ze_device_handle_t getCoreDeviceHandle() override {
return pParentSysmanDeviceImp->hCoreDevice;
}
static MockOsSysman *create(L0::SysmanDeviceImp *pParentSysmanDeviceImp) {
MockOsSysman *pTestSysmanImp = new MockOsSysman(pParentSysmanDeviceImp);
return static_cast<MockOsSysman *>(pTestSysmanImp);
}
};
TEST_F(SysmanDeviceFixture, GivenValidDeviceHandleWhenisDriverModelSupportedReturnsTrueThenSuccessIsReturned) {
auto osSysmanOriginal = pSysmanDeviceImp->pOsSysman;
MockOsSysman *testOsSysman = MockOsSysman::create(pSysmanDeviceImp);
testOsSysman->mockInitResult = ZE_RESULT_SUCCESS;
testOsSysman->mockDriverVersionSupported = true;
pSysmanDeviceImp->pOsSysman = testOsSysman;
EXPECT_EQ(ZE_RESULT_SUCCESS, pSysmanDeviceImp->init());
pSysmanDeviceImp->pOsSysman = osSysmanOriginal;
delete testOsSysman;
}
TEST_F(SysmanDeviceFixture, GivenValidDeviceHandleWhenisDriverModelSupportedReturnsFalseThenUnSupportedIsReturned) {
auto osSysmanOriginal = pSysmanDeviceImp->pOsSysman;
MockOsSysman *testOsSysman = MockOsSysman::create(pSysmanDeviceImp);
testOsSysman->mockInitResult = ZE_RESULT_SUCCESS;
testOsSysman->mockDriverVersionSupported = false;
pSysmanDeviceImp->pOsSysman = testOsSysman;
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pSysmanDeviceImp->init());
pSysmanDeviceImp->pOsSysman = osSysmanOriginal;
delete testOsSysman;
}
TEST_F(SysmanDeviceFixture, GivenValidSysmanDeviceImpWhenOsSysmanInitFailsThenUnSupportedIsReturned) {
auto osSysmanOriginal = pSysmanDeviceImp->pOsSysman;
MockOsSysman *testOsSysman = MockOsSysman::create(pSysmanDeviceImp);
testOsSysman->mockInitResult = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
pSysmanDeviceImp->pOsSysman = testOsSysman;
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pSysmanDeviceImp->init());
pSysmanDeviceImp->pOsSysman = osSysmanOriginal;
delete testOsSysman;
}
TEST_F(SysmanDeviceFixture, GivenValidLinuxSysmanImpWhenDrmVersionIsXeThenFalseIsReturned) {
VariableBackup<decltype(SysCalls::sysCallsIoctl)> mockIoctl(&SysCalls::sysCallsIoctl, [](int fileDescriptor, unsigned long int request, void *arg) -> int {
const char *drmVersion = "xe";
if (request == DRM_IOCTL_VERSION) {
auto pVersion = static_cast<DrmVersion *>(arg);
memcpy_s(pVersion->name, pVersion->nameLen, drmVersion, std::min(pVersion->nameLen, strlen(drmVersion) + 1));
}
return 0;
});
EXPECT_EQ(false, pLinuxSysmanImp->isDriverModelSupported());
}
TEST_F(SysmanDeviceFixture, GivenValidLinuxSysmanImpWhenDrmVersionIsi915ThenTrueIsReturned) {
VariableBackup<decltype(SysCalls::sysCallsIoctl)> mockIoctl(&SysCalls::sysCallsIoctl, [](int fileDescriptor, unsigned long int request, void *arg) -> int {
const char *drmVersion = "i915";
if (request == DRM_IOCTL_VERSION) {
auto pVersion = static_cast<DrmVersion *>(arg);
memcpy_s(pVersion->name, pVersion->nameLen, drmVersion, std::min(pVersion->nameLen, strlen(drmVersion) + 1));
}
return 0;
});
EXPECT_EQ(true, pLinuxSysmanImp->isDriverModelSupported());
}
} // namespace ult
} // namespace L0

View File

@@ -53,5 +53,47 @@ TEST_F(SysmanDeviceFixture, GivenValidDeviceHandleWhenGetOsInterfaceIsInvokedThe
EXPECT_EQ(pWddmSysmanImp, osInterface);
}
class MockOsSysman : public L0::OsSysman {
L0::SysmanDeviceImp *pParentSysmanDeviceImp;
public:
ze_result_t mockReturnResult = ZE_RESULT_SUCCESS;
MockOsSysman(L0::SysmanDeviceImp *pParentSysmanDeviceImp) {
this->pParentSysmanDeviceImp = pParentSysmanDeviceImp;
}
ze_result_t init() override { return mockReturnResult; }
ze_bool_t isDriverModelSupported() override { return false; }
std::vector<ze_device_handle_t> &getDeviceHandles() override {
return pParentSysmanDeviceImp->deviceHandles;
}
ze_device_handle_t getCoreDeviceHandle() override {
return pParentSysmanDeviceImp->hCoreDevice;
}
static MockOsSysman *create(L0::SysmanDeviceImp *pParentSysmanDeviceImp) {
MockOsSysman *pTestSysmanImp = new MockOsSysman(pParentSysmanDeviceImp);
return static_cast<MockOsSysman *>(pTestSysmanImp);
}
};
TEST_F(SysmanDeviceFixture, GivenValidDeviceHandleWhenDrmVersionIsXeThenUnSupportedIsReturned) {
auto osSysmanOriginal = pSysmanDeviceImp->pOsSysman;
MockOsSysman *testOsSysman = MockOsSysman::create(pSysmanDeviceImp);
testOsSysman->mockReturnResult = ZE_RESULT_SUCCESS;
pSysmanDeviceImp->pOsSysman = testOsSysman;
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pSysmanDeviceImp->init());
pSysmanDeviceImp->pOsSysman = osSysmanOriginal;
delete testOsSysman;
}
TEST_F(SysmanDeviceFixture, GivenValidSysmanDeviceImpWhenOsSysmanInitFailsThenUnSupportedIsReturned) {
auto osSysmanOriginal = pSysmanDeviceImp->pOsSysman;
MockOsSysman *testOsSysman = MockOsSysman::create(pSysmanDeviceImp);
testOsSysman->mockReturnResult = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
pSysmanDeviceImp->pOsSysman = testOsSysman;
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pSysmanDeviceImp->init());
pSysmanDeviceImp->pOsSysman = osSysmanOriginal;
delete testOsSysman;
}
} // namespace ult
} // namespace L0
} // namespace L0