From 249f7e45ccb2cecd546bcd90270e4cfc1fbc7313 Mon Sep 17 00:00:00 2001 From: Jitendra Sharma Date: Wed, 3 Mar 2021 12:34:30 +0530 Subject: [PATCH] Adding more features to Sysman's memory and Temperature APIs This change - - Add support for memoryGetBandwidth API - Update temperature offsets - Update ULTs accordingly Signed-off-by: Jitendra Sharma --- .../source/sysman/linux/pmt/CMakeLists.txt | 3 +- .../tools/source/sysman/linux/pmt/pmt.cpp | 12 ++-- .../tools/source/sysman/linux/pmt/pmt.h | 1 + .../source/sysman/linux/pmt/pmt_helper.cpp | 23 ++++++++ level_zero/tools/source/sysman/sysman_const.h | 5 +- .../temperature/linux/os_temperature_imp.h | 2 + .../linux/mock_sysfs_temperature.h | 55 ++++++++++++------- 7 files changed, 73 insertions(+), 28 deletions(-) create mode 100644 level_zero/tools/source/sysman/linux/pmt/pmt_helper.cpp diff --git a/level_zero/tools/source/sysman/linux/pmt/CMakeLists.txt b/level_zero/tools/source/sysman/linux/pmt/CMakeLists.txt index 3acf7aa0b4..9fdd7c774f 100644 --- a/level_zero/tools/source/sysman/linux/pmt/CMakeLists.txt +++ b/level_zero/tools/source/sysman/linux/pmt/CMakeLists.txt @@ -5,7 +5,8 @@ # set(L0_SRCS_TOOLS_SYSMAN_LINUX_PMT - ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/pmt.cpp + ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/pmt_helper.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/pmt.cpp ${CMAKE_CURRENT_SOURCE_DIR}/pmt.h ) if(UNIX) diff --git a/level_zero/tools/source/sysman/linux/pmt/pmt.cpp b/level_zero/tools/source/sysman/linux/pmt/pmt.cpp index d2226f042d..35fbcaf31e 100644 --- a/level_zero/tools/source/sysman/linux/pmt/pmt.cpp +++ b/level_zero/tools/source/sysman/linux/pmt/pmt.cpp @@ -20,12 +20,6 @@ const std::string PlatformMonitoringTech::baseTelemSysFS("/sys/class/intel_pmt") const std::string PlatformMonitoringTech::telem("telem"); uint32_t PlatformMonitoringTech::rootDeviceTelemNodeIndex = 0; -const std::map deviceKeyOffsetMap = { - {"PACKAGE_ENERGY", 0x400}, - {"COMPUTE_TEMPERATURES", 0x68}, - {"SOC_TEMPERATURES", 0x60}, - {"CORE_TEMPERATURES", 0x6c}}; - ze_result_t PlatformMonitoringTech::enumerateRootTelemIndex(FsAccess *pFsAccess, std::string &rootPciPathOfGpuDevice) { std::vector listOfTelemNodes; auto result = pFsAccess->listDirectory(baseTelemSysFS, listOfTelemNodes); @@ -96,7 +90,11 @@ void PlatformMonitoringTech::init(FsAccess *pFsAccess) { retVal = result; return; } - keyOffsetMap = deviceKeyOffsetMap; + if (getKeyOffsetMap(guid, keyOffsetMap) != ZE_RESULT_SUCCESS) { + // We didnt have any entry for this guid in guidToKeyOffsetMap + retVal = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; + return; + } std::string sizePath = baseTelemSysFSNode + std::string("/size"); result = pFsAccess->read(sizePath, size); diff --git a/level_zero/tools/source/sysman/linux/pmt/pmt.h b/level_zero/tools/source/sysman/linux/pmt/pmt.h index 559b5a71df..3f3d90108b 100644 --- a/level_zero/tools/source/sysman/linux/pmt/pmt.h +++ b/level_zero/tools/source/sysman/linux/pmt/pmt.h @@ -32,6 +32,7 @@ class PlatformMonitoringTech : NEO::NonCopyableOrMovableClass { char *mappedMemory = nullptr; static uint32_t rootDeviceTelemNodeIndex; std::map keyOffsetMap; + ze_result_t getKeyOffsetMap(std::string guid, std::map &keyOffsetMap); private: void init(FsAccess *pFsAccess); diff --git a/level_zero/tools/source/sysman/linux/pmt/pmt_helper.cpp b/level_zero/tools/source/sysman/linux/pmt/pmt_helper.cpp new file mode 100644 index 0000000000..a0681f9df9 --- /dev/null +++ b/level_zero/tools/source/sysman/linux/pmt/pmt_helper.cpp @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2020-2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "level_zero/tools/source/sysman/linux/pmt/pmt.h" + +namespace L0 { + +const std::map deviceKeyOffsetMap = { + {"PACKAGE_ENERGY", 0x400}, + {"COMPUTE_TEMPERATURES", 0x68}, + {"SOC_TEMPERATURES", 0x60}, + {"CORE_TEMPERATURES", 0x6c}}; + +ze_result_t PlatformMonitoringTech::getKeyOffsetMap(std::string guid, std::map &keyOffsetMap) { + keyOffsetMap = deviceKeyOffsetMap; + return ZE_RESULT_SUCCESS; +} + +} // namespace L0 \ No newline at end of file diff --git a/level_zero/tools/source/sysman/sysman_const.h b/level_zero/tools/source/sysman/sysman_const.h index 988f8db2fb..0c070d30d6 100644 --- a/level_zero/tools/source/sysman/sysman_const.h +++ b/level_zero/tools/source/sysman/sysman_const.h @@ -40,4 +40,7 @@ constexpr uint64_t minTimeoutModeHeartbeat = 5000u; constexpr uint64_t minTimeoutInMicroSeconds = 1000u; constexpr uint16_t milliSecsToMicroSecs = 1000; constexpr uint32_t milliFactor = 1000u; -constexpr uint32_t microFacor = milliFactor * milliFactor; \ No newline at end of file +constexpr uint32_t microFacor = milliFactor * milliFactor; + +constexpr int32_t memoryBusWidth = 128; // bus width in bits +constexpr int32_t numMemoryChannels = 8; \ No newline at end of file diff --git a/level_zero/tools/source/sysman/temperature/linux/os_temperature_imp.h b/level_zero/tools/source/sysman/temperature/linux/os_temperature_imp.h index da209f8712..dc381aa29a 100644 --- a/level_zero/tools/source/sysman/temperature/linux/os_temperature_imp.h +++ b/level_zero/tools/source/sysman/temperature/linux/os_temperature_imp.h @@ -16,6 +16,7 @@ namespace L0 { class SysfsAccess; class PlatformMonitoringTech; +struct Device; class LinuxTemperatureImp : public OsTemperature, NEO::NonCopyableOrMovableClass { public: ze_result_t getProperties(zes_temp_properties_t *pProperties) override; @@ -28,6 +29,7 @@ class LinuxTemperatureImp : public OsTemperature, NEO::NonCopyableOrMovableClass protected: PlatformMonitoringTech *pPmt = nullptr; + Device *pDevice = nullptr; zes_temp_sensors_t type = ZES_TEMP_SENSORS_GLOBAL; private: diff --git a/level_zero/tools/test/unit_tests/sources/sysman/temperature/linux/mock_sysfs_temperature.h b/level_zero/tools/test/unit_tests/sources/sysman/temperature/linux/mock_sysfs_temperature.h index a3af35c39d..175edc67cd 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/temperature/linux/mock_sysfs_temperature.h +++ b/level_zero/tools/test/unit_tests/sources/sysman/temperature/linux/mock_sysfs_temperature.h @@ -14,10 +14,16 @@ namespace L0 { namespace ult { -constexpr uint8_t tempArrForSubDevices[28] = {0x12, 0, 0, 0, 0, 0, 0, 0, 0x45, 0, 0, 0, 0x6f, 0, 0, 0, 0x34, 0, 0, 0, 0x16, 0, 0, 0, 0x1d, 0, 0, 0}; +constexpr uint8_t memory0MaxTemperature = 0x12; +constexpr uint8_t memory1MaxTemperature = 0x45; +constexpr uint8_t memory2MaxTemperature = 0x32; +constexpr uint8_t memory3MaxTemperature = 0x36; +constexpr uint8_t tempArrForSubDevices[28] = {memory0MaxTemperature, 0, 0, 0, 0, 0, 0, 0, memory1MaxTemperature, 0, 0, 0, 0x6f, 0, 0, 0, 0x34, 0, 0, 0, 0x16, 0, 0, 0, 0x1d, 0, 0, 0}; constexpr uint64_t offsetForSubDevices = 28; -constexpr uint8_t memory0MaxTempIndex = 0; -constexpr uint8_t memory1MaxTempIndex = 8; +constexpr uint16_t memory0MaxTempIndex = 0; +constexpr uint16_t memory1MaxTempIndex = 8; +constexpr uint16_t memory2MaxTempIndex = 300; +constexpr uint16_t memory3MaxTempIndex = 308; constexpr uint8_t subDeviceMinTempIndex = 12; constexpr uint8_t subDeviceMaxTempIndex = 16; constexpr uint8_t gtMinTempIndex = 20; @@ -28,8 +34,19 @@ constexpr uint64_t offsetForNoSubDevices = 0x60; constexpr uint8_t computeIndexForNoSubDevices = 9; constexpr uint8_t globalIndexForNoSubDevices = 3; -constexpr uint64_t mappedLength = 256; +constexpr uint64_t mappedLength = 400; const std::string baseTelemSysFS("/sys/class/intel_pmt"); +std::string rootPciPathOfGpuDeviceInTemperature = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0"; +const std::string realPathTelem1 = "/sys/devices/pci0000:89/0000:89:02.0/0000:86:00.0/0000:8b:02.0/0000:8e:00.1/pmt_telemetry.1.auto/intel_pmt/telem1"; +const std::string realPathTelem2 = "/sys/devices/pci0000:89/0000:89:02.0/0000:86:00.0/0000:8b:02.0/0000:8e:00.1/pmt_telemetry.1.auto/intel_pmt/telem2"; +const std::string realPathTelem3 = "/sys/devices/pci0000:89/0000:89:02.0/0000:86:00.0/0000:8b:02.0/0000:8e:00.1/pmt_telemetry.1.auto/intel_pmt/telem3"; +const std::string realPathTelem4 = "/sys/devices/pci0000:89/0000:89:02.0/0000:86:00.0/0000:8b:02.0/0000:8e:00.1/pmt_telemetry.1.auto/intel_pmt/telem4"; +const std::string realPathTelem5 = "/sys/devices/pci0000:89/0000:89:02.0/0000:86:00.0/0000:8b:02.0/0000:8e:00.1/pmt_telemetry.1.auto/intel_pmt/telem5"; +const std::string sysfsPahTelem1 = "/sys/class/intel_pmt/telem1"; +const std::string sysfsPahTelem2 = "/sys/class/intel_pmt/telem2"; +const std::string sysfsPahTelem3 = "/sys/class/intel_pmt/telem3"; +const std::string sysfsPahTelem4 = "/sys/class/intel_pmt/telem4"; +const std::string sysfsPahTelem5 = "/sys/class/intel_pmt/telem5"; class TemperaturePmt : public PlatformMonitoringTech { public: TemperaturePmt(FsAccess *pFsAccess, ze_bool_t onSubdevice, uint32_t subdeviceId) : PlatformMonitoringTech(pFsAccess, onSubdevice, subdeviceId) {} @@ -49,15 +66,16 @@ struct Mock : public TemperaturePmt { } void mockedInit(FsAccess *pFsAccess) { - mappedMemory = new char[mappedLength]; - std::string rootPciPathOfGpuDevice = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0"; - if (ZE_RESULT_SUCCESS != PlatformMonitoringTech::enumerateRootTelemIndex(pFsAccess, rootPciPathOfGpuDevice)) { + mappedMemory = new char[mappedLength](); + if (ZE_RESULT_SUCCESS != PlatformMonitoringTech::enumerateRootTelemIndex(pFsAccess, rootPciPathOfGpuDeviceInTemperature)) { return; } // Fill mappedMemory to validate cases when there are subdevices for (uint64_t i = 0; i < sizeof(tempArrForSubDevices) / sizeof(uint8_t); i++) { mappedMemory[offsetForSubDevices + i] = tempArrForSubDevices[i]; } + mappedMemory[memory2MaxTempIndex] = memory2MaxTemperature; + mappedMemory[memory3MaxTempIndex] = memory3MaxTemperature; // Fill mappedMemory to validate cases when there are no subdevices for (uint64_t i = 0; i < sizeof(tempArrForNoSubDevices) / sizeof(uint8_t); i++) { mappedMemory[offsetForNoSubDevices + i] = tempArrForNoSubDevices[i]; @@ -65,8 +83,7 @@ struct Mock : public TemperaturePmt { } void mockedInitWithoutMappedMemory(FsAccess *pFsAccess) { - std::string rootPciPathOfGpuDevice = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0"; - if (ZE_RESULT_SUCCESS != PlatformMonitoringTech::enumerateRootTelemIndex(pFsAccess, rootPciPathOfGpuDevice)) { + if (ZE_RESULT_SUCCESS != PlatformMonitoringTech::enumerateRootTelemIndex(pFsAccess, rootPciPathOfGpuDeviceInTemperature)) { return; } } @@ -92,16 +109,16 @@ struct Mock : public TemperatureFsAccess { return ZE_RESULT_ERROR_NOT_AVAILABLE; } ze_result_t getRealPathSuccess(const std::string path, std::string &buf) { - if (path.compare("/sys/class/intel_pmt/telem1") == 0) { - buf = "/sys/devices/pci0000:89/0000:89:02.0/0000:86:00.0/0000:8b:02.0/0000:8e:00.1/pmt_telemetry.1.auto/intel_pmt/telem1"; - } else if (path.compare("/sys/class/intel_pmt/telem2") == 0) { - buf = "/sys/devices/pci0000:89/0000:89:02.0/0000:86:00.0/0000:8b:02.0/0000:8e:00.1/pmt_telemetry.1.auto/intel_pmt/telem2"; - } else if (path.compare("/sys/class/intel_pmt/telem3") == 0) { - buf = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:02.0/0000:8e:00.1/pmt_telemetry.1.auto/intel_pmt/telem3"; - } else if (path.compare("/sys/class/intel_pmt/telem4") == 0) { - buf = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:02.0/0000:8e:00.1/pmt_telemetry.1.auto/intel_pmt/telem4"; - } else if (path.compare("/sys/class/intel_pmt/telem5") == 0) { - buf = "/sys/devices/pci0000:89/0000:89:02.0/0000:8a:00.0/0000:8b:02.0/0000:8e:00.1/pmt_telemetry.1.auto/intel_pmt/telem5"; + if (path.compare(sysfsPahTelem1) == 0) { + buf = realPathTelem1; + } else if (path.compare(sysfsPahTelem2) == 0) { + buf = realPathTelem2; + } else if (path.compare(sysfsPahTelem3) == 0) { + buf = realPathTelem3; + } else if (path.compare(sysfsPahTelem4) == 0) { + buf = realPathTelem4; + } else if (path.compare(sysfsPahTelem5) == 0) { + buf = realPathTelem5; } else { return ZE_RESULT_ERROR_NOT_AVAILABLE; }