From 220c5758506e7cca16900ae3c34de6909c562c83 Mon Sep 17 00:00:00 2001 From: mraghuwa Date: Wed, 5 Aug 2020 00:52:42 +0530 Subject: [PATCH] Update Ras Api's as per latest spec Change-Id: I29b77eee0832fcca6d989f9ef41b01b17232a91e Signed-off-by: mraghuwa --- level_zero/api/sysman/zes_sysman.cpp | 10 +- .../source/sysman/ras/linux/os_ras_imp.cpp | 4 +- level_zero/tools/source/sysman/ras/ras.h | 1 + .../tools/source/sysman/ras/ras_imp.cpp | 4 + level_zero/tools/source/sysman/ras/ras_imp.h | 1 + level_zero/tools/source/sysman/sysman.h | 1 + level_zero/tools/source/sysman/sysman_imp.cpp | 9 ++ level_zero/tools/source/sysman/sysman_imp.h | 2 + .../sources/sysman/ras/linux/CMakeLists.txt | 6 +- .../sysman/ras/linux/test_sysman_ras.cpp | 115 ------------------ .../sources/sysman/ras/linux/test_zes_ras.cpp | 60 +++++++++ 11 files changed, 87 insertions(+), 126 deletions(-) delete mode 100644 level_zero/tools/test/unit_tests/sources/sysman/ras/linux/test_sysman_ras.cpp create mode 100644 level_zero/tools/test/unit_tests/sources/sysman/ras/linux/test_zes_ras.cpp diff --git a/level_zero/api/sysman/zes_sysman.cpp b/level_zero/api/sysman/zes_sysman.cpp index 84d5d40be1..db87442369 100644 --- a/level_zero/api/sysman/zes_sysman.cpp +++ b/level_zero/api/sysman/zes_sysman.cpp @@ -621,28 +621,28 @@ zesDeviceEnumRasErrorSets( zes_device_handle_t hDevice, uint32_t *pCount, zes_ras_handle_t *phRas) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; + return L0::SysmanDevice::fromHandle(hDevice)->rasGet(pCount, phRas); } ZE_APIEXPORT ze_result_t ZE_APICALL zesRasGetProperties( zes_ras_handle_t hRas, zes_ras_properties_t *pProperties) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; + return L0::Ras::fromHandle(hRas)->rasGetProperties(pProperties); } ZE_APIEXPORT ze_result_t ZE_APICALL zesRasGetConfig( zes_ras_handle_t hRas, zes_ras_config_t *pConfig) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; + return L0::Ras::fromHandle(hRas)->rasGetConfig(pConfig); } ZE_APIEXPORT ze_result_t ZE_APICALL zesRasSetConfig( zes_ras_handle_t hRas, const zes_ras_config_t *pConfig) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; + return L0::Ras::fromHandle(hRas)->rasSetConfig(pConfig); } ZE_APIEXPORT ze_result_t ZE_APICALL @@ -650,7 +650,7 @@ zesRasGetState( zes_ras_handle_t hRas, ze_bool_t clear, zes_ras_state_t *pState) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; + return L0::Ras::fromHandle(hRas)->rasGetState(pState); } ZE_APIEXPORT ze_result_t ZE_APICALL diff --git a/level_zero/tools/source/sysman/ras/linux/os_ras_imp.cpp b/level_zero/tools/source/sysman/ras/linux/os_ras_imp.cpp index 9041e21f58..a7eb0aa644 100644 --- a/level_zero/tools/source/sysman/ras/linux/os_ras_imp.cpp +++ b/level_zero/tools/source/sysman/ras/linux/os_ras_imp.cpp @@ -25,9 +25,7 @@ bool LinuxRasImp::isRasSupported(void) { if (osRasErrorType == ZES_RAS_ERROR_TYPE_CORRECTABLE) { return false; } else { - // i915 support for UNCORRECTABLE errors is assumed true - // since support for reset event is already available. - return true; + return false; } } diff --git a/level_zero/tools/source/sysman/ras/ras.h b/level_zero/tools/source/sysman/ras/ras.h index ac1451f3ab..1a1087334a 100644 --- a/level_zero/tools/source/sysman/ras/ras.h +++ b/level_zero/tools/source/sysman/ras/ras.h @@ -23,6 +23,7 @@ class Ras : _zes_ras_handle_t { virtual ze_result_t rasGetProperties(zes_ras_properties_t *pProperties) = 0; virtual ze_result_t rasGetConfig(zes_ras_config_t *pConfig) = 0; virtual ze_result_t rasSetConfig(const zes_ras_config_t *pConfig) = 0; + virtual ze_result_t rasGetState(const zes_ras_state_t *pState) = 0; static Ras *fromHandle(zes_ras_handle_t handle) { return static_cast(handle); diff --git a/level_zero/tools/source/sysman/ras/ras_imp.cpp b/level_zero/tools/source/sysman/ras/ras_imp.cpp index 207e46fe24..c8b0f09f18 100644 --- a/level_zero/tools/source/sysman/ras/ras_imp.cpp +++ b/level_zero/tools/source/sysman/ras/ras_imp.cpp @@ -30,6 +30,10 @@ ze_result_t RasImp::rasSetConfig(const zes_ras_config_t *pConfig) { return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; } +ze_result_t RasImp::rasGetState(const zes_ras_state_t *pState) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + void RasImp::init() { pOsRas->setRasErrorType(this->rasErrorType); isRasErrorSupported = pOsRas->isRasSupported(); diff --git a/level_zero/tools/source/sysman/ras/ras_imp.h b/level_zero/tools/source/sysman/ras/ras_imp.h index 33980e3bdc..d16957cf40 100644 --- a/level_zero/tools/source/sysman/ras/ras_imp.h +++ b/level_zero/tools/source/sysman/ras/ras_imp.h @@ -19,6 +19,7 @@ class RasImp : public Ras, NEO::NonCopyableOrMovableClass { ze_result_t rasGetProperties(zes_ras_properties_t *pProperties) override; ze_result_t rasGetConfig(zes_ras_config_t *pConfig) override; ze_result_t rasSetConfig(const zes_ras_config_t *pConfig) override; + ze_result_t rasGetState(const zes_ras_state_t *pConfig) override; RasImp() = default; RasImp(OsSysman *pOsSysman, zes_ras_error_type_t type); diff --git a/level_zero/tools/source/sysman/sysman.h b/level_zero/tools/source/sysman/sysman.h index c732d659ff..6cf60ca28e 100644 --- a/level_zero/tools/source/sysman/sysman.h +++ b/level_zero/tools/source/sysman/sysman.h @@ -42,6 +42,7 @@ struct SysmanDevice : _ze_device_handle_t { virtual ze_result_t pciGetBars(uint32_t *pCount, zes_pci_bar_properties_t *pProperties) = 0; virtual ze_result_t pciGetStats(zes_pci_stats_t *pStats) = 0; virtual ze_result_t schedulerGet(uint32_t *pCount, zes_sched_handle_t *phScheduler) = 0; + virtual ze_result_t rasGet(uint32_t *pCount, zes_ras_handle_t *phRas) = 0; virtual ~SysmanDevice() = default; }; diff --git a/level_zero/tools/source/sysman/sysman_imp.cpp b/level_zero/tools/source/sysman/sysman_imp.cpp index 8507ca240f..7ec4ca4790 100644 --- a/level_zero/tools/source/sysman/sysman_imp.cpp +++ b/level_zero/tools/source/sysman/sysman_imp.cpp @@ -29,9 +29,11 @@ SysmanDeviceImp::SysmanDeviceImp(ze_device_handle_t hDevice) { pStandbyHandleContext = new StandbyHandleContext(pOsSysman); pEngineHandleContext = new EngineHandleContext(pOsSysman); pSchedulerHandleContext = new SchedulerHandleContext(pOsSysman); + pRasHandleContext = new RasHandleContext(pOsSysman); } SysmanDeviceImp::~SysmanDeviceImp() { + freeResource(pRasHandleContext); freeResource(pSchedulerHandleContext); freeResource(pEngineHandleContext); freeResource(pStandbyHandleContext); @@ -69,6 +71,9 @@ void SysmanDeviceImp::init() { if (pSchedulerHandleContext) { pSchedulerHandleContext->init(); } + if (pRasHandleContext) { + pRasHandleContext->init(); + } } ze_result_t SysmanDeviceImp::frequencyGet(uint32_t *pCount, zes_freq_handle_t *phFrequency) { @@ -115,4 +120,8 @@ ze_result_t SysmanDeviceImp::schedulerGet(uint32_t *pCount, zes_sched_handle_t * return pSchedulerHandleContext->schedulerGet(pCount, phScheduler); } +ze_result_t SysmanDeviceImp::rasGet(uint32_t *pCount, zes_ras_handle_t *phRas) { + return pRasHandleContext->rasGet(pCount, phRas); +} + } // namespace L0 diff --git a/level_zero/tools/source/sysman/sysman_imp.h b/level_zero/tools/source/sysman/sysman_imp.h index 45b994e7fb..8a29085908 100644 --- a/level_zero/tools/source/sysman/sysman_imp.h +++ b/level_zero/tools/source/sysman/sysman_imp.h @@ -34,6 +34,7 @@ struct SysmanDeviceImp : SysmanDevice, NEO::NonCopyableOrMovableClass { StandbyHandleContext *pStandbyHandleContext = nullptr; EngineHandleContext *pEngineHandleContext = nullptr; SchedulerHandleContext *pSchedulerHandleContext = nullptr; + RasHandleContext *pRasHandleContext = nullptr; ze_result_t powerGet(uint32_t *pCount, zes_pwr_handle_t *phPower) override; ze_result_t frequencyGet(uint32_t *pCount, zes_freq_handle_t *phFrequency) override; @@ -46,6 +47,7 @@ struct SysmanDeviceImp : SysmanDevice, NEO::NonCopyableOrMovableClass { ze_result_t pciGetBars(uint32_t *pCount, zes_pci_bar_properties_t *pProperties) override; ze_result_t pciGetStats(zes_pci_stats_t *pStats) override; ze_result_t schedulerGet(uint32_t *pCount, zes_sched_handle_t *phScheduler) override; + ze_result_t rasGet(uint32_t *pCount, zes_ras_handle_t *phRas) override; private: template diff --git a/level_zero/tools/test/unit_tests/sources/sysman/ras/linux/CMakeLists.txt b/level_zero/tools/test/unit_tests/sources/sysman/ras/linux/CMakeLists.txt index c8fa8b5fee..3b4a93c393 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/ras/linux/CMakeLists.txt +++ b/level_zero/tools/test/unit_tests/sources/sysman/ras/linux/CMakeLists.txt @@ -7,8 +7,8 @@ if(UNIX) target_sources(${TARGET_NAME} PRIVATE - # ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt - # ${CMAKE_CURRENT_SOURCE_DIR}/test_sysman_ras.cpp - # ${CMAKE_CURRENT_SOURCE_DIR}/mock_fs_ras.h + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/test_zes_ras.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/mock_fs_ras.h ) endif() diff --git a/level_zero/tools/test/unit_tests/sources/sysman/ras/linux/test_sysman_ras.cpp b/level_zero/tools/test/unit_tests/sources/sysman/ras/linux/test_sysman_ras.cpp deleted file mode 100644 index 6f17c0fa24..0000000000 --- a/level_zero/tools/test/unit_tests/sources/sysman/ras/linux/test_sysman_ras.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (C) 2020 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h" -#include "level_zero/tools/source/sysman/sysman_imp.h" - -#include "gmock/gmock.h" -#include "gtest/gtest.h" -#include "mock_fs_ras.h" - -using ::testing::_; -using ::testing::Invoke; -using ::testing::Matcher; -using ::testing::NiceMock; - -namespace L0 { -namespace ult { - -struct SysmanRasFixture : public DeviceFixture, public ::testing::Test { - protected: - std::unique_ptr sysmanImp; - zet_sysman_handle_t hSysman; - zes_ras_handle_t hSysmanRas; - Mock *pFsAccess = nullptr; - OsRas *pOsRas = nullptr; - PublicLinuxRasImp linuxRasImp; - RasImp *pRasImp = nullptr; - unsigned long numRasHandlesSetup = 0; - - void SetUp() override { - DeviceFixture::SetUp(); - sysmanImp = std::make_unique(device->toHandle()); - pFsAccess = new NiceMock>; - linuxRasImp.pFsAccess = pFsAccess; - pOsRas = static_cast(&linuxRasImp); - pRasImp = new RasImp(); - pRasImp->pOsRas = pOsRas; - ON_CALL(*pFsAccess, read(_, Matcher(_))) - .WillByDefault(::testing::Invoke(pFsAccess, &Mock::getVal)); - ON_CALL(*pFsAccess, fileExists(_)) - .WillByDefault(::testing::Invoke(pFsAccess, &Mock::checkFileExists)); - pRasImp->rasErrorType = ZES_RAS_ERROR_TYPE_UNCORRECTABLE; - pRasImp->init(); - pOsRas->setRasErrorType(ZES_RAS_ERROR_TYPE_UNCORRECTABLE); - sysmanImp->pRasHandleContext->handleList.push_back(pRasImp); - numRasHandlesSetup = sysmanImp->pRasHandleContext->handleList.size(); - hSysman = sysmanImp->toHandle(); - hSysmanRas = pRasImp->toHandle(); - } - void TearDown() override { - pRasImp->pOsRas = nullptr; - if (pFsAccess != nullptr) { - delete pFsAccess; - pFsAccess = nullptr; - } - DeviceFixture::TearDown(); - } -}; - -TEST_F(SysmanRasFixture, GivenValidRasHandleWhenCallingSysmanRasGetThenExpectCallToSucceed) { - zes_ras_handle_t rasHandle; - uint32_t count = 0; - ze_result_t result = zetSysmanRasGet(hSysman, &count, NULL); - - EXPECT_EQ(ZE_RESULT_SUCCESS, result); - EXPECT_EQ(numRasHandlesSetup, count); - - uint32_t testcount = count + 1; - - result = zetSysmanRasGet(hSysman, &testcount, NULL); - - EXPECT_EQ(ZE_RESULT_SUCCESS, result); - EXPECT_EQ(testcount, count); - - result = zetSysmanRasGet(hSysman, &count, &rasHandle); - - EXPECT_EQ(ZE_RESULT_SUCCESS, result); - EXPECT_EQ(numRasHandlesSetup, count); -} - -TEST_F(SysmanRasFixture, GivenCorrectCounterNameWhenCheckingRasCounterSupportThenExpectTrue) { - EXPECT_TRUE(pOsRas->isRasSupported()); -} -TEST_F(SysmanRasFixture, GivenCorrectableTypeWhenCheckingRasErrorSupportThenExpectFalse) { - pOsRas->setRasErrorType(ZES_RAS_ERROR_TYPE_CORRECTABLE); - EXPECT_FALSE(pOsRas->isRasSupported()); -} - -TEST_F(SysmanRasFixture, GivenIncorrectDirectoryNameWhenCheckingRasCounterSupportThenExpectFalse) { - pFsAccess->setRasDirName("wrong/ras/Dir"); - EXPECT_FALSE(pOsRas->isRasSupported()); -} - -TEST_F(SysmanRasFixture, GivenValidRasHandleWhenCallingSysmanGetPropertiesThenExpectCallToSucceed) { - zes_ras_properties_t properties; - - EXPECT_EQ(ZE_RESULT_SUCCESS, zetSysmanRasGetProperties(hSysmanRas, &properties)); - EXPECT_EQ(ZES_RAS_ERROR_TYPE_UNCORRECTABLE, properties.type); - EXPECT_FALSE(properties.onSubdevice); -} - -TEST_F(SysmanRasFixture, GivenNullptrForRasDetailsWhenCallingSysmanRasGetStateThenExpectCallToReturnTotalErrorsOnly) { - uint64_t totalErrors; - ze_result_t result; - - result = zetSysmanRasGetState(hSysmanRas, false, &totalErrors, nullptr); - EXPECT_EQ(ZE_RESULT_SUCCESS, result); - EXPECT_EQ(totalErrors, mockResetCount); -} -} // namespace ult -} // namespace L0 diff --git a/level_zero/tools/test/unit_tests/sources/sysman/ras/linux/test_zes_ras.cpp b/level_zero/tools/test/unit_tests/sources/sysman/ras/linux/test_zes_ras.cpp new file mode 100644 index 0000000000..a0ba03d66d --- /dev/null +++ b/level_zero/tools/test/unit_tests/sources/sysman/ras/linux/test_zes_ras.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "level_zero/tools/test/unit_tests/sources/sysman/mock_sysman_fixture.h" + +#include "mock_fs_ras.h" + +using ::testing::_; +using ::testing::Matcher; +using ::testing::NiceMock; + +namespace L0 { +namespace ult { + +struct SysmanRasFixture : public SysmanDeviceFixture { + protected: + std::unique_ptr> ptestFsAccess; + FsAccess *pOriginalFsAccess = nullptr; + + void SetUp() override { + SysmanDeviceFixture::SetUp(); + ptestFsAccess = std::make_unique>>(); + pOriginalFsAccess = pLinuxSysmanImp->pFsAccess; + pLinuxSysmanImp->pFsAccess = ptestFsAccess.get(); + ON_CALL(*ptestFsAccess.get(), read(_, Matcher(_))) + .WillByDefault(::testing::Invoke(ptestFsAccess.get(), &Mock::getVal)); + ON_CALL(*ptestFsAccess.get(), fileExists(_)) + .WillByDefault(::testing::Invoke(ptestFsAccess.get(), &Mock::checkFileExists)); + pSysmanDeviceImp->pRasHandleContext->handleList.clear(); + pSysmanDeviceImp->pRasHandleContext->init(); + } + void TearDown() override { + SysmanDeviceFixture::TearDown(); + pLinuxSysmanImp->pFsAccess = pOriginalFsAccess; + } +}; + +TEST_F(SysmanRasFixture, GivenValidSysmanHandleWhenRetrievingRasZeroHandlesInReturn) { + uint32_t count = 0; + ze_result_t result = zesDeviceEnumRasErrorSets(device->toHandle(), &count, NULL); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); + EXPECT_EQ(count, 0u); + + uint32_t testcount = count + 1; + result = zesDeviceEnumRasErrorSets(device->toHandle(), &testcount, NULL); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); + EXPECT_EQ(testcount, 0u); + + count = 0; + std::vector handles(count, nullptr); + EXPECT_EQ(zesDeviceEnumRasErrorSets(device->toHandle(), &count, handles.data()), ZE_RESULT_SUCCESS); + EXPECT_EQ(count, 0u); +} + +} // namespace ult +} // namespace L0