From 05406722b9062f25344f9e316c4f61088c0247e3 Mon Sep 17 00:00:00 2001 From: shubham kumar Date: Thu, 9 May 2024 07:15:57 +0000 Subject: [PATCH] feature(sysman): Add pciGetStats support in win Related-To: NEO-10662 Signed-off-by: shubham kumar --- .../source/api/pci/linux/sysman_os_pci_imp.cpp | 6 +++++- .../sysman/source/api/pci/linux/sysman_os_pci_imp.h | 3 ++- level_zero/sysman/source/api/pci/sysman_os_pci.h | 3 ++- level_zero/sysman/source/api/pci/sysman_pci.h | 3 ++- level_zero/sysman/source/api/pci/sysman_pci_imp.cpp | 7 ++++++- level_zero/sysman/source/api/pci/sysman_pci_imp.h | 3 ++- .../source/api/pci/windows/sysman_os_pci_imp.cpp | 11 ++++++++--- .../source/api/pci/windows/sysman_os_pci_imp.h | 5 ++++- .../sysman/source/device/sysman_device_imp.cpp | 4 ++-- .../windows/product_helper/sysman_product_helper.h | 3 +++ .../product_helper/sysman_product_helper_hw.h | 3 +++ .../product_helper/sysman_product_helper_hw.inl | 5 +++++ .../unit_tests/sources/pci/windows/CMakeLists.txt | 3 ++- .../test/unit_tests/sources/pci/windows/mock_pci.h | 13 ++++++++++++- .../unit_tests/sources/pci/windows/test_zes_pci.cpp | 10 +++++++++- .../tools/test/black_box_tests/zello_sysman.cpp | 13 +++++++++++++ 16 files changed, 80 insertions(+), 15 deletions(-) diff --git a/level_zero/sysman/source/api/pci/linux/sysman_os_pci_imp.cpp b/level_zero/sysman/source/api/pci/linux/sysman_os_pci_imp.cpp index d8a30ade8c..c7c3101daa 100644 --- a/level_zero/sysman/source/api/pci/linux/sysman_os_pci_imp.cpp +++ b/level_zero/sysman/source/api/pci/linux/sysman_os_pci_imp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -290,6 +290,10 @@ ze_result_t LinuxPciImp::getState(zes_pci_state_t *state) { return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; } +ze_result_t LinuxPciImp::getStats(zes_pci_stats_t *stats) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + bool LinuxPciImp::getPciConfigMemory(std::string pciPath, std::vector &configMem) { if (!pSysfsAccess->isRootUser()) { NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Need to be root to read config space \n", __FUNCTION__); diff --git a/level_zero/sysman/source/api/pci/linux/sysman_os_pci_imp.h b/level_zero/sysman/source/api/pci/linux/sysman_os_pci_imp.h index 0f64b4303d..0fcd514ad9 100644 --- a/level_zero/sysman/source/api/pci/linux/sysman_os_pci_imp.h +++ b/level_zero/sysman/source/api/pci/linux/sysman_os_pci_imp.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -25,6 +25,7 @@ class LinuxPciImp : public OsPci, NEO::NonCopyableOrMovableClass { ze_result_t getPciBdf(zes_pci_properties_t &pciProperties) override; void getMaxLinkCaps(double &maxLinkSpeed, int32_t &maxLinkWidth) override; ze_result_t getState(zes_pci_state_t *state) override; + ze_result_t getStats(zes_pci_stats_t *stats) override; ze_result_t getProperties(zes_pci_properties_t *properties) override; bool resizableBarSupported() override; bool resizableBarEnabled(uint32_t barIndex) override; diff --git a/level_zero/sysman/source/api/pci/sysman_os_pci.h b/level_zero/sysman/source/api/pci/sysman_os_pci.h index b57790ac2e..475f4ccd5d 100644 --- a/level_zero/sysman/source/api/pci/sysman_os_pci.h +++ b/level_zero/sysman/source/api/pci/sysman_os_pci.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -21,6 +21,7 @@ class OsPci { virtual ze_result_t getPciBdf(zes_pci_properties_t &pciProperties) = 0; virtual void getMaxLinkCaps(double &maxLinkSpeed, int32_t &maxLinkWidth) = 0; virtual ze_result_t getState(zes_pci_state_t *state) = 0; + virtual ze_result_t getStats(zes_pci_stats_t *stats) = 0; virtual ze_result_t getProperties(zes_pci_properties_t *properties) = 0; virtual bool resizableBarSupported() = 0; virtual bool resizableBarEnabled(uint32_t barIndex) = 0; diff --git a/level_zero/sysman/source/api/pci/sysman_pci.h b/level_zero/sysman/source/api/pci/sysman_pci.h index 1f39a3c39f..3d5449c2ae 100644 --- a/level_zero/sysman/source/api/pci/sysman_pci.h +++ b/level_zero/sysman/source/api/pci/sysman_pci.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -17,6 +17,7 @@ class Pci { virtual ze_result_t pciStaticProperties(zes_pci_properties_t *pProperties) = 0; virtual ze_result_t pciGetInitializedBars(uint32_t *pCount, zes_pci_bar_properties_t *pProperties) = 0; virtual ze_result_t pciGetState(zes_pci_state_t *pState) = 0; + virtual ze_result_t pciGetStats(zes_pci_stats_t *pStats) = 0; virtual void init() = 0; }; diff --git a/level_zero/sysman/source/api/pci/sysman_pci_imp.cpp b/level_zero/sysman/source/api/pci/sysman_pci_imp.cpp index 6f8824a500..93f5ea1bb0 100644 --- a/level_zero/sysman/source/api/pci/sysman_pci_imp.cpp +++ b/level_zero/sysman/source/api/pci/sysman_pci_imp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -128,6 +128,11 @@ ze_result_t PciImp::pciGetState(zes_pci_state_t *pState) { return pOsPci->getState(pState); } +ze_result_t PciImp::pciGetStats(zes_pci_stats_t *pStats) { + initPci(); + return pOsPci->getStats(pStats); +} + void PciImp::pciGetStaticFields() { pOsPci->getProperties(&pciProperties); resizableBarSupported = pOsPci->resizableBarSupported(); diff --git a/level_zero/sysman/source/api/pci/sysman_pci_imp.h b/level_zero/sysman/source/api/pci/sysman_pci_imp.h index a134a4b375..8d3365423b 100644 --- a/level_zero/sysman/source/api/pci/sysman_pci_imp.h +++ b/level_zero/sysman/source/api/pci/sysman_pci_imp.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -24,6 +24,7 @@ class PciImp : public L0::Sysman::Pci, NEO::NonCopyableOrMovableClass { ze_result_t pciStaticProperties(zes_pci_properties_t *pProperties) override; ze_result_t pciGetInitializedBars(uint32_t *pCount, zes_pci_bar_properties_t *pProperties) override; ze_result_t pciGetState(zes_pci_state_t *pState) override; + ze_result_t pciGetStats(zes_pci_stats_t *pStats) override; void pciGetStaticFields(); PciImp(L0::Sysman::OsSysman *pOsSysman) : pOsSysman(pOsSysman){}; diff --git a/level_zero/sysman/source/api/pci/windows/sysman_os_pci_imp.cpp b/level_zero/sysman/source/api/pci/windows/sysman_os_pci_imp.cpp index 2028ea17db..fff41c6afa 100644 --- a/level_zero/sysman/source/api/pci/windows/sysman_os_pci_imp.cpp +++ b/level_zero/sysman/source/api/pci/windows/sysman_os_pci_imp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,8 +7,8 @@ #include "level_zero/sysman/source/api/pci/windows/sysman_os_pci_imp.h" +#include "level_zero/sysman/source/shared/windows/product_helper/sysman_product_helper.h" #include "level_zero/sysman/source/shared/windows/sysman_kmd_sys_manager.h" -#include "level_zero/sysman/source/shared/windows/zes_os_sysman_imp.h" namespace L0 { namespace Sysman { @@ -154,6 +154,11 @@ ze_result_t WddmPciImp::getState(zes_pci_state_t *state) { return ZE_RESULT_SUCCESS; } +ze_result_t WddmPciImp::getStats(zes_pci_stats_t *stats) { + auto pSysmanProductHelper = pWddmSysmanImp->getSysmanProductHelper(); + return pSysmanProductHelper->getPciStats(stats, pWddmSysmanImp); +} + bool WddmPciImp::resizableBarSupported() { uint32_t valueSmall = 0; bool supported = false; @@ -200,7 +205,7 @@ ze_result_t WddmPciImp::initializeBarProperties(std::vector(pOsSysman); + pWddmSysmanImp = static_cast(pOsSysman); pKmdSysManager = &pWddmSysmanImp->getKmdSysManager(); isLmemSupported = !(pWddmSysmanImp->getSysmanDeviceImp()->getRootDeviceEnvironment().getHardwareInfo()->capabilityTable.isIntegratedDevice); diff --git a/level_zero/sysman/source/api/pci/windows/sysman_os_pci_imp.h b/level_zero/sysman/source/api/pci/windows/sysman_os_pci_imp.h index f7eafd5639..a9071dff03 100644 --- a/level_zero/sysman/source/api/pci/windows/sysman_os_pci_imp.h +++ b/level_zero/sysman/source/api/pci/windows/sysman_os_pci_imp.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -9,6 +9,7 @@ #include "shared/source/helpers/non_copyable_or_moveable.h" #include "level_zero/sysman/source/api/pci/sysman_os_pci.h" +#include "level_zero/sysman/source/shared/windows/zes_os_sysman_imp.h" namespace L0 { namespace Sysman { @@ -19,6 +20,7 @@ class WddmPciImp : public OsPci, NEO::NonCopyableOrMovableClass { ze_result_t getPciBdf(zes_pci_properties_t &pciProperties) override; void getMaxLinkCaps(double &maxLinkSpeed, int32_t &maxLinkWidth) override; ze_result_t getState(zes_pci_state_t *state) override; + ze_result_t getStats(zes_pci_stats_t *stats) override; ze_result_t getProperties(zes_pci_properties_t *properties) override; bool resizableBarSupported() override; bool resizableBarEnabled(uint32_t barIndex) override; @@ -28,6 +30,7 @@ class WddmPciImp : public OsPci, NEO::NonCopyableOrMovableClass { bool isLocalMemSupported(); protected: + WddmSysmanImp *pWddmSysmanImp = nullptr; KmdSysManager *pKmdSysManager = nullptr; private: diff --git a/level_zero/sysman/source/device/sysman_device_imp.cpp b/level_zero/sysman/source/device/sysman_device_imp.cpp index ce10219313..5ab49d643f 100644 --- a/level_zero/sysman/source/device/sysman_device_imp.cpp +++ b/level_zero/sysman/source/device/sysman_device_imp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -173,7 +173,7 @@ ze_result_t SysmanDeviceImp::pciGetBars(uint32_t *pCount, zes_pci_bar_properties } ze_result_t SysmanDeviceImp::pciGetStats(zes_pci_stats_t *pStats) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; + return pPci->pciGetStats(pStats); } ze_result_t SysmanDeviceImp::fanGet(uint32_t *pCount, zes_fan_handle_t *phFan) { diff --git a/level_zero/sysman/source/shared/windows/product_helper/sysman_product_helper.h b/level_zero/sysman/source/shared/windows/product_helper/sysman_product_helper.h index f6fadfa09a..a3336efd84 100644 --- a/level_zero/sysman/source/shared/windows/product_helper/sysman_product_helper.h +++ b/level_zero/sysman/source/shared/windows/product_helper/sysman_product_helper.h @@ -43,6 +43,9 @@ class SysmanProductHelper { // Temperature virtual ze_result_t getSensorTemperature(double *pTemperature, zes_temp_sensors_t type, WddmSysmanImp *pWddmSysmanImp) = 0; + // Pci + virtual ze_result_t getPciStats(zes_pci_stats_t *pStats, WddmSysmanImp *pWddmSysmanImp) = 0; + protected: SysmanProductHelper() = default; }; diff --git a/level_zero/sysman/source/shared/windows/product_helper/sysman_product_helper_hw.h b/level_zero/sysman/source/shared/windows/product_helper/sysman_product_helper_hw.h index 3224b6ef42..e8df9961a8 100644 --- a/level_zero/sysman/source/shared/windows/product_helper/sysman_product_helper_hw.h +++ b/level_zero/sysman/source/shared/windows/product_helper/sysman_product_helper_hw.h @@ -27,6 +27,9 @@ class SysmanProductHelperHw : public SysmanProductHelper { // Temperature ze_result_t getSensorTemperature(double *pTemperature, zes_temp_sensors_t type, WddmSysmanImp *pWddmSysmanImp) override; + // Pci + ze_result_t getPciStats(zes_pci_stats_t *pStats, WddmSysmanImp *pWddmSysmanImp) override; + protected: SysmanProductHelperHw() = default; }; diff --git a/level_zero/sysman/source/shared/windows/product_helper/sysman_product_helper_hw.inl b/level_zero/sysman/source/shared/windows/product_helper/sysman_product_helper_hw.inl index b1888a1c98..09e406c583 100644 --- a/level_zero/sysman/source/shared/windows/product_helper/sysman_product_helper_hw.inl +++ b/level_zero/sysman/source/shared/windows/product_helper/sysman_product_helper_hw.inl @@ -51,5 +51,10 @@ ze_result_t SysmanProductHelperHw::getSensorTemperature(double *pTem return status; } +template +ze_result_t SysmanProductHelperHw::getPciStats(zes_pci_stats_t *pStats, WddmSysmanImp *pWddmSysmanImp) { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; +} + } // namespace Sysman } // namespace L0 diff --git a/level_zero/sysman/test/unit_tests/sources/pci/windows/CMakeLists.txt b/level_zero/sysman/test/unit_tests/sources/pci/windows/CMakeLists.txt index ddb4f67d62..154e230d9d 100644 --- a/level_zero/sysman/test/unit_tests/sources/pci/windows/CMakeLists.txt +++ b/level_zero/sysman/test/unit_tests/sources/pci/windows/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (C) 2023 Intel Corporation +# Copyright (C) 2023-2024 Intel Corporation # # SPDX-License-Identifier: MIT # @@ -12,3 +12,4 @@ if(WIN32) ${CMAKE_CURRENT_SOURCE_DIR}/mock_pci.h ) endif() +add_subdirectories() \ No newline at end of file diff --git a/level_zero/sysman/test/unit_tests/sources/pci/windows/mock_pci.h b/level_zero/sysman/test/unit_tests/sources/pci/windows/mock_pci.h index 40de36b46d..bf779dd75d 100644 --- a/level_zero/sysman/test/unit_tests/sources/pci/windows/mock_pci.h +++ b/level_zero/sysman/test/unit_tests/sources/pci/windows/mock_pci.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -14,6 +14,11 @@ namespace L0 { namespace Sysman { namespace ult { +constexpr uint64_t mockRxCounter = 242000000000; +constexpr uint64_t mockTxCounter = 231000000000; +constexpr uint64_t mockRxPacketCounter = 3000000000; +constexpr uint64_t mockTxPacketCounter = 2000000000; + struct PciKmdSysManager : public MockKmdSysManager { // PciCurrentDevice, PciParentDevice, PciRootPort uint32_t mockDomain[3] = {0, 0, 0}; @@ -118,6 +123,12 @@ struct PciKmdSysManager : public MockKmdSysManager { } }; +class PublicPlatformMonitoringTech : public L0::Sysman::PlatformMonitoringTech { + public: + PublicPlatformMonitoringTech(std::vector deviceInterfaceList) : PlatformMonitoringTech(deviceInterfaceList) {} + using PlatformMonitoringTech::keyOffsetMap; +}; + } // namespace ult } // namespace Sysman } // namespace L0 diff --git a/level_zero/sysman/test/unit_tests/sources/pci/windows/test_zes_pci.cpp b/level_zero/sysman/test/unit_tests/sources/pci/windows/test_zes_pci.cpp index 5a31e1e92d..71ccd141bc 100644 --- a/level_zero/sysman/test/unit_tests/sources/pci/windows/test_zes_pci.cpp +++ b/level_zero/sysman/test/unit_tests/sources/pci/windows/test_zes_pci.cpp @@ -1,10 +1,12 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * */ +#include "shared/test/common/test_macros/hw_test.h" + #include "level_zero/sysman/source/sysman_const.h" #include "level_zero/sysman/test/unit_tests/sources/windows/mock_sysman_fixture.h" @@ -199,6 +201,12 @@ TEST_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetB } } +HWTEST2_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenCallingzesPciGetStatsThenCallReturnsUnsupported, IsAtMostDg2) { + zes_pci_stats_t stats; + ze_result_t result = zesDevicePciGetStats(pSysmanDevice->toHandle(), &stats); + EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, result); +} + TEST_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetStatsWithLocalMemoryThenVerifyzetSysmanPciGetBarsCallSucceeds) { setLocalMemorySupportedAndReinit(true); diff --git a/level_zero/tools/test/black_box_tests/zello_sysman.cpp b/level_zero/tools/test/black_box_tests/zello_sysman.cpp index 5c323c3038..62a36cd001 100644 --- a/level_zero/tools/test/black_box_tests/zello_sysman.cpp +++ b/level_zero/tools/test/black_box_tests/zello_sysman.cpp @@ -562,6 +562,19 @@ void testSysmanPci(ze_device_handle_t &device) { pciBarProps[i].pNext = static_cast(&pciBarExtProps[i]); } + zes_pci_stats_t pciStats = {}; + VALIDATECALL(zesDevicePciGetStats(device, &pciStats)); + if (verbose) { + std::cout << "pciStats.replayCounter = " << std::dec << pciStats.replayCounter << std::endl; + std::cout << "pciStats.packetCounter = " << std::dec << pciStats.packetCounter << std::endl; + std::cout << "pciStats.rxCounter = " << std::dec << pciStats.rxCounter << std::endl; + std::cout << "pciStats.txCounter = " << std::dec << pciStats.txCounter << std::endl; + std::cout << "pciStats.timestamp = " << std::dec << pciStats.timestamp << std::endl; + std::cout << "pciStats.speed.gen = " << std::dec << pciStats.speed.gen << std::endl; + std::cout << "pciStats.speed.width = " << std::dec << pciStats.speed.width << std::endl; + std::cout << "pciStats.speed.maxBandWidth = " << std::dec << pciStats.speed.maxBandwidth << std::endl; + } + VALIDATECALL(zesDevicePciGetBars(device, &count, pciBarProps.data())); if (verbose) { for (uint32_t i = 0; i < count; i++) {